コード例 #1
0
        private static ApplicationConfig GetApplicationConfig(XmlDocument document)
        {
            var databases = document.GetElementsByTagName("Application");
            if (databases.Count == 0)
                return null;

            var flushSecondsInterval = 10;
            var debugMode = false;
            var metadata = true;
            var maxQueueSize = 20000;
            foreach (XmlElement item in databases[0].ChildNodes)
            {
                switch (item.Name)
                {
                    case "FlushSecondsInterval":
                        if (!int.TryParse(item.InnerText, out flushSecondsInterval))
                        {
                            flushSecondsInterval = 10;
                        }
                        break;
                    case "Debug":
                        if (!bool.TryParse(item.InnerText, out debugMode))
                        {
                            debugMode = false;
                        }
                        break;
                    case "Metadata":
                        if (!bool.TryParse(item.InnerText, out metadata))
                        {
                            metadata = false;
                        }
                        break;
                    case "MaxQueueSize":
                        if (!int.TryParse(item.InnerText, out maxQueueSize))
                        {
                            maxQueueSize = 20000;
                        }
                        break;
                    case "":
                        break;
                }
            }

            var database = new ApplicationConfig(flushSecondsInterval, debugMode, metadata, maxQueueSize);
            return database;
        }
コード例 #2
0
        public IConfig LoadFiles(string[] configurationFilenames)
        {
            if (!configurationFilenames.Any())
            {
                configurationFilenames = GetConfigFiles().ToArray();
            }

            var databases = new List<IDatabaseConfig>();
            var groups = new List<ICounterGroup>();
            var publishers = new List<ICounterPublisher>();
            IApplicationConfig application = null;
            var tags = new List<ITag>();

            foreach (var configurationFilename in configurationFilenames)
            {
                var fileData = _fileLoaderAgent.ReadAllText(configurationFilename);

                var document = new XmlDocument();
                document.LoadXml(fileData);

                var dbs = GetDatabaseConfig(document);
                var grps = GetCounterGroups(document).ToList();
                var pbs = GetPublishers(document).ToList();
                var app = GetApplicationConfig(document);
                var tgs = GetGlobalTags(document);

                foreach (var db in dbs)
                {
                    databases.Add(db);
                }

                foreach (var grp in grps)
                {
                    if (groups.Any(x => x.Name == grp.Name))
                    {
                        OnInvalidConfigEvent(grp.Name, null, configurationFilename);
                    }
                    else
                    {
                        groups.Add(grp);
                    }
                }

                foreach (var pb in pbs)
                {
                    if (publishers.Any(x => pb.CounterName == x.CounterName))
                    {
                        OnInvalidConfigEvent(pb.CounterName, null, configurationFilename);
                    }
                    else
                    {
                        publishers.Add(pb);
                    }
                }

                if (app != null)
                {
                    if (application != null)
                    {
                        throw new InvalidOperationException("There are application configuration sections in more than one config file.");
                    }

                    application = app;
                }

                foreach (var tg in tgs)
                {
                    if (tags.Any(x => x.Name == tg.Name))
                    {
                        OnInvalidConfigEvent(null, tg.Name, configurationFilename);
                    }
                    else
                    {
                        tags.Add(tg);
                    }
                }
            }

            if (application == null)
            {
                application = new ApplicationConfig(10, false, true, 20000);
            }

            var config = new Config(databases, application, groups, publishers, tags);
            return config;
        }
コード例 #3
0
 public void SaveApplicationConfig(int flushSecondsInterval, bool debugMode, bool metadata, int maxQueueSize)
 {
     var newDbConfig = new ApplicationConfig(flushSecondsInterval, debugMode, metadata, maxQueueSize);
     SaveApplicationConfigEx(newDbConfig);
 }
コード例 #4
0
        private void SaveApplicationConfigEx(ApplicationConfig applicationConfig)
        {
            var path = GetAppDataFolder();
            var applicationConfigFilePath = path + "\\application.xml";

            var xml = new XmlDocument();
            var xme = xml.CreateElement(Constants.ServiceName);
            xml.AppendChild(xme);
            var dme = xml.CreateElement("Application");
            xme.AppendChild(dme);

            var xmeFlushSecondsInterval = xml.CreateElement("FlushSecondsInterval");
            xmeFlushSecondsInterval.InnerText = applicationConfig.FlushSecondsInterval.ToString();
            dme.AppendChild(xmeFlushSecondsInterval);

            if (applicationConfig.DebugMode)
            {
                var xmeDebug = xml.CreateElement("Debug");
                xmeDebug.InnerText = applicationConfig.DebugMode.ToString();
                dme.AppendChild(xmeDebug);
            }

            var xmeMetadata = xml.CreateElement("Metadata");
            xmeMetadata.InnerText = applicationConfig.Metadata.ToString();
            dme.AppendChild(xmeMetadata);

            var xmeMaxQueueSize = xml.CreateElement("MaxQueueSize");
            xmeMaxQueueSize.InnerText = applicationConfig.MaxQueueSize.ToString();
            dme.AppendChild(xmeMaxQueueSize);

            var xmlData = xml.ToFormattedString();

            _fileLoaderAgent.WriteAllText(applicationConfigFilePath, xmlData);
        }
コード例 #5
0
 public void SaveApplicationConfig(int flushSecondsInterval, bool debugMode)
 {
     var newDbConfig = new ApplicationConfig(flushSecondsInterval, debugMode);
     SaveApplicationConfigEx(newDbConfig);
 }