public void CreateDirectory(string path) { if (!DirectoryExists(path)) { var change = FileSystemChanges.FirstOrDefault(f => f.FullPath.Equals(path, PathComparisonType) && f.FileSystemChangeType == FileSystemChangeType.RemoveDirectory); if (change != null) { // If the directory was deleted, just remove the change. // The directory could have been deleted to remove its children then added back. FileSystemChangeTracker.RemoveChange(change); } else { FileSystemChangeInformation addDirectoryInformation = new FileSystemChangeInformation() { FullPath = path, FileSystemChangeType = FileSystemChangeType.AddDirectory }; FileSystemChangeTracker.AddChange(addDirectoryInformation); } var deletedParents = FileSystemChanges.Where(f => path.StartsWith(f.FullPath) && f.FileSystemChangeType == FileSystemChangeType.RemoveDirectory); foreach (var deletedParent in deletedParents) { FileSystemChangeTracker.RemoveChange(deletedParent); } } }
/// <summary> /// Adds a piece of metadata to communicate back to the scaffolding server. /// This currently uses the FileSystemChangeInformation message. /// At some point an additional message type should be added specifically for metadata exchange. /// </summary> /// <param name="metadata">The data to send back. It will be put in the FullPath property of the message.</param> public void AddMetadataMessage(string metadata) { FileSystemChangeInformation metadataInfo = new FileSystemChangeInformation() { FullPath = metadata, FileSystemChangeType = FileSystemChangeType.AddFile, FileContents = string.Empty }; FileSystemChangeTracker.AddChange(metadataInfo); }
public void AddChange(FileSystemChangeInformation fileSystemChangeInfo) { if (fileSystemChangeInfo == null) { throw new ArgumentNullException(nameof(fileSystemChangeInfo)); } // The last change always wins. readerWriterLock.EnterWriteLock(); _changes[fileSystemChangeInfo.FullPath] = fileSystemChangeInfo; readerWriterLock.ExitWriteLock(); }
public void RemoveChange(FileSystemChangeInformation fileSystemChangeInfo) { if (fileSystemChangeInfo == null) { throw new ArgumentNullException(nameof(fileSystemChangeInfo)); } readerWriterLock.EnterWriteLock(); if (_changes.ContainsKey(fileSystemChangeInfo.FullPath)) { _changes.Remove(fileSystemChangeInfo.FullPath); } readerWriterLock.ExitWriteLock(); }
public void WriteAllText(string path, string contents) { if (!DirectoryExists(Path.GetDirectoryName(path))) { throw new IOException(string.Format(MessageStrings.PathNotFound, path)); } var fileWriteInformation = new FileSystemChangeInformation() { FullPath = path, FileSystemChangeType = FileSystemChangeType.AddFile, FileContents = contents }; if (FileExists(path)) { fileWriteInformation.FileSystemChangeType = FileSystemChangeType.EditFile; } FileSystemChangeTracker.AddChange(fileWriteInformation); }
protected override bool HandleMessageInternal(IMessageSender sender, Message message) { // What if the deserialization fails? FileSystemChangeInformation info = message.Payload.ToObject <FileSystemChangeInformation>(); if (info == null) { Logger.LogMessage(MessageStrings.InvalidFileSystemChangeMessage); Logger.LogMessage(message.Payload.ToString()); } Logger.LogMessage($"{Environment.NewLine}\t\t{MessageStrings.StartFileSystemChangeToken}"); switch (info.FileSystemChangeType) { case FileSystemChangeType.AddFile: Logger.LogMessage(string.Format(MessageStrings.AddFileMessage, info.FullPath)); Logger.LogMessage(string.Format(MessageStrings.ContentsMessage, info.FileContents)); break; case FileSystemChangeType.EditFile: Logger.LogMessage(string.Format(MessageStrings.EditFileMessage, info.FullPath)); Logger.LogMessage(string.Format(MessageStrings.ContentsMessage, info.FileContents)); break; case FileSystemChangeType.DeleteFile: Logger.LogMessage(string.Format(MessageStrings.DeleteFileMessage, info.FullPath)); break; case FileSystemChangeType.AddDirectory: Logger.LogMessage(string.Format(MessageStrings.AddDirectoryMessage, info.FullPath)); break; case FileSystemChangeType.RemoveDirectory: Logger.LogMessage(string.Format(MessageStrings.RemoveDirectoryMessage, info.FullPath)); break; } Logger.LogMessage($"\t\t{MessageStrings.EndFileSystemChangeToken}{Environment.NewLine}"); return(true); }