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);
        }
        public bool CreateConfig(string fileName, List<ICounterGroup> counterGroups)
        {
            var document = new XmlDocument();
            var xme = document.CreateElement(Constants.ServiceName);
            document.AppendChild(xme);
            var groupElements = document.CreateElement("CounterGroups");
            xme.AppendChild(groupElements);
            foreach (var group in counterGroups)
            {
                var groupElement = document.CreateElement("CounterGroup");
                groupElement.SetAttribute("Name", group.Name);
                groupElement.SetAttribute("SecondsInterval", group.SecondsInterval.ToString());
                groupElement.SetAttribute("RefreshInstanceInterval", group.RefreshInstanceInterval.ToString());

                foreach (var counter in group.Counters)
                {
                    groupElements.AppendChild(groupElement);
                    var counterElement = document.CreateElement("Counter");
                    groupElement.AppendChild(counterElement);

                    var categoryName = document.CreateElement("CategoryName");
                    categoryName.InnerText = counter.CategoryName;
                    counterElement.AppendChild(categoryName);

                    var counterName = document.CreateElement("CounterName");
                    counterName.InnerText = counter.CounterName;
                    counterElement.AppendChild(counterName);

                    var instanceName = document.CreateElement("InstanceName");
                    instanceName.InnerText = counter.InstanceName;
                    counterElement.AppendChild(instanceName);
                }
            }

            var applicationFolderPath = _fileLoaderAgent.GetApplicationFolderPath();
            if (File.Exists(applicationFolderPath + "\\" + fileName))
                return false;

            var contents = document.ToFormattedString();

            File.WriteAllText(applicationFolderPath + "\\" + fileName, contents);

            return true;
        }
        private void SaveDatabaseConfigEx(InfluxDatabaseConfig newDbConfig)
        {
            var path = GetAppDataFolder();
            var databaseConfigFilePath = path + "\\database.xml";

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

            var xmeUrl = xml.CreateElement("Url");
            xmeUrl.InnerText = newDbConfig.Url;
            dme.AppendChild(xmeUrl);

            var xmeUsername = xml.CreateElement("Username");
            xmeUsername.InnerText = newDbConfig.Username;
            dme.AppendChild(xmeUsername);

            var xmePassword = xml.CreateElement("Password");
            xmePassword.InnerText = Encrypt(newDbConfig.Password);
            dme.AppendChild(xmePassword);

            var xmeName = xml.CreateElement("Name");
            xmeName.InnerText = newDbConfig.Name;
            dme.AppendChild(xmeName);

            var xmlData = xml.ToFormattedString();

            _fileLoaderAgent.WriteAllText(databaseConfigFilePath, xmlData);
        }