private void ProcessAttributeAssignOrUpdateList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken, AttributeAssignOrUpdateList attributeAssignOrUpdateList, ref RequestUpdate result) { Type myRequestedType; switch (attributeAssignOrUpdateList.CollectionDefinition.CollectionType) { case CollectionType.Set: #region set if (((TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition).All(_ => _.Value is ValueDefinition)) { #region base-set //has to be list of comparables SetCollectionWrapper setWrapper = new SetCollectionWrapper(); if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString)) { myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType; } else { myRequestedType = typeof(String); } foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition) { setWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType)); } result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, setWrapper); #endregion } else { #region edge-set EdgePredefinition edgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString); if (!vertexType.HasAttribute(attributeAssignOrUpdateList.AttributeIDChain.ContentString)) { throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeAssignOrUpdateList.AttributeIDChain.ContentString)); } IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString); foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.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"); } } if (attributeAssignOrUpdateList.Assign) { result.UpdateEdge(edgeDefinition); } else { result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, edgeDefinition); } #endregion } #endregion return; case CollectionType.List: #region list //has to be list of comparables ListCollectionWrapper listWrapper = new ListCollectionWrapper(); if (vertexType.HasProperty(attributeAssignOrUpdateList.AttributeIDChain.ContentString)) { myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString)).BaseType; } else { myRequestedType = typeof(String); } foreach (var aTupleElement in (TupleDefinition)attributeAssignOrUpdateList.CollectionDefinition.TupleDefinition) { listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType)); } result.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, listWrapper); #endregion return; case CollectionType.SetOfUUIDs: #region SetOfUUIDs EdgePredefinition anotheredgeDefinition = new EdgePredefinition(attributeAssignOrUpdateList.AttributeIDChain.ContentString); foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeAssignOrUpdateList.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.AddElementsToCollection(attributeAssignOrUpdateList.AttributeIDChain.ContentString, anotheredgeDefinition); #endregion return; default: return; } }
/// <summary> /// Parsing properties. /// </summary> /// <param name="myVertexNode">The vertex node.</param> /// <returns>A tuple with the property name and the value.</returns> private Tuple <String, Object> ParseProperties(XmlNode myVertexNode) { var property = myVertexNode.FirstChild; String key = String.Empty; Object value = null; String type = String.Empty; Boolean isCollectionSet = false; Boolean isCollectionList = false; while (property != null) { if (property.HasChildNodes) { switch (property.Name) { case "ID": key = property.InnerText; break; case "Type": if (property.InnerText.Contains(typeof(ListCollectionWrapper).Name)) { type = property.InnerText.Split('(', ')').ElementAt(1); isCollectionList = true; } else if (property.InnerText.Contains(typeof(SetCollectionWrapper).Name)) { type = property.InnerText.Split('(', ')').ElementAt(1); isCollectionSet = true; } else { type = property.InnerText; } break; case "Value": if (isCollectionList) { Regex regExp = new Regex(@"(?<=\[)(.*?)(?=\])"); var matches = regExp.Matches(property.InnerText); value = new ListCollectionWrapper(); foreach (var item in matches) { ((ListCollectionWrapper)value).Add((IComparable)TypeMapper(type, item.ToString())); } isCollectionList = false; } else if (isCollectionSet) { Regex regExp = new Regex(@"\[(/?[^\]]+)\]"); var matches = regExp.Matches(property.InnerText); value = new SetCollectionWrapper(); foreach (var item in matches) { ((SetCollectionWrapper)value).Add((IComparable)TypeMapper(type, item.ToString())); } isCollectionSet = false; } else { value = TypeMapper(type, property.InnerText); } break; } } property = property.NextSibling; } if (value == null) { if (isCollectionList) { value = new ListCollectionWrapper(); } if (isCollectionSet) { value = new SetCollectionWrapper(); } } return(new Tuple <string, object>(key, value)); }