Пример #1
0
        //void ReloadConectionGroupInfos()
        //{
        //    var filenames = _filesProvider.GetConnectionsFilenames();
        //    _connections = new List<ConnectionGroupInfo>();
        //    foreach (var filename in filenames)
        //    {
        //        _connections.AddRange(ConnectionsLoader.LoadFromXml(filename));
        //    }
        //}

        /// <summary>
        /// Load Template
        /// </summary>
        /// <param name="filename">Xml-file name</param>
        /// <param name="connectionGroup"></param>
        /// <param name="isExternal">Is opened from user file template</param>
        /// <returns>Tree template</returns>
        public TemplateNodeInfo LoadTemplateNodes(
            string filename,
            bool isExternal,
            out string startupTemplateId,
            out Stack <string> startupTemplateInfoIdStack
            )
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Template needed!");
            }

            var doc = new XmlDocument();

            doc.Load(filename);

            if (AppVersionHelper.IsNotDebug() && !isExternal)
            {
                var cryptoProcessor = new CryptoProcessor(
                    this.Settings.SystemSettings.PublicKeyXmlSign,
                    this.Settings.SystemSettings.PrivateKeyXmlDecrypt
                    );

                cryptoProcessor.DecryptXmlDocument(doc);
            }

            return(TemplateNodesLoader.LoadFromXml(this, doc, out startupTemplateId, out startupTemplateInfoIdStack));
        }
Пример #2
0
 private void CinfigureMainMenu()
 {
     if (AppVersionHelper.IsTrial())
     {
         this.mnuNewTab.Visible   = false;
         this.mnuLicenses.Visible = false;
     }
 }
Пример #3
0
        private void PrepareView()
        {
            if (AppVersionHelper.IsNotTrial())
            {
                lbAdditionalSql.Visible = false;
                tbAdditionalSql.Visible = false;

                lblAdditionalTemplate.Visible = false;
            }
        }
        /// <summary>
        /// Initializing object frmComponents.
        /// </summary>
        public frmComponents()
        {
            string isDebug = string.Empty;

            if (AppVersionHelper.IsDebug())
            {
                isDebug = " DEBUG";
            }

            InitializeComponent();

            this.Text = String.Format(GetLocalizedText("captionText"), CurrentAssembly.Title) + isDebug;

            textBoxDescription.Font = new Font(FontFamily.GenericMonospace, textBoxDescription.Font.Size);

            textBoxDescription.Text = BuildDescripionFieldText();
        }
Пример #5
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;
            }
        }
Пример #6
0
        public static Template GetTemplateByFile(string strFileName)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(strFileName);

                Template retTemplate;

                if (AppVersionHelper.IsNotDebug())
                {
                    var cryptoProcessor = new CryptoProcessor(
                        Program.Model.Settings.SystemSettings.PublicKeyXmlSign,
                        Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt);

                    cryptoProcessor.DecryptXmlDocument(doc);
                }

                using (var nodeReader = new XmlNodeReader(doc))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Template));

                    using (var xmlReader = XmlReader.Create(nodeReader, XmlUtils.GetXmlReaderSettings()))
                    {
                        retTemplate = (Template)serializer.Deserialize(xmlReader);
                    }
                }

                return(retTemplate);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(null);
        }
Пример #7
0
        /// <summary>
        /// Item1 = name. Item2 = directory.
        /// </summary>
        /// <param name="templateID"></param>
        /// <returns></returns>
        public static Tuple <string, string> GetTemplateById(string templateID)
        {
            string          strFileName   = string.Empty;
            string          strFolderName = string.Empty;
            List <Template> retList       = new List <Template>();
            DirectoryInfo   directoryInfo = new DirectoryInfo(
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Program.Model.Settings.TemplateDirectory));

            if (directoryInfo.Exists)
            {
                try
                {
                    var serializer = new XmlSerializer(typeof(Template));

                    var files = directoryInfo.GetFiles("*.xml");

                    foreach (FileInfo file in files)
                    {
                        try
                        {
                            var doc = new XmlDocument();
                            doc.Load(file.FullName);

                            if (AppVersionHelper.IsNotDebug())
                            {
                                var cryptoProcessor = new CryptoProcessor(
                                    Program.Model.Settings.SystemSettings.PublicKeyXmlSign,
                                    Program.Model.Settings.SystemSettings.PrivateKeyXmlDecrypt);

                                cryptoProcessor.DecryptXmlDocument(doc);
                            }

                            //
                            // #248 - fix memory leaks during XML files processing
                            //
                            // var nodeReader = new XmlNodeReader(doc);
                            using (var nodeReader = new XmlNodeReader(doc))
                            {
                                using (var xmlReader = XmlReader.Create(nodeReader, XmlUtils.GetXmlReaderSettings()))
                                {
                                    var template = (Template)serializer.Deserialize(xmlReader);

                                    if (templateID == template.Id)
                                    {
                                        strFileName   = file.Name;
                                        strFolderName = file.DirectoryName;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex);

                            if (file != null)
                            {
                                log.ErrorFormat("File:'{0}'", file);
                            }

                            log.ErrorFormat("Folder:'{0}'", directoryInfo);
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    log.ErrorFormat("Folder:'{0}'", directoryInfo);
                }
            }
            else
            {
                log.Error("Folder with models is not exists");
                log.ErrorFormat("Folder:'{0}'", directoryInfo);
            }

            return(new Tuple <string, string>(strFileName, strFolderName));
        }
Пример #8
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);
        }
Пример #9
0
        static void Main(string[] args)
        {
            GlobalContext.Properties["LogFileName"] = CurrentAssembly.ProcessNameBase;
            log4net.Config.XmlConfigurator.Configure();

            log.Debug("Application is starting...");

            Options options = new Options();

            var result = Parser.Default.ParseArguments <Options>(args);

            log.Debug("Command line parameters have been processed.");

            switch (result.Tag)
            {
            case ParserResultType.Parsed:
                log.Debug("Command line options have been successfully parced.");
                break;

            case ParserResultType.NotParsed:
                log.Error("Error by processing command line options.");
                options.intPosX = -1;
                break;

            default:
                log.Error("Unknown status by processing command line options.");
                options.intPosX = -1;
                break;
            }

            if (AppVersionHelper.IsNotDebug())
            {
                AppDomain.CurrentDomain.UnhandledException += frmExceptionBox.CurrentDomainUnhandledException;
                Application.ThreadException += frmExceptionBox.ApplicationOnThreadException;
            }

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            TaskScheduler.UnobservedTaskException += OnUnobservedException;

            _fMain = new frmMain(
                options.intMonitor,
                options.intPosX,
                options.intPosY,
                options.intWidth,
                options.intHeight,
                options.isDisableStatusLine,
                options.isDisableMainMenu,
                options.strServerName,
                options.strTemplate,
                options.strDatabaseType,
                options.isDisableNavigationPanel
                );

            _model = new MsSqlAuditorModel();
            _fMain.SetModel(_model);

            _model.Initialize();
            _model.Settings.WarnAboutUnsignedQuery = args.All(a => a != "/!w");

            _webServer = new WebServerManager(_model);

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(Model.Settings.InterfaceLanguage);

            log.Debug("Inner data model has been initialized. Main form is going to be shown...");

            Application.Run(_fMain);

            log.Debug("Application is closed...");
        }
Пример #10
0
        /// <summary>
        /// Load queries with signature check
        /// </summary>
        /// <param name="filename">Xml-file name</param>
        /// <param name="isExternal">Is opened from user file template</param>
        /// <returns>Queries list</returns>
        public List <QueryInfo> LoadQueries(string filename, bool isExternal)
        {
            log.InfoFormat("filename:'{0}',isExternal:'{1}'",
                           filename ?? "<null>",
                           isExternal
                           );

            List <string>   wrongQueries    = new List <string>();
            CryptoProcessor cryptoProcessor = null;

            try
            {
                if (AppVersionHelper.IsNotDebug())
                {
                    cryptoProcessor = new CryptoProcessor(
                        Settings.SystemSettings.PublicKeyXmlSign,
                        Settings.SystemSettings.PrivateKeyXmlDecrypt
                        );
                }
            }
            catch (System.Security.XmlSyntaxException ex)
            {
                log.Error(ex);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                log.Error(ex.GetBaseException());
            }

            List <QueryInfo> queries = QueriesLoader.LoadFromXml(filename, cryptoProcessor, isExternal);

            for (int i = queries.Count - 1; i >= 0; i--)
            {
                QueryInfo query = queries[i];

                log.InfoFormat("query:'{0}'", query);

                if (AppVersionHelper.IsNotDebug() && !isExternal)
                {
                    for (int j = query.DatabaseSelect.Count - 1; j >= 0; j--)
                    {
                        QueryItemInfo queryItem = query.DatabaseSelect[j];

                        if (cryptoProcessor != null && !cryptoProcessor.Verify(queryItem.Text, queryItem.Signature))
                        {
                            if (!wrongQueries.Contains(query.Name))
                            {
                                wrongQueries.Add(query.Name);
                            }

                            query.DatabaseSelect.RemoveAt(j);
                        }
                    }

                    for (int j = query.Items.Count - 1; j >= 0; j--)
                    {
                        QueryItemInfo queryItem = query.Items[j];

                        log.InfoFormat("queryItem.Text:'{0}'", queryItem.Text);

                        if (cryptoProcessor != null && !cryptoProcessor.Verify(queryItem.Text, queryItem.Signature))
                        {
                            if (!wrongQueries.Contains(query.Name))
                            {
                                wrongQueries.Add(query.Name);
                            }

                            query.Items.RemoveAt(j);
                        }
                    }
                }

                if (query.Items.Count == 0)
                {
                    queries.RemoveAt(i);
                }
            }

            if ((Settings.WarnAboutUnsignedQuery) && (wrongQueries.Count > 0))
            {
                StringBuilder sb = new StringBuilder();

                sb.Append(filename + Environment.NewLine + Environment.NewLine);

                foreach (string wrongQuery in wrongQueries)
                {
                    sb.Append(wrongQuery + Environment.NewLine);
                }

                MessageBox.Show(sb.ToString(), LocaleManager.GetLocalizedText(LocaleManager.Exceptions, "wrongQueriesSignatures"));
            }

            return(queries);
        }
        public VisualizeData GetVisualizeData(
            NodeDataProvider dataProvider,
            GraphicsInfo graphicsInfo
            )
        {
            XmlDocument          xmlData       = dataProvider.XmlDocument;
            MultyQueryResultInfo queriesResult = dataProvider.QueryResult;

            VisualizeData result = new VisualizeData
            {
                NodeLastUpdated        = queriesResult.NodeLastUpdated,
                NodeLastUpdateDuration = queriesResult.NodeLastUpdateDuration
            };

            if (xmlData != null && xmlData.DocumentElement != null)
            {
                result.SourceXml = xmlData.FormatXml();
            }

            ConcreteTemplateNodeDefinition nodeDefinition = dataProvider.NodeDefinition;

            string xslFileName = GetXslFileName(nodeDefinition);

            if (xslFileName != null && File.Exists(xslFileName))
            {
                XmlDocument xslDoc = new XmlDocument();

                xslDoc.Load(xslFileName);

                ConnectionGroupInfo connectionGroup = nodeDefinition.Connection;

                if (AppVersionHelper.IsNotDebug() && !connectionGroup.IsExternal)
                {
                    CryptoProcessor cryptoProcessor = new CryptoProcessor(
                        this._model.Settings.SystemSettings.PublicKeyXmlSign,
                        this._model.Settings.SystemSettings.PrivateKeyXmlDecrypt
                        );

                    cryptoProcessor.DecryptXmlDocument(xslDoc);
                }

                try
                {
                    XslPreprocessManager preprocessManager = GetManager(
                        dataProvider,
                        graphicsInfo
                        );

                    List <PreprocessorAreaData> datas;

                    using (preprocessManager.ExecuteXslPreprocessing(xslDoc, out datas))
                    {
                    }

                    foreach (PreprocessorAreaData preprocessorAreaData in datas)
                    {
                        preprocessorAreaData.CheckPreprocessors();
                    }

                    result.PreprocessorAreas = datas.ToList();
                }
                catch (Exception ex)
                {
                    log.ErrorFormat(
                        "nodeDefinition.TemplateNode.Queries(.Name)='{0}';xslFileName='{1}';Exception:'{2}'",
                        nodeDefinition.TemplateNode.Queries.Select(q => q.QueryName).Join(", "),
                        xslFileName,
                        ex
                        );
                }
            }

            return(result);
        }