コード例 #1
0
        public static GraphPath New()
        {
            var rv = new GraphPath();

            rv.AddSegment(GraphSegment.New("root"));
            return(rv);
        }
コード例 #2
0
ファイル: NodeStoreUtil.cs プロジェクト: Piirtaa/Decoratid
        /// <summary>
        /// given a path and a nodestore, tries to locate a node
        /// </summary>
        /// <param name="path"></param>
        /// <param name="nodeStore"></param>
        /// <returns></returns>
        public static GraphNode GetNode(this IStoreOf<GraphNode> nodeStore, GraphPath path)
        {
            Condition.Requires(path).IsNotNull();
            Condition.Requires(nodeStore).IsNotNull();

            var node = nodeStore.Get<GraphNode>(path.Path);
            return node;
        }
コード例 #3
0
        public static GraphPath New(List <IGraphSegment> paths)
        {
            Condition.Requires(paths).IsNotEmpty();
            var rv   = new GraphPath();
            var segs = paths.GetRange(0, paths.Count);

            segs.WithEach(x =>
            {
                rv.AddSegment(x);
            });
            return(rv);
        }
コード例 #4
0
        public static GraphPath New(GraphPath path)
        {
            Condition.Requires(path).IsNotNull();
            var rv   = new GraphPath();
            var segs = path.Segments.GetRange(0, path.Segments.Count);

            segs.WithEach(x =>
            {
                rv.AddSegment(x);
            });
            return(rv);
        }
コード例 #5
0
ファイル: GraphingUtil.cs プロジェクト: Piirtaa/Decoratid
        /// <summary>
        /// for a given node returns all the child nodes
        /// </summary>
        /// <param name="nodeValue"></param>
        /// <param name="parentNodePath"></param>
        /// <returns></returns>
        public static List<Tuple<object, GraphPath>> GetChildTraversalNodes(object nodeValue, GraphPath parentNodePath,
            Func<object, GraphPath, bool> doNotTraverseFilter = null)
        {
            List<Tuple<object, GraphPath>> rv = new List<Tuple<object, GraphPath>>();

            //if the node is IEnumerable, recurse here
            if (nodeValue is IEnumerable && (nodeValue is string) == false)
            {
                IEnumerable objEnumerable = nodeValue as IEnumerable;

                int index = 0;
                foreach (var each in objEnumerable)
                {
                    //build the path
                    var path = GraphPath.New(parentNodePath);
                    path.AddSegment(EnumeratedItemSegment.New(index));

                    if (doNotTraverseFilter != null &&
                        doNotTraverseFilter(each, path))
                        continue;

                    rv.Add(new Tuple<object, GraphPath>(each, path));
                    index++;
                }
            }
            else
            {
                //recurse the fields   
                var fields = GraphingUtil.GetNestingNotatedFieldInfos(nodeValue.GetType());

                foreach (var field in fields)
                {
                    //get field value
                    var obj = field.Item2.GetValue(nodeValue);

                    var path = GraphPath.New(parentNodePath);
                    path.AddSegment(GraphSegment.New(field.Item1));

                    if (doNotTraverseFilter != null &&
                        doNotTraverseFilter(obj, path))
                        continue;

                    //build the node and recurse
                    rv.Add(new Tuple<object, GraphPath>(obj, path));

                }
            }
            return rv;
        }
コード例 #6
0
ファイル: NodeStoreUtil.cs プロジェクト: Piirtaa/Decoratid
        /// <summary>
        /// given a nodestore finds the current node's parent node
        /// </summary>
        /// <param name="nodeStore"></param>
        /// <returns></returns>
        public static GraphNode GetParentNode(this IStoreOf<GraphNode> nodeStore, GraphPath path)
        {
            Condition.Requires(nodeStore).IsNotNull();

            GraphNode rv = null;

            //if we're on a root node, there is no parent
            if (path.IsRoot)
                return null;

            var parentPath = path.ParentPath;
            var matches = nodeStore.SearchOf(LogicOfTo<GraphNode, bool>.New((x) => { return x.Id.Equals(parentPath); }));
            rv = matches.FirstOrDefault();
            return rv;
        }
コード例 #7
0
 public List<Tuple<object, GraphPath>> GetChildTraversalNodes(object obj, GraphPath nodePath)
 {
     return null;
 }
コード例 #8
0
        //public void RewriteNodePath(GraphPath path, object obj)
        //{
        //    GraphingUtil.RewriteBackingFieldNodePath(path);

        //    //hack the path here to change "_Decorated " to the type name
        //    if (path.CurrentSegment.Path.Contains("_Decorated "))
        //    {
        //        path.ChangeCurrentSegmentPath(obj.GetType().Name);
        //    }
        //}
        public List<Tuple<object, GraphPath>> GetChildTraversalNodes(object nodeValue, GraphPath nodePath)
        {
            var rv = GraphingUtil.GetChildTraversalNodes(nodeValue, nodePath, DoNotTraverseFilter);

            return rv;
        }
コード例 #9
0
ファイル: GraphPath.cs プロジェクト: Piirtaa/Decoratid
 public static GraphPath New(List<IGraphSegment> paths)
 {
     Condition.Requires(paths).IsNotEmpty();
     var rv = new GraphPath();
     var segs = paths.GetRange(0, paths.Count);
     segs.WithEach(x =>
     {
         rv.AddSegment(x);
     });
     return rv;
 }
コード例 #10
0
ファイル: GraphPath.cs プロジェクト: Piirtaa/Decoratid
 public static GraphPath New(GraphPath path)
 {
     Condition.Requires(path).IsNotNull();
     var rv = new GraphPath();
     var segs = path.Segments.GetRange(0, path.Segments.Count);
     segs.WithEach(x =>
     {
         rv.AddSegment(x);
     });
     return rv;
 }
コード例 #11
0
ファイル: GraphPath.cs プロジェクト: Piirtaa/Decoratid
 public static GraphPath New()
 {
     var rv = new GraphPath();
     rv.AddSegment(GraphSegment.New("root"));
     return rv;
 }
コード例 #12
0
ファイル: NodeStoreUtil.cs プロジェクト: Piirtaa/Decoratid
 /// <summary>
 /// gets all children of the current node (those with paths that begin with the current node's path)
 /// </summary>
 /// <param name="nodeStore"></param>
 /// <returns></returns>
 public static List<GraphNode> GetChildNodes(this IStoreOf<GraphNode> nodeStore, GraphPath path)
 {
     Condition.Requires(nodeStore).IsNotNull();
     var matches = nodeStore.SearchOf(LogicOfTo<GraphNode,bool>.New((x) => { return x.Path.Path.StartsWith(path.Path); }));
     return matches;
 }
コード例 #13
0
ファイル: Graph.cs プロジェクト: Piirtaa/Decoratid
        /// <summary>
        /// the recursive call
        /// </summary>
        /// <param name="nodeValue"></param>
        /// <param name="nodePath"></param>
        /// <param name="nodeStore"></param>
        /// <param name="traversalIndex"></param>
        private void BuildNode(object nodeValue, GraphPath nodePath)
        {
            //skip if indicated
            if (this.SkipFilter != null && this.SkipFilter(nodeValue, nodePath))
                return;

            //get the manager for this node value
            var manager = this.ChainOfResponsibility.FindHandlingValueManager(nodeValue, this);
            Condition.Requires(manager).IsNotNull();

            //using the manager, serialize node value, and build the node
            var val = manager.DehydrateValue(nodeValue, this);
            this.Counter.Increment();
            var node = GraphNode.New(nodePath, nodeValue, this.Counter.Current, manager.Id, val);

            //save the node
            this.NodeStore.SaveItem(node);

            var traverseList = manager.GetChildTraversalNodes(nodeValue, nodePath);
            traverseList.WithEach(tuple =>
            {
                BuildNode(tuple.Item1, tuple.Item2);
            });

        }