Esempio n. 1
0
        internal GreenModel RemoveObject(ObjectId oid)
        {
            Debug.Assert(!this.lazyProperties.ContainsKey(oid));
            ImmutableDictionary <ObjectId, GreenObject> objects = this.objects;
            ImmutableDictionary <ObjectId, ImmutableHashSet <Slot> > refs;

            if (this.references.TryGetValue(oid, out refs))
            {
                foreach (var refEntry in refs)
                {
                    GreenObject green;
                    if (this.objects.TryGetValue(refEntry.Key, out green))
                    {
                        GreenObject oldGreen = green;
                        foreach (var slot in refEntry.Value)
                        {
                            object value;
                            if (green.Slots.TryGetValue(slot, out value))
                            {
                                if (value is GreenList)
                                {
                                    GreenList list = (GreenList)value;
                                    green = green.Update(
                                        green.Parent == oid ? null : green.Parent,
                                        green.Children.RemoveAll(item => item == oid),
                                        green.Slots.SetItem(slot, list.RemoveAll(oid)));
                                }
                                else if ((ObjectId)value == oid)
                                {
                                    green = green.Update(
                                        green.Parent == oid ? null : green.Parent,
                                        green.Children.RemoveAll(item => item == oid),
                                        green.Slots.SetItem(slot, GreenObject.Unassigned));
                                }
                            }
                        }
                        if (green != oldGreen)
                        {
                            objects.SetItem(refEntry.Key, green);
                        }
                    }
                }
                return(this.Update(
                           this.name,
                           this.version,
                           objects.Remove(oid),
                           this.strongObjects.Remove(oid),
                           this.lazyProperties.Remove(oid),
                           this.references.Remove(oid)));
            }
            return(this);
        }
Esempio n. 2
0
        internal GreenList AddRange(GreenList items)
        {
            GreenList result = this;

            foreach (var item in items)
            {
                if (item == null)
                {
                    continue;
                }
                if (!this.unique || !result.Contains(item))
                {
                    result = result.Update(result.items.Add(item), this.lazyItems);
                }
            }
            return(result);
        }
Esempio n. 3
0
        internal GreenModel ReplaceObject(ObjectId oid, ObjectId targetOid)
        {
            Debug.Assert(!this.lazyProperties.ContainsKey(oid));
            ImmutableDictionary <ObjectId, GreenObject> objects = this.objects;
            ImmutableDictionary <ObjectId, ImmutableHashSet <Slot> > refs;

            if (this.references.TryGetValue(oid, out refs))
            {
                ImmutableDictionary <ObjectId, ImmutableHashSet <Slot> > targetRefs;
                if (!this.references.TryGetValue(targetOid, out targetRefs))
                {
                    targetRefs = ImmutableDictionary <ObjectId, ImmutableHashSet <Slot> > .Empty;
                }
                foreach (var refEntry in refs)
                {
                    GreenObject green;
                    if (this.objects.TryGetValue(refEntry.Key, out green))
                    {
                        GreenObject             oldGreen = green;
                        ImmutableHashSet <Slot> targetSlots;
                        if (!targetRefs.TryGetValue(refEntry.Key, out targetSlots))
                        {
                            targetSlots = ImmutableHashSet <Slot> .Empty;
                        }
                        foreach (var slot in refEntry.Value)
                        {
                            object value;
                            if (green.Slots.TryGetValue(slot, out value))
                            {
                                if (value is GreenList)
                                {
                                    GreenList list = (GreenList)value;
                                    green = green.Update(
                                        green.Parent == oid ? targetOid : green.Parent,
                                        green.Children.Replace(oid, targetOid),
                                        green.Slots.SetItem(slot, list.Replace(oid, targetOid)));
                                    targetSlots = targetSlots.Add(slot);
                                }
                                else if ((ObjectId)value == oid)
                                {
                                    green = green.Update(
                                        green.Parent == oid ? targetOid : green.Parent,
                                        green.Children.Replace(oid, targetOid),
                                        green.Slots.SetItem(slot, targetOid));
                                    targetSlots = targetSlots.Add(slot);
                                }
                            }
                        }
                        if (green != oldGreen)
                        {
                            objects.SetItem(refEntry.Key, green);
                        }
                        if (targetSlots.Count > 0)
                        {
                            targetRefs = targetRefs.SetItem(refEntry.Key, targetSlots);
                        }
                    }
                }
                return(this.Update(
                           this.name,
                           this.version,
                           objects.Remove(oid),
                           this.strongObjects.Remove(oid),
                           this.lazyProperties.Remove(oid),
                           targetRefs.Count > 0 ? this.references.Remove(oid).SetItem(targetOid, targetRefs) : this.references.Remove(oid)));
            }
            return(this);
        }