Пример #1
0
        public void FromYaml(YamlNode yamlNode)
        {
            YamlMappingNode node = yamlNode as YamlMappingNode;

            if (node.ContainsKey("enabled"))
            {
                Enabled = (node["enabled"] as YamlScalarNode).Value == "true";
            }

            if (node.ContainsKey("thread-pool-size"))
            {
                ThreadPoolSize = Convert.ToInt32((node["thread-pool-size"] as YamlScalarNode).Value);
            }

            Sessions.Clear();

            var seq = node[SessionTagName] as YamlSequenceNode;

            foreach (YamlMappingNode master in seq.Children)
            {
                var session = Session.FromYaml(Name, master);
                Sessions.Add(session);
                session.Index = Sessions.Count - 1;
            }
        }
        public static Session FromYaml(string plugInName, YamlMappingNode master)
        {
            Session session = new Session(plugInName);

            try
            {
                if (master.ContainsKey(PathKey))
                {
                    session.RuntimeFilePath = (master[PathKey] as YamlScalarNode).Value;
                }

                if (master.ContainsKey(TemplateFilePathKey))
                {
                    session.LocalFilePath = (master[TemplateFilePathKey] as YamlScalarNode).Value;
                }
                else
                {
                    session.LocalFilePath = session.RuntimeFilePath;
                }

                if (master.ContainsKey(SessionNameKey))
                {
                    session.Name = (master[SessionNameKey] as YamlScalarNode).Value;
                }
            }
            catch (Exception ex)
            {
                _logger.Log(Level.Error, ex.Message, ex);
            }

            var overrideSeq = master[OverridesKey] as YamlSequenceNode;

            foreach (var o in overrideSeq)
            {
                if (o is YamlScalarNode)
                {
                    // Older version of
                    session.Overrides.Add(new Override((o as YamlScalarNode).Value));
                }
                else if (o is YamlMappingNode)
                {
                    var map   = o as YamlMappingNode;
                    var key   = (map[KeyKey] as YamlScalarNode).Value;
                    var value = (map[ValueKey] as YamlScalarNode).Value;
                    session.Overrides.Add(new Override(key, value));
                }
            }
            return(session);
        }
Пример #3
0
        public void FromYaml(YamlNode yamlNode)
        {
            YamlMappingNode node = yamlNode as YamlMappingNode;

            foreach (var p in Plugins)
            {
                if (p.Name == ModbusMaster)
                {
                    if (node.ContainsKey(p.Name))
                    {
                        p.FromYaml(node[p.Name]);
                    }
                    else if (node.ContainsKey("modbus"))
                    {
                        p.FromYaml(node["modbus"]);
                    }
                }
                else if (p.Name == Dnp3Master)
                {
                    if (node.ContainsKey(p.Name))
                    {
                        p.FromYaml(node[p.Name]);
                    }
                    else if (node.ContainsKey("dnp3"))
                    {
                        p.FromYaml(node["dnp3"]);
                    }
                }
                else
                {
                    if (node.ContainsKey(p.Name))
                    {
                        p.FromYaml(node[p.Name]);
                    }
                }
            }
        }
Пример #4
0
        public void FromYaml(YamlNode yamlNode)
        {
            YamlMappingNode node = yamlNode as YamlMappingNode;

            if (node.ContainsKey("id"))
            {
                Id = ConfigFileTypeString.Convert((node["id"] as YamlScalarNode).Value);
            }

            if (node.ContainsKey("edition"))
            {
                Edition = (node["edition"] as YamlScalarNode).Value;
            }

            if (node.ContainsKey("version"))
            {
                Version = (node["version"] as YamlScalarNode).Value;
            }

            if (node.ContainsKey("plugin"))
            {
                Plugin = (node["plugin"] as YamlScalarNode).Value;
            }
        }