コード例 #1
0
        public object this[string key]
        {
            get
            {
                ArgumentTree child = null;
                if (children.TryGetValue(key, out child))
                {
                    return(child.value);
                }

                return(null);
            }
            set
            {
                ArgumentTree child = null;
                if (children.TryGetValue(key, out child))
                {
                    child.value = value;
                }
                else
                {
                    children[key] = new ArgumentTree(value);
                }
            }
        }
コード例 #2
0
 public PluginEnvironment(IMessageReceiver receiver) : base(receiver)
 {
     plugins = new List <IPlugin>();
     config  = new ArgumentTree(null);
     sources = new Dictionary <string, IDataSource>();
     hooks   = new Dictionary <string, List <IMessageReceiver> >();
 }
コード例 #3
0
        protected void LoadConfigurationFile(string conffile)
        {
            configPath = conffile;
            // first load the config file
            XmlDocument doc = new XmlDocument();

            doc.Load(conffile);
            config = ArgumentTree.LoadFromXml(doc.DocumentElement);
        }
コード例 #4
0
        public bool Contains(KeyValuePair <string, object> item)
        {
            ArgumentTree child = null;

            if (children.TryGetValue(item.Key, out child))
            {
                return(child.value == item.Value);
            }

            return(false);
        }
コード例 #5
0
        public PluginEnvironment(IMessageReceiver receiver)
        {
            this.receiver = receiver;

            plugins     = new List <IPlugin>();
            config      = new ArgumentTree(null);
            sources     = new Dictionary <string, IDataSource>();
            actions     = new Dictionary <string, List <IAction> >();
            actions[""] = new List <IAction>();

            hooks = new Dictionary <string, List <IMessageReceiver> >();
        }
コード例 #6
0
        public void SetConfig(string key, object value)
        {
            ArgumentTree node = null;

            if (!config.Children.TryGetValue(key, out node))
            {
                config.Children[key] = new ArgumentTree(value);
            }
            else
            {
                node.Value = value;
            }
        }
コード例 #7
0
        public object GetConfig(string key)
        {
            ArgumentTree node = null;

            if (!config.Children.TryGetValue(key, out node))
            {
                return(null);
            }
            else
            {
                return(node.Value);
            }
        }
コード例 #8
0
        public string GetConfigDirectory(string key)
        {
            ArgumentTree node = null;

            if (!config.Children.TryGetValue(key, out node))
            {
                return(null);
            }
            else
            {
                return(Path.Combine(Directory.GetParent(configPath).FullName, (string)node.Value).ToString());
            }
        }
コード例 #9
0
        public bool TryGetValue(string key, out object value)
        {
            ArgumentTree child = null;

            if (children.TryGetValue(key, out child))
            {
                value = child.value;
                return(true);
            }

            value = null;
            return(false);
        }
コード例 #10
0
        public object Clone()
        {
            ArgumentTree copy = (ArgumentTree)MemberwiseClone();

            copy.children = new Dictionary <string, ArgumentTree>();

            foreach (KeyValuePair <string, ArgumentTree> child in children)
            {
                copy.children[child.Key] = (ArgumentTree)child.Value.Clone();
            }

            return(copy);
        }
コード例 #11
0
 public ArgumentTree(object value)
 {
     if (value is ArgumentTree)
     {
         ArgumentTree clone = (ArgumentTree)((ArgumentTree)value).Clone();
         value    = clone.value;
         children = clone.children;
     }
     else
     {
         this.value = value;
         children   = new Dictionary <string, ArgumentTree>();
     }
 }
コード例 #12
0
 public ArgumentTree(ArgumentTree copy)
 {
     if (copy == null)
     {
         // treat as ArgumentTree(object)
         this.value = null;
         children   = new Dictionary <string, ArgumentTree>();
     }
     else
     {
         ArgumentTree clone = (ArgumentTree)copy.Clone();
         value    = clone.value;
         children = clone.Children;
     }
 }
コード例 #13
0
        public static ArgumentTree LoadFromXml(XmlNode root)
        {
            // Find the value of this node
            object value = GetAttribute(root, "value");

            if (value == null)
            {
                // Use the inner text (that isn't included in other nodes) as the value
                StringBuilder text = new StringBuilder();
                foreach (XmlNode child in root.ChildNodes)
                {
                    if (child is XmlText)
                    {
                        text.Append(((XmlText)child).Data);
                    }
                    else if (child is XmlWhitespace)
                    {
                        text.Append(" ");
                    }
                }

                string strtext = text.ToString().Trim();
                if (strtext.Length > 0)
                {
                    value = strtext;
                }
            }

            ArgumentTree node = new ArgumentTree(value);

            foreach (XmlAttribute attr in root.Attributes)
            {
                if (attr.Name.ToLower() != "value")
                {
                    node.children[attr.Name] = new ArgumentTree(attr.Value);
                }
            }

            foreach (XmlNode child in root.ChildNodes)
            {
                if (child is XmlElement)
                {
                    node.children[child.Name] = LoadFromXml(child);
                }
            }

            return(node);
        }
コード例 #14
0
 public ArgumentTreeEnumerator(ArgumentTree tree)
 {
     elements = tree.children.GetEnumerator();
 }