コード例 #1
0
        public async Task <Errorable <TreeNode[]> > GetTreeNodesAlongPath(TreeTreePath path)
        {
            // TODO: test me!
            List <TreeNode>      trnodes = new List <TreeNode>(path.Path.Parts.Count + 1);
            Errorable <TreeNode> etr;

            etr = await getTree(path.RootTreeID);

            if (etr.HasErrors)
            {
                return(etr.Errors);
            }
            trnodes.Add(etr.Value);

            for (int i = 0; i < path.Path.Parts.Count; ++i)
            {
                TreeTreeReference trrf = etr.Value.Trees.SingleOrDefault(tr => tr.Name == path.Path.Parts[i]);
                if (trrf == null)
                {
                    break;
                }

                etr = await getTree(trrf.TreeID);

                if (etr.HasErrors)
                {
                    return(etr.Errors);
                }

                trnodes.Add(etr.Value);
            }

            return(trnodes.ToArray());
        }
コード例 #2
0
        public async Task <Errorable <TreeIDPathMapping> > GetTreeIDByPath(TreeTreePath path)
        {
            var treeIDs = await db.ExecuteSingleQueryAsync(new QueryTreeIDsByPaths(path.RootTreeID, path.Path));

            if (treeIDs.Count == 0)
            {
                return(new TreeIDPathMapping(path, (TreeID?)null));
            }
            return(treeIDs[0]);
        }
コード例 #3
0
        private async Task <Errorable <TreeIDPathMapping> > getTreeIDByPath(TreeTreePath path)
        {
            // Get the root Tree:
            var eroot = await getTree(path.RootTreeID).ConfigureAwait(continueOnCapturedContext: false);

            if (eroot.HasErrors)
            {
                return(eroot.Errors);
            }

            TreeNode root = eroot.Value;

            return(await getTreeIDByPath(root, path));
        }
コード例 #4
0
        public async Task <Errorable <TreeTree> > GetTreeRecursivelyFromPath(TreeTreePath path)
        {
            // Find the TreeID given the path and its root TreeID:
            var etpm = await getTreeIDByPath(path).ConfigureAwait(continueOnCapturedContext: false);

            if (etpm.HasErrors)
            {
                return(etpm.Errors);
            }

            TreeIDPathMapping tpm = etpm.Value;

            // TODO: TreePathNotFoundError
            if (!tpm.TreeID.HasValue)
            {
                return((TreeTree)null);
            }

            // Now use GetTreeRecursively to do the rest:
            return(await GetTreeRecursively(tpm.TreeID.Value).ConfigureAwait(continueOnCapturedContext: false));
        }
コード例 #5
0
        public async Task<Errorable<TreeTree>> GetTreeRecursivelyFromPath(TreeTreePath path)
        {
            // Find the TreeID given the path and its root TreeID:
            var etpm = await getTreeIDByPath(path).ConfigureAwait(continueOnCapturedContext: false);
            if (etpm.HasErrors) return etpm.Errors;

            TreeIDPathMapping tpm = etpm.Value;
            // TODO: TreePathNotFoundError
            if (!tpm.TreeID.HasValue) return (TreeTree)null;

            // Now use GetTreeRecursively to do the rest:
            return await GetTreeRecursively(tpm.TreeID.Value).ConfigureAwait(continueOnCapturedContext: false);
        }
コード例 #6
0
        public async Task<Errorable<TreeNode[]>> GetTreeNodesAlongPath(TreeTreePath path)
        {
            // TODO: test me!
            List<TreeNode> trnodes = new List<TreeNode>(path.Path.Parts.Count + 1);
            Errorable<TreeNode> etr;

            etr = await getTree(path.RootTreeID);
            if (etr.HasErrors) return etr.Errors;
            trnodes.Add(etr.Value);

            for (int i = 0; i < path.Path.Parts.Count; ++i)
            {
                TreeTreeReference trrf = etr.Value.Trees.SingleOrDefault(tr => tr.Name == path.Path.Parts[i]);
                if (trrf == null) break;

                etr = await getTree(trrf.TreeID);
                if (etr.HasErrors) return etr.Errors;

                trnodes.Add(etr.Value);
            }

            return trnodes.ToArray();
        }
コード例 #7
0
        private async Task<Errorable<TreeIDPathMapping>> getTreeIDByPath(TreeNode root, TreeTreePath path)
        {
            ReadOnlyCollection<string> parts = path.Path.Parts;
            if (parts.Count == 0) return new TreeIDPathMapping(path, path.RootTreeID);

            int j = 0;

            // Start descending into child nodes:
            TreeNode node = root, nextNode;
            while (node != null)
            {
                nextNode = null;

                // Check all child nodes against the next name in the path:
                for (int i = 0; i < node.Trees.Length; ++i)
                    // TODO: specific string comparison logic!
                    if (parts[j] == node.Trees[i].Name)
                    {
                        TreeID nextID = node.Trees[i].TreeID;

                        // Run out of path components? This is it!
                        if (++j == parts.Count) return new TreeIDPathMapping(path, (TreeID?)nextID);

                        // Load up the next node so we can scan through its child nodes:
                        var enextNode = await getTree(nextID).ConfigureAwait(continueOnCapturedContext: false);
                        if (enextNode.HasErrors) return enextNode.Errors;

                        nextNode = enextNode.Value;
                        break;
                    }

                // Attempt to continue:
                node = nextNode;
            }

            // If we got here it means that we didn't find what we were looking for:
            return new TreeIDPathMapping(path, (TreeID?)null);
        }
コード例 #8
0
 public Task<Errorable<TreeIDPathMapping>> GetTreeIDByPath(TreeTreePath path)
 {
     return getTreeIDByPath(path);
 }
コード例 #9
0
 public TreeIDPathMapping(TreeTreePath path, TreeID? id)
 {
     this.Path = path;
     this.TreeID = id;
 }
コード例 #10
0
        private async Task<Errorable<TreeIDPathMapping>> getTreeIDByPath(TreeTreePath path)
        {
            // Get the root Tree:
            var eroot = await getTree(path.RootTreeID).ConfigureAwait(continueOnCapturedContext: false);
            if (eroot.HasErrors) return eroot.Errors;

            TreeNode root = eroot.Value;

            return await getTreeIDByPath(root, path);
        }
コード例 #11
0
 public Task<Errorable<TreeNode[]>> GetTreeNodesAlongPath(TreeTreePath path)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public Task <Errorable <TreeTree> > GetTreeRecursivelyFromPath(TreeTreePath path)
 {
     return(db.ExecuteSingleQueryAsync(new QueryTreeRecursivelyByPath(path)));
 }
コード例 #13
0
 public Task<Errorable<TreeTree>> GetTreeRecursivelyFromPath(TreeTreePath path)
 {
     return db.ExecuteSingleQueryAsync(new QueryTreeRecursivelyByPath(path));
 }
コード例 #14
0
 public Task <Errorable <TreeIDPathMapping> > GetTreeIDByPath(TreeTreePath path)
 {
     return(getTreeIDByPath(path));
 }
コード例 #15
0
        private async Task <Errorable <TreeIDPathMapping> > getTreeIDByPath(TreeNode root, TreeTreePath path)
        {
            ReadOnlyCollection <string> parts = path.Path.Parts;

            if (parts.Count == 0)
            {
                return(new TreeIDPathMapping(path, path.RootTreeID));
            }

            int j = 0;

            // Start descending into child nodes:
            TreeNode node = root, nextNode;

            while (node != null)
            {
                nextNode = null;

                // Check all child nodes against the next name in the path:
                for (int i = 0; i < node.Trees.Length; ++i)
                {
                    // TODO: specific string comparison logic!
                    if (parts[j] == node.Trees[i].Name)
                    {
                        TreeID nextID = node.Trees[i].TreeID;

                        // Run out of path components? This is it!
                        if (++j == parts.Count)
                        {
                            return(new TreeIDPathMapping(path, (TreeID?)nextID));
                        }

                        // Load up the next node so we can scan through its child nodes:
                        var enextNode = await getTree(nextID).ConfigureAwait(continueOnCapturedContext: false);

                        if (enextNode.HasErrors)
                        {
                            return(enextNode.Errors);
                        }

                        nextNode = enextNode.Value;
                        break;
                    }
                }

                // Attempt to continue:
                node = nextNode;
            }

            // If we got here it means that we didn't find what we were looking for:
            return(new TreeIDPathMapping(path, (TreeID?)null));
        }
コード例 #16
0
 public Task <Errorable <TreeNode[]> > GetTreeNodesAlongPath(TreeTreePath path)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public TreeTreePathDoesNotExistError(TreeTreePath path) : base("A tree with path '{0}' does not exist", path) { }
コード例 #18
0
 public async Task<Errorable<TreeIDPathMapping>> GetTreeIDByPath(TreeTreePath path)
 {
     var treeIDs = await db.ExecuteSingleQueryAsync(new QueryTreeIDsByPaths(path.RootTreeID, path.Path));
     if (treeIDs.Count == 0) return new TreeIDPathMapping(path, (TreeID?)null);
     return treeIDs[0];
 }
コード例 #19
0
 public QueryTreeByPath(TreeTreePath path)
 {
     this._path = path;
 }
コード例 #20
0
 public TreeTreePathDoesNotExistError(TreeTreePath path) : base("A tree with path '{0}' does not exist", path)
 {
 }
コード例 #21
0
 public QueryTreeRecursivelyByPath(TreeTreePath path)
 {
     this._path = path;
 }