예제 #1
0
        private static DeviceEntry LoadFromConfig(string deviceName, string configFile)
        {
            if (!File.Exists(configFile))
            {
                return(null);
            }

            using (ScadaReader sr = new ScadaReader(configFile))
            {
                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);
                // Dictionary<string, string> config = new Dictionary<string, string>();
                DeviceEntry entry = new DeviceEntry();
                while (result == ReadLineResult.OK)
                {
                    result = sr.ReadLine(out secType, out line, out key, out value);

                    if (secType == SectionType.KeyWithStringValue)
                    {
                        entry[key] = value;
                    }
                }
                DirectoryInfo di         = Directory.GetParent(configFile);
                string        devicePath = di.FullName;
                // Path
                entry[DeviceEntry.Path]     = new StringValue(devicePath);
                entry[DeviceEntry.Identity] = new StringValue(deviceName);


                return(entry);
            }
        }
예제 #2
0
        private static DeviceEntry LoadFromConfig(string deviceName, string configFile)
        {
            if (!File.Exists(configFile))
                return null;

            using (ScadaReader sr = new ScadaReader(configFile))
            {
                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);
                // Dictionary<string, string> config = new Dictionary<string, string>();
                DeviceEntry entry = new DeviceEntry();
                while (result == ReadLineResult.OK)
                {
                    result = sr.ReadLine(out secType, out line, out key, out value);

                    if (secType == SectionType.KeyWithStringValue)
                    {
                        entry[key] = value;
                    }
                }
                DirectoryInfo di = Directory.GetParent(configFile);
                string devicePath = di.FullName;
                // Path
                entry[DeviceEntry.Path] = new StringValue(devicePath);
                entry[DeviceEntry.Identity] = new StringValue(deviceName);

                return entry;
            }
        }
예제 #3
0
        private void LoadDevicesInfo(string installPath)
        {
            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);
                }
            }
        }