コード例 #1
0
ファイル: Watcher.cs プロジェクト: lelmarir/CmisSync
        private void handleFileSwap(LinkedListIterator<FileSystemEventArgs> renameIterator, LinkedListIterator<FileSystemEventArgs> deleteIterator)
        {
            FileSystemEventArgs delete = deleteIterator.Current;
            Utils.LinkedListIterator<FileSystemEventArgs> innerIterator = renameIterator.Clone();
            while (innerIterator.hasNext())
            {
                FileSystemEventArgs nextChange = innerIterator.Next();
                if(nextChange == delete) {
                    return;
                }
                RenamedEventArgs erlierRename = renameIterator.Current as RenamedEventArgs;
                RenamedEventArgs rename = nextChange as RenamedEventArgs;
                if (rename != null && Object.Equals(erlierRename.OldFullPath, rename.FullPath))
                {
                    //this is a file swap!
                    renameIterator.Remove();
                    innerIterator.Remove();
                    deleteIterator.Current = new FileSystemEventArgs(
                        WatcherChangeTypes.Changed,
                        Path.GetDirectoryName(erlierRename.OldFullPath),
                        Path.GetFileName(erlierRename.OldFullPath));

                    //remove any events related to temporary swap file (rename.OldFullPath)
                    string tmpFileFullPath = rename.OldFullPath;
                    Utils.LinkedListIterator<FileSystemEventArgs> tmpIterator = renameIterator.Clone();
                    while (tmpIterator.HasPrevious())
                    {
                        FileSystemEventArgs e = tmpIterator.Previous();
                        if(Object.Equals(e.FullPath, tmpFileFullPath))
                        {
                            if(e.ChangeType == WatcherChangeTypes.Renamed){
                                handleRenamed(tmpIterator);
                                if (tmpIterator.Current != null && tmpIterator.Current.ChangeType == WatcherChangeTypes.Renamed)
                                {
                                    tmpFileFullPath = ((RenamedEventArgs)tmpIterator.Current).OldFullPath;
                                }
                            }
                            if (tmpIterator.Current != null)
                            {
                                tmpIterator.Remove();
                            }
                        }
                    }
                }
            }
        }