private static void ProcessStructuredProperty(GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken, IVertexType vertexType, AAttributeAssignOrUpdate aAttributeDefinition, ref RequestInsertVertex result) { #region AttributeAssignOrUpdateValue if (aAttributeDefinition is AttributeAssignOrUpdateValue) { var value = aAttributeDefinition as AttributeAssignOrUpdateValue; result.AddUnknownProperty(value.AttributeIDChain.ContentString, value.Value); return; } #endregion #region AttributeAssignOrUpdateList if (aAttributeDefinition is AttributeAssignOrUpdateList) { var value = aAttributeDefinition as AttributeAssignOrUpdateList; switch (value.CollectionDefinition.CollectionType) { case CollectionType.Set: #region set if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString)) { throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, aAttributeDefinition.AttributeIDChain.ContentString)); } IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition .AttributeIDChain .ContentString); EdgePredefinition edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString); foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition) { if (aTupleElement.Value is BinaryExpressionDefinition) { #region BinaryExpressionDefinition var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType; foreach (var aVertex in ProcessBinaryExpression( (BinaryExpressionDefinition)aTupleElement.Value, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType)) { var inneredge = new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID); foreach (var aStructuredProperty in aTupleElement.Parameters) { inneredge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value); } edgeDefinition.AddEdge(inneredge); } #endregion } else { throw new NotImplementedQLException("TODO"); } } result.AddEdge(edgeDefinition); #endregion) return; case CollectionType.List: #region list //has to be list of comparables ListCollectionWrapper listWrapper = new ListCollectionWrapper(); Type myRequestedType; if (vertexType.HasProperty(aAttributeDefinition.AttributeIDChain.ContentString)) { myRequestedType = ((IPropertyDefinition)vertexType .GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString)).BaseType; } else { myRequestedType = typeof(String); } foreach (var aTupleElement in (TupleDefinition)value.CollectionDefinition.TupleDefinition) { listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType)); } result.AddStructuredProperty(aAttributeDefinition.AttributeIDChain.ContentString, listWrapper); #endregion) return; case CollectionType.SetOfUUIDs: #region SetOfUUIDs EdgePredefinition anotheredgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString); foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)value.CollectionDefinition.TupleDefinition).Elements) { foreach (var aVertexIDTuple in aTupleElement.VertexIDs) { var innerEdge = new EdgePredefinition(); foreach (var aStructuredProperty in aVertexIDTuple.Item2) { innerEdge.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value); } innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1); anotheredgeDefinition.AddEdge(innerEdge); } } result.AddEdge(anotheredgeDefinition); #endregion return; default: return; } } #endregion #region SetRefNode if (aAttributeDefinition is AttributeAssignOrUpdateSetRef) { var value = aAttributeDefinition as AttributeAssignOrUpdateSetRef; var edgeDefinition = new EdgePredefinition(value.AttributeIDChain.ContentString); if (value.SetRefDefinition.IsREFUUID) { #region direct vertex ids foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition) { if (aTupleElement.Value is ValueDefinition) { #region ValueDefinition foreach (var aProperty in aTupleElement.Parameters) { edgeDefinition.AddUnknownProperty(aProperty.Key, aProperty.Value); } edgeDefinition.AddVertexID(value.SetRefDefinition.ReferencedVertexType, Convert.ToInt64(((ValueDefinition) aTupleElement.Value).Value)); #endregion } else { throw new NotImplementedQLException("TODO"); } } #endregion } else { #region expression if (!vertexType.HasAttribute(aAttributeDefinition.AttributeIDChain.ContentString)) { throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, aAttributeDefinition.AttributeIDChain.ContentString)); } IAttributeDefinition attribute = vertexType.GetAttributeDefinition(aAttributeDefinition.AttributeIDChain.ContentString); foreach (var aTupleElement in value.SetRefDefinition.TupleDefinition) { if (aTupleElement.Value is BinaryExpressionDefinition) { #region BinaryExpressionDefinition var targetVertexType = ((IOutgoingEdgeDefinition)attribute).TargetVertexType; var vertexIDs = ProcessBinaryExpression( (BinaryExpressionDefinition)aTupleElement.Value, myPluginManager, myGraphDB, mySecurityToken, myTransactionToken, targetVertexType).ToList(); if (vertexIDs.Count > 1) { throw new ReferenceAssignmentExpectedException(String.Format("It is not possible to create a single edge pointing to {0} vertices", vertexIDs.Count)); } var inneredge = new EdgePredefinition(); foreach (var aStructuredProperty in aTupleElement.Parameters) { edgeDefinition.AddUnknownProperty(aStructuredProperty.Key, aStructuredProperty.Value); } edgeDefinition.AddVertexID(vertexIDs.FirstOrDefault().VertexTypeID, vertexIDs.FirstOrDefault().VertexID); #endregion } else { throw new NotImplementedQLException(""); } } #endregion } result.AddEdge(edgeDefinition); return; } #endregion }
/// <summary> /// Reads the attributes of a vertex based on the attribute definitions. /// /// Updates the RequestInsertVertex with the read attributes. /// </summary> /// <param name='myReader'> /// XmlReader /// </param> /// <param name='myRequestInsertVertex'> /// RequestInsertVertex where the attributes will be added. /// </param> private void ReadVertexAttributes(XmlReader myReader, RequestInsertVertex myRequestInsertVertex) { using (var vertexDataReader = myReader.ReadSubtree()) { //read attributes while (vertexDataReader.Read()) { if (vertexDataReader.Name == GraphMLTokens.DATA) { var key = myReader.GetAttribute(GraphMLTokens.KEY); var value = myReader.ReadElementContentAsString(); if (key != null) { var tupel = _AttributeDefinitions[key]; if (tupel != null) { var attrName = tupel.Item2; var attrType = tupel.Item3; if (value == null) //use default value { value = tupel.Item4; } if (attrType != null && value != null) { // myRequestInsertVertex.AddStructuredProperty(attrName, // (IComparable)ParseValue(attrType, value)); myRequestInsertVertex.AddUnknownProperty(attrName, Convert.ChangeType(ParseValue(attrType, value), typeof(String), CultureInfo.GetCultureInfo("en-us"))); } } } } } } }