public TValue this[TKey key]
 {
     get
     {
         var entry = internalDictCase2[key];
         return((TValue)entry.Target);
     }
     set
     {
         //Was there a value
         CollectionStateObjectReference oldCollectionReference;
         if (internalDictCase2.TryGetValue(key, out oldCollectionReference))
         {
             if (!oldCollectionReference.IsNull)
             {
                 _referencesManager.UnSubscribe(_parent, oldCollectionReference.TargetUniqueID);
             }
         }
         //Now we can assign the new value
         internalDictCase2[key] = new CollectionStateObjectReference((IStateObject)value);
         var stateObject = (IStateObject)value;
         if (stateObject != null)
         {
             if (!_stateManager.IsStateObjectAllAttached(stateObject))
             {
                 _stateManager.RegisterPossibleOrphan(_parent, stateObject);
             }
             _referencesManager.Subscribe(_parent, stateObject);
         }
     }
 }
            private object ReadInputAsStateObject()
            {
                object val   = reader.Value; reader.Read();
                string value = (string)val;
                var    refe  = new CollectionStateObjectReference(value);

                return(refe);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Removing the reference from the surrogate.
        /// </summary>
        /// <param name="internalValue"></param>
        private void RemoveReferenceFromStateObjectSurrogate(CollectionStateObjectReference internalValue)
        {
            var obj = internalValue.Target as IPromise;

            if (obj != null)
            {
                var surrogate = DictionaryUtils.GetObjectContainingMethod(obj) as IStateObjectSurrogate;
                if (surrogate != null)
                {
                    surrogateManager.RemoveSurrogateReference(surrogate, (IStateObject)obj);
                }
            }
        }
 public TValue this [TKey key] {
     get {
         var internalValue = internalDictCase4 [new CollectionStateObjectReference((IStateObject)key)];
         if (internalValue.IsNull != null)
         {
             return((TValue)internalValue.Target);
         }
         return(default(TValue));
     }
     set {
         internalDictCase4 [new CollectionStateObjectReference((IStateObject)key)] =
             new CollectionStateObjectReference((IStateObject)value);
     }
 }
        public void UpdateReference(string oldUniqueID, string newUniqueID)
        {
            TKey key   = default(TKey);
            bool found = false;

            foreach (var pair in internalDictCase2)
            {
                if (pair.Value.TargetUniqueID == oldUniqueID)
                {
                    key   = pair.Key;
                    found = true;
                    break;
                }
            }
            if (found)
            {
                internalDictCase2[key] = new CollectionStateObjectReference(newUniqueID);
            }
        }
        public TValue this[TKey key]
        {
            get
            {
                var entry     = internalDictCase6[key];
                var surrogate = entry.Target as IStateObjectSurrogate;
                if (surrogate != null)
                {
                    return((TValue)surrogate.Value);
                }
                return(default(TValue));
            }
            set
            {
                CollectionStateObjectReference valueRef;
                if (internalDictCase6.TryGetValue(key, out valueRef) /*&& valueRef!=null*/)
                {
                    if (!valueRef.IsNull /* != NullCollectionStateObjectReference.CommonInstance*/)
                    {
                        referencesManager.UnSubscribe(valueObject: _parent, UniqueID: valueRef.Target.UniqueID);
                    }
                }


                var surrogate = surrogateManager.GetStateObjectSurrogate(value, true);
                //TODO: There is a risk of having the UniqueId become invalid.
                surrogateManager.AddSurrogateReference(surrogate, _parent);


                internalDictCase6[key] = new CollectionStateObjectReference((IStateObject)surrogate);
                var stateObject = (IStateObject)surrogate;
                //Possible orphan
                if (stateObject != null)
                {
                    if (!_stateManager.IsStateObjectAllAttached(stateObject))
                    {
                        _stateManager.RegisterPossibleOrphan(_parent, stateObject);
                    }
                    referencesManager.Subscribe(_parent, stateObject);
                }
            }
        }
 /// <summary>
 /// Updates all the Targets of the References to match the new value.
 /// </summary>
 /// <param name="uniqueID"></param>
 public void UpdateReferencesTable(string oldParent, string newParent, string oldUniqueID, string newUniqueID)
 {
     for (int i = References.Count - 1; i >= 0 && References.Count > 0; i--)
     {
         var reference = References[i];
         if (reference.TargetUniqueID.Contains(oldParent))
         {
             References[i] = new CollectionStateObjectReference(UniqueIDGenerator.ReplaceParent(reference.TargetUniqueID, oldParent, newParent));
         }
         else if (reference.Target == null)
         {
             lock (_referencesLock)
             {
                 References.RemoveAt(i);
                 MarkAsDirty();
             }
         }
         else if (reference.Target is StateObjectPointerReference)
         {
             ((StateObjectPointerReference)reference.Target).Target = ReferencedObject;
             StateManager.Current.MarkAsDirty((StateObjectPointerReference)reference.Target, "Target");
         }
         else if (reference.Target is IReferenceWatcher)
         {
             ((IReferenceWatcher)reference.Target).UpdateReference(oldUniqueID, newUniqueID);
         }
         else if (reference.Target is Page
                  //When a List's UniqueID has been switched, we have to notify the Page's Parent property,
                  //which hold the List's UniqueID, and updates the List's uniqueID
                  )
         {
             var parent = StateManager.Current.GetObject(newParent);
             if (parent is IVirtualListSerializable)
             {
                 //Update the Parent property, which is the List's uniqueID
                 ((Page)reference.Target).Parent = parent;
                 StateManager.Current.MarkAsDirty(((Page)reference.Target), "Parent");
             }
         }
     }
 }
Ejemplo n.º 8
0
 public TValue this [TKey key] {
     get {
         var    entry5    = internalDictCase5[key];
         TValue retEntry5 = (TValue)DictionaryUtils.RetrieveDelegateFromPromise(typeof(TValue), (IPromise)entry5.Target);
         return(retEntry5);
     }
     set {
         //Erase old reference
         CollectionStateObjectReference internalValue;
         if (internalDictCase5.TryGetValue(key, out internalValue) /*&& internalValue !=null*/)
         {
             if (!internalValue.IsNull)
             {
                 stateManager.RemoveObject(internalValue.TargetUniqueID, mustDetach: true, deep: true);
                 RemoveReferenceFromStateObjectSurrogate(internalValue);
             }
         }
         //This is multicast delegate create contiuation
         var val = DictionaryUtils.CreatePromise(stateManager, ((Delegate)(object)value));
         internalDictCase5 [key] = new CollectionStateObjectReference((IStateObject)val);
         AddReferenceIntoStateObjectSurrogate(val);
     }
 }