Exemple #1
0
        /// <summary>
        /// Searches recursively for a VersionData of a given filepath
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public VersionData PathGetFile(string path)
        {
            //path example: thisfilename/childfilename/morestuff
            string rootDir = VersionDataPath.GetRootDirectory(path);

            if (rootDir == path)
            {
                if (filename == path)
                {
                    return(this);
                }
                else
                {
                    throw new ArgumentException("file or directory " + path + " not found");
                }
            }
            if (filetype == FileType.File)
            {
                throw new ArgumentException(filename + " is not a directory for " + path);
            }
            string childPath = VersionDataPath.RemoveRootDirectory(path);   //childPath example: childfilename/morestuff
            string childName = VersionDataPath.GetRootDirectory(childPath); //childName example: childfilename

            if (children.TryGetValue(childName, out VersionData child))
            {
                return(child.PathGetFile(childPath));
            }
            else
            {
                throw new ArgumentException("");
            }
        }
        /// <summary>
        /// Adds a VersionData to the tree in its specified path
        /// </summary>
        /// <param name="path"></param>
        /// <param name="vdata"></param>
        public void AddVersionData(string path, VersionData vdata)
        {
            string[] directoryPath = VersionDataPath.SplitDirectories(path);
            DataNode node          = GetParentNode(directoryPath);
            string   filename      = directoryPath[directoryPath.Length - 1];

            if (node.children.Contains(filename))
            {
                node.children[filename].data = vdata;
            }
            else
            {
                node.children.Add(new DataNode(vdata));
            }
        }
        public void RenameVersionData(string oldPath, string newPath)
        {
            string[] oldDirPath  = VersionDataPath.SplitDirectories(oldPath);
            string[] newDirPath  = VersionDataPath.SplitDirectories(newPath);
            DataNode parentNode  = GetParentNode(oldDirPath);
            string   oldfilename = oldDirPath[oldDirPath.Length - 1];
            string   newfilename = newDirPath[newDirPath.Length - 1];

            if (!parentNode.children.Contains(oldfilename))
            {
                throw new ArgumentException(oldPath + " does not exist");
            }
            DataNode node = parentNode.children[oldfilename];

            node.filename = newfilename;
            parentNode.children.Remove(node);
            parentNode = GetParentNode(newDirPath);
            parentNode.children.Add(node);
        }
Exemple #4
0
        /// <summary>
        /// Queries a VersionData using the specified filepath
        /// </summary>
        /// <param name="filepath">A relative filepath beginning at Data.Children
        /// (eg. a file located at ".../Versions/vname/dir1/file.txt" would be queried by "dir1/file.txt"</param>
        /// <returns></returns>
        public VersionData GetVersionData(string filepath)
        {
            string path = VersionDataPath.PrefixFilename(Data.Filename, filepath);

            return(Data.PathGetFile(path));
        }
Exemple #5
0
 private static string PrefixFilename(string prefix, string filename)
 {
     return(VersionDataPath.PrefixFilename(prefix, filename));
 }