Ejemplo n.º 1
0
        private void WriteConfiguration()
        {
            // Backup config file
            try
            {
                File.Move(configFilePath, configFilePath + ".bak");
            }
            catch { }

            Xmlconfig myXmlcfg = new Xmlconfig(configFilePath, true);

            myXmlcfg.Settings["Cpu"]["ImportanceFactor"].floatValue = cpuImportance;
            myXmlcfg.Settings["Cpu"]["ThresholdValue"].intValue     = cpuThresholdValue;
            myXmlcfg.Settings["Ram"]["ImportanceFactor"].floatValue = ramImportance;
            myXmlcfg.Settings["Ram"]["ThresholdValue"].floatValue   = ramThresholdValue;

            if (myTCPServices.Count == 0)
            {
                // Demo TCPService
                TCPService myTCPService = new TCPService();
                myXmlcfg.Settings["TCPService"]["Name"].Value                  = myTCPService.serviceName;
                myXmlcfg.Settings["TCPService"]["IPAddress"].Value             = myTCPService.serviceIPAddress;
                myXmlcfg.Settings["TCPService"]["Port"].intValue               = myTCPService.servicePort;
                myXmlcfg.Settings["TCPService"]["MaxConnections"].intValue     = myTCPService.serviceMaxConnections;
                myXmlcfg.Settings["TCPService"]["ImportanceFactor"].floatValue = myTCPService.serviceImportance;
            }
            else
            {
                foreach (TCPService myTCPService in myTCPServices)
                {
                    myXmlcfg.Settings["TCPService"]["Name"].Value                  = myTCPService.serviceName;
                    myXmlcfg.Settings["TCPService"]["IPAddress"].Value             = myTCPService.serviceIPAddress;
                    myXmlcfg.Settings["TCPService"]["Port"].intValue               = myTCPService.servicePort;
                    myXmlcfg.Settings["TCPService"]["MaxConnections"].intValue     = myTCPService.serviceMaxConnections;
                    myXmlcfg.Settings["TCPService"]["ImportanceFactor"].floatValue = myTCPService.serviceImportance;
                }
            }

            myXmlcfg.Settings["ReadAgentStatusFromConfig"].boolValue        = readAgentStatusFromConfig;
            myXmlcfg.Settings["ReadAgentStatusFromConfigInterval"].intValue = readAgentStatusFromConfigInterval;
            myXmlcfg.Settings["AgentStatus"].Value = agentStatus;

            myXmlcfg.Settings["Interval"].intValue = interval;

            myXmlcfg.Save(configFilePath);
            myXmlcfg.Dispose();
        }
Ejemplo n.º 2
0
        private void ReadConfiguration()
        {
            Xmlconfig myXmlcfg = new Xmlconfig(configFilePath, false);

            cpuImportance     = myXmlcfg.Settings["Cpu"]["ImportanceFactor"].floatValue;
            cpuThresholdValue = myXmlcfg.Settings["Cpu"]["ThresholdValue"].intValue;
            ramImportance     = myXmlcfg.Settings["Ram"]["ImportanceFactor"].floatValue;
            ramThresholdValue = myXmlcfg.Settings["Ram"]["ThresholdValue"].intValue;

            myTCPServices.Clear();

            if (myXmlcfg.Settings.GetNamedChildrenCount("TCPService") > 0)
            {
                foreach (ConfigSetting cs in myXmlcfg.Settings.GetNamedChildren("TCPService"))
                {
                    TCPService myTCPService = new TCPService();
                    myTCPService.serviceName           = cs["Name"].Value;
                    myTCPService.serviceIPAddress      = cs["IPAddress"].Value;
                    myTCPService.servicePort           = cs["Port"].intValue;
                    myTCPService.serviceMaxConnections = cs["MaxConnections"].intValue;
                    myTCPService.serviceImportance     = cs["ImportanceFactor"].floatValue;
                    myTCPServices.Add(myTCPService);
                }
            }

            readAgentStatusFromConfig         = myXmlcfg.Settings["ReadAgentStatusFromConfig"].boolValue;
            readAgentStatusFromConfigInterval = myXmlcfg.Settings["ReadAgentStatusFromConfigInterval"].intValue;
            agentStatus = myXmlcfg.Settings["AgentStatus"].Value;

            interval = myXmlcfg.Settings["Interval"].intValue;


            if (agentStatus.Length == 0)
            {
                readAgentStatusFromConfig         = false;
                readAgentStatusFromConfigInterval = 5;
                agentStatus = "Normal";
                throw new Exception("Configuration not complete.");
            }

            myXmlcfg.Dispose();
        }