コード例 #1
0
        public LicenseViewModel(UserControl _userControl, CryptoLicense _cryptoLicense)
        {
            currentUserControl = _userControl;
            cryptoLicense      = _cryptoLicense;

            //Check cryptoLicense status
            if (!cryptoLicense.ValidateSignature())
            {
                this.LicenseStatusText = string.Format("Die Lizenz ist  ungültig!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.", cryptoLicense.Status);
            }
            else if (cryptoLicense.IsLicenseDisabledInService())
            {
                this.LicenseStatusText = "Diese Lizenz wurde deaktiviert!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.";
            }
            else if (cryptoLicense.IsEvaluationExpired() || DateTime.Now > cryptoLicense.DateExpires)
            {
                this.LicenseStatusText = "Der Testzeitraum ist leider abgelaufen!\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.";
            }
            else if (cryptoLicense.IsEvaluationLicense())
            {
                this.IsLicenseValid    = true;
                this.LicenseStatusText = "Vielen Dank, dass Sie diese Software testen!";

                if (cryptoLicense.HasDateExpires)
                {
                    TimeSpan ts        = (cryptoLicense.DateExpires.Date - DateTime.Now.Date);
                    int      remaining = ts.Days;
                    if (remaining < 0)
                    {
                        remaining = 0;
                    }
                    int max = (cryptoLicense.DateExpires.Date - cryptoLicense.DateGenerated.Date).Days;
                    if (max < 0)
                    {
                        max = 0;
                    }
                    this.EvaluationProgressMax   = max;
                    this.EvaluationProgressValue = remaining;
                    this.EvaluationProgressText  = string.Format("Die Lizenz läuft am {0} aus! {1} Tage verbleibend", cryptoLicense.DateExpires.ToString("dd-MMM-yyyy"), remaining);
                }
                if (cryptoLicense.HasMaxUsageDays)
                {
                    int remaining = cryptoLicense.MaxUsageDays - cryptoLicense.CurrentUsageDays;
                    if (remaining < 0)
                    {
                        remaining = 0;
                    }
                    else
                    {
                        remaining++;
                    }

                    this.EvaluationProgressMax   = cryptoLicense.MaxUsageDays;
                    this.EvaluationProgressValue = remaining;
                    this.EvaluationProgressText  = string.Format("{0} von {1} Tagen verbleibend", remaining, cryptoLicense.MaxUsageDays);
                }
                if (cryptoLicense.HasMaxUniqueUsageDays)
                {
                    int remaining = cryptoLicense.MaxUniqueUsageDays - cryptoLicense.CurrentUniqueUsageDays;
                    if (remaining < 0)
                    {
                        remaining = 0;
                    }
                    else if (remaining < cryptoLicense.MaxUniqueUsageDays)
                    {
                        remaining++;
                    }

                    this.EvaluationProgressMax   = cryptoLicense.MaxUsageDays;
                    this.EvaluationProgressValue = remaining;
                    this.EvaluationProgressText  = string.Format("{0} von {1} kompletten Nutzungstagen verbleibend", remaining, cryptoLicense.MaxUniqueUsageDays);
                }
                if (cryptoLicense.HasMaxExecutions)
                {
                    int remaining = cryptoLicense.MaxExecutions - cryptoLicense.CurrentExecutions;
                    if (remaining < 0)
                    {
                        remaining = 0;
                    }
                    else if (remaining < cryptoLicense.MaxExecutions)
                    {
                        remaining++;
                    }

                    this.EvaluationProgressMax   = cryptoLicense.MaxExecutions;
                    this.EvaluationProgressValue = remaining;
                    this.EvaluationProgressText  = string.Format("{0} von {1} Programmstarts verbleibend", remaining, cryptoLicense.MaxExecutions);
                }
            }
            else
            {
                this.LicenseStatusText = string.Format("Die Lizenz ist  ungültig:  {0}\nUm die Software weiter zu verwenden, wird ein gültiger Lizenzkey benötigt.", cryptoLicense.Status);
            }
        }