コード例 #1
0
        private string CreatePath(string pathCreate, string root, bool returnFull = false)
        {
            if (FileSystemObject.IsPathSystemRooted(pathCreate))
            {
                var path = FileSystemObject.BluntStart(pathCreate.ForwardSlashes(), root);

                return(this.CreatePath(path, root, returnFull));
            }
            else
            {
                string   path;
                string[] parts;
                Folder   parentFolder = null;

                if (returnFull)
                {
                    path = PathCombine(root, pathCreate, true);

                    if (path.StartsWith(this.Root))
                    {
                        parts = FileSystemObject.BluntStart(path, this.Root).SplitCombine('/');
                    }
                    else if (path.StartsWith(this.ServicesRoot))
                    {
                        parts = FileSystemObject.BluntStart(path, this.ServicesRoot).SplitCombine('/');
                    }
                    else if (path.StartsWith(this.ProjectRoot))
                    {
                        parts = FileSystemObject.BluntStart(path, this.ProjectRoot).SplitCombine('/');
                    }
                    else
                    {
                        e.Throw <InvalidOperationException>("Unrecognized path prefix");
                        parts = null;
                    }
                }
                else
                {
                    path = PathCombine(root, pathCreate, true);

                    if (path.StartsWith(this.Root))
                    {
                        path  = FileSystemObject.BluntStart(path, this.Root);
                        parts = path.SplitCombine('/');
                    }
                    else if (path.StartsWith(this.ServicesRoot))
                    {
                        path  = FileSystemObject.BluntStart(path, this.ServicesRoot);
                        parts = path.SplitCombine('/');
                    }
                    else if (path.StartsWith(this.ProjectRoot))
                    {
                        path  = FileSystemObject.BluntStart(path, this.ProjectRoot);
                        parts = path.SplitCombine('/');
                    }
                    else
                    {
                        e.Throw <InvalidOperationException>("Unrecognized path prefix");
                        parts = null;
                    }
                }

                foreach (var part in parts)
                {
                    if (this.Index.ContainsKey(part))
                    {
                        parentFolder = (Folder)this.Index[part];
                    }
                    else
                    {
                        var newFolder = new Folder(this, PathCombine(this.Root, part, true));

                        parentFolder.Folders.Add(newFolder);
                        parentFolder = newFolder;
                    }
                }

                var debug = false;

                if (debug)
                {
                    var folders = this.GetAllFolders();
                }

                return(path);
            }
        }