Beispiel #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;
 }
        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);
            }
        }
 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)
 {
 }
Beispiel #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);
 }
Beispiel #7
0
 internal ConfigLeafNode(dynamic v, KeyType key, ConfigNode parent)
     : base(key, parent)
 {
     _state = new PlainLeafNodeState(v);
 }
 public static ConfigNode CreateConfigLeafNode(dynamic dy, KeyType key, ConfigNode parent)
 {
     return new ConfigLeafNode(dy, key, parent);
 }
 internal ConfigObjectNode(KeyType key, ConfigNode parent)
     : base(key, parent)
 {
     _children = new Dictionary<string, ConfigNode>();
 }
 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);
     }
 }