public bool LoadConfigSetting()
        {
            try
            {
                string PathConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");

                if (File.Exists(PathConfigFile))
                {
                    ConfigSettingObj = ConfigSettings.LoadConfigSettingFromFile(PathConfigFile);

                    ConnectionString = ConfigSettingObj.ConnectionString;
                    DBType           = ConfigSettingObj.DBType;

                    if (DBType == "MySQL")
                    {
                        ItIsMySQL = true;
                    }
                    else if (DBType == "MS SQL Server")
                    {
                        ItIsMSSQL = true;
                    }
                    else if (DBType == "ElasticSearch")
                    {
                        ItIsElasticSearch = true;
                    }

                    this.SleepTime = this.ConfigSettingObj.RepeatTime * 1000;

                    foreach (InfobaseSetting IBConfig in ConfigSettingObj.Infobases)
                    {
                        string IB_ID      = IBConfig.DatabaseID;
                        string IB_Name    = IBConfig.DatabaseName;
                        string IB_Catalog = IBConfig.DatabaseCatalog;

                        EventLogProcessor EventLogProcessorObj = new EventLogProcessor
                        {
                            Log                         = NLog.LogManager.GetLogger("CurrentThread"),
                            InfobaseGuid                = IB_ID,
                            InfobaseName                = IB_Name,
                            Catalog                     = IB_Catalog,
                            ConnectionString            = this.ConnectionString,
                            SleepTime                   = this.SleepTime,
                            ItIsMSSQL                   = this.ItIsMSSQL,
                            ItIsMySQL                   = this.ItIsMySQL,
                            ItIsElasticSearch           = this.ItIsElasticSearch,
                            ESIndexName                 = this.ConfigSettingObj.ESIndexName,
                            ESServerName                = IBConfig.ESServerName,
                            ESUseSynonymsForFieldsNames = this.ConfigSettingObj.ESUseSynonymsForFieldsNames,
                            ESFieldSynonyms             = this.ConfigSettingObj.ESFieldSynonyms
                        };

                        try
                        {
                            EventLogProcessorObj.LoadEventsStartingAt = DateTime.Parse(IBConfig.StartDate);
                        }
                        catch (Exception ex)
                        {
                            EventLogProcessorObj.LoadEventsStartingAt = new DateTime(1900, 1, 1);

                            Log.Error(ex, this.GetType().ToString());
                        }

                        ListOfProcessors.Add(EventLogProcessorObj);
                    }

                    return(true);
                }
                else
                {
                    Log.Error("File config.json was not found!");

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Parameters cannot be load from config.json file (it may be corrupted)");

                throw ex;
            }
        }
Exemplo n.º 2
0
        public static void SaveConfigSettingToFile(ConfigSetting ConfigSettingObj, string ConfigFilePath)
        {
            string JsonText = JsonConvert.SerializeObject(ConfigSettingObj, Formatting.Indented);

            File.WriteAllText(ConfigFilePath, JsonText);
        }