Exemplo n.º 1
0
 public InvalidTypeAssignmentException(ConfigItem oldItem, ConfigItem newItem)
 {
     OldItem = oldItem; NewItem = newItem;
 }
Exemplo n.º 2
0
 public override bool Equals(ConfigItem other)
 {
     return((other is SingleItem <T> otherItem) && Equals(otherItem));
 }
Exemplo n.º 3
0
        public override void Assign(ConfigItem other)
        {
            if (other is DynamicMap <T> otherMap)
            {
                var deleted = new List <KeyValuePair <string, T> >();
                var added   = new List <KeyValuePair <string, T> >();
                var updated = new List <KeyValuePair <string, T> >();
                var assignmentExceptions = new List <InvalidAssignmentException>();

                foreach (var key in _mapKeys().ToList())
                {
                    if (!otherMap._mapKeys().Contains(key))
                    {
                        deleted.Add(new KeyValuePair <string, T>(key, _mapGet(key)));
                        dictionary.Remove(key);
                    }
                }

                foreach (var key in otherMap._mapKeys())
                {
                    var newItem = otherMap._mapGet(key);

                    if (_mapKeys().Contains(key))
                    {
                        var oldItem = _mapGet(key);
                        if (object.ReferenceEquals(oldItem, null))
                        {
                            if (object.ReferenceEquals(newItem, null))
                            {
                                continue;
                            }
                            else
                            {
                                dictionary[key] = newItem;
                                added.Add(new KeyValuePair <string, T>(key, newItem));
                            }
                        }
                        else
                        {
                            if (object.ReferenceEquals(newItem, null))
                            {
                                deleted.Add(new KeyValuePair <string, T>(key, oldItem));
                                dictionary[key] = newItem;
                            }
                            else
                            {
                                if (!oldItem.Equals(newItem))
                                {
                                    try {
                                        oldItem.Assign(newItem);
                                        updated.Add(new KeyValuePair <string, T>(key, oldItem));
                                    } catch (InvalidAssignmentException e) {
                                        assignmentExceptions.Add(e);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        dictionary[key] = newItem;
                        added.Add(new KeyValuePair <string, T>(key, newItem));
                    }
                }

                deleted.ForEach(kv => ItemDeleted?.Invoke(this, new ItemDeletedArgs {
                    Key = kv.Key, OldItem = kv.Value
                }));
                added.ForEach(kv => ItemAdded?.Invoke(this, new ItemAddedArgs   {
                    Key = kv.Key, NewItem = kv.Value
                }));
                updated.ForEach(kv => ItemUpdated?.Invoke(this, new ItemUpdatedArgs {
                    Key = kv.Key, Item = kv.Value
                }));
                Updated?.Invoke(this, new UpdatedArgs {
                    DeletedItems = deleted, AddedItems = added, UpdatedItems = updated
                });

                if (assignmentExceptions.Count > 0)
                {
                    throw new InvalidChildAssignmentException(assignmentExceptions);
                }
            }
            else
            {
                throw new InvalidTypeAssignmentException(this, other);
            }
        }
Exemplo n.º 4
0
 public override bool Equals(ConfigItem other)
 {
     return((other is StaticMap <T> otherMap) && Equals(otherMap));
 }
Exemplo n.º 5
0
 public override bool Equals(ConfigItem other)
 {
     return((other is ItemList <T> otherList) && Equals(otherList));
 }