Beispiel #1
0
        private Dictionary <PropertyDescriptor, IEnumerable <ChangeSetEntry> > GetAssociatedChanges(object entity)
        {
            Func <ChangeSetEntry, bool> predicate = null;
            Func <int, ChangeSetEntry>  selector  = null;
            Func <int, ChangeSetEntry>  func3     = null;
            Dictionary <PropertyDescriptor, IEnumerable <ChangeSetEntry> > dictionary = null;

            if (this._associatedChangesMap == null)
            {
                this._associatedChangesMap = new Dictionary <object, Dictionary <PropertyDescriptor, IEnumerable <ChangeSetEntry> > >();
            }
            else if (this._associatedChangesMap.TryGetValue(entity, out dictionary))
            {
                return(dictionary);
            }
            Dictionary <int, ChangeSetEntry> entityOperationMap = this._changeSetEntries.ToDictionary <ChangeSetEntry, int>(p => p.Id);

            dictionary = new Dictionary <PropertyDescriptor, IEnumerable <ChangeSetEntry> >();
            foreach (PropertyDescriptor descriptor in from p in TypeDescriptor.GetProperties(entity.GetType()).Cast <PropertyDescriptor>()
                     where p.Attributes[typeof(CompositionAttribute)] != null
                     select p)
            {
                List <ChangeSetEntry> list = new List <ChangeSetEntry>();
                if (predicate == null)
                {
                    predicate = p => p.Entity == entity;
                }
                ChangeSetEntry entry = this._changeSetEntries.Single <ChangeSetEntry>(predicate);
                if ((entry.Associations != null) && entry.Associations.ContainsKey(descriptor.Name))
                {
                    int[] source = entry.Associations[descriptor.Name];
                    if (selector == null)
                    {
                        selector = p => entityOperationMap[p];
                    }
                    IEnumerable <ChangeSetEntry> collection = source.Select <int, ChangeSetEntry>(selector);
                    list.AddRange(collection);
                }
                if ((entry.OriginalAssociations != null) && entry.OriginalAssociations.ContainsKey(descriptor.Name))
                {
                    int[] numArray2 = entry.OriginalAssociations[descriptor.Name];
                    if (func3 == null)
                    {
                        func3 = p => entityOperationMap[p];
                    }
                    IEnumerable <ChangeSetEntry> enumerable3 = from p in numArray2.Select <int, ChangeSetEntry>(func3)
                                                               where p.Operation == DomainOperation.Delete
                                                               select p;
                    list.AddRange(enumerable3);
                }
                dictionary[descriptor] = list;
            }
            this._associatedChangesMap[entity] = dictionary;
            return(dictionary);
        }
Beispiel #2
0
        private void OrderOperations(ChangeSetEntry operation, Dictionary <ChangeSetEntry, List <ChangeSetEntry> > operationChildMap, List <ChangeSetEntry> orderedOperations)
        {
            List <ChangeSetEntry> list;

            orderedOperations.Add(operation);
            if (operationChildMap.TryGetValue(operation, out list))
            {
                foreach (ChangeSetEntry entry in list)
                {
                    this.OrderOperations(entry, operationChildMap, orderedOperations);
                }
            }
        }
Beispiel #3
0
        public TEntity GetOriginal <TEntity>(TEntity clientEntity) where TEntity : class
        {
            if (clientEntity == null)
            {
                throw new ArgumentNullException("clientEntity");
            }
            ChangeSetEntry entry = this._changeSetEntries.FirstOrDefault <ChangeSetEntry>(p => object.ReferenceEquals(p.Entity, clientEntity));

            if (entry == null)
            {
                throw new ArgumentException("ChangeSet_ChangeSetEntryNotFound");
            }
            if (entry.Operation == DomainOperation.Insert)
            {
                throw new InvalidOperationException("ChangeSet_OriginalNotValidForInsert");
            }
            return((TEntity)entry.OriginalEntity);
        }
Beispiel #4
0
 public ChangeSet(ChangeSetEntry changeSetEntry) : this(new List <ChangeSetEntry> {
     changeSetEntry
 })
 {
 }
Beispiel #5
0
        private IEnumerable <ChangeSetEntry> OrderChangeset(IEnumerable <ChangeSetEntry> changeSetEntries)
        {
            Dictionary <int, ChangeSetEntry> dictionary = changeSetEntries.ToDictionary <ChangeSetEntry, int>(p => p.Id);
            Dictionary <ChangeSetEntry, List <ChangeSetEntry> > operationChildMap = new Dictionary <ChangeSetEntry, List <ChangeSetEntry> >();
            bool flag = false;

            foreach (IGrouping <Type, ChangeSetEntry> grouping in from p in changeSetEntries group p by p.Entity.GetType())
            {
                IEnumerable <PropertyDescriptor> enumerable = (from p in TypeDescriptor.GetProperties(grouping.Key).Cast <PropertyDescriptor>()
                                                               where p.Attributes[typeof(CompositionAttribute)] != null
                                                               select p).ToArray <PropertyDescriptor>();
                foreach (ChangeSetEntry entry in grouping)
                {
                    foreach (PropertyDescriptor descriptor in enumerable)
                    {
                        flag = true;
                        List <int> source = new List <int>();
                        if ((entry.Associations != null) && entry.Associations.ContainsKey(descriptor.Name))
                        {
                            source.AddRange(entry.Associations[descriptor.Name]);
                        }
                        if ((entry.OriginalAssociations != null) && entry.OriginalAssociations.ContainsKey(descriptor.Name))
                        {
                            source.AddRange(entry.OriginalAssociations[descriptor.Name]);
                        }
                        foreach (int num in source.Distinct <int>())
                        {
                            ChangeSetEntry entry2 = null;
                            if (dictionary.TryGetValue(num, out entry2))
                            {
                                List <ChangeSetEntry> list2;
                                if (entry2.ParentOperation != null)
                                {
                                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "ChangeSet_ChildHasMultipleParents", new object[] { entry2.Id }));
                                }
                                entry2.ParentOperation = entry;
                                if (!operationChildMap.TryGetValue(entry, out list2))
                                {
                                    list2 = new List <ChangeSetEntry>();
                                    operationChildMap[entry] = list2;
                                }
                                list2.Add(entry2);
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                return(changeSetEntries);
            }
            List <ChangeSetEntry> orderedOperations = new List <ChangeSetEntry>();

            foreach (ChangeSetEntry entry3 in from p in changeSetEntries
                     where p.ParentOperation == null
                     select p)
            {
                this.OrderOperations(entry3, operationChildMap, orderedOperations);
            }
            return(orderedOperations.Union <ChangeSetEntry>(changeSetEntries).ToArray <ChangeSetEntry>());
        }