Ejemplo n.º 1
0
        private IDictionary <string, object> GetNodes(GraphType graph, PropertyInfo nodesProperty, Type nodesType,
                                                      IList nodesList, object output)
        {
            var result = new Dictionary <string, object>();

            if (graph.Node?.Any() ?? false)
            {
                var keySetters = keySetterFactory.Get(
                    type: nodesType,
                    keyForType: KeyForType.Node);

                foreach (var node in graph.Node)
                {
                    var content = Activator.CreateInstance(nodesType);

                    if (node.Graph != default)
                    {
                        var contentNodes = nodesGetter.Invoke(
                            arg1: node.Graph,
                            arg2: nodesType,
                            arg3: content);

                        if (contentNodes?.Any() ?? false)
                        {
                            foreach (var childNode in contentNodes)
                            {
                                result.Add(
                                    key: childNode.Key,
                                    value: childNode.Value);
                            }
                        }
                    }

                    if (keySetters?.Any() ?? false)
                    {
                        foreach (var keySetter in keySetters)
                        {
                            keySetter.Invoke(
                                arg1: node,
                                arg2: content);
                        }
                    }

                    nodesList.Add(content);

                    result.Add(
                        key: node.Id,
                        value: content);
                }

                nodesProperty.SetCollection(
                    obj: output,
                    items: nodesList);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void SetEdges(GraphType graph, IDictionary <string, object> nodes, PropertyInfo edgesProperty,
                              PropertyInfo sourceProperty, PropertyInfo targetProperty, Type edgesType, IList edgesList, object output)
        {
            if ((graph.Edge?.Any() ?? false) &&
                (nodes?.Any() ?? false))
            {
                var keySetters = keySetterFactory.Get(
                    type: edgesType,
                    keyForType: KeyForType.Edge);

                foreach (var edge in graph.Edge)
                {
                    if (nodes.ContainsKey(edge.Source) &&
                        nodes.ContainsKey(edge.Target))
                    {
                        var content = Activator.CreateInstance(edgesType);

                        sourceProperty.SetValue(
                            obj: content,
                            value: nodes[edge.Source]);

                        targetProperty.SetValue(
                            obj: content,
                            value: nodes[edge.Target]);

                        if (keySetters?.Any() ?? false)
                        {
                            foreach (var keySetter in keySetters)
                            {
                                keySetter.Invoke(
                                    arg1: edge,
                                    arg2: content);
                            }
                        }

                        edgesList.Add(content);
                    }
                }

                edgesProperty.SetCollection(
                    obj: output,
                    items: edgesList);
            }
        }