예제 #1
0
파일: XML_IO.cs 프로젝트: dbludau/sones
        /// <summary>
        /// Generates a xml vertex view class.
        /// </summary>
        /// <param name="aVertex">The vertex view of the query result.</param>
        /// <returns>An generated xml class.</returns>
        private SchemaToClassesGenerator.VertexView GenerateVertexView(IVertexView aVertex)
        {
            var resultVertex = new SchemaToClassesGenerator.VertexView();

            if (aVertex != null)
            {
                #region properties

                List<Property> properties = new List<Property>();

                foreach (var aProperty in aVertex.GetAllProperties())
                {
                    var property = new Property();

                    property.ID = aProperty.Item1;

                    if (aProperty.Item2 != null)
                    {
                        if (aProperty.Item2 is ICollectionWrapper)
                        {
                            HandleListProperties((ICollectionWrapper)aProperty.Item2, ref property);
                        }
                        else
                        {

                            if (aProperty.Item2.GetType().IsSubclassOf(typeof(AUserdefinedDataType)))
                            {
                                property.Value = ((AUserdefinedDataType)aProperty.Item2).Value;
                            }
                            else
                            {
                                property.Value = aProperty.Item2.ToString();                                
                            }

                            property.Type = aProperty.Item2.GetType().Name;
                        }
                        
                    }
                    else
                    {
                        property.Value = String.Empty;
                        property.Type = "null";
                    }

                    properties.Add(property);
                }

                resultVertex.Properties = properties.ToArray();

                #endregion

                #region binaries

                List<BinaryData> binProperties = new List<BinaryData>();

                foreach (var aProperty in aVertex.GetAllBinaryProperties())
                {
                    var binProp = new BinaryData();

                    binProp.ID = aProperty.Item1;
                    var content = new byte[aProperty.Item2.Length];
                    aProperty.Item2.Read(content, 0, content.Length);

                    binProp.Content = content;

                    binProperties.Add(binProp);
                }

                resultVertex.BinaryProperties = binProperties.ToArray();

                #endregion

                #region edges

                List<SchemaToClassesGenerator.EdgeView> edges = new List<SchemaToClassesGenerator.EdgeView>();

                foreach (var aEdge in aVertex.GetAllEdges())
                {
                    if (aEdge.Item2 is IHyperEdgeView)
                    {
                        List<Tuple<SchemaToClassesGenerator.VertexView, IEnumerable<Tuple<String, Object>>>> innerVertices = new List<Tuple<SchemaToClassesGenerator.VertexView, IEnumerable<Tuple<String, Object>>>>();

                        #region single edges

                        foreach (var SingleEdges in ((sones.GraphQL.Result.HyperEdgeView)aEdge.Item2).GetAllEdges())
                        {
                            innerVertices.Add(new Tuple<SchemaToClassesGenerator.VertexView, IEnumerable<Tuple<String, Object>>>(GenerateVertexView(SingleEdges.GetTargetVertex()), SingleEdges.GetAllProperties()));
                        }

                        #endregion

                        var hyperEdge = new SchemaToClassesGenerator.HyperEdgeView();

                        hyperEdge.Name = aEdge.Item1;

                        #region set hyperedge properties

                        var edgeProperties = aEdge.Item2.GetAllProperties().ToArray();
                        hyperEdge.Properties = new Property[edgeProperties.Count()];

                        for (Int32 i = 0; i < edgeProperties.Count(); i++)
                        {
                            hyperEdge.Properties[i] = new Property();
                            hyperEdge.Properties[i].ID = edgeProperties[i].Item1;

                            if (edgeProperties[i].Item2 is ICollectionWrapper)
                            {
                                HandleListProperties((ICollectionWrapper)edgeProperties[i].Item2, ref hyperEdge.Properties[i]);
                            }
                            else
                            {
                                if (edgeProperties[i].Item2.GetType().IsSubclassOf(typeof(AUserdefinedDataType)))
                                {
                                    hyperEdge.Properties[i].Value = ((AUserdefinedDataType)edgeProperties[i].Item2).Value;
                                }
                                else
                                {
                                    hyperEdge.Properties[i].Value = edgeProperties[i].Item2.ToString();
                                }

                                hyperEdge.Properties[i].Type = edgeProperties[i].Item2.GetType().Name;
                            }                            
                        }

                        #endregion

                        hyperEdge.SingleEdge = new SchemaToClassesGenerator.SingleEdgeView[innerVertices.Count];

                        for (Int32 i = 0; i < innerVertices.Count; i++)
                        {
                            hyperEdge.SingleEdge[i] = new SchemaToClassesGenerator.SingleEdgeView();
                            var SingleEdgesProperties = innerVertices[i].Item2.ToArray();
                            
                            hyperEdge.SingleEdge[i].Properties = new Property[SingleEdgesProperties.Count()];

                            #region single edge properties

                            for (Int32 j = 0; j < SingleEdgesProperties.Count(); j++)
                            {
                                hyperEdge.SingleEdge[i].Properties[j] = new Property();
                                hyperEdge.SingleEdge[i].Properties[j].ID = SingleEdgesProperties[j].Item1;

                                if (SingleEdgesProperties[j].Item2 is ICollectionWrapper)
                                {
                                    HandleListProperties((ICollectionWrapper)SingleEdgesProperties[j].Item2, ref hyperEdge.SingleEdge[i].Properties[j]);
                                }
                                else
                                {
                                    if (SingleEdgesProperties[j].Item2.GetType().IsSubclassOf(typeof(AUserdefinedDataType)))
                                    {
                                        hyperEdge.SingleEdge[i].Properties[j].Value = ((AUserdefinedDataType)SingleEdgesProperties[j].Item2).Value;
                                    }
                                    else
                                    {
                                        hyperEdge.SingleEdge[i].Properties[j].Value = SingleEdgesProperties[j].Item2.ToString();
                                    }

                                    hyperEdge.SingleEdge[i].Properties[j].Type = SingleEdgesProperties[j].Item2.GetType().Name;
                                }
                            }

                            #endregion

                            #region target vertex

                            hyperEdge.SingleEdge[i].TargetVertex = new SchemaToClassesGenerator.VertexView();
                            
                            if (innerVertices[i].Item1.Properties != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.Properties = innerVertices[i].Item1.Properties.ToArray();
                            }

                            if (innerVertices[i].Item1.BinaryProperties != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.BinaryProperties = innerVertices[i].Item1.BinaryProperties.ToArray();
                            }

                            if (innerVertices[i].Item1.Edges != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.Edges = innerVertices[i].Item1.Edges.ToArray();
                            }

                            #endregion
                        }

                        edges.Add(hyperEdge);

                    }
                    else
                    {
                        var SingleEdges = new SchemaToClassesGenerator.SingleEdgeView();

                        SingleEdges.Name = aEdge.Item1;

                        var edgeProperties = aEdge.Item2.GetAllProperties().ToArray();

                        #region properties

                        SingleEdges.Properties = new Property[edgeProperties.Count()];

                        for (Int32 i = 0; i < edgeProperties.Count(); i++)
                        {
                            SingleEdges.Properties[i] = new Property();
                            SingleEdges.Properties[i].ID = edgeProperties[i].Item1;

                            if (edgeProperties[i].Item2 is ICollectionWrapper)
                            {
                                HandleListProperties((ICollectionWrapper)edgeProperties[i].Item2, ref SingleEdges.Properties[i]);
                            }
                            else
                            {
                                if (edgeProperties[i].Item2.GetType().IsSubclassOf(typeof(AUserdefinedDataType)))
                                {
                                    SingleEdges.Properties[i].Value = ((AUserdefinedDataType)edgeProperties[i].Item2).Value;
                                }
                                else
                                {
                                    SingleEdges.Properties[i].Value = edgeProperties[i].Item2.ToString();
                                }

                                SingleEdges.Properties[i].Type = edgeProperties[i].Item2.GetType().Name;
                            }
                        }

                        #endregion

                        #region target vertex

                        SingleEdges.TargetVertex = new SchemaToClassesGenerator.VertexView();
                        
                        var edgeTargetVertex = ((sones.GraphQL.Result.SingleEdgeView)aEdge.Item2).GetTargetVertex();

                        var targetVertex = GenerateVertexView(edgeTargetVertex);

                        if (edgeTargetVertex != null)
                        {
                            SingleEdges.TargetVertex.Properties = targetVertex.Properties.ToArray();
                            SingleEdges.TargetVertex.BinaryProperties = targetVertex.BinaryProperties.ToArray();
                            SingleEdges.TargetVertex.Edges = targetVertex.Edges.ToArray();
                        }

                        #endregion

                        edges.Add(SingleEdges);

                    }

                #endregion

                }

                resultVertex.Edges = edges.ToArray();

                #endregion
            }
            return resultVertex;
        }
예제 #2
0
파일: XML_IO.cs 프로젝트: alrehamy/sones
        /// <summary>
        /// Generates a xml vertex view class.
        /// </summary>
        /// <param name="aVertex">The vertex view of the query result.</param>
        /// <returns>An generated xml class.</returns>
        private SchemaToClassesGenerator.VertexView GenerateVertexView(IVertexView aVertex)
        {
            var resultVertex = new SchemaToClassesGenerator.VertexView();

            if (aVertex != null)
            {
                #region properties

                List <Property> properties = new List <Property>();

                foreach (var aProperty in aVertex.GetAllProperties())
                {
                    var property = new Property();

                    property.ID = aProperty.PropertyName;

                    if (aProperty.Property != null)
                    {
                        if (aProperty.Property is ICollectionWrapper)
                        {
                            HandleListProperties((ICollectionWrapper)aProperty.Property, ref property);
                        }
                        else
                        {
                            property.Value = aProperty.Property.ToString();
                            property.Type  = aProperty.Property.GetType().Name;
                        }
                    }
                    else
                    {
                        property.Value = String.Empty;
                        property.Type  = "null";
                    }

                    properties.Add(property);
                }

                resultVertex.Properties = properties.ToArray();

                #endregion

                #region binaries

                List <BinaryData> binProperties = new List <BinaryData>();

                foreach (var aProperty in aVertex.GetAllBinaryProperties())
                {
                    var binProp = new BinaryData();

                    binProp.ID = aProperty.PropertyName;
                    var content = new byte[aProperty.BinaryPropery.Length];
                    aProperty.BinaryPropery.Read(content, 0, content.Length);

                    binProp.Content = content;

                    binProperties.Add(binProp);
                }

                resultVertex.BinaryProperties = binProperties.ToArray();

                #endregion

                #region edges

                List <SchemaToClassesGenerator.EdgeView> edges = new List <SchemaToClassesGenerator.EdgeView>();

                foreach (var aEdge in aVertex.GetAllEdges())
                {
                    if (aEdge.Edge is IHyperEdgeView)
                    {
                        List <Tuple <SchemaToClassesGenerator.VertexView, IEnumerable <PropertyViewContainer> > > innerVertices = new List <Tuple <SchemaToClassesGenerator.VertexView, IEnumerable <PropertyViewContainer> > >();

                        #region single edges

                        foreach (var SingleEdges in ((sones.GraphQL.Result.HyperEdgeView)aEdge.Edge).GetAllEdges())
                        {
                            innerVertices.Add(new Tuple <SchemaToClassesGenerator.VertexView, IEnumerable <PropertyViewContainer> >(GenerateVertexView(SingleEdges.GetTargetVertex()), SingleEdges.GetAllProperties()));
                        }

                        #endregion

                        var hyperEdge = new SchemaToClassesGenerator.HyperEdgeView();

                        hyperEdge.Name = aEdge.EdgeName;

                        #region set hyperedge properties

                        var edgeProperties = aEdge.Edge.GetAllProperties().ToArray();
                        hyperEdge.Properties = new Property[edgeProperties.Count()];

                        for (Int32 i = 0; i < edgeProperties.Count(); i++)
                        {
                            hyperEdge.Properties[i]    = new Property();
                            hyperEdge.Properties[i].ID = edgeProperties[i].PropertyName;

                            if (edgeProperties[i].Property is ICollectionWrapper)
                            {
                                HandleListProperties((ICollectionWrapper)edgeProperties[i].Property, ref hyperEdge.Properties[i]);
                            }
                            else
                            {
                                hyperEdge.Properties[i].Type  = edgeProperties[i].Property.GetType().Name;
                                hyperEdge.Properties[i].Value = edgeProperties[i].Property.ToString();
                            }
                        }

                        #endregion

                        hyperEdge.SingleEdge = new SchemaToClassesGenerator.SingleEdgeView[innerVertices.Count];

                        for (Int32 i = 0; i < innerVertices.Count; i++)
                        {
                            hyperEdge.SingleEdge[i] = new SchemaToClassesGenerator.SingleEdgeView();
                            var SingleEdgesProperties = innerVertices[i].Item2.ToArray();

                            hyperEdge.SingleEdge[i].Properties = new Property[SingleEdgesProperties.Count()];

                            #region single edge properties

                            for (Int32 j = 0; j < SingleEdgesProperties.Count(); j++)
                            {
                                hyperEdge.SingleEdge[i].Properties[j]    = new Property();
                                hyperEdge.SingleEdge[i].Properties[j].ID = SingleEdgesProperties[j].PropertyName;

                                if (SingleEdgesProperties[j].Property is ICollectionWrapper)
                                {
                                    HandleListProperties((ICollectionWrapper)SingleEdgesProperties[j].Property, ref hyperEdge.SingleEdge[i].Properties[j]);
                                }
                                else
                                {
                                    hyperEdge.SingleEdge[i].Properties[j].Type  = SingleEdgesProperties[j].Property.GetType().Name;
                                    hyperEdge.SingleEdge[i].Properties[j].Value = SingleEdgesProperties[j].Property.ToString();
                                }
                            }

                            #endregion

                            #region target vertex

                            hyperEdge.SingleEdge[i].TargetVertex = new SchemaToClassesGenerator.VertexView();

                            if (innerVertices[i].Item1.Properties != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.Properties = innerVertices[i].Item1.Properties.ToArray();
                            }

                            if (innerVertices[i].Item1.BinaryProperties != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.BinaryProperties = innerVertices[i].Item1.BinaryProperties.ToArray();
                            }

                            if (innerVertices[i].Item1.Edges != null)
                            {
                                hyperEdge.SingleEdge[i].TargetVertex.Edges = innerVertices[i].Item1.Edges.ToArray();
                            }

                            #endregion
                        }

                        edges.Add(hyperEdge);
                    }
                    else
                    {
                        var SingleEdges = new SchemaToClassesGenerator.SingleEdgeView();

                        SingleEdges.Name = aEdge.EdgeName;

                        var edgeProperties = aEdge.Edge.GetAllProperties().ToArray();

                        #region properties

                        SingleEdges.Properties = new Property[edgeProperties.Count()];

                        for (Int32 i = 0; i < edgeProperties.Count(); i++)
                        {
                            SingleEdges.Properties[i]    = new Property();
                            SingleEdges.Properties[i].ID = edgeProperties[i].PropertyName;

                            if (edgeProperties[i].Property is ICollectionWrapper)
                            {
                                HandleListProperties((ICollectionWrapper)edgeProperties[i].Property, ref SingleEdges.Properties[i]);
                            }
                            else
                            {
                                SingleEdges.Properties[i].Type  = edgeProperties[i].Property.GetType().Name;
                                SingleEdges.Properties[i].Value = edgeProperties[i].Property.ToString();
                            }
                        }

                        #endregion

                        #region target vertex

                        SingleEdges.TargetVertex = new SchemaToClassesGenerator.VertexView();

                        var edgeTargetVertex = ((sones.GraphQL.Result.SingleEdgeView)aEdge.Edge).GetTargetVertex();

                        var targetVertex = GenerateVertexView(edgeTargetVertex);

                        if (edgeTargetVertex != null)
                        {
                            SingleEdges.TargetVertex.Properties       = targetVertex.Properties.ToArray();
                            SingleEdges.TargetVertex.BinaryProperties = targetVertex.BinaryProperties.ToArray();
                            SingleEdges.TargetVertex.Edges            = targetVertex.Edges.ToArray();
                        }

                        #endregion

                        edges.Add(SingleEdges);
                    }

                    #endregion
                }

                resultVertex.Edges = edges.ToArray();

                #endregion
            }
            return(resultVertex);
        }