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

            if (!File.Exists(settingFileName))
            {
                return;
            }

            this.IsCAS = false;
            string cfg2FileName = ConfigPath.GetConfigFilePath("dsm2.cfg");

            if (File.Exists(cfg2FileName))
            {
                this.IsCAS = true;
            }

            doc.Load(settingFileName);

            var     application = doc.SelectNodes("//application");
            XmlNode appNode     = application[0];

            this.ApplicationName = this.GetAttribute(appNode, "title", "MainVision");
            this.StationName     = this.GetAttribute(appNode, "station", "????自动站");
            this.Status          = this.GetAttribute(appNode, "status", "试运行");
            this.StationId       = this.GetAttribute(appNode, "stationId", "00000000001");
            this.Pos             = this.GetAttribute(appNode, "pos", "未知GPS信息");
            this.UserComp        = this.GetAttribute(appNode, "usercomp", "未知用户单位");
            this.AdminComp       = this.GetAttribute(appNode, "admincomp", "未知运营单位");
            this.BuildComp       = this.GetAttribute(appNode, "buildcomp", "未知承建单位");
        }
Example #2
0
        private void InitMenuStatus()
        {
            string statusPath = ConfigPath.GetConfigFilePath("status");

            if (Directory.Exists(statusPath))
            {
                string[] filePaths  = Directory.GetFiles(statusPath, @"@*");
                var      deviceKeys = filePaths.Select((string path) =>
                {
                    string fileName = Path.GetFileName(path);
                    return(fileName.ToLower().Substring(1));
                });

                var menus = SettingsToolStripMenuItem.DropDownItems;
                foreach (ToolStripMenuItem m in menus)
                {
                    string tag = m.Tag as string;
                    if (string.IsNullOrEmpty(tag))
                    {
                        continue;
                    }
                    m.Checked = false;
                    tag       = tag.ToLower();
                    foreach (var deviceKey in deviceKeys)
                    {
                        if (deviceKey == tag)
                        {
                            m.Checked = true;
                        }
                    }
                }
            }
        }
Example #3
0
        private void ExecSample24HourMeasure()
        {
            // 首先清除原有进程
            try
            {
                Process[] processes = Process.GetProcesses();

                foreach (Process process in processes)
                {
                    if (process.ProcessName.ToLower() == "gv32")
                    {
                        process.Kill();
                    }
                }
            }
            catch (Exception e1)
            {
                string msg = string.Format("Kill GammaVision进程失败, 错误:{0}", e1.Message);
                RecordManager.DoSystemEventRecord(this, msg, RecordType.Event);

                return;
            }

            // 启动新的JOB文件
            var bat = ConfigPath.GetConfigFilePath("devices/Scada.HPGE/0.9/script/SampleMeasure24.bat");

            using (Process p = Process.Start(bat))
            {
            }
        }
Example #4
0
        internal bool GetThreshold(string polId, out string th1, out string th2)
        {
            th1 = "";
            th2 = "";
            string settingFileName = ConfigPath.GetConfigFilePath("agent.settings");

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

            // Data Center
            var polNotes = doc.SelectNodes("//polId");

            foreach (XmlNode polIdNode in polNotes)
            {
                var nameAttr = polIdNode.Attributes.GetNamedItem("name");
                if (nameAttr != null)
                {
                    string name = nameAttr.Value;
                    if (name == polId)
                    {
                        th1 = polIdNode.Attributes.GetNamedItem("v1").Value;
                        th2 = polIdNode.Attributes.GetNamedItem("v2").Value;
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #5
0
        private void PutDeviceFile(bool running)
        {
            string statusPath = ConfigPath.GetConfigFilePath("status");

            if (!Directory.Exists(statusPath))
            {
                Directory.CreateDirectory(statusPath);
            }

            string relFileName = string.Format("status\\@{0}-running", this.deviceKey);
            string fileName    = ConfigPath.GetConfigFilePath(relFileName);

            if (running)
            {
                try
                {
                    using (File.Create(fileName))
                    {
                    }
                }
                catch (Exception)
                { }
            }
            else
            {
                try
                {
                    File.Delete(fileName);
                }
                catch (Exception)
                {
                }
            }
        }
Example #6
0
        private static string GetScadaSqlFile()
        {
            Type   type        = typeof(Program);
            string fn          = type.Assembly.Location;
            string sqlFileName = ConfigPath.GetConfigFilePath("scada.sql");

            return(sqlFileName);
        }
        private void ExecSample24HourMeasure()
        {
            var bat = ConfigPath.GetConfigFilePath("devices/Scada.HPGE/0.9/script/SampleMeasure24.bat");

            using (Process p = Process.Start(bat))
            {
            }
        }
Example #8
0
        private bool RecoverCheck()
        {
            string statusPath = ConfigPath.GetConfigFilePath("status");

            if (!Directory.Exists(statusPath))
            {
                return(false);
            }

            string runningDevicesFile = Path.Combine(statusPath, "running.devices");

            if (!File.Exists(runningDevicesFile))
            {
                return(false);
            }

            try
            {
                using (FileStream fs = File.Open(runningDevicesFile, FileMode.Open))
                {
                    // Recover
                    this.CheckAllDevices(false);

                    long   len   = fs.Length;
                    byte[] bytes = new byte[len];
                    fs.Read(bytes, 0, (int)len);

                    StringReader sr = new StringReader(Encoding.ASCII.GetString(bytes));

                    string deviceKeyLine = sr.ReadLine();
                    while (deviceKeyLine != null)
                    {
                        string deviceKey = deviceKeyLine.ToLower().Trim();

                        if (!string.IsNullOrEmpty(deviceKey))
                        {
                            foreach (ListViewItem item in this.deviceListView.Items)
                            {
                                string itemTextLower = item.Text.ToLower();
                                if (itemTextLower == deviceKey)
                                {
                                    item.Checked = true;
                                }
                            }
                        }

                        deviceKeyLine = sr.ReadLine();
                    }
                    return(true);
                }
            }
            catch (Exception)
            {
            }
            return(false);
        }
Example #9
0
        private void LoadConfig()
        {
            string fileName = "dsm.cfg";

            if (Settings.Instance.IsCAS)
            {
                fileName = "dsm2.cfg";
            }
            string filePath = ConfigPath.GetConfigFilePath(fileName);

            Config.Instance().Load(filePath);
        }
        private bool CheckDeviceFile()
        {
            string statusPath = ConfigPath.GetConfigFilePath("status");

            if (!Directory.Exists(statusPath))
            {
                Directory.CreateDirectory(statusPath);
            }

            string relFileName = string.Format("status\\@{0}-running", this.DeviceKey);
            string fileName    = ConfigPath.GetConfigFilePath(relFileName);

            return(File.Exists(fileName));
        }
Example #11
0
        private void BringDataUploadUI()
        {
            string dataUploadExe = "Scada.Data.Client.exe";

            if (!File.Exists(ConfigPath.GetConfigFilePath("agent.http.settings")))
            {
                dataUploadExe = "Scada.DataCenterAgent.exe";
            }

            Process[] ps = Process.GetProcessesByName(dataUploadExe);
            if (ps == null || ps.Length == 0)
            {
                this.OpenProcessByName(dataUploadExe);
            }
        }
Example #12
0
        public static void SetDeviceConfigPath(string deviceName, bool hide)
        {
            string deviceConfigPath = ConfigPath.GetConfigFilePath(DevicePath);
            string devicePath1      = string.Format("{0}\\{1}", deviceConfigPath, deviceName);
            string devicePath2      = string.Format("{0}\\!{1}", deviceConfigPath, deviceName);

            if (hide && Directory.Exists(devicePath1))
            {
                Directory.Move(devicePath1, devicePath2);
                // Rename(devicePath1, devicePath2);
            }
            else if (!hide && Directory.Exists(devicePath2))
            {
                Directory.Move(devicePath2, devicePath1);
            }
        }
Example #13
0
        internal void SetThreshold(string polId, string th1, string th2)
        {
            string settingFileName = ConfigPath.GetConfigFilePath("agent.settings");

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

            // Data Center
            var     polNotes     = doc.SelectNodes("//polId");
            XmlNode thePolIdNode = null;

            foreach (XmlNode polIdNode in polNotes)
            {
                var nameAttr = polIdNode.Attributes.GetNamedItem("name");
                if (nameAttr != null)
                {
                    string name = nameAttr.Value;
                    if (name == polId)
                    {
                        thePolIdNode = polIdNode;

                        XmlAttribute v1Attr = (XmlAttribute)thePolIdNode.Attributes.GetNamedItem("v1");
                        v1Attr.Value = th1;
                        XmlAttribute v2Attr = (XmlAttribute)thePolIdNode.Attributes.GetNamedItem("v2");
                        v2Attr.Value = th2;
                        doc.Save(settingFileName);
                        return;
                    }
                }
            }

            if (thePolIdNode == null)
            {
                var thresholdNode = polNotes[0].ParentNode;

                thePolIdNode = doc.CreateElement("polId");
                thresholdNode.AppendChild(thePolIdNode);

                this.AddAttribute(doc, thePolIdNode, "name", polId);
                this.AddAttribute(doc, thePolIdNode, "v1", th1);
                this.AddAttribute(doc, thePolIdNode, "v2", th2);
                doc.Save(settingFileName);
            }
        }
Example #14
0
        private void HandleCheckedChanged(string deviceKey, bool check)
        {
            string relFileName = string.Format("status\\@{0}", deviceKey);
            string fileName    = ConfigPath.GetConfigFilePath(relFileName);

            if (check)
            {
                if (!File.Exists(fileName))
                {
                    using (File.Create(fileName))
                    { }
                }
            }
            else
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
Example #15
0
        // to test;
        internal void AddNewIpAddress(string wireIp, string wirePort, string wirelessIp, string wirelessPort, bool country)
        {
            string settingFileName = ConfigPath.GetConfigFilePath(AgentXml);

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

            // Data Center
            var dsNotes = doc.SelectNodes("//datacenter2");
            var ds      = dsNotes[0].ParentNode;

            XmlNode newDataCenterNode = doc.CreateElement("datacenter2");

            ds.AppendChild(newDataCenterNode);
            this.AddAttribute(doc, newDataCenterNode, "ip", wireIp);
            this.AddAttribute(doc, newDataCenterNode, "port", wirePort);
            this.AddAttribute(doc, newDataCenterNode, "wirelessip", wirelessIp);
            this.AddAttribute(doc, newDataCenterNode, "wirelessport", wirelessPort);
            this.AddAttribute(doc, newDataCenterNode, "type", "3");
            doc.Save(settingFileName);
        }
Example #16
0
        private void SelectDevices()
        {
            StringBuilder sb = new StringBuilder();

            foreach (ListViewItem item in this.deviceListView.Items)
            {
                if (item.Checked)
                {
                    string deviceName = item.SubItems[0].Text;
                    string version    = item.SubItems[1].Text;
                    Program.DeviceManager.SelectDevice(deviceName, version, true);

                    sb.AppendLine(deviceName);
                }
            }

            // Dump the running devices.
            string statusPath = ConfigPath.GetConfigFilePath("status");

            if (!Directory.Exists(statusPath))
            {
                Directory.CreateDirectory(statusPath);
            }

            string runningDevicesFile = Path.Combine(statusPath, "running.devices");

            if (File.Exists(runningDevicesFile))
            {
                File.Delete(runningDevicesFile);
            }

            using (FileStream fs = File.Open(runningDevicesFile, FileMode.CreateNew))
            {
                byte[] bytes = Encoding.ASCII.GetBytes(sb.ToString());
                fs.Write(bytes, 0, bytes.Length);
            }
        }
Example #17
0
        // to test;
        internal void AddNewIpAddress(string wireIp, string wirePort, string wirelessIp, string wirelessPort, bool country)
        {
            string settingFileName = ConfigPath.GetConfigFilePath("agent.settings");

            // string settingFileName = string.Format("{0}\\..\\{1}", Application.ExecutablePath, "agent.settings");
            if (File.Exists(settingFileName))
            {
                doc.Load(settingFileName);
            }

            // Data Center
            var dsNotes = doc.SelectNodes("//datacenter");
            var ds      = dsNotes[0].ParentNode;

            XmlNode newDataCenterNode = doc.CreateElement("datacenter");

            ds.AppendChild(newDataCenterNode);
            this.AddAttribute(doc, newDataCenterNode, "ip", wireIp);
            this.AddAttribute(doc, newDataCenterNode, "port", wirePort);
            this.AddAttribute(doc, newDataCenterNode, "wirelessip", wirelessIp);
            this.AddAttribute(doc, newDataCenterNode, "wirelessport", wirelessPort);
            this.AddAttribute(doc, newDataCenterNode, "type", country ? "2" : "1");
            doc.Save(settingFileName);
        }
Example #18
0
        private string GetUpdateStatusUri()
        {
            if (string.IsNullOrEmpty(this.DataCenterBaseUrl))
            {
                const string AgentXml        = "agent.http.settings";
                string       settingFileName = ConfigPath.GetConfigFilePath(AgentXml);
                XmlDocument  doc             = new XmlDocument();
                if (File.Exists(settingFileName))
                {
                    doc.Load(settingFileName);
                }

                var datacenters = doc.SelectNodes("//datacenter2");
                foreach (XmlNode dcn in datacenters)
                {
                    this.DataCenterBaseUrl = this.GetAttribute(dcn, "BaseUrl");
                    break;
                }

                var siteNode = doc.SelectNodes("//site")[0];
                this.StationId = this.GetAttribute(siteNode, "station");
            }
            return(string.Format("{0}/command/cinderella/{1}", this.DataCenterBaseUrl, this.StationId));
        }
Example #19
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 #20
0
        private string GetPasswordFile()
        {
            string pwFileName = ConfigPath.GetConfigFilePath("password");

            return(pwFileName);
        }
Example #21
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 #22
0
        private void LoadDevicesInfo(string installPath)
        {
            this.dict.Clear();
            string[] deviceConfigPaths = Directory.GetDirectories(ConfigPath.GetConfigFilePath(DevicePath));
            foreach (string devicePath in deviceConfigPaths)
            {
                string deviceName = DirectoryName(devicePath);
                if (deviceName.StartsWith("!") || deviceName.StartsWith("."))
                {
                    continue;
                }
                string deviceKey = deviceName.ToLower();

                DevicesInfo di = null;
                if (!dict.ContainsKey(deviceKey))
                {
                    di = new DevicesInfo()
                    {
                        Name = deviceName
                    };
                    di.Versions = new List <string>();
                    dict.Add(deviceKey, di);
                }
                else
                {
                    di = dict[deviceKey];
                }

                string displayConfig = devicePath + "\\display.cfg";
                if (File.Exists(displayConfig))
                {
                    using (ScadaReader sr = new ScadaReader(displayConfig))
                    {
                        // TODO: Xml Reader parse the whole file.
                        // And retrieve the resulr, no need to loop reading line
                        //
                        SectionType    secType = SectionType.None;
                        string         line    = null;
                        string         key     = null;
                        IValue         value   = null;
                        ReadLineResult result  = sr.ReadLine(out secType, out line, out key, out value);

                        while (result == ReadLineResult.OK)
                        {
                            if (key.ToLower() == "name")
                            {
                                di.DisplayName = value.ToString();
                            }
                            result = sr.ReadLine(out secType, out line, out key, out value);
                        }
                    }
                }

                string[] versionPaths = Directory.GetDirectories(devicePath);
                foreach (string versionPath in versionPaths)
                {
                    string version = DirectoryName(versionPath);
                    di.Versions.Add(version);
                }
            }
        }
Example #23
0
 private string GetPasswordFile()
 {
     return(ConfigPath.GetConfigFilePath("password"));
 }
Example #24
0
        public static string GetDeviceConfigPath(string deviceName, string version)
        {
            string deviceConfigPath = ConfigPath.GetConfigFilePath(DevicePath);

            return(string.Format("{0}\\{1}\\{2}", deviceConfigPath, deviceName, version));
        }