当前位置: 首页>>代码示例>>C#>>正文


C# Assembly.InformationalVersion方法代码示例

本文整理汇总了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;
        }
开发者ID:icygit,项目名称:Orchestra,代码行数:20,代码来源:VersionHelper.cs

示例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;
        }
开发者ID:WildGums,项目名称:Orc.LicenseManager,代码行数:86,代码来源:LicenseValidationService.cs


注:本文中的System.Reflection.Assembly.InformationalVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。