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); }
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); } }
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); } }
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(); } }
public int IndexOfOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item) { return(ProcessIndexOfForMostCases(services, ctx, item)); }
public object GetterOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index) { object item = ProcessIndexGetterForMostCases(services, ctx, index); return(item); }
public bool ContainsOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item) { return(ProcessContainsForMostCases(services, ctx, item)); }
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"); }
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); }
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); }
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"); }
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); } }
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); }
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); }
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); }
public void InsertOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item, int index, object parent) { ProcessInsertionForMostCases(services, ctx, item, index, parent); }
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)); }
public void RemoveAtOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, int index) { ProcessRemoveAtForMostCases(services, ctx, index); }
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); }
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)); } }
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); }
public bool RemoveOperation(IVirtualListServiceDependencies services, IVirtualListContext ctx, object item) { return(ProcessDeletionForValueType(services, ctx, item)); }
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); }