コード例 #1
0
        private void ApplyLicense(string licenseKey)
        {
            LicenseExists = false;
            XmlData.Clear();
            RaisePropertyChanged(nameof(XmlData));

            LicenseInfo.Key = licenseKey;

            if (string.IsNullOrWhiteSpace(licenseKey))
            {
                FailureOccurred = false;
                ShowFailure     = false;
                return;
            }

            XmlData.Clear();

            var xmlList = _licenseService.LoadXmlFromLicense(LicenseInfo.Key);

            if (xmlList == null)
            {
                FailureOccurred = false;
                ShowFailure     = false;
                return;
            }

            xmlList.ForEach(x =>
            {
                if (string.Equals(x.Name, "Expiration"))
                {
                    x.Name = "Maintenance End Date";
                }

                XmlData.Add(x);
            });

            var validationContext = _licenseValidationService.ValidateLicense(licenseKey);

            if (validationContext.HasErrors)
            {
                var xmlFirstError = _licenseValidationService.ValidateXml(licenseKey).GetBusinessRuleErrors().FirstOrDefault();
                if (xmlFirstError == null)
                {
                    var normalFirstError = _licenseValidationService.ValidateLicense(LicenseInfo.Key).GetBusinessRuleErrors().FirstOrDefault();
                    if (normalFirstError != null)
                    {
                        ShowFailure    = true;
                        FailureMessage = normalFirstError.Message;
                    }
                }
                else
                {
                    ShowFailure    = true;
                    FailureMessage = xmlFirstError.Message;
                }
            }
            else
            {
                FailureOccurred = false;
                ShowFailure     = false;
            }

            LicenseExists = true;
            RaisePropertyChanged(nameof(XmlData));
        }