コード例 #1
0
        private void StartCreateWorkers()
        {
            Worker worker = null;

            for (int i = 0; (worker = MakeNextWorker()) != null; i++)
            {
                NewWorkerReady?.Invoke(worker);
            }

            if (itemsForSync.Count == 0)
            {
                StartSyncTimer();
            }
        }
コード例 #2
0
        private void OnWorkerCompleted(Worker worker, ProgressableEventArgs args)
        {
            logger.Info("{0} completed with success = {1}", worker.TaskName, args.Successfull);

            if (args.Successfull == false)
            {
                if (args.Error is WebException)
                {
                    WebException ex       = args.Error as WebException;
                    var          response = ex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        switch ((int)response.StatusCode)
                        {
                            //case: HttpStatusCode.Unauthorized
                        }
                    }
                    worker.Status = "Attempt";
                }
                if (args.Error is HttpRequestException)
                {
                    logger.Error(args.Error, worker.TaskName);
                }
                if (args.Error is TaskCanceledException || args.Error is OperationCanceledException)
                {
                    logger.Error(args.Error, worker.TaskName);
                }
                if (args.Error is DismantileWorkerException || args.Error is FileMismatchSizeException)
                {
                    itemsForSync.Enqueue(worker.SyncItem);
                    return;
                }
            }

            var copyWorker = worker as CopyFileWorker;

            if (copyWorker != null)
            {
                if (args.Successfull)
                {
                    App.NotificationSender.Value.NotifyDownLoadSuccess(Owner.UserData, copyWorker.DestinationFullFilePath);
                }
                else
                {
                    App.NotificationSender.Value.NotifyDownLoadFailed(Owner.UserData, copyWorker.SyncItem.Name, args.Error.ToString());
                }
            }

            if ((Suspended || !IsActive) && worker.SyncItem.CurrentState == SyncState.RemovedFromCloud)
            {
                return;
            }
            var newWorker = MakeNextWorker(worker.SyncItem.CurrentState != SyncState.RemovedFromCloud && args.Successfull ? worker.SyncItem : null);

            if (newWorker != null)
            {
                NewWorkerReady?.Invoke(newWorker);
            }
            else
            {
                if (!string.IsNullOrEmpty(nextLink))
                {
                    string linkForLoad = nextLink;
                    nextLink = null;
                    Sync(linkForLoad);
                }
                else
                {
                    StartSyncTimer();
                }
            }
        }