Beispiel #1
0
        public bool RemoveOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            bool removed = false;

            if (typeof(IStateObject).IsAssignableFrom(item.GetType()))
            {
                removed = ProcessDeletionForMostCases(services, ctx, item);
            }
            else if (item.GetType().IsValueType || item.GetType() == typeof(String))
            {
                removed = ProcessDeletionForValueType(services, ctx, item);
            }
            else if (services.SurrogateManager.IsSurrogateRegistered(item.GetType()))
            {
                IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);
                if (baptizedItem != null)
                {
                    removed = ProcessDeletionForMostCases(services, ctx, baptizedItem);
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(removed);
        }
        public bool RemoveOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            //The item is a pure object, which is not yet be encapsulated into a StateObjectSurrogate
            //We are going to baptize the item
            IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);

            return(ProcessDeletionForMostCases(services, ctx, baptizedItem));
        }
        public void SetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index, object value)
        {
            IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(value, true);

            if (baptizedItem != null)
            {
                this.ProcessIndexSetterForMostCases(services, ctx, index, baptizedItem);
            }
        }
        public void InsertOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item, int index, object parent)
        {
            //The item is a pure object, which is not yet be encapsulated into a StateObjectSurrogate
            //We are going to baptize the item
            IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);

            //Should I register a Posible orphan for this baptizedItem?
            services.SurrogateManager.AddSurrogateReference(baptizedItem, (IStateObject)parent);

            ProcessInsertionForMostCases(services, ctx, baptizedItem, index, parent);
        }
Beispiel #5
0
 public void InsertOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item, int index, object parent)
 {
     if (services.SurrogateManager.IsSurrogateRegistered(item.GetType()))
     {
         IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);
         services.SurrogateManager.AddSurrogateReference(baptizedItem, (IStateObject)parent);
         ProcessInsertionForMostCases(services, ctx, baptizedItem, index, parent);
     }
     else
     {
         ProcessInsertionForMostCases(services, ctx, item, index, parent);
     }
 }
Beispiel #6
0
        public object GetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
        {
            object item = ProcessIndexGetterForMostCases(services, ctx, index);

            if (typeof(IStateObjectSurrogate).IsAssignableFrom(item.GetType()))
            {
                return(((IStateObjectSurrogate)item).Value);
            }
            else
            {
                return(item);
            }
        }
Beispiel #7
0
 public int IndexOfOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     if (typeof(IStateObject).IsAssignableFrom(item.GetType()))
     {
         return(ProcessIndexOfForMostCases(services, ctx, item));
     }
     else if (item.GetType().IsValueType || item.GetType() == typeof(String))
     {
         return(ProcessIndexOfForValueType(services, ctx, item));
     }
     else if (services.SurrogateManager.IsSurrogateRegistered(item.GetType()))
     {
         IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);
         return(ProcessIndexOfForMostCases(services, ctx, baptizedItem));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Beispiel #8
0
 public int IndexOfOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     return(ProcessIndexOfForMostCases(services, ctx, item));
 }
Beispiel #9
0
        public object GetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
        {
            object item = ProcessIndexGetterForMostCases(services, ctx, index);

            return(item);
        }
Beispiel #10
0
 public bool ContainsOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     return(ProcessContainsForMostCases(services, ctx, item));
 }
Beispiel #11
0
        protected void ProcessRemoveAtForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
        {
            ValidateIndexOutOfRange(ctx.pageIndexes, index);

            // Get the page's unique id that is located the index
            string pageUniqueID = ctx.pageIndexes[index] as string;

            // Loads the page from storage or from cache
            Page page = services.Pager.LoadPage(pageUniqueID);

            // Get the initial index of the corresponding page
            int pageIndex = ctx.initialIndexDictionary[page.UniqueID];

            // Get the real index inside the page
            int indexInsidePage = index - pageIndex;

            // Get the object related with the index
            LazyObject obj = (LazyObject)page.GetAtSafe(indexInsidePage);

            var stateobject = obj.Target as IStateObject;

            if (stateobject != null)
            {
                // Unsubscribes the object from the page's reference table
                services.ReferenceManager.UnSubscribe(page, stateobject.UniqueID);
            }

            // Removes the object from the stored objects
            page.RemoveAtSafe(indexInsidePage);

            // Updates the indexes of the Initial Index Dictionary
            UpdateIndexDictionary(page, pageIndex, -1, ctx.pageIndexes, ctx.initialIndexDictionary);

            ctx.pageIndexes.RemoveAt(index);

            //Mark the page as dirty in order to be serialized again
            services.StateManager.MarkAsDirty(page, "StoredObjects");
        }
Beispiel #12
0
 protected int ProcessIndexOfForValueType(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     foreach (var pageId in ctx.initialIndexDictionary.Keys)
     {
         Page          p   = services.Pager.LoadPage(pageId);
         List <object> l   = WakeUpTheLazyObjectsInsideThePage(p.GetStoredObjectsSafe());
         int           idx = l.IndexOf(item);
         if (idx >= 0)
         {
             int initialIndex = ctx.initialIndexDictionary[p.UniqueID];
             return(initialIndex + idx);
         }
     }
     return(-1);
 }
Beispiel #13
0
 public void SetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index, object value)
 {
     this.ProcessIndexSetterForMostCases(services, ctx, index, value);
 }
        public object GetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
        {
            IStateObjectSurrogate item = (IStateObjectSurrogate)ProcessIndexGetterForMostCases(services, ctx, index);

            return(item.Value);
        }
Beispiel #15
0
        protected void ProcessIndexSetterForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index, object value)
        {
            ValidateIndexOutOfRange(ctx.pageIndexes, index);

            // Get the page's unique id that is located the index
            string pageUniqueID = ctx.pageIndexes[index] as string;

            // Loads the page from storage or from cache
            Page page = services.Pager.LoadPage(pageUniqueID);

            // Get the initial index of the corresponding page
            int pageIndex = ctx.initialIndexDictionary[page.UniqueID];

            // Get the real index inside the page
            int indexInsidePage = index - pageIndex;

            // Get the object related with the index
            LazyObject obj = (LazyObject)page.GetAtSafe(indexInsidePage);

            var stateobject = obj.Target as IStateObject;

            if (stateobject != null)
            {
                //Detach the reference
                services.ReferenceManager.UnSubscribe(page, stateobject.UniqueID);
            }

            var elementToSet = value as IStateObject;

            if (elementToSet != null)
            {
                if (!services.StateManager.IsStateObjectAttached(elementToSet))
                {
                    services.StateManager.PromoteObject(elementToSet, services.UniqueIdGenerator.GetPageItemUniqueID());
                    page.SetAtSafe(indexInsidePage, GetLazyObjectFor(elementToSet, services.StateManager));
                }
                else if (!services.StateManager.IsStateObjectAllAttached(elementToSet))
                {
                    page.SetAtSafe(indexInsidePage, GetLazyObjectFor(elementToSet, services.StateManager));
                }
                else
                {
                    //Is all branches attached
                    page.SetAtSafe(indexInsidePage, GetLazyObjectFor(elementToSet, services.StateManager));
                }
                //Subscribe to IReferenceManager in order to listen reference changes updates.
                SubscribeToReferenceManager(services.ReferenceManager, page, elementToSet);
            }
            else
            {
                //Assign the new value
                page.SetAtSafe(indexInsidePage, GetLazyObjectFor(value, services.StateManager));
            }
            services.StateManager.MarkAsDirty(page, "StoredObjects");
        }
Beispiel #16
0
        private IEnumerable <Page> GivenAnItemGetThePagesThatHoldsAReferenceOfTheItem(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            //Given the value, first we need to retrieve its Reference Table.
            IReferenceTable refTable = services.ReferenceManager.GetReferenceTable(item);

            if (refTable != null)
            {
                //Given a ReferenceTable, returns the page that matches with the item's unique id
                IEnumerable <Page> pages = GetPageFromReferenceTable(refTable, item, ctx.initialIndexDictionary, services.Pager);
                return(pages);
            }
            else
            {
                return(null);
            }
        }
Beispiel #17
0
        protected bool ProcessDeletionForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            IEnumerable <Page> pages = GivenAnItemGetThePagesThatHoldsAReferenceOfTheItem(services, ctx, item);

            if (pages == null)
            {
                return(false);
            }
            Page p;

            //Delete the item inside the page
            RemoveObjectFromPage(item, pages, services.StateManager, out p);
            if (p != null)
            {
                //Unsubscribe to the ReferenceManager
                UnSubscribeToReferenceManager(services.ReferenceManager, p, item);

                //Update the Dictionary if needed
                UpdateIndexDictionary(p, ctx.pageIndexes.LastIndexOf(p.UniqueID), -1, ctx.pageIndexes, ctx.initialIndexDictionary);

                ctx.pageIndexes.Remove(p.UniqueID);
            }
            else
            {
                //Item nof found in all the pages.
                return(false);
            }
            return(true);
        }
Beispiel #18
0
        protected void ProcessInsertionForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item, int index, object parent)
        {
            ValidateIndexOutOfRange(ctx.pageIndexes, index);

            int pageIndex;
            //1.If there is no pages in the list, create a new page, otherwise retrieve the correct page
            Page page = GetPage(ctx.pageIndexes, services.Pager, index, ctx.initialIndexDictionary, out pageIndex, parent);

            //2.Update the Page Indexes array
            UpdatePageIndexesArray(ctx.pageIndexes, index, page);

            //3.Subscribe to IReferenceManager in order to listen reference changes updates.
            SubscribeToReferenceManager(services.ReferenceManager, page, item);

            //4.Insert the IStateObject into the correct position of the array of IStateObject of the Page.
            int InitialIndexOfThePage = GetInitialIndexOfThePage(pageIndex, ctx.initialIndexDictionary, ctx.pageIndexes);

            InsertElementToPage(index, item, page, InitialIndexOfThePage, services.StateManager, services.UniqueIdGenerator, services.ServerEventAggregator);

            //5.Update the Initial Index of all the pages that is located at right of the current page
            UpdateIndexDictionary(page, pageIndex, 1, ctx.pageIndexes, ctx.initialIndexDictionary);
        }
Beispiel #19
0
 protected bool ProcessDeletionForValueType(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     foreach (var pageId in ctx.initialIndexDictionary.Keys)
     {
         Page          p       = services.Pager.LoadPage(pageId);
         List <object> l       = WakeUpTheLazyObjectsInsideThePage(p.GetStoredObjectsSafe());
         var           idx     = l.IndexOf(item);
         bool          removed = false;
         if (idx >= 0)
         {
             p.RemoveAtSafe(idx);
             removed = true;
         }
         if (removed)
         {
             UpdateIndexDictionary(p, ctx.pageIndexes.LastIndexOf(p.UniqueID), -1, ctx.pageIndexes, ctx.initialIndexDictionary);
             ctx.pageIndexes.Remove(p.UniqueID);
             services.StateManager.MarkAsDirty(p, "StoredObjects");
             return(true);
         }
     }
     return(false);
 }
Beispiel #20
0
 public void InsertOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item, int index, object parent)
 {
     ProcessInsertionForMostCases(services, ctx, item, index, parent);
 }
Beispiel #21
0
 public bool RemoveOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object value)
 {
     return(ProcessDeletionForMostCases(services, ctx, value));
 }
        public int IndexOfOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            IStateObjectSurrogate baptizedItem = services.SurrogateManager.GetStateObjectSurrogate(item, true);

            return(ProcessIndexOfForMostCases(services, ctx, baptizedItem));
        }
Beispiel #23
0
 public void RemoveAtOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
 {
     ProcessRemoveAtForMostCases(services, ctx, index);
 }
Beispiel #24
0
        protected object ProcessIndexGetterForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index)
        {
            ValidateIndexOutOfRange(ctx.pageIndexes, index);
            // Get the page's unique id that is located the index
            string pageUniqueID = ctx.pageIndexes[index] as string;
            // Loads the page from storage or from cache
            Page page = services.Pager.LoadPage(pageUniqueID);
            // Get the initial index of the corresponding page
            int pageIndex = ctx.initialIndexDictionary[page.UniqueID];
            // Get the real index inside the page
            int indexInsidePage = index - pageIndex;
            // Get the object related with the index
            LazyObject obj = (LazyObject)page.GetAtSafe(indexInsidePage);

            return(obj.Target);
        }
Beispiel #25
0
        protected bool ProcessContainsForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            IEnumerable <Page> pages = GivenAnItemGetThePagesThatHoldsAReferenceOfTheItem(services, ctx, item);

            if (pages == null)
            {
                return(false);
            }
            else
            {
                return(FindItemInAllFoundPages(item, pages));
            }
        }
Beispiel #26
0
        protected int ProcessIndexOfForMostCases(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
        {
            IEnumerable <Page> pages = GivenAnItemGetThePagesThatHoldsAReferenceOfTheItem(services, ctx, item);

            if (pages == null)
            {
                return(-1);
            }
            Page p;
            int  idx = FindItemInAllFoundPagesAndReturnTheIndex(item, pages, out p);

            if (idx >= 0)
            {
                int initialIndex = ctx.initialIndexDictionary[p.UniqueID];
                return(initialIndex + idx);
            }
            return(-1);
        }
Beispiel #27
0
 public bool RemoveOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     return(ProcessDeletionForValueType(services, ctx, item));
 }
Beispiel #28
0
 protected bool ProcessContainsForValueType(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item)
 {
     foreach (var pageId in ctx.initialIndexDictionary.Keys)
     {
         Page          p        = services.Pager.LoadPage(pageId);
         List <object> l        = WakeUpTheLazyObjectsInsideThePage(p.GetStoredObjectsSafe());
         bool          contains = l.Contains(item);
         if (contains)
         {
             return(true);
         }
     }
     return(false);
 }