/// <summary> /// Moves the specified folder and all of its content, by creating a ItemsDeletedChange and a ItemsCreatedChange. /// The two changes is returned inside of a ICollection. /// </summary> /// <param name="from">The relative path to copy from</param> /// <param name="to">The relative path to copy to</param> /// <returns>Returns the changes that makes the move possible</returns> protected ICollection<AbstractChange> MoveFolder(string from, string to) { ICollection<AbstractChange> returnCollection = new List<AbstractChange>(); ItemsCreatedChange itemsCreation = new ItemsCreatedChange(); SortedSet<String> entriesFullPaths = VersionSystemFacade.GetEntryPaths(from); itemsCreation.CreateItem(new FolderCreation(to)); foreach (var entry in entriesFullPaths) { string newPath = to + "\\" + entry; newPath = newPath.Replace("\\\\", "\\"); string oldPath = from + "\\" + entry; oldPath = oldPath.Replace("\\\\", "\\"); if (VersionSystemFacade.GetVersionControlSystem(oldPath).IsDirectory(oldPath)) { itemsCreation.CreateItem(new FolderCreation(newPath + (newPath.EndsWith("\\") ? string.Empty : "\\"))); } else { string[] content = VersionSystemFacade.GetFileText(oldPath); itemsCreation.CreateItem(new FileCreation(newPath, content)); } } returnCollection.Add(itemsCreation); returnCollection.Add(DeleteFolder(from)); return returnCollection; }
/// <summary> /// Is called when an the add-item button is clicked. Make sure that the new item is added. /// </summary> protected void Add_Item(object sender, EventArgs e) { // You cant add an item to something that aint a folder! if (!_isDir) return; string newItemName = ItemNameTextBox.Text; string pathToNewItem = _path.Substring(3) + "\\" + newItemName; pathToNewItem = pathToNewItem.StartsWith("\\") ? pathToNewItem.Remove(0, 1) : pathToNewItem; string selectedItemType = ItemTypeDropDown.SelectedItem.ToString().ToLower(); VersionControlSystem vcs = VersionSystemFacade.GetVersionControlSystem(pathToNewItem); ItemsCreatedChange itemsCreation = new ItemsCreatedChange(); if (selectedItemType.Equals("folder")) { itemsCreation.CreateItem(new FolderCreation(pathToNewItem + (pathToNewItem.EndsWith("\\") ? string.Empty : "\\"))); } else { // Make sure that a file has an extension! if (!pathToNewItem.Contains(".")) { pathToNewItem += ".txt"; newItemName += ".txt"; } itemsCreation.CreateItem(new FileCreation(pathToNewItem, new string[] {""})); } if (vcs.Save(itemsCreation) == null) { Response.Redirect("Info.aspx?path=" + _path + "\\" + newItemName); } else { base.ShowWarning(); } }
/// <summary> /// Moves the specified file, by creating a ItemsDeletedChange (deleting the old file) and a ItemsCreatedChange (creating the file at the new path, with the content). /// The two changes is returned inside of a ICollection. /// </summary> /// <param name="from">The relative path to copy from</param> /// <param name="to">The relative path to copy to</param> /// <param name="content">The content of the file</param> /// <returns>Returns the changes that makes the move possible</returns> protected ICollection<AbstractChange> MoveFile(string from, string to, string content) { ICollection<AbstractChange> returnCollection = new List<AbstractChange>(); ICreation creation = new FileCreation((to), content.Split('\n')); ItemsCreatedChange itemCreation = new ItemsCreatedChange(); itemCreation.CreateItem(creation); ItemsDeletedChange itemDeletion = new ItemsDeletedChange(); itemDeletion.DeleteItem(from); returnCollection.Add(itemCreation); returnCollection.Add(itemDeletion); return returnCollection; }
/// <summary> /// Listens to the renaming of files in the file system. /// </summary> /// <param name="oldPath">The path to the old file.</param> /// <param name="newPath">The path to the new file.</param> public void OnRenamed(String oldPath, String newPath) { // Create the changes var created = new ItemsCreatedChange(); var deleted = new ItemsDeletedChange(); // Delete the item in the change deleted.DeleteItem(oldPath); // Create the item if (IsDirectory(newPath)) { created.CreateItem(new FolderCreation(newPath)); } else { // Read the new path on purpose, since the old path no longer exist (the file has been deleted) created.CreateItem(new FileCreation(newPath, ReadAllLines(newPath))); } // Make the cache up to date _cache.Delete(oldPath); _cache.Update(newPath); // Commit Commit(new List<AbstractChange> { deleted, created }); }
/// <summary> /// Listens to creations of files in the file system. /// </summary> /// <param name="path">The path to the item that has been created</param> public void OnCreated(String path) { // Create the change ItemsCreatedChange change = new ItemsCreatedChange(); if (IsDirectory(path)) { change.CreateItem(new FolderCreation(path)); } else { change.CreateItem(new FileCreation(path, ReadAllLines(path))); } // Keep the track up to date _cache.Update(path); Commit(new List<AbstractChange> { change }); }