Пример #1
0
 public SyncElementExecutionInfo(SyncElementInfo syncElementInfo, SyncDirection dir, bool remove)
 {
     SyncElementInfo = syncElementInfo;
     SyncElementInfo.SyncExecutionInfo = this;
     Direction = dir;
     Remove    = remove;
     SyncElementInfo.SyncStatus = SyncElementStatus.ChangeFound;
 }
Пример #2
0
 public SyncElementExecutionInfo(SyncElementInfo syncElementInfo, SyncDirection dir, bool remove)
 {
     SyncElementInfo = syncElementInfo;
     SyncElementInfo.SyncExecutionInfo = this;
     Direction = dir;
     Remove = remove;
     SyncElementInfo.SyncStatus = SyncElementStatus.ChangeFound;
 }
Пример #3
0
 /// <summary>
 /// create ElementConflictInfo
 /// </summary>
 /// <param name="type"></param>
 /// <param name="conflictPath"></param>
 /// <param name="context"></param>
 /// <param name="message"></param>
 /// <param name="exception"></param>
 protected ElementConflictInfo(SyncElementInfo syncElementInfo, ConflictType type, int conflictPath, string context, string message, Exception exception)
 {
     SyncElementInfo = syncElementInfo;
     Type = type;
     ConflictPath = conflictPath;
     Context = context;
     Message = message;
     Exception = exception;
 }
Пример #4
0
 /// <summary>
 /// create ElementConflictInfo
 /// </summary>
 /// <param name="type"></param>
 /// <param name="conflictPath"></param>
 /// <param name="context"></param>
 /// <param name="message"></param>
 /// <param name="exception"></param>
 protected ElementConflictInfo(SyncElementInfo syncElementInfo, ConflictType type, int conflictPath, string context, string message, Exception exception)
 {
     SyncElementInfo = syncElementInfo;
     Type            = type;
     ConflictPath    = conflictPath;
     Context         = context;
     Message         = message;
     Exception       = exception;
 }
Пример #5
0
 public void DetectingEnded(SyncElementInfo sei)
 {
     if (typeof(SyncFileInfo) == sei.GetType())
     {
         _filesDetectedCount++;
     }
     else
     {
         _dirsDetectedCount++;
     }
 }
Пример #6
0
        public void SyncElementStatusChanged(SyncElementInfo sei)
        {
            bool isFile = typeof(SyncFileInfo) == sei.GetType();

            switch (sei.SyncStatus)
            {
                case SyncElementStatus.ElementFound:
                    if (isFile)
                    {
                        _filesFoundCount++;
                        DirTree.AddFile((MyFileInfo)sei.ElementInfo);
                    }
                    else
                    {
                        _dirsFoundCount++;
                        DirTree.AddDir((MyDirInfo)sei.ElementInfo);
                    }
                    break;
                case SyncElementStatus.ChangeDetectingStarted:

                    break;
                case SyncElementStatus.NoChangeFound:

                    break;
                case SyncElementStatus.ChangeFound:
                    if (isFile)
                    {
                        SyncFileExecutionInfos.Add((SyncFileExecutionInfo)sei.SyncExecutionInfo);

                        if (sei.SyncExecutionInfo.Remove)
                        {
                            _filesToRemoveCount++;
                            _filesTotalSizeToRemove += ((MyFileInfo)sei.ElementInfo).Size;
                        }
                        else
                        {
                            _filesToCopyCount++;
                            _filesTotalSizeToCopy += ((MyFileInfo)sei.ElementInfo).Size;
                        }
                    }
                    else
                    {
                        SyncDirExecutionInfos.Add((SyncDirExecutionInfo)sei.SyncExecutionInfo);

                        if (sei.SyncExecutionInfo.Remove)
                            _dirsToRemoveCount++;
                        else
                            _dirsToCreateCount++;
                    }
                    break;
                case SyncElementStatus.ChangeApplied:
                    if (isFile)
                    {
                        if (sei.SyncExecutionInfo.Remove)
                        {
                            _fileSizeRemoved += ((SyncFileInfo)sei).FileInfo.Size;
                            _filesRemovedCount++;
                        }
                        else
                        {
                            _fileSizeCopied += ((SyncFileInfo)sei).FileInfo.Size;
                            _filesCopiedCount++;
                        }
                    }
                    else
                    {
                        if (sei.SyncExecutionInfo.Remove)
                            _dirsRemovedCount++;
                        else
                            _dirsCreatedCount++;
                    }
                    break;
                case SyncElementStatus.Conflicted:
                    ConflictInfos.Add(sei.ConflictInfo);
                    break;
            }

            _listener?.OnSyncElementStatusChanged(sei);
        }
Пример #7
0
 public void DetectingEnded(SyncElementInfo sei)
 {
     if (typeof(SyncFileInfo) == sei.GetType())
         _filesDetectedCount++;
     else
         _dirsDetectedCount++;
 }
Пример #8
0
        public void OnSyncElementStatusChanged(SyncElementInfo sei)
        {
            bool isFile = typeof(SyncFileInfo) == sei.GetType();

            switch (sei.SyncStatus)
            {
                case SyncElementStatus.ElementFound:
                    
                    //update treeview
                    TreeNodeCollection tnc = treeView1.Nodes;
                    TreeNode treeNode;
                    for (int i = 0; i < sei.ElementInfo.TreePath.Count; i++)
                    {
                        treeNode = tnc[sei.ElementInfo.TreePath[i].Info.Name];
                        if (treeNode == null)
                            return;

                        tnc = treeNode.Nodes;
                    }
                    treeView1.Invoke(new Action(() =>
                    {
                        if (isFile)
                            AddFileTreeNode(tnc, (MyFileInfo)sei.ElementInfo);
                        else
                            AddDirTreeNode(tnc, (MyDirInfo)sei.ElementInfo);
                    }));
                        
                    break;
                case SyncElementStatus.ChangeDetectingStarted:
                    Console.WriteLine("Start detecting file:" + sei.ElementInfo.FullPath);
                    break;
                case SyncElementStatus.NoChangeFound:

                    break;
                case SyncElementStatus.ChangeFound:
                    TreeNode tn1 = getTreeNode(sei.ElementInfo);
                    if (tn1 == null)
                        break;
                    tn1.ForeColor = Color.Blue;
                    
                    if (tn1 != null)
                        treeView1.Invoke( new Action(() => {
                            foreach (TreeNode ptn in NextParentNode(tn1))
                                ptn.Text = ptn.Text + " - #cf";
                        }));
                    
                    if (isFile)
                    {
                        Console.WriteLine("file change detected:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                    }
                    else
                    {
                        Console.WriteLine("directory change detected:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                    }
                    break;
                case SyncElementStatus.ChangeApplied:
                    TreeNode tn2 = getTreeNode(sei.ElementInfo);
                    if (tn2 != null)
                        treeView1.Invoke(new Action(() => {
                            foreach (TreeNode ptn in NextParentNode(tn2))
                                ptn.Text = ptn.Text + " - #ca";
                        }));

                    if (isFile)
                    {
                        if (sei.SyncExecutionInfo.Remove)
                            Console.WriteLine("file deleted:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                        else
                            Console.WriteLine("file copied:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                    }
                    else
                    {
                        if (sei.SyncExecutionInfo.Remove)
                            Console.WriteLine("directory removed:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                        else
                            Console.WriteLine("Directory created:" + sei.SyncExecutionInfo.AbsoluteDestPath);
                    }
                    break;
                case SyncElementStatus.Conflicted:
                    string elementType = isFile ? "file" : "dir";
                    string conflictType = "";
                    switch (sei.ConflictInfo.Type)
                    {
                        case ConflictType.IO:
                            conflictType = "IO";
                            break;
                        case ConflictType.UA:
                            conflictType = "Access Denied";
                            break;
                        case ConflictType.Unknown:
                            conflictType = "Unknown";
                            break;
                    }

                    AddLogLine($"Conflict ({conflictType}) at {elementType}: {sei.ConflictInfo.GetAbsolutePath()}");
                    break;
            }
        }
Пример #9
0
        public void SyncElementStatusChanged(SyncElementInfo sei)
        {
            bool isFile = typeof(SyncFileInfo) == sei.GetType();

            switch (sei.SyncStatus)
            {
            case SyncElementStatus.ElementFound:
                if (isFile)
                {
                    _filesFoundCount++;
                    DirTree.AddFile((MyFileInfo)sei.ElementInfo);
                }
                else
                {
                    _dirsFoundCount++;
                    DirTree.AddDir((MyDirInfo)sei.ElementInfo);
                }
                break;

            case SyncElementStatus.ChangeDetectingStarted:

                break;

            case SyncElementStatus.NoChangeFound:

                break;

            case SyncElementStatus.ChangeFound:
                if (isFile)
                {
                    SyncFileExecutionInfos.Add((SyncFileExecutionInfo)sei.SyncExecutionInfo);

                    if (sei.SyncExecutionInfo.Remove)
                    {
                        _filesToRemoveCount++;
                        _filesTotalSizeToRemove += ((MyFileInfo)sei.ElementInfo).Size;
                    }
                    else
                    {
                        _filesToCopyCount++;
                        _filesTotalSizeToCopy += ((MyFileInfo)sei.ElementInfo).Size;
                    }
                }
                else
                {
                    SyncDirExecutionInfos.Add((SyncDirExecutionInfo)sei.SyncExecutionInfo);

                    if (sei.SyncExecutionInfo.Remove)
                    {
                        _dirsToRemoveCount++;
                    }
                    else
                    {
                        _dirsToCreateCount++;
                    }
                }
                break;

            case SyncElementStatus.ChangeApplied:
                if (isFile)
                {
                    if (sei.SyncExecutionInfo.Remove)
                    {
                        _fileSizeRemoved += ((SyncFileInfo)sei).FileInfo.Size;
                        _filesRemovedCount++;
                    }
                    else
                    {
                        _fileSizeCopied += ((SyncFileInfo)sei).FileInfo.Size;
                        _filesCopiedCount++;
                    }
                }
                else
                {
                    if (sei.SyncExecutionInfo.Remove)
                    {
                        _dirsRemovedCount++;
                    }
                    else
                    {
                        _dirsCreatedCount++;
                    }
                }
                break;

            case SyncElementStatus.Conflicted:
                ConflictInfos.Add(sei.ConflictInfo);
                break;
            }

            _listener?.OnSyncElementStatusChanged(sei);
        }
Пример #10
0
 /// <summary>
 /// create StatusChangedEvent
 /// </summary>
 /// <param name="syncElementInfo">reference to the element, whose status has been changed</param>
 /// <param name="createStatus">the status of the element, which should be preserved</param>
 public StatusChangedEvent(SyncElementInfo syncElementInfo, SyncElementStatus createStatus)
 {
     SyncElementInfo = syncElementInfo;
     CreateStatus = createStatus;
 }
Пример #11
0
        /// <summary>
        /// is called when the status of a sync-element has changed
        /// </summary>
        /// <param name="sei"></param>
        public void OnSyncElementStatusChanged(SyncElementInfo sei)
        {
            //parallel access management
            _statusChangedEventsSetAccessRequested = true;
            if (_statusChangedEventsGetAccessRequested && _statusChangedEvents.Count >= maxPendingStatusChangedEventsToProcess)
                _statusChangedEventsGetAccess = true;
            while (_statusChangedEventsGetAccess)
                Thread.Sleep(1);
            _statusChangedEventsSetAccessRequested = false;

            // Add events to list, in order to process them in another thread.
            // So the sync execution is not delayed.
            _statusChangedEvents.Add(new StatusChangedEvent(sei, sei.SyncStatus));
        }