Ejemplo n.º 1
0
 /// <summary>
 /// Limpa uma página.
 /// </summary>
 /// <param name="data"></param>
 protected virtual void ClearPage(VirtualListLoaderResult <T> data)
 {
     if (data == null)
     {
         throw new InvalidOperationException("LoadResult cannot be null.");
     }
     if ((data.UpdateCount && (_count == 0 || _count != data.NewCount)) || !InstanceInitialized)
     {
         _count = data.NewCount;
         int numberSessions = PageSize == 0 || _count == 0 ? 1 : (int)Math.Ceiling(_count / (double)PageSize);
         if (Sessions != null)
         {
             for (int i = 0; i < Sessions.Length; i++)
             {
                 if (Sessions[i] != null)
                 {
                     Sessions[i].Dispose();
                     Sessions[i] = null;
                 }
             }
         }
         Sessions = new IDataPage <T> [numberSessions];
         _version++;
         RaisePropertyChanged("Count");
         RaiseCollectionReset();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Método assíncrono que faz a carga da contagem.
        /// </summary>
        /// <param name="args"></param>
        private void LoadCountWork(object args)
        {
            var loaderArgs = (VirtualListLoaderEventArgs)args;
            VirtualListLoaderResult <DataWrapper <T> > result = null;

            if (Loader != null)
            {
                try
                {
                    result = Loader.Load(this, loaderArgs.StartRow, loaderArgs.PageSize, loaderArgs.NeedItemsCount, loaderArgs.ReferenceObject);
                }
                catch (Exception ex)
                {
                    result = new VirtualListLoaderResult <DataWrapper <T> >(ex);
                }
            }
            else
            {
                result = new VirtualListLoaderResult <DataWrapper <T> >(new DataWrapper <T> [0], 0);
            }
            if (_synchronizationContext != null)
            {
                _synchronizationContext.Send(LoadCountCompleted, new object[] {
                    loaderArgs,
                    result
                });
            }
            if (result.Error != null)
            {
                OnAsyncVirtualListError(result.Error);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Define a contagem inicial.
        /// </summary>
        /// <param name="count"></param>
        internal void SetInitialCount(int count)
        {
            var result = new VirtualListLoaderResult <DataWrapper <T> >(null, count);

            ClearPage(result);
            InstanceInitialized = true;
            RaiseCollectionReset();
            RaisePropertyChanged("Count");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Popula uma página.
        /// </summary>
        /// <param name="data">Dados a se popular.</param>
        /// <param name="index">Índice da página.</param>
        protected virtual void PopulatePage(VirtualListLoaderResult <T> data, int index)
        {
            ClearPage(data);
            int sessionIndex = PageSize == 0 ? 0 : (int)Math.Floor(index / (double)PageSize);
            var page         = CreateDataPage(sessionIndex);

            page.Populate(data.Items);
            Sessions[sessionIndex] = page;
            OnDataPageLoaded(new DataPageLoadedEventArgs <T>(page));
        }