Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigNode" /> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="parent">The parent.</param>
 protected ConfigNode(KeyType key, ConfigNode parent)
 {
     _isSelected = false;
     _isExpanded = true;
     _key = key;
     _parent = parent;
 }
Exemplo n.º 2
0
        internal ConfigObjectNode(dynamic n, KeyType key, ConfigNode parent)
            : base(key, parent)
        {
            _children = new Dictionary<string, ConfigNode>();

            var expando = n as IDictionary<string, object>;
            foreach (var kvp in expando)
            {
                ConfigNode valueNode;
                var newKey = new StringKey(kvp.Key);

                if (kvp.Value is ExpandoObject)
                {
                    valueNode = ConfigNodeFactory.CreateConfigObjectNode(kvp.Value, newKey, this);
                }
                else if (kvp.Value is IList<object>)
                {
                    valueNode = ConfigNodeFactory.CreateConfigListNode(kvp.Value, newKey, this);
                }
                else
                {
                    valueNode = ConfigNodeFactory.CreateConfigLeafNode(kvp.Value, newKey, this);
                }

                _children.Add(kvp.Key, valueNode);
            }
        }
Exemplo n.º 3
0
 public static ConfigNode CreateConfigObjectNode(dynamic dy, KeyType key, ConfigNode parent)
 {
     var dict = dy as IDictionary<string, object>;
     var isEncrypted = dict.ContainsKey("EncryptionMethod") 
         && dict.ContainsKey("Content") 
         && dict.Count == 2;
     if (isEncrypted)
     {
         var encrypt = dict["EncryptionMethod"];
         var em = (EncryptionMethod) Enum.Parse(typeof (EncryptionMethod), (string) encrypt);
         return new ConfigLeafNode(dict["Content"], key, parent, em);
     }
     return new ConfigObjectNode(dy, key, parent);
 }
 internal abstract void ReplaceChild(ConfigNode n, KeyType key);
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <param name="parent"></param>
 protected AbsCollectionConfigNode(KeyType key, ConfigNode parent)
     : base(key, parent)
 {
 }
Exemplo n.º 6
0
 internal ConfigLeafNode(dynamic v, KeyType key, ConfigNode parent, EncryptionMethod em)
     : base(key, parent)
 {
     _state = em == EncryptionMethod.DPAPI_MACHINE ?
         (ILeafNodeState) new DPAPIMachineState(v, true) : new DPAPIUserState(v, true);
 }
Exemplo n.º 7
0
 internal ConfigLeafNode(dynamic v, KeyType key, ConfigNode parent)
     : base(key, parent)
 {
     _state = new PlainLeafNodeState(v);
 }
Exemplo n.º 8
0
 public static ConfigNode CreateConfigLeafNode(dynamic dy, KeyType key, ConfigNode parent)
 {
     return new ConfigLeafNode(dy, key, parent);
 }
Exemplo n.º 9
0
 internal ConfigObjectNode(KeyType key, ConfigNode parent)
     : base(key, parent)
 {
     _children = new Dictionary<string, ConfigNode>();
 }
Exemplo n.º 10
0
 internal override void ReplaceChild(ConfigNode n, KeyType key)
 {
     if (!(key is StringKey))
     {
         throw new ArgumentException("Replacing node on Object asks for a string key.");
     }
     string k = key.RawValue();
     if (_children.ContainsKey(k))
     {
         if (_children[k].NodeType == ConfigNodeType.LEAF && n.NodeType == ConfigNodeType.LEAF)
         {
             var node = _children[k] as ConfigLeafNode;
             if (node != null)
             {
                 if (node.IsEncrypted)
                 {
                     node.ReplaceEncryptedContent(((ConfigLeafNode)n).RawValue);
                 }
                 else
                 {
                     node.RawValue = ((ConfigLeafNode)n).RawValue;
                 }
             }
         }
         else
         {
             _children[k] = n;
             n.IsSelected = true;
             n.SavePropertyChangeHandler(_currentChangedHandler); //wire handlers to new nodes
             OnPropertyChanged("Children");
             PropagateChange(new ReplaceChangeEventArgs(KeyLabel, n.KeyLabel));
         }
     }
     else
     {
         throw new KeyNotFoundException("No child with key " + key + " is found in " + KeyLabel);
     }
 }