Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the specified folder and all of its content, by creating a ItemsDeletedChange.
        /// This ItemsDeletedChange is then returned.
        /// </summary>
        /// <param name="path">The path to remove from</param>
        /// <returns>Returns the changes that makes the deletion possible</returns>
        protected ItemsDeletedChange DeleteFolder(string path)
        {
            ItemsDeletedChange itemsDeletion = new ItemsDeletedChange();

            SortedSet<String> entriesFullPaths = VersionSystemFacade.GetEntryPaths(path);

            foreach (var entry in entriesFullPaths)
            {
                string truePath = path + "\\" + entry;
                itemsDeletion.DeleteItem(truePath.Replace("\\\\", "\\"));
            }

            itemsDeletion.DeleteItem(path);

            return itemsDeletion;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes the current file.
        /// </summary>
        protected void DeleteFile(object sender, EventArgs e)
        {
            ItemsDeletedChange itemDeletion = new ItemsDeletedChange();

            string relativePath = _path.Substring(3);

            itemDeletion.DeleteItem(relativePath);

            var vsc = VersionSystemFacade.GetVersionControlSystem(relativePath);

            if (vsc.Save(itemDeletion) == null)
            {
                Response.Redirect("info.aspx?path=Pie");
            }
            else
            {
                base.ShowWarning();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the changes into change objects.
        /// </summary>
        /// <param name="text">The text to parse change objects from.</param>
        /// <returns>A list of change objects. NOTE: If no items have been deleted, index = 0 will be null. If no items have been created, index = 1 will be null</returns>
        public static IList<AbstractChange> ParseChanges(String[] text)
        {
            if (text.Any(s => s == null)) throw new ArgumentNullException("text");
            if (!text.Any()) throw new ArgumentException("Argument was empty");

            IList<AbstractChange> parsedChanges = new List<AbstractChange>();

            ItemsCreatedChange itemsCreated = null;
            ItemsDeletedChange itemsDeleted = null;

            parsedChanges.Add(itemsDeleted);
            parsedChanges.Add(itemsCreated);

            int pointer = 0;
            while (pointer < text.Length)
            {
                if (text[pointer].StartsWith(AbstractChange.ItemCreationMark))
                {   // An item has been created

                    if (parsedChanges[1] == null)
                    {
                        parsedChanges[1] = new ItemsCreatedChange();
                    }
                    // The item is a folder
                    if (text[pointer].EndsWith(FileSystem.PathSeparator))
                    {
                        if (parsedChanges[1] is ItemsCreatedChange)
                        {
                            ((ItemsCreatedChange)parsedChanges[1]).CreateItem(new FolderCreation(text[pointer].Substring(AbstractChange.ItemCreationMark.Length)));
                        }
                        pointer++;
                    }
                    else
                    {
                        IList<String> fileContents = new List<string>();
                        String createdFilePath = text[pointer].Substring(AbstractChange.ItemCreationMark.Length);
                        pointer++;
                        while (pointer < text.Length)
                        {
                            // No more modifications for this file
                            if (text[pointer].Equals(AbstractChange.BlockSeparatorMark)) break;
                            // Line insertion
                            if (text[pointer].StartsWith(AbstractChange.LineInsertionMark))
                            {
                                String lineNumber = text[pointer].Substring(AbstractChange.LineInsertionMark.Length);
                                int tmp = lineNumber.IndexOf(AbstractChange.LineInsertionMark);
                                String line = lineNumber.Substring(tmp + AbstractChange.LineInsertionMark.Length);
                                fileContents.Add(line);
                                pointer++;
                            }
                        }
                        if (parsedChanges[1] is ItemsCreatedChange)
                        {
                            ((ItemsCreatedChange)parsedChanges[1]).CreateItem(new FileCreation(createdFilePath, fileContents.ToArray()));
                        }
                    }
                }
                else if (text[pointer].StartsWith(AbstractChange.ItemDeletionMark))
                {
                    // An item has been deleted
                    String path = text[pointer].Substring(AbstractChange.ItemDeletionMark.Length);
                    if (parsedChanges[0] == null)
                    {
                        parsedChanges[0] = new ItemsDeletedChange();
                    }
                    if (parsedChanges[0] is ItemsDeletedChange)
                    {
                        ((ItemsDeletedChange)parsedChanges[0]).DeleteItem(path);
                    }
                    pointer++;
                }
                else if (text[pointer].StartsWith(AbstractChange.ItemModificationMark))
                {
                    // A file has been modified

                    String path = text[pointer].Substring(AbstractChange.ItemModificationMark.Length);
                    FileModifiedChange modified = new FileModifiedChange(path);
                    pointer++;
                    // Iterate through the file modifications until there are no more (end of file or linebreak)
                    while (pointer < text.Length)
                    {
                        // No more modifications for this file
                        if (text[pointer].Equals(AbstractChange.BlockSeparatorMark)) break;
                        // Line insertion
                        if (text[pointer].StartsWith(AbstractChange.LineInsertionMark))
                        {
                            String lineNumber = text[pointer].Substring(AbstractChange.LineInsertionMark.Length);
                            int tmp = lineNumber.IndexOf(AbstractChange.LineInsertionMark);
                            int number = int.Parse(lineNumber.Substring(0, tmp));
                            String line = lineNumber.Substring(tmp + AbstractChange.LineInsertionMark.Length);
                            modified.AddInsertion(number, line);
                            pointer++;
                        }
                        // Line deletion
                        if (text[pointer].StartsWith(AbstractChange.LineDeletionMark))
                        {
                            String lineNumber = text[pointer].Substring(AbstractChange.LineDeletionMark.Length);
                            int tmp = lineNumber.IndexOf(AbstractChange.LineDeletionMark);
                            int number = int.Parse(lineNumber.Substring(0, tmp));
                            String line = lineNumber.Substring(tmp + AbstractChange.LineDeletionMark.Length);
                            modified.AddDeletion(number, line);
                            pointer++;
                        }
                    }
                    parsedChanges.Add(modified);
                }
                if (pointer < text.Length && text[pointer].Equals(AbstractChange.BlockSeparatorMark))
                {   // Current line is empty
                    pointer++;
                }
            }

            return parsedChanges;
        }
        /// <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 deletions of files in the file system.
        /// </summary>
        /// <param name="path">The path to the item that has been deleted</param>
        public void OnDeleted(String path)
        {
            // Create the change
            ItemsDeletedChange change = new ItemsDeletedChange();
            if (IsDirectory(FileSystem.CACHE_DIR + path))
            {
                path = path + ((path.EndsWith(FileSystem.PathSeparator) ? String.Empty : FileSystem.PathSeparator));
                change.DeleteItem(path);
            }
            else
            {
                change.DeleteItem(path);
            }

            // Keep the cache up to date
            _cache.Delete(path);

            Commit(new List<AbstractChange> { change });
        }