private IList <BasePromiseInfo> CreatePromises()
        {
            var stateCache = StateManager.Current;
            var uid        = UniqueIDGenerator.GetRelativeUniqueID(this, "Promises");
            var promises   = IocContainerImplWithUnity.Current.Resolve <IList <BasePromiseInfo> >();

            stateCache.PromoteObject((IStateObject)promises, uid);
            return(promises);
        }
Example #2
0
 private static void ProcessStaticAdoption(IStateObject parent, IStateObject orphan)
 {
     //if (child is still orphan)
     if (!StateManager.AllBranchesAttached(orphan))
     {
         //Get relative id for orphan
         var orphanID    = StateManager.Current.UniqueIDGenerator.GetOrphanUniqueID();
         var newUniqueID = UniqueIDGenerator.GetRelativeUniqueID(parent, orphanID);
         LazyBehaviours.AddDependent(parent, orphanID);
         StateManager.Current.SwitchOrPromoteObject(orphan, newUniqueID, inAdoption: true);
     }
 }
        private void GetResolvedValueEx(DependencyResolutionInfo dependency)
        {
            var surrogateManager  = _stateManager.surrogateManager;
            var value             = dependency.value;
            var istateObjectValue = dependency.value as IStateObject;

            if (istateObjectValue != null)
            {
                //The value is an state object
                if (_stateManager.IsInElementsToRemove(istateObjectValue.UniqueID))
                {
                    //If the object is present in the elements it is detached from so its UniqueID
                    //is changed to a temporal one.
                    //The current in the session must be removed
                    _stateManager.DettachObject(istateObjectValue);
                }
                dependency.canBeAnOrphan = !StateManager.AllBranchesAttached(istateObjectValue);
                dependency.ResolvedValue = istateObjectValue;
                dependency.IsStateObject = true;
            }
            else if (value is ISurrogateEventsInfo)
            {
                dependency.ResolvedValue = value;
                dependency.isEventsInfo  = true;
            }
            else
            {
                //if (surrogateManager.IsSurrogateRegistered(value.GetType())) Commented for performance
                StateObjectSurrogate currentSurrogate = null;
                //Get the surrogate instance from the surrogates that are already loaded in memory or create one
                dependency.ResolvedValue = currentSurrogate = dependency.ResolvedSurrogate = surrogateManager.GetSurrogateFor(value, generateIfNotFound: true);

                if (currentSurrogate == null)
                {
                    throw new ArgumentException("A surrogate could not be gotten for value of type " + value.GetType().FullName);
                }

                if (_stateManager.IsInElementsToRemove(currentSurrogate.UniqueID))
                {
                    //If the object is present in the elements it is restored,
                    //since it is a top element no adoption needs to be performed
                    _stateManager.UndoRemove(currentSurrogate.UniqueID);
                    //We must unremove the Value surrogate
                    var valueUniqueID = UniqueIDGenerator.GetRelativeUniqueID(currentSurrogate, StateObjectSurrogate.VALUE_PREFIX);
                    _stateManager.UndoRemove(valueUniqueID);
                }
                else
                {
                    //OK
                }
            }
        }
Example #4
0
 private bool ProcessAdoption(IStateObject parent, IStateObject orphan)
 {
     if (!_promotedOrphans.Contains(orphan))
     {
         //Get relative id for orphan
         var orphanID    = _uniqueIdGenerator.GetOrphanUniqueID();
         var newUniqueID = UniqueIDGenerator.GetRelativeUniqueID(parent, orphanID);
         _stateManager.PromoteObject(orphan, newUniqueID, inAdoption: true);
         LazyBehaviours.AddDependent(parent, orphanID);
         _promotedOrphans.Add(orphan);
         return(true);
     }
     return(false);
 }
Example #5
0
        public void SaveSurrogate(StateObjectSurrogate surrogate)
        {
            //Save surrogate header
            var surrogateContext = StateManager.Current.surrogateManager.GetSurrogateContext(surrogate.UniqueID, surrogate);
            var raw = SurrogatesDirectory.ObjectToRaw(surrogate, surrogateContext);

            SaveRaw(surrogate.UniqueID, raw);

            //Save surrogate value
            var uid = UniqueIDGenerator.GetRelativeUniqueID(surrogate, StateObjectSurrogate.VALUE_PREFIX);

            surrogateContext = StateManager.Current.surrogateManager.GetSurrogateContext(uid, surrogate.Value);
            raw = SurrogatesDirectory.ObjectToRaw(surrogate.Value, surrogateContext);
            SaveRaw(uid, raw);
        }
Example #6
0
        public void SaveSurrogate(StateObjectSurrogate surrogate)
        {
            //Saving surrogate header
            var surrogatecontext = _surrogateManager.GetSurrogateContext(surrogate.UniqueID, surrogate);
            var raw = SurrogatesDirectory.ObjectToRaw(surrogate, surrogatecontext);

            SaveRaw(surrogate.UniqueID, raw);
            //Saving surrogateValue
            if (surrogate.ShouldSerializeValue)
            {
                var uid = UniqueIDGenerator.GetRelativeUniqueID(surrogate, StateObjectSurrogate.VALUE_PREFIX);
                surrogatecontext = _surrogateManager.GetSurrogateContext(uid, surrogate.Value);
                raw = SurrogatesDirectory.ObjectToRaw(surrogate.Value, surrogatecontext);
                SaveRaw(uid, raw);
            }
        }
Example #7
0
        private static IStateObject GetCurrentValue(StateManager stateManager, PropertyInfoEx propEx, IStateObject parentInstance, out string valueRelativeUid, bool isNew = false)
        {
            var propName = GetPropertyName(propEx);

            valueRelativeUid = UniqueIDGenerator.GetRelativeUniqueID(parentInstance, propName);
            //First Try: Let's get the object from the Storage.
            var currentValue = stateManager.GetObject(valueRelativeUid);

            if (currentValue == null)
            {
                var pointerRelativeUid = UniqueIDGenerator.GetPointerRelativeUniqueID(parentInstance, propName);
                //Second try: get the Reference if present.
                currentValue = stateManager.GetObject(pointerRelativeUid, isNew: isNew);
            }
            return(currentValue);
        }
Example #8
0
        internal static void ProcessSetterSimpleTypes(PropertyInfoEx propEx, object parentObject, object newObjectValue, bool isNew = false)
        {
            if (isNew)
            {
                return;
            }
            string propName       = propEx.prop.Name;
            var    parentInstance = (IStateObject)parentObject;
            var    tracker        = StateManager.Current.Tracker;

            // Delta Tracking of modified property
            if (!tracker.IsDirtyModel(parentInstance))
            {
                tracker.MarkAsModified(parentInstance, propEx.propertyPositionIndex);
            }
            var stateManager = StateManager.Current;

            if (!stateManager.flagInBind)
            {
                var bindinguid     = UniqueIDGenerator.GetRelativeUniqueID(parentInstance, propName + StateManager.BindingKey);
                var bindingPointer = StateManager.Current.GetObject(bindinguid) as StateObjectPointer;
                if (bindingPointer != null)
                {
                    var bindingSurrogate = bindingPointer.Target as StateObjectSurrogate;
                    if (bindingSurrogate != null)
                    {
                        var binding = bindingSurrogate.Value as DataBinding;
                        if (binding != null)
                        {
                            var dataSource = binding.DataSourceReference;
                            if (dataSource is StateObjectSurrogate)
                            {
                                var surrogate      = (StateObjectSurrogate)dataSource;
                                var surrogateValue = surrogate.Value;
                                var setter         = SurrogatesDirectory.GetPropertySetter(surrogate.Value);
                                setter(surrogateValue, binding.DataSourceProperty, newObjectValue);
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                    }
                }
            }
        }