예제 #1
0
        /// <summary>
        /// Load queries from Xml-file
        /// </summary>
        /// <param name="fileName">Xml-file name</param>
        /// <param name="cryptoProcessor">Encoder</param>
        /// <param name="isExternal">Is opened from user file template</param>
        /// <returns>List of queries</returns>
        public static List <QueryInfo> LoadFromXml(string fileName, CryptoProcessor cryptoProcessor, bool isExternal)
        {
            if (AppVersionHelper.IsDebug() || isExternal)
            {
                if (cryptoProcessor == null)
                {
                    return(LoadFromXml(fileName));
                }
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true;
                doc.Load(fileName);

                if (AppVersionHelper.IsRelease() || (AppVersionHelper.IsNotRelease() && cryptoProcessor != null))
                {
                    cryptoProcessor.DecryptXmlDocument(doc);
                }

                byte[] bytes = Encoding.UTF8.GetBytes(doc.OuterXml);

                XmlSerializer s = new XmlSerializer(typeof(LoaderRootWrapper));

                using (var includingReader = new MemoryStream(bytes))
                {
                    using (var xmlReader = XmlReader.Create(includingReader, XmlUtils.GetXmlReaderSettings()))
                    {
                        return(GetQueries(((LoaderRootWrapper)s.Deserialize(xmlReader))));
                    }
                }
            }
            catch (Exception exception)
            {
                log.Error(exception);

                if (AppVersionHelper.IsDebug() || isExternal)
                {
                    return(LoadFromXml(fileName));
                }

                throw;
            }
        }
예제 #2
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);
        }