예제 #1
0
        /// <summary>
        /// Show notifications and run any pending WebUI actions
        /// </summary>
        private void Finish()
        {
            Notifications.ChangeTrayText(MessageType.AllSynced);

            // Update the FileLog with all latest changes

            Log.Write(l.Info, "Found in completed list:");
            foreach (var d in _completedList.Where(x => x.Status == StatusType.Success))
            {
                Log.Write(l.Info, string.Format("{0,-40} {1,-10}", d.NewCommonPath, d.Status));
            }

            // Notifications time

            var folders = _completedList.Count(x => x.Item.Type == ClientItemType.Folder && x.Status == StatusType.Success && !x.SkipNotification);
            var files   = _completedList.Count(x => x.Item.Type == ClientItemType.File && x.Status == StatusType.Success && !x.SkipNotification);
            var failed  = _completedList.Count(x => x.Status == StatusType.Failure);

            Log.Write(l.Info, "###############################");
            Log.Write(l.Info, "{0} files successfully synced", files);
            Log.Write(l.Info, "{0} folders successfully synced", folders);
            Log.Write(l.Info, "{0} failed to sync", failed);
            Log.Write(l.Info, "###############################");

            if (folders > 0 && files > 0)
            {
                Notifications.Show(files, folders);
            }
            else if (folders == 1 && files == 0)
            {
                var lastFolder = _completedList.Last(x => x.Item.Type == ClientItemType.Folder && x.Status == StatusType.Success && !x.SkipNotification);
                if (lastFolder.ActionType == ChangeAction.renamed)
                {
                    Notifications.Show(Common._name(lastFolder.CommonPath), ChangeAction.renamed, Common._name(lastFolder.NewCommonPath));
                }
                else
                {
                    Notifications.Show(lastFolder.Item.Name, lastFolder.ActionType, false);
                }
            }
            else if (folders > 0 && files == 0)
            {
                Notifications.Show(folders, false);
            }
            else if (folders == 0 && files == 1)
            {
                var lastFile = _completedList.Last(x => x.Item.Type == ClientItemType.File && x.Status == StatusType.Success && !x.SkipNotification);
                if (lastFile.ActionType == ChangeAction.renamed)
                {
                    Notifications.Show(Common._name(lastFile.CommonPath), ChangeAction.renamed, Common._name(lastFile.NewCommonPath));
                }
                else
                {
                    Notifications.Show(lastFile.Item.Name, lastFile.ActionType, true);
                }
            }
            else if (folders == 0 && files > 1)
            {
                Notifications.Show(files, true);
            }

            // print completed list
            const string frmt = "{0, -9}{1, -20}{2, -8}{3, -8}{4, -7}";
            var          head = string.Format(frmt, "Added On", "Common Path", "Action", "SyncTo", "Status");

            Log.Write(l.Info, head);
            foreach (var i in _completedList.OrderBy(x => x.AddedOn))
            {
                Log.Write(l.Info, string.Format(frmt, i.AddedOn.FormatDate(), i.CommonPath, i.ActionType, i.SyncTo, i.Status));
            }

            _completedList.RemoveAll(x => x.Status != StatusType.Waiting);
            _controller.LoadLocalFolders();

            // Check for any pending WebUI actions
            if (_controller.WebInterface.DeletePending || _controller.WebInterface.UpdatePending)
            {
                _controller.WebInterface.Update();
            }
            else
            {
                if (_controller.Account.SyncMethod == SyncMethod.Automatic)
                {
                    SetTimer();
                }
                Running = false;
            }
        }
예제 #2
0
        public async Task StartQueue()
        {
            var isAutoCheck = this.Count == 1 &&
                              !autoSyncCancelation.IsCancellationRequested &&
                              this.ElementAt(0).Item.FullPath == ".";

            if (!isAutoCheck)
            {
                Notifications.ChangeTrayText(MessageType.Syncing);
            }

            while (this.Count > 0)
            {
                var item   = this.First();
                var status = StatusType.Waiting;
                RemoveAt(0);

                if ((_controller.Account.SyncDirection == SyncDirection.Local && item.SyncTo == SyncTo.Remote) ||
                    (_controller.Account.SyncDirection == SyncDirection.Remote && item.SyncTo == SyncTo.Local))
                {
                    item.SkipNotification = true;
                    status = StatusType.Skipped;
                }
                else
                {
                    // do stuff here
                    switch (item.ActionType)
                    {
                    case ChangeAction.deleted:
                        status = await DeleteItem(item);

                        break;

                    case ChangeAction.renamed:
                        status = await RenameItem(item);

                        break;

                    case ChangeAction.changed:
                    case ChangeAction.created:
                        await Task.Delay(2000);

                        status = await CheckUpdateItem(item);

                        break;
                    }
                }
                item.Status = status;
                _completedList.Add(item, status);

                RemoveLast(item);

                if (this.Count == 0)
                {
                    await Task.Delay(1000);
                }
            }

            Settings.SaveProfile();

            Notifications.ChangeTrayText(MessageType.AllSynced);

            // Notifications time

            var successful = _completedList.Where(x => x.Value == StatusType.Success && !x.Key.SkipNotification).Select(x => x.Key);
            var failed     = _completedList.Values.Count(status => status == StatusType.Failure);
            var folders    = successful.Count(x => x.Item.Type == ClientItemType.Folder);
            var files      = successful.Count(x => x.Item.Type == ClientItemType.File);

            Log.Write(l.Info, "###############################");
            Log.Write(l.Info, "{0} files successfully synced", files);
            Log.Write(l.Info, "{0} folders successfully synced", folders);
            Log.Write(l.Info, "{0} failed to sync", failed);
            Log.Write(l.Info, "###############################");

            if (folders > 0 && files > 0)
            {
                Notifications.Show(files, folders);
            }
            else if ((folders == 1 && files == 0) || (folders == 0 && files == 1))
            {
                var lastItem = files == 1
                    ? successful.Last(x => x.Item.Type == ClientItemType.File)
                    : successful.Last(x => x.Item.Type == ClientItemType.Folder);
                if (lastItem.ActionType == ChangeAction.renamed)
                {
                    Notifications.Show(Common._name(lastItem.CommonPath), ChangeAction.renamed,
                                       Common._name(lastItem.NewCommonPath));
                }
                else
                {
                    Notifications.Show(lastItem.Item.Name, lastItem.ActionType, files == 1);
                }
            }
            else if (!(files == 0 && folders == 0))
            {
                var count = (folders == 0) ? files : folders;
                Notifications.Show(count, folders == 0);
            }

            // print completed list
            const string frmt = "{0, -9}{1, -9}{2, -9}{3, -10}{4}";

            Log.Write(l.Info, string.Format(frmt, "Added On", "Action", "SyncTo", "Status", "Common Path"));

            foreach (var i in _completedList.Keys.OrderBy(x => x.AddedOn))
            {
                Log.Write(l.Info, string.Format(frmt, i.AddedOn.FormatDate(), i.ActionType, i.SyncTo, i.Status, i.CommonPath));
            }

            _completedList.Clear();

            _controller.LoadLocalFolders();

            // Check for any pending WebUI actions
            if (_controller.WebInterface.DeletePending || _controller.WebInterface.UpdatePending)
            {
                await _controller.WebInterface.Update();
            }
            else
            {
                if (_controller.Account.SyncMethod == SyncMethod.Automatic)
                {
                    await ScheduleAutoSync();
                }
                Running = false;
            }
        }