Example #1
0
        /// <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);
        }
Example #2
0
 /// <summary>
 /// adds an auditing decoration of StoredItemAuditPoint.  Apply after all data modifying decorations.
 /// </summary>
 /// <param name="decorated"></param>
 /// <param name="auditStore"></param>
 /// <returns></returns>
 public static AuditingDecoration <StoredItemAuditPoint> BasicAudit(this IStore decorated,
                                                                    IStoreOf <StoredItemAuditPoint> auditStore)
 {
     Condition.Requires(decorated).IsNotNull();
     return(new AuditingDecoration <StoredItemAuditPoint>(decorated, auditStore,
                                                          StoredItemAuditPoint.GetBuilderFunction()));
 }
Example #3
0
 /// <summary>
 /// adds an auditing decoration.  Apply after all data modifying decorations.
 /// </summary>
 /// <typeparam name="TAuditPoint"></typeparam>
 /// <param name="decorated"></param>
 /// <param name="auditStore"></param>
 /// <param name="auditItemBuildStrategy"></param>
 /// <returns></returns>
 public static AuditingDecoration <TAuditPoint> Audit <TAuditPoint>(this IStore decorated,
                                                                    IStoreOf <TAuditPoint> auditStore,
                                                                    Func <IHasId, StoredItemAccessMode, TAuditPoint> auditItemBuildStrategy)
     where TAuditPoint : IStoredItemAuditPoint
 {
     Condition.Requires(decorated).IsNotNull();
     return(new AuditingDecoration <TAuditPoint>(decorated, auditStore, auditItemBuildStrategy));
 }
Example #4
0
        /// <summary>
        /// if the path points to an IHasId node value, we grab the Id branches
        /// </summary>
        /// <param name="path"></param>
        /// <param name="nodeStore"></param>
        /// <returns></returns>
        //public static List<GraphNode> GetIdNodesFromNode(GraphPath path, IStoreOf<GraphNode> nodeStore)
        //{
        //    var node = GetNode(path, nodeStore);
        //    if (node == null)
        //        return null;

        //    //find the immediate child id node
        //    var children = node.GetImmediateChildNodes(nodeStore);

        //    if(children != null && children.Count > 0)
        //    {
        //        foreach(var each in children)
        //        {
        //            if (!(each.Path.CurrentSegment is GraphSegment))
        //            {
        //                continue;
        //            }
        //            var seg = (GraphSegment)each.Path.CurrentSegment;
        //            if(seg.SegmentName
        //        }
        //    }
        //}

        #endregion


        #region Static List/Store  Serialization/Hydration
        /// <summary>
        /// converts Node Store to a list of nodes and serializes it
        /// </summary>
        /// <param name="nodeStore"></param>
        /// <returns></returns>
        public static string DehydrateNodeStore(this IStoreOf <GraphNode> nodeStore)
        {
            Condition.Requires(nodeStore).IsNotNull();
            var nodes = nodeStore.GetAll();
            var rv    = DehydrateNodeList(nodes);

            return(rv);
        }
Example #5
0
        /// <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);
        }
Example #6
0
 public AuditingDecoration(
     IStore decorated, IStoreOf <TAuditPoint> auditStore,
     Func <IHasId, StoredItemAccessMode, TAuditPoint> auditItemBuildStrategy)
     : base(decorated)
 {
     Condition.Requires(auditStore).IsNotNull();
     Condition.Requires(auditItemBuildStrategy).IsNotNull();
     this.AuditStore       = auditStore;
     this.AuditItemFactory = auditItemBuildStrategy;
 }
Example #7
0
 public NessManager(IStoreOf<INess> store = null)
 {
     if (store == null)
     {
         this.Store = NaturalInMemoryStore.New().IsOf<INess>();
     }
     else
     {
         this.Store = store;
     }
 }
Example #8
0
        public StringStateMachineGraph(string initialState, IStoreOf <StringStateTransition> store)
        {
            if (initialState == null)
            {
                throw new ArgumentNullException("initialState");
            }
            this.InitialState = initialState;
            this.CurrentState = initialState;

            Condition.Requires(store).IsNotNull();
            this.Store = store;
        }
Example #9
0
 public TokenLexer(NessManager nessManager, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     if (storeOfStores == null)
     {
         this.StoreOfStores = NaturalInMemoryStore.New().IsOf <NamedNaturalInMemoryStore>();
     }
     else
     {
         this.StoreOfStores = storeOfStores;
     }
     this.NessManager = nessManager;
 }
Example #10
0
        /// <summary>
        /// given a Node Store, hydrates the value of each node, and wires the entire graph back together
        /// </summary>
        /// <param name="nodeStore"></param>
        /// <returns>the root node value</returns>
        private object ReconstituteFromNodeStore(IStoreOf <GraphNode> nodeStore)
        {
            Condition.Requires(nodeStore).IsNotNull();
            this.NodeStore = nodeStore;

            //iterate over all of the non-duplicate values and Reconstitute these nodes
            var nodes = NodeStore.GetAll();

            nodes.WithEach(node =>
            {
                if (node.ValueManagerId != DuplicateValueManager.ID)
                {
                    var mgr        = this.ChainOfResponsibility.GetValueManagerById(node.ValueManagerId);
                    var obj        = mgr.HydrateValue(node.Context, this);
                    node.NodeValue = obj;
                }
            });
            //wire the circ refs from the bottom up
            nodes = nodes.OrderByDescending((x) => { return(x.TraversalIndex); }).ToList();
            foreach (var node in nodes)
            {
                if (node.ValueManagerId == DuplicateValueManager.ID)
                {
                    var mgr = this.ChainOfResponsibility.GetValueManagerById(node.ValueManagerId);
                    var obj = mgr.HydrateValue(node, this);
                    node.NodeValue = obj;
                }
            }

            Dictionary <string, string> hasProcessed = new Dictionary <string, string>();

            //moving from bottom, wire children to parents
            foreach (var node in nodes)
            {
                //get the parent
                var parent = nodeStore.GetParentNode(node.Path);

                if (parent != null && hasProcessed.ContainsKey(parent.Id) == false)
                {
                    hasProcessed.Add(parent.Id, null);
                    WireParentToChildren(parent, nodeStore);
                }
            }

            //return root node
            var root = nodeStore.GetRootNode();

            return(root.NodeValue);
        }
Example #11
0
        /// <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);
        }
Example #12
0
 public CLConfig(NessManager nessManager = null, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     if (storeOfStores == null)
     {
         this.StoreOfStores = NaturalInMemoryStore.New().IsOf <NamedNaturalInMemoryStore>();
     }
     else
     {
         this.StoreOfStores = storeOfStores;
     }
     if (nessManager == null)
     {
         this.NessManager = NessManager.New();
     }
     else
     {
         this.NessManager = nessManager;
     }
 }
Example #13
0
        public CLConfig(NessManager nessManager = null, IStoreOf<NamedNaturalInMemoryStore> storeOfStores = null)
        {
            if (storeOfStores == null)
            {
                this.StoreOfStores = NaturalInMemoryStore.New().IsOf<NamedNaturalInMemoryStore>();

            }
            else
            {
                this.StoreOfStores = storeOfStores;
            }
            if (nessManager == null)
            {
                this.NessManager = NessManager.New();
            }
            else
            {
                this.NessManager = nessManager;
            }
        }
Example #14
0
 public static NessManager New(IStoreOf<INess> store = null)
 {
     return new NessManager(store);
 }
Example #15
0
        /// <summary>
        /// given a parent node and a store of nodes, identifies the children of the parent and wires
        /// their values to the parent node's value
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="nodeStore"></param>
        private void WireParentToChildren(GraphNode parentNode, IStoreOf<GraphNode> nodeStore)
        {
            Condition.Requires(parentNode).IsNotNull();
            Condition.Requires(nodeStore).IsNotNull();

            List<string> skipFilter = new List<string>() { NullValueManager.ID, DelegateValueManager.ID, PrimitiveValueManager.ID };
            if (skipFilter.Contains(parentNode.ValueManagerId))
                return;

            var children = nodeStore.GetImmediateChildNodes(parentNode.Path).OrderBy((x) => { return x.Path.EnumeratedSegmentIndex; }).ToList();
            var fields = GraphingUtil.GetNestingNotatedFieldInfos(parentNode.NodeValue.GetType());

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

            var traverseList = manager.GetChildTraversalNodes(parentNode.NodeValue, parentNode.Path);
            traverseList.WithEach(tuple =>
            {
                BuildNode(tuple.Item1, tuple.Item2);
            });

            foreach (var each in children)
            {
                //add the children
                if (each.Path.IsEnumeratedSegment)
                {
                    if (each.NodeValue is IDictionary)
                    {
                        IDictionary dict = parentNode.NodeValue as IDictionary;
                        DictionaryEntry de = (DictionaryEntry)each.NodeValue;
                        dict.Add(de.Key, de.Value);
                    }
                    else if (each.NodeValue is Stack)
                    {
                        Stack stack = parentNode.NodeValue as Stack;
                        stack.Push(each.NodeValue);
                    }
                    else if (each.NodeValue is Queue)
                    {
                        Queue queue = parentNode.NodeValue as Queue;
                        queue.Enqueue(each.NodeValue);
                    }
                    else if (each.NodeValue is IList)
                    {
                        IList list = parentNode.NodeValue as IList;
                        list.Add(each.NodeValue);
                    }
                }
                else
                {
                    //get the matching field
                    GraphSegment gSeg = each.Path.CurrentSegment as GraphSegment;

                    //TODO: refactor implicit contract - that the paths match field names (GraphingUtil.GetNestingNotatedFieldInfos)
                    var matches = fields.Filter((x) => { return x.Item1 == gSeg.Path; });
                    Condition.Requires(matches).IsNotNull().HasLength(1);

                    var fi = matches.First();
                    fi.Item2.SetValue(parentNode.NodeValue, each.NodeValue);
                }
            }
        }
Example #16
0
 public static StringStateMachineGraph New(string initialState, IStoreOf <StringStateTransition> store)
 {
     return(new StringStateMachineGraph(initialState, store));
 }
Example #17
0
 public static CLConfig New(NessManager nessManager = null, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     return(new CLConfig(nessManager, storeOfStores));
 }
Example #18
0
 public static CLConfig New(NessManager nessManager = null, IStoreOf<NamedNaturalInMemoryStore> storeOfStores = null)
 {
     return new CLConfig(nessManager, storeOfStores);
 }
Example #19
0
 public static GraphNode GetRootNode(this IStoreOf <GraphNode> nodeStore)
 {
     return(GetNode(nodeStore, GraphPath.New()));
 }
Example #20
0
 public TokenEvaluator(NessManager nessManager, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
 }
Example #21
0
 public static StateMachineGraph <TState, TTrigger> New(TState initialState, IStoreOf <StateTransition <TState, TTrigger> > store)
 {
     return(new StateMachineGraph <TState, TTrigger>(initialState, store));
 }
Example #22
0
 public static TokenEvaluator New(NessManager nessManager, IStoreOf<NamedNaturalInMemoryStore> storeOfStores = null)
 {
     return new TokenEvaluator(nessManager, storeOfStores);
 }
Example #23
0
        /// <summary>
        /// given a parent node and a store of nodes, identifies the children of the parent and wires
        /// their values to the parent node's value
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="nodeStore"></param>
        private void WireParentToChildren(GraphNode parentNode, IStoreOf <GraphNode> nodeStore)
        {
            Condition.Requires(parentNode).IsNotNull();
            Condition.Requires(nodeStore).IsNotNull();

            List <string> skipFilter = new List <string>()
            {
                NullValueManager.ID, DelegateValueManager.ID, PrimitiveValueManager.ID
            };

            if (skipFilter.Contains(parentNode.ValueManagerId))
            {
                return;
            }

            var children = nodeStore.GetImmediateChildNodes(parentNode.Path).OrderBy((x) => { return(x.Path.EnumeratedSegmentIndex); }).ToList();
            var fields   = GraphingUtil.GetNestingNotatedFieldInfos(parentNode.NodeValue.GetType());

            //get the manager for this node value
            var manager = this.ChainOfResponsibility.FindHandlingValueManager(parentNode.NodeValue, this);

            Condition.Requires(manager).IsNotNull();

            var traverseList = manager.GetChildTraversalNodes(parentNode.NodeValue, parentNode.Path);

            traverseList.WithEach(tuple =>
            {
                BuildNode(tuple.Item1, tuple.Item2);
            });

            foreach (var each in children)
            {
                //add the children
                if (each.Path.IsEnumeratedSegment)
                {
                    if (each.NodeValue is IDictionary)
                    {
                        IDictionary     dict = parentNode.NodeValue as IDictionary;
                        DictionaryEntry de   = (DictionaryEntry)each.NodeValue;
                        dict.Add(de.Key, de.Value);
                    }
                    else if (each.NodeValue is Stack)
                    {
                        Stack stack = parentNode.NodeValue as Stack;
                        stack.Push(each.NodeValue);
                    }
                    else if (each.NodeValue is Queue)
                    {
                        Queue queue = parentNode.NodeValue as Queue;
                        queue.Enqueue(each.NodeValue);
                    }
                    else if (each.NodeValue is IList)
                    {
                        IList list = parentNode.NodeValue as IList;
                        list.Add(each.NodeValue);
                    }
                }
                else
                {
                    //get the matching field
                    GraphSegment gSeg = each.Path.CurrentSegment as GraphSegment;

                    //TODO: refactor implicit contract - that the paths match field names (GraphingUtil.GetNestingNotatedFieldInfos)
                    var matches = fields.Filter((x) => { return(x.Item1 == gSeg.Path); });
                    Condition.Requires(matches).IsNotNull().HasLength(1);

                    var fi = matches.First();
                    fi.Item2.SetValue(parentNode.NodeValue, each.NodeValue);
                }
            }
        }
Example #24
0
        /// <summary>
        /// given a Node Store, hydrates the value of each node, and wires the entire graph back together
        /// </summary>
        /// <param name="nodeStore"></param>
        /// <returns>the root node value</returns>
        private object ReconstituteFromNodeStore(IStoreOf<GraphNode> nodeStore)
        {
            Condition.Requires(nodeStore).IsNotNull();
            this.NodeStore = nodeStore;

            //iterate over all of the non-duplicate values and Reconstitute these nodes
            var nodes = NodeStore.GetAll();
            nodes.WithEach(node =>
            {
                if (node.ValueManagerId != DuplicateValueManager.ID)
                {
                    var mgr = this.ChainOfResponsibility.GetValueManagerById(node.ValueManagerId);
                    var obj = mgr.HydrateValue(node.Context, this);
                    node.NodeValue = obj;
                }
            });
            //wire the circ refs from the bottom up 
            nodes = nodes.OrderByDescending((x) => { return x.TraversalIndex; }).ToList();
            foreach (var node in nodes)
            {
                if (node.ValueManagerId == DuplicateValueManager.ID)
                {
                    var mgr = this.ChainOfResponsibility.GetValueManagerById(node.ValueManagerId);
                    var obj = mgr.HydrateValue(node, this);
                    node.NodeValue = obj;
                }
            }

            Dictionary<string, string> hasProcessed = new Dictionary<string, string>();

            //moving from bottom, wire children to parents
            foreach (var node in nodes)
            {
                //get the parent
                var parent = nodeStore.GetParentNode(node.Path);

                if (parent != null && hasProcessed.ContainsKey(parent.Id) == false)
                {
                    hasProcessed.Add(parent.Id, null);
                    WireParentToChildren(parent, nodeStore);
                }
            }

            //return root node
            var root = nodeStore.GetRootNode();
            return root.NodeValue;
        }
Example #25
0
 public static TokenEvaluator New(NessManager nessManager, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     return(new TokenEvaluator(nessManager, storeOfStores));
 }
Example #26
0
        public TokenEvaluator(NessManager nessManager, IStoreOf<NamedNaturalInMemoryStore> storeOfStores = null)
        {

        }