Example #1
0
        public Settings()
        {
            // "Agent.Settings"
            string settingFileName = ConfigPath.GetConfigFilePath("agent.settings");

            if (File.Exists(settingFileName))
            {
                doc.Load(settingFileName);
            }

            // Code for quick test.
            // AddNewIpAddress("", "", "", "", true);

            // Data Center
            var datacenters = doc.SelectNodes("//datacenter");

            foreach (XmlNode dcn in datacenters)
            {
                DataCenter dc = new DataCenter();

                dc.Ip            = this.GetAttribute(dcn, "ip");
                dc.Port          = int.Parse(this.GetAttribute(dcn, "port", "0"));
                dc.WirelessIp    = this.GetAttribute(dcn, "wirelessip");
                dc.WirelessPort  = int.Parse(this.GetAttribute(dcn, "wirelessport", "0"));
                dc.CountryCenter = this.GetAttribute(dcn, "type", "1") == "2";
                dataCenters.Add(dc);
            }

            // Site
            var siteNode = doc.SelectNodes("//site")[0];

            this.SysName = this.GetAttribute(siteNode, "sysname");
            this.SysSt   = this.GetAttribute(siteNode, "sysst");
            this.Mn      = this.GetAttribute(siteNode, "mn");
            this.Sno     = this.GetAttribute(siteNode, "sno");

            this.LoadPassword();

            // Devices
            var devices = doc.SelectNodes("//devices/device");

            foreach (XmlNode deviceNode in devices)
            {
                Device device = this.ParseDeviceNode(deviceNode);
                this.devices.Add(device);
                var codes = deviceNode.SelectNodes("code");
                foreach (XmlNode codeNode in codes)
                {
                    string  code      = codeNode.InnerText;
                    XmlNode fieldNode = codeNode.Attributes.GetNamedItem("field");
                    if (fieldNode != null)
                    {
                        device.AddCode(code, fieldNode.Value);
                    }
                }
            }


            // Load NaI device config.
            // TODO:

            this.NaIFilePath = string.Format("{0}\\..\\devices\\Scada.NaIDevice\\0.9", Application.ExecutablePath);



            const string NaIDeviceKey = "scada.naidevice";
            DeviceEntry  entry        = LoadFromConfig(NaIDeviceKey, ConfigPath.GetDeviceConfigFilePath(NaIDeviceKey, "0.9"));

            this.NaIDeviceSn  = (StringValue)entry["DeviceSn"];
            this.MinuteAdjust = (StringValue)entry["MinuteAdjust"];
        }
Example #2
0
        public void LoadSettings()
        {
            string settingFileName = ConfigPath.GetConfigFilePath(AgentXml);

            if (File.Exists(settingFileName))
            {
                doc.Load(settingFileName);
            }

            var datacenters = doc.SelectNodes("//datacenter2");

            foreach (XmlNode dcn in datacenters)
            {
                DataCenter2 dc = new DataCenter2();

                dc.BaseUrl = this.GetAttribute(dcn, "BaseUrl");

                dataCenters.Add(dc);
            }

            // Site
            var siteNode = doc.SelectNodes("//site")[0];

            this.SysName = this.GetAttribute(siteNode, "sysname");
            this.SysSt   = this.GetAttribute(siteNode, "sysst");
            this.Mn      = this.GetAttribute(siteNode, "mn");
            this.Sno     = this.GetAttribute(siteNode, "sno");
            this.Station = this.GetAttribute(siteNode, "station");

            // debug-data-time
            var    devicesNode   = doc.SelectNodes("//devices")[0];
            string debugDataTime = this.GetAttribute(devicesNode, "use-debug-data-time");

            if (!string.IsNullOrEmpty(debugDataTime))
            {
                this.UseDebugDataTime = debugDataTime == "true";
            }
            // Load Password
            this.LoadPassword();

            // Devices
            var devices = doc.SelectNodes("//devices/device");

            foreach (XmlNode deviceNode in devices)
            {
                Device device = this.ParseDeviceNode(deviceNode);
                this.devices.Add(device);
                var codes = deviceNode.SelectNodes("code");
                foreach (XmlNode codeNode in codes)
                {
                    string  code      = codeNode.InnerText;
                    XmlNode fieldNode = codeNode.Attributes.GetNamedItem("field");
                    if (fieldNode != null)
                    {
                        XmlNode typeNode = codeNode.Attributes.GetNamedItem("type");
                        string  dataType = "real";
                        if (typeNode != null)
                        {
                            dataType = typeNode.Value;
                        }
                        device.AddCode(code, fieldNode.Value, dataType);
                    }
                }
            }

            // Load NaI device config.
            // TODO:
            string configLabrPath = ConfigPath.GetDeviceConfigFilePath(Devices.Labr, "0.9");

            if (File.Exists(configLabrPath))
            {
                DeviceEntry entry = LoadFromConfig(Devices.Labr, configLabrPath);

                this.NaIDeviceSn  = (StringValue)entry["DeviceSn"];
                this.MinuteAdjust = (StringValue)entry["MinuteAdjust"];
            }
        }
Example #3
0
 public static string GetDeviceConfigFile(string deviceKey)
 {
     return(ConfigPath.GetDeviceConfigFilePath(deviceKey, "0.9"));
 }