示例#1
0
        protected override void ProcessCompletedTask(AsyncDataSourcePageTaskHolder completedTask, int currentDelay, int pageIndex, AsyncVirtualDataSourceProviderTaskDataHolder taskDataHolder)
        {
            SQLiteVirtualDataSourceProviderTaskDataHolder h = (SQLiteVirtualDataSourceProviderTaskDataHolder)taskDataHolder;
            IDataSourceSchema           schema = null;
            SQLiteDataSourceQueryResult result = null;
            int schemaFetchCount = -1;

            try
            {
                if (pageIndex == SchemaRequestIndex)
                {
                    Task <int> task = (Task <int>)completedTask.Task;

                    schemaFetchCount = task.Result;
                }
                else
                {
                    Task <SQLiteDataSourceQueryResult> task = (Task <SQLiteDataSourceQueryResult>)completedTask.Task;

                    result = task.Result;
                }
            }
            catch (AggregateException e)
            {
                bool allCancels = true;
                foreach (var ex in e.Flatten().InnerExceptions)
                {
                    if (!(ex is TaskCanceledException))
                    {
                        allCancels = false;
                    }
                }
                if (!allCancels)
                {
                    RetryIndex(pageIndex, currentDelay);
                    return;
                }
                else
                {
                    RetryIndex(pageIndex, currentDelay);
                    return;
                }
            }
            catch (TaskCanceledException e)
            {
                RetryIndex(pageIndex, currentDelay);
                //TODO: other exceptions? Is there a way to skip this state for canceled stuff?
                return;
            }

            IDataSourceExecutionContext  executionContext;
            DataSourcePageLoadedCallback pageLoaded;

            ISectionInformation[] groupInformation = null;

            lock (SyncLock)
            {
                if (schemaFetchCount >= 0)
                {
                    ActualCount = schemaFetchCount;
                }
                else
                {
                    ActualCount = result.FullCount;
                }

                schema           = ActualSchema;
                groupInformation = _groupInformation;
            }

            if (schema == null)
            {
                schema = ResolveSchema();
            }

            lock (SyncLock)
            {
                ActualSchema     = schema;
                executionContext = ExecutionContext;
                pageLoaded       = PageLoaded;
            }

            SQLiteDataSourcePage page = null;

            if (result != null)
            {
                page = new SQLiteDataSourcePage(result, schema, groupInformation, pageIndex);
                lock (SyncLock)
                {
                    if (!IsLastPage(pageIndex) && page.Count() > 0 && !PopulatedActualPageSize)
                    {
                        PopulatedActualPageSize = true;
                        ActualPageSize          = page.Count();
                    }
                }
            }
            else
            {
                page = new SQLiteDataSourcePage(null, schema, groupInformation, pageIndex);
            }

            if (PageLoaded != null)
            {
                if (ExecutionContext != null)
                {
                    if (executionContext == null || pageLoaded == null)
                    {
                        Shutdown();
                        return;
                    }

                    executionContext.Execute(() =>
                    {
                        pageLoaded(page, ActualCount, ActualPageSize);
                    });
                }
                else
                {
                    if (pageLoaded == null)
                    {
                        Shutdown();
                        return;
                    }

                    pageLoaded(page, ActualCount, ActualPageSize);
                }
            }
        }
示例#2
0
        protected override AsyncVirtualDataSourceProviderTaskDataHolder GetTaskDataHolder()
        {
            SQLiteVirtualDataSourceProviderTaskDataHolder holder = new SQLiteVirtualDataSourceProviderTaskDataHolder();

            return(holder);
        }