Exemplo n.º 1
0
        private void ProcessNodes(Node startNode, string nodeSetFile, NodeSetModel nodeSet)
        {
            if (startNode.Children != null)
            {
                startNode.Children = new List <Node>(startNode.Children.OrderBy(childNode => childNode.ExecutionOrder));
            }

            if (startNode.Views != null)
            {
                startNode.Views = new List <View>(startNode.Views.OrderBy(viewDefinition => viewDefinition.ExecutionOrder));
            }

            ReorderPlugins(startNode.Read);
            ReorderPlugins(startNode.Write);

            LoadQueryFiles(nodeSetFile, startNode);
            LoadFileContent(nodeSetFile, startNode);
            startNode.NodeSet = nodeSet;
            startNode.Setup();

            foreach (Node node in startNode.Children)
            {
                node.ParentNode = startNode;
                ProcessNodes(node, nodeSetFile, nodeSet);
            }
        }
Exemplo n.º 2
0
        public LoadedNodeSet LoadNodeSet(string module, string treeNodesName, string nodeName)
        {
            LoadedNodeSet loaderContext = new LoadedNodeSet();
            //find the node definition in the directory specified
            //load the definition
            //parse the definition and populate into the models
            NodeSetModel nodeSet         = null;
            string       NODESET_DIRNAME = "NodeSets";
            string       cacheKey        = $"NodeSet_{module}_{treeNodesName}";

            nodeSet = _CachingService.Get <NodeSetModel>(cacheKey);
            if (nodeSet == null)
            {
                nodeSet = new NodeSetModel();
                string nodeSetDir  = Path.Combine(_KraftGlobalConfigurationSettings.GeneralSettings.ModulesRootFolder(module), module, NODESET_DIRNAME, treeNodesName);
                string nodeSetFile = Path.Combine(nodeSetDir, "Definition.json");

                if (!File.Exists(nodeSetFile))
                {
                    throw new FileNotFoundException($"The requested file: {nodeSetFile} was not found");
                }

                PhysicalFileProvider fileProvider = new PhysicalFileProvider(nodeSetDir);

                using (StreamReader file = File.OpenText(nodeSetFile))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    RootObject     result     = (RootObject)serializer.Deserialize(file, typeof(RootObject));
                    nodeSet = result.NodeSet;
                };

                nodeSet.Name = treeNodesName;

                ProcessNodes(nodeSet.Root, nodeSetFile, nodeSet);
                _CachingService.Insert(cacheKey, nodeSet, fileProvider.Watch("**/*.*"));
            }

            loaderContext.NodeSet   = nodeSet;
            loaderContext.StartNode =
                (!string.IsNullOrEmpty(nodeName))
                    ? FindNode(nodeSet.Root.Children, ParseNodePath(nodeName), n => n.Children, n => n.NodeKey.Trim())
                    : nodeSet.Root;

            return(loaderContext);
        }