本文整理汇总了C#中System.Reflection.Assembly.InformationalVersion方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.InformationalVersion方法的具体用法?C# Assembly.InformationalVersion怎么用?C# Assembly.InformationalVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.InformationalVersion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentVersion
/// <summary>
/// Gets the current version of the specified assembly.
/// </summary>
/// <param name="assembly">The assembly. If <c>null</c>, <see cref="AssemblyHelper.GetEntryAssembly"/> will be used.</param>
/// <returns>System.String.</returns>
public static string GetCurrentVersion(Assembly assembly = null)
{
if (assembly == null)
{
assembly = Catel.Reflection.AssemblyHelper.GetEntryAssembly();
}
var version = assembly.InformationalVersion();
if (string.IsNullOrWhiteSpace(version))
{
version = assembly.Version();
}
return version;
}
示例2: ValidateLicenseOnServer
/// <summary>
/// Validates the license on the server.
/// </summary>
/// <param name="license">The license.</param>
/// <param name="serverUrl">The server URL.</param>
/// <param name="assembly">The assembly to get the information from. If <c>null</c>, the entry assembly will be used.</param>
/// <returns><c>true</c> if the license is valid, <c>false</c> otherwise.</returns>
public LicenseValidationResult ValidateLicenseOnServer(string license, string serverUrl, Assembly assembly = null)
{
Argument.IsNotNullOrWhitespace(() => license);
Argument.IsNotNullOrWhitespace(() => serverUrl);
if (assembly == null)
{
assembly = AssemblyHelper.GetEntryAssembly();
}
LicenseValidationResult validationResult = null;
try
{
var webRequest = WebRequest.Create(serverUrl);
webRequest.ContentType = "application/json";
webRequest.Method = "POST";
using (var sw = new StreamWriter(webRequest.GetRequestStream()))
{
var version = "unknown version";
if (assembly != null)
{
try
{
version = assembly.InformationalVersion();
if (string.IsNullOrWhiteSpace(version))
{
version = assembly.Version();
}
}
catch (Exception ex)
{
Log.Error(ex, "Failed to retrieve the product version");
}
}
var serviceLicenseValidation = new ServerLicenseValidation
{
MachineId = _identificationService.GetMachineId(),
ProductName = (assembly != null) ? assembly.Product() : "unknown product",
ProductVersion = version,
License = license
};
var json = JsonConvert.SerializeObject(serviceLicenseValidation);
sw.Write(json);
}
using (var httpWebResponse = webRequest.GetResponse())
{
using (var responseStream = httpWebResponse.GetResponseStream())
{
using (var streamReader = new StreamReader(responseStream))
{
var json = streamReader.ReadToEnd();
validationResult = JsonConvert.DeserializeObject<LicenseValidationResult>(json);
}
}
}
}
catch (Exception ex)
{
Log.Error(ex, "Failed to validate the license on the server");
}
if (validationResult == null)
{
validationResult = new LicenseValidationResult()
{
// We return success if we can't validate on the server, then it's up to the client to validate
IsValid = true,
AdditionalInfo = "Failed to check the license on the server"
};
}
return validationResult;
}