Exemplo n.º 1
0
        private void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            logger.Debug("A new file has been renamed from {oldName} to {name}", e.OldName, e.Name);

            rootNode.GetOrCreateChild(e.OldFullPath).CleanupNode();
            var fileInfo = new FileInfo(e.FullPath);
            var dirInfo  = new DirectoryInfo(e.FullPath);

            fileInfo.Refresh();
            dirInfo.Refresh();

            if (fileInfo.Exists)
            {
                rootNode.GetOrCreateChild(e.FullPath).UpdateInfo(FileType.File, fileInfo.Length, fileInfo.CreationTime);
            }
            else if (dirInfo.Exists)
            {
                var node = rootNode.RemoveNode(e.OldFullPath);
                if (node != null)
                {
                    rootNode.InsertNode(e.FullPath, node);
                }
                else
                {
                    throw new Exception("Race condition");
                }
            }
        }