예제 #1
0
        /// <summary>
        /// Check license correctness for available data fields (machine name, os user, expiry date)
        /// </summary>
        public LicenseState IsLicenseInfoCorrect()
        {
            var foundProblems = new LicenseState();

            if (Environment.MachineName.ToLower() != HostName.ToLower())
            {
                foundProblems.AddProblem(LicenseProblemType.WrongHost, "current:" + Environment.MachineName.ToLower() + "; licensed for:" + HostName.ToLower());
            }

            var currentUserName = Environment.UserDomainName.ToLower() + @"\" + Environment.UserName.ToLower();

            if (currentUserName != OsUserName.ToLower())
            {
                foundProblems.AddProblem(LicenseProblemType.WrongUser, "current:" + currentUserName + "; licensed for:" + OsUserName.ToLower());
            }

            return(foundProblems);
        }
예제 #2
0
 /// <summary>
 /// Add problems in list
 /// </summary>
 /// <param name="source">State of the ptoblem.</param>
 public void AddProblems(LicenseState source)
 {
     this._problems.AddRange(source._problems);
     this._problems2.AddRange(source._problems2);
 }
예제 #3
0
 /// <summary>
 /// Initializes the object LicenseStateException.
 /// </summary>
 /// <param name="state">State of the license.</param>
 public LicenseStateException(LicenseState state) : base(state.ProblemsText)
 {
 }
예제 #4
0
		/// <summary>
		/// The validate license.
		/// </summary>
		/// <param name="fullSlowCheck">The full slow check.</param>
		/// <returns>
		/// The <see cref="LicenseState" />.
		/// </returns>
		public LicenseState ValidateLicense(bool fullSlowCheck, bool withCheckConnection = true)
		{
			if (this._foundLicenseState != null)
			{
				return this._foundLicenseState;
			}

			this._foundLicenseState = new LicenseState
			{
				Instance = this.Instance
			};

			if (this.LicenseInfo == null)
			{
				if (AppVersionHelper.IsNotRelease())
				{
					return this._foundLicenseState;
				}

				this._foundLicenseState.AddProblem(LicenseProblemType.LicenseNotDefined, string.Empty);
			}
			else
			{
				this._foundLicenseState.AddProblems(this.LicenseInfo.IsLicenseInfoCorrect());

				DateTime dateTime;

				if (fullSlowCheck && withCheckConnection)
				{
					if (this._serverProperties != null)
					{
						dateTime = this._serverProperties.Date;
					}
					else
					{
						try
						{
							ServerProperties props = ServerProperties.Query(this);

							dateTime = props.Date;

							this._serverProperties = props;
						}
						catch (Exception exc)
						{
							log.Error("Exception:", exc);

							log.ErrorFormat(
								"Instance:'{0}';Authentication:'{1}';Exception:'{2}'",
								Instance,
								Authentication,
								exc
							);

							dateTime = DateTime.MaxValue;
						}
					}
				}
				else
				{
					dateTime = DateTime.Now;
				}

				var buildDateObject =
					Assembly.GetExecutingAssembly()
						.GetCustomAttributes(typeof (BuildDateAttribute), false)
						.FirstOrDefault();

				DateTime buildDate = DateTime.MaxValue;

				if (buildDateObject is BuildDateAttribute)
				{
					buildDate = (buildDateObject as BuildDateAttribute).BuildDate;
				}

				if (dateTime == DateTime.MaxValue)
				{
					this._foundLicenseState.AddProblem(LicenseProblemType.CantConnect, string.Empty);
				}
				else if (this._foundLicenseState.IsCorrect && fullSlowCheck && (dateTime > this.LicenseInfo.ExpiryDate))
				{
					this._foundLicenseState.AddProblem(LicenseProblemType.Expired, string.Empty);
				}
				else if (buildDate > this.LicenseInfo.BuildExpiryDate)
				{
					this._foundLicenseState.AddProblem(LicenseProblemType.BuildExpiryDateNotValid, string.Empty);
				}
				else
				{
					if (AppVersionHelper.IsNotDebug())
					{
						string hash = this.GetHash();

						CryptoProcessor cryptoProcessor =
							new CryptoProcessor(
								Program.Model.Settings.SystemSettings.PublicKeyXmlSign,
								Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt
							);

						if (!cryptoProcessor.Verify(hash, this.LicenseInfo.Signature))
						{
							this._foundLicenseState.AddProblem(LicenseProblemType.WrongSignature, string.Empty);
						}
					}
				}
			}

			var result = this._foundLicenseState;

			if (!fullSlowCheck)
			{
				this._foundLicenseState = null;
			}

			return result;
		}
예제 #5
0
		/// <summary>
		/// Check license correctness for available data fields (machine name, os user, expiry date)
		/// </summary>
		public LicenseState IsLicenseInfoCorrect()
		{
			var foundProblems = new LicenseState();

			if (Environment.MachineName.ToLower() != HostName.ToLower())
			{
				foundProblems.AddProblem(LicenseProblemType.WrongHost, "current:" + Environment.MachineName.ToLower() + "; licensed for:" + HostName.ToLower());
			}

			var currentUserName = Environment.UserDomainName.ToLower() + @"\" + Environment.UserName.ToLower();

			if (currentUserName != OsUserName.ToLower())
			{
				foundProblems.AddProblem(LicenseProblemType.WrongUser, "current:" + currentUserName + "; licensed for:" + OsUserName.ToLower());
			}

			return foundProblems;
		}
예제 #6
0
        /// <summary>
        /// The validate license.
        /// </summary>
        /// <param name="fullSlowCheck">The full slow check.</param>
        /// <returns>
        /// The <see cref="LicenseState" />.
        /// </returns>
        public LicenseState ValidateLicense(bool fullSlowCheck, bool withCheckConnection = true)
        {
            if (this._foundLicenseState != null)
            {
                return(this._foundLicenseState);
            }

            this._foundLicenseState = new LicenseState
            {
                Instance = this.Instance
            };

            if (this.LicenseInfo == null)
            {
                if (AppVersionHelper.IsNotRelease())
                {
                    return(this._foundLicenseState);
                }

                this._foundLicenseState.AddProblem(LicenseProblemType.LicenseNotDefined, string.Empty);
            }
            else
            {
                this._foundLicenseState.AddProblems(this.LicenseInfo.IsLicenseInfoCorrect());

                DateTime dateTime;

                if (fullSlowCheck && withCheckConnection)
                {
                    if (this._serverProperties != null)
                    {
                        dateTime = this._serverProperties.Date;
                    }
                    else
                    {
                        try
                        {
                            ServerProperties props = ServerProperties.Query(this);

                            dateTime = props.Date;

                            this._serverProperties = props;
                        }
                        catch (Exception exc)
                        {
                            log.Error("Exception:", exc);

                            log.ErrorFormat(
                                "Instance:'{0}';Authentication:'{1}';Exception:'{2}'",
                                Instance,
                                Authentication,
                                exc
                                );

                            dateTime = DateTime.MaxValue;
                        }
                    }
                }
                else
                {
                    dateTime = DateTime.Now;
                }

                var buildDateObject =
                    Assembly.GetExecutingAssembly()
                    .GetCustomAttributes(typeof(BuildDateAttribute), false)
                    .FirstOrDefault();

                DateTime buildDate = DateTime.MaxValue;

                if (buildDateObject is BuildDateAttribute)
                {
                    buildDate = (buildDateObject as BuildDateAttribute).BuildDate;
                }

                if (dateTime == DateTime.MaxValue)
                {
                    this._foundLicenseState.AddProblem(LicenseProblemType.CantConnect, string.Empty);
                }
                else if (this._foundLicenseState.IsCorrect && fullSlowCheck && (dateTime > this.LicenseInfo.ExpiryDate))
                {
                    this._foundLicenseState.AddProblem(LicenseProblemType.Expired, string.Empty);
                }
                else if (buildDate > this.LicenseInfo.BuildExpiryDate)
                {
                    this._foundLicenseState.AddProblem(LicenseProblemType.BuildExpiryDateNotValid, string.Empty);
                }
                else
                {
                    if (AppVersionHelper.IsNotDebug())
                    {
                        string hash = this.GetHash();

                        CryptoProcessor cryptoProcessor =
                            new CryptoProcessor(
                                Program.Model.Settings.SystemSettings.PublicKeyXmlSign,
                                Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt
                                );

                        if (!cryptoProcessor.Verify(hash, this.LicenseInfo.Signature))
                        {
                            this._foundLicenseState.AddProblem(LicenseProblemType.WrongSignature, string.Empty);
                        }
                    }
                }
            }

            var result = this._foundLicenseState;

            if (!fullSlowCheck)
            {
                this._foundLicenseState = null;
            }

            return(result);
        }
예제 #7
0
 /// <summary>
 /// Add problems in list
 /// </summary>
 /// <param name="source">State of the ptoblem.</param>
 public void AddProblems(LicenseState source)
 {
     this._problems.AddRange(source._problems);
     this._problems2.AddRange(source._problems2);
 }
예제 #8
0
        /// <summary>
        /// Initializes the object LicenseStateException.
        /// </summary>
        /// <param name="state">State of the license.</param>
        public LicenseStateException(LicenseState state) : base(state.ProblemsText)
        {

        }