예제 #1
0
		public Result<ISourcePage> Insert(ISourcePage aDoc, Result<ISourcePage> aResult)
		{
			ArgCheck.NotNull("aDoc", aDoc);
			Coroutine.Invoke(CreateHelper, aDoc, new Result<ISourcePage>()).WhenDone(
				aResult.Return,
				aResult.Throw
				);
			return aResult;
		}
예제 #2
0
		public Result<ISourcePage> Update(string aSourcePageId, string aSourcePageRev, ISourcePage aDoc, Result<ISourcePage> aResult)
		{
			ArgCheck.NotNull("aDoc", aDoc);
			ArgCheck.NotNullNorEmpty("id", aSourcePageId);
			ArgCheck.NotNullNorEmpty("rev", aSourcePageRev);

			Coroutine.Invoke(UpdateHelper, aSourcePageId, aSourcePageRev, aDoc, new Result<ISourcePage>()).WhenDone(
				aResult.Return,
				aResult.Throw
				);
			return aResult;
		}
        private async void DoRealPageGet(Object voc, ISourcePage <T> page, int pageOffset, int index, CancellationTokenSource cts)
        {
            //Debug.WriteLine("DoRealPageGet: pageOffset=" + pageOffset + " index=" + index);
            VirtualizingObservableCollection <T> realVOC        = (VirtualizingObservableCollection <T>)voc;
            List <PlaceholderReplaceWA <T> >     listOfReplaces = new List <PlaceholderReplaceWA <T> >();

            if (realVOC != null)
            {
                if (cts.IsCancellationRequested)
                {
                    return;
                }

                var data = await ProviderAsync.GetItemsAtAsync(pageOffset, page.ItemsPerPage, false);

                if (cts.IsCancellationRequested)
                {
                    return;
                }

                page.WiredDateTime = data.LoadedAt;

                int i = 0;
                foreach (var item in data.Items)
                {
                    if (cts.IsCancellationRequested)
                    {
                        RemovePageRequest(page.Page);
                        return;
                    }

                    ClearOptimizations();
                    if (page.ReplaceNeeded(i))
                    {
                        var old = page.GetAt(i);
                        if (old == null)
                        {
                        }

                        ClearOptimizations();
                        //Debug.WriteLine("Replacing:" + old.ToString() + " with " + item.ToString());

                        page.ReplaceAt(i, old, item, null, null);
                        //VirtualizationManager.Instance.RunOnUI(new PlaceholderReplaceWA<T>(realVOC, old, item, pageOffset+i));
                        listOfReplaces.Add(new PlaceholderReplaceWA <T>(realVOC, old, item, pageOffset + i));
                    }
                    else
                    {
                        page.ReplaceAt(i, default(T), item, null, null);
                    }

                    i++;
                }
            }

            page.PageFetchState = PageFetchStateEnum.Fetched;

            ClearOptimizations();
            foreach (var replace in listOfReplaces)
            {
                if (cts.IsCancellationRequested)
                {
                    RemovePageRequest(page.Page);
                    return;
                }
                VirtualizationManager.Instance.RunOnUI(replace);
            }

            RemovePageRequest(page.Page);
        }
        /// <summary>
        /// Gets the page, if use placeholders is false - then gets page sync else async.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="allowPlaceholders">if set to <c>true</c> [allow placeholders].</param>
        /// <param name="voc">The voc.</param>
        /// <param name="index">The index that this page refers to (effectively the pageoffset.</param>
        /// <returns></returns>
        protected ISourcePage <T> SafeGetPage(int page, bool allowPlaceholders, object voc, int index)
        {
            ISourcePage <T> ret = null;

            lock (_PageLock)
            {
                if (_Pages.ContainsKey(page))
                {
                    ret = _Pages[page];
                    _Reclaimer.OnPageTouched(ret);
                }
                else
                {
                    PageDelta delta = null;
                    if (_Deltas.ContainsKey(page))
                    {
                        delta = _Deltas[page];
                    }
                    int pageOffset = (page - _BasePage) * this.PageSize + (from d in _Deltas.Values where d.Page < page select d.Delta).Sum();
                    int pageSize   = Math.Min(this.PageSize, this.GetCount(false) - pageOffset);
                    if (delta != null)
                    {
                        pageSize += delta.Delta;
                    }
                    var newPage = this._Reclaimer.MakePage(page, pageSize);
                    _Pages.Add(page, newPage);

                    if (!IsAsync)
                    {
                        FillPage(newPage, pageOffset);

                        ret = newPage;
                    }
                    else
                    {
                        bool up = allowPlaceholders;

                        if (up && voc != null)
                        {
                            // Fill with placeholders
                            //Debug.WriteLine("Filling with placeholders, pagesize=" + pageSize);
                            for (int loop = 0; loop < pageSize; loop++)
                            {
                                newPage.Append(this.ProviderAsync.GetPlaceHolder(index + loop, newPage.Page, loop), null, this.ExpiryComparer);
                            }

                            ret = newPage;

                            CancellationTokenSource cts = StartPageRequest(newPage.Page);
                            Task.Run(() => DoRealPageGet(voc, newPage, pageOffset, index, cts));
                        }
                        else
                        {
                            FillPageFromAsyncProvider(newPage, pageOffset);
                            ret = newPage;
                        }
                    }
                }
            }

            return(ret);
        }
 public SourceFooterBarItems(ISourcePage sourcePage)
 {
     SourcePage = sourcePage;
 }
예제 #6
0
		private Yield CreateHelper(ISourcePage aDoc, Result<ISourcePage> aResult)
		{

			//Check that the sources aren't null and does exists
			yield return Coroutine.Invoke(CheckSource, aDoc, new Result());

			//Insert a the score and return
			Result<ISourcePage> resultCreate = new Result<ISourcePage>();
			yield return theSourcePageDataMapper.Create(aDoc, resultCreate);
			aResult.Return(resultCreate.Value);
		} 
예제 #7
0
		private Yield CheckSource(ISourcePage aSourcePage, Result aResult)
		{
			//can't be null, it must have a source
			if (aSourcePage.SourceId == null)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}

			// if this source exists
			Result<bool> validSourceResult = new Result<bool>();
			yield return Context.Current.Instance.SourceController.Exists(aSourcePage.SourceId, validSourceResult);
			if (!validSourceResult.Value)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}
			aResult.Return();
		}
예제 #8
0
		private Yield UpdateHelper(string id, string rev, ISourcePage aDoc, Result<ISourcePage> aResult)
		{
			//Check if a SourcePage with this id exists.
			Result<ISourcePage> validSourcePageResult = new Result<ISourcePage>();
			yield return theSourcePageDataMapper.Retrieve(aDoc.Id, validSourcePageResult);
			if (validSourcePageResult.Value == null)
			{
				aResult.Throw(new ArgumentException());
				yield break;
			}

			//Check if the source in the SourcePage exist and are not null.
			Coroutine.Invoke(CheckSource, aDoc, new Result());

			//Update and return the updated SourcePage.
			Result<ISourcePage> SourcePageResult = new Result<ISourcePage>();
			yield return theSourcePageDataMapper.Update(id, rev, aDoc, SourcePageResult);
			aResult.Return(SourcePageResult.Value);
		}
예제 #9
0
		public string ToJson(ISourcePage anObject)
		{
			ArgCheck.NotNull("anObject", anObject);
			return theSourcePageDataMapper.ToJson(anObject);
		}