コード例 #1
0
        private void OnCheckKey()
        {
            try
            {
                //Show wait screen
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Show();

                // Create temp cryptoLicense object
                CryptoLicense _temp = Activator.CreateInstance(cryptoLicense.GetType()) as CryptoLicense;
                _temp.StorageMode       = cryptoLicense.StorageMode;
                _temp.ValidationKey     = cryptoLicense.ValidationKey;
                _temp.LicenseServiceURL = cryptoLicense.LicenseServiceURL;
                _temp.HostAssembly      = cryptoLicense.HostAssembly;
                _temp.LicenseServiceSettingsFilePath = cryptoLicense.LicenseServiceSettingsFilePath;
                _temp.RegistryStoragePath            = cryptoLicense.RegistryStoragePath;
                _temp.FileStoragePath = cryptoLicense.FileStoragePath;

                //Check if internet connection to cryptoLicenseService is working
                if (_temp.PingLicenseService() != null)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("Leider ist der Lizenzserver nicht erreichbar.\nUm Ihre Lizenz zu aktivieren, wird eine funktionierende Internetverbindung benötigt.", "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }

                // See if its a serial
                SerialValidationResult result = _temp.GetLicenseFromSerial(this.LicenseInput_Key, string.Empty);
                if (result == SerialValidationResult.Failed)
                {
                    // Its a serial, but is invalid
                    string    str = "Serial Überprüfung fehlgeschlagen: ";
                    Exception ex  = _temp.GetStatusException(LicenseStatus.SerialCodeInvalid);
                    if (ex != null) // Additional info available for the status
                    {
                        str += ex.Message;
                    }
                    else
                    {
                        str += "<no additional information>";
                    }

                    Xceed.Wpf.Toolkit.MessageBox.Show("Es ist ein Fehler aufgetreten: " + str, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }

                // Not a serial, set .LicenseCode property
                if (result == SerialValidationResult.NotASerial)
                {
                    _temp.LicenseCode = this.LicenseInput_Key;
                }

                // Validate cryptoLicense
                if (_temp.Status == LicenseStatus.Valid)
                {
                    // Valid , dispose old cryptoLicense, replace with 'temp' cryptoLicense
                    cryptoLicense.Dispose();
                }

                //Close wait screen
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close();

                //Show result
                if (_temp.Status != LicenseStatus.Valid)
                {
                    string    additional = "Error code: " + _temp.Status.ToString();
                    Exception ex         = _temp.GetStatusException(_temp.Status);
                    if (ex != null)
                    {
                        additional += ". Error message: " + ex.Message;
                    }

                    Xceed.Wpf.Toolkit.MessageBox.Show("Die eingegebene Lizenz war leider ungültig. Bitte geben Sie einen gültigen Lizenzkey ein und versuchen es erneut.\n" + additional, "RescueInformationSystem - ERROR", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }
                else
                {
                    cryptoLicense.Save();
                    this.IsLicenseValid = true;
                    this.ParseLicenseInfosForThanks();
                    this.CurrentUserControl = new Views.LicenseThanksUserControl();
                }
            }
            catch (Exception ex)
            {
                SRS.Utilities.Logger.Instance.WriteError(System.Reflection.MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ServiceLocator.Current.GetInstance <RIS.Views.WaitSplashScreen>().Close();
            }
        }