예제 #1
0
        /// <summary>
        /// Moves the last item from the queue to the CompletedList and adds it to FileLog
        /// </summary>
        /// <param name="status"></param>
        public void RemoveLast(StatusType status)
        {
            _completedList.Add(new SyncQueueItem(_controller)
            {
                Status           = status,
                Item             = Next.Item,
                ActionType       = Next.ActionType,
                AddedOn          = Next.AddedOn,
                CompletedOn      = DateTime.Now,
                SkipNotification = Next.SkipNotification
            });
            // Add last item to FileLog
            if (status == StatusType.Success)
            {
                switch (Next.Item.Type)
                {
                case ClientItemType.Folder:
                    switch (Next.ActionType)
                    {
                    case ChangeAction.deleted:
                        _controller.FileLog.RemoveFolder(Next.CommonPath);
                        break;

                    case ChangeAction.renamed:
                        _controller.FileLog.PutFolder(Next.NewCommonPath, Next.CommonPath);
                        break;

                    default:
                        _controller.FileLog.PutFolder(Next.CommonPath);
                        break;
                    }
                    break;

                case ClientItemType.File:
                    switch (Next.ActionType)
                    {
                    case ChangeAction.deleted:
                        _controller.RemoveFromLog(Next.CommonPath);
                        break;

                    case ChangeAction.renamed:
                        _controller.RemoveFromLog(Next.CommonPath);
                        _controller.FileLog.PutFile(Next);
                        break;

                    default:
                        _controller.FileLog.PutFile(Next);
                        break;
                    }
                    break;
                }
            }
            // Remove from queue
            RemoveAt(0);
        }
예제 #2
0
 /// <summary>
 /// Moves the last item from the queue to the CompletedList and adds it to FileLog
 /// </summary>
 /// <param name="status"></param>
 public void RemoveLast(StatusType status)
 {
     CompletedList.Add(new SyncQueueItem(controller)
     {
         Status           = status,
         Item             = Next.Item,
         ActionType       = Next.ActionType,
         AddedOn          = Next.AddedOn,
         CompletedOn      = DateTime.Now,
         SkipNotification = Next.SkipNotification
     });
     // Add last item to FileLog
     if (status == StatusType.Success)
     {
         if (Next.Item.Type == ClientItemType.Folder)
         {
             if (Next.ActionType == ChangeAction.deleted)
             {
                 controller.FileLog.removeFolder(Next.CommonPath);
             }
             else if (Next.ActionType == ChangeAction.renamed)
             {
                 controller.FileLog.putFolder(Next.NewCommonPath, Next.CommonPath);
             }
             else
             {
                 controller.FileLog.putFolder(Next.CommonPath);
             }
         }
         else if (Next.Item.Type == ClientItemType.File)
         {
             if (Next.ActionType == ChangeAction.deleted)
             {
                 controller.RemoveFromLog(Next.CommonPath);
             }
             else if (Next.ActionType == ChangeAction.renamed)
             {
                 controller.RemoveFromLog(Next.CommonPath);
                 controller.FileLog.putFile(Next);
             }
             else
             {
                 controller.FileLog.putFile(Next);
             }
         }
     }
     // Remove from queue
     RemoveAt(0);
 }
예제 #3
0
        /// <summary>
        /// Moves the last item from the queue to the CompletedList and adds it to FileLog
        /// </summary>
        /// <param name="item"></param>
        public void RemoveLast(SyncQueueItem item)
        {
            item.CompletedOn = DateTime.Now;

            // Add last item to FileLog
            if (item.Status == StatusType.Success)
            {
                if (item.Item.Type == ClientItemType.Folder)
                {
                    switch (item.ActionType)
                    {
                    case ChangeAction.deleted:
                        _controller.FileLog.RemoveFolder(item.CommonPath);
                        break;

                    case ChangeAction.renamed:
                        _controller.FileLog.PutFolder(item.NewCommonPath, item.CommonPath);
                        break;

                    default:
                        _controller.FileLog.PutFolder(item.CommonPath);
                        break;
                    }
                }
                else if (item.Item.Type == ClientItemType.File)
                {
                    switch (item.ActionType)
                    {
                    case ChangeAction.deleted:
                        _controller.RemoveFromLog(item.CommonPath);
                        break;

                    case ChangeAction.renamed:
                        _controller.RemoveFromLog(item.CommonPath);
                        _controller.FileLog.PutFile(item);
                        break;

                    default:
                        _controller.FileLog.PutFile(item);
                        break;
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Update log, 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.ToString()));

                if (d.Item.Type == ClientItemType.Folder)
                {
                    if (d.ActionType == ChangeAction.deleted)
                    {
                        controller.FileLog.removeFolder(d.CommonPath);
                    }
                    else if (d.ActionType == ChangeAction.renamed)
                    {
                        controller.FileLog.putFolder(d.NewCommonPath, d.CommonPath);
                    }
                    else
                    {
                        controller.FileLog.putFolder(d.CommonPath);
                    }
                }
                else if (d.Item.Type == ClientItemType.File)
                {
                    if (d.ActionType == ChangeAction.deleted)
                    {
                        controller.RemoveFromLog(d.CommonPath);
                    }
                    else if (d.ActionType == ChangeAction.renamed)
                    {
                        controller.RemoveFromLog(d.CommonPath);
                        controller.FileLog.putFile(d);
                    }
                    else
                    {
                        controller.FileLog.putFile(d);
                    }
                }
            }

            // Notifications time

            int folders = CompletedList.Count(x => x.Item.Type == ClientItemType.Folder && x.Status == StatusType.Success && !x.SkipNotification);
            int files   = CompletedList.Count(x => x.Item.Type == ClientItemType.File && x.Status == StatusType.Success && !x.SkipNotification);
            int 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}";
            string       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.ToString(), i.SyncTo.ToString(), i.Status.ToString()));
            }

            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;
            }
        }