private String Recurs(String str, IVertexType StartType, List <TypeWithProperty> type_property_object, List <Tuple <long, long> > PATHShortDSF) { var hyperEdgeOut = StartType.GetOutgoingEdgeDefinitions(true); var hyperEdgeInc = StartType.GetIncomingEdgeDefinitions(true); foreach (IOutgoingEdgeDefinition value in hyperEdgeOut) { if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null) { if (type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID).Count() > 0) { var temp = str; foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID)) { _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name)); } str = temp + '.' + value.Name; Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF); str = temp; } else { var temp = str; str += '.' + value.Name; Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF); str = temp; } } } foreach (IIncomingEdgeDefinition value in hyperEdgeInc) { if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null) { if (type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID).Count() > 0) { var temp = str; foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID)) { _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name)); } str = temp + '.' + value.Name; Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF); str = temp; } else { var temp = str; str += '.' + value.Name; Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF); str = temp; } } } str = ""; return(null); }
void DFS(IVertexType start, IVertexType end, List<Tuple<long,long>> Parents) { var outEdges = start.GetOutgoingEdgeDefinitions(true); var incEdges = start.GetIncomingEdgeDefinitions(true); foreach (IOutgoingEdgeDefinition vertexType in outEdges) { if (Parents.Where(x=>x.Item1 == vertexType.TargetVertexType.ID).Count()==0)//(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID))) { var current_parents = Parents.ToList(); Parents.Add(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID)); if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents)) _path.Add(Parents); else { DFS(vertexType.TargetVertexType, end, Parents); } Parents = current_parents; } } foreach (IIncomingEdgeDefinition vertexType in incEdges) { if (Parents.Where(x => x.Item1 == vertexType.RelatedEdgeDefinition.SourceVertexType.ID).Count() == 0) //if (!Parents.Contains(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID))) { var current_parents = Parents.ToList(); Parents.Add(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID,vertexType.ID)); if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents)) { _path.Add(Parents); } else { DFS(vertexType.RelatedEdgeDefinition.SourceVertexType, end, Parents); } Parents = current_parents; } } }
void DFS(IVertexType start, IVertexType end, List <Tuple <long, long> > Parents) { var outEdges = start.GetOutgoingEdgeDefinitions(true); var incEdges = start.GetIncomingEdgeDefinitions(true); foreach (IOutgoingEdgeDefinition vertexType in outEdges) { if (Parents.Where(x => x.Item1 == vertexType.TargetVertexType.ID).Count() == 0) //(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID))) { var current_parents = Parents.ToList(); Parents.Add(Tuple.Create(vertexType.TargetVertexType.ID, vertexType.ID)); if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents)) { _path.Add(Parents); } else { DFS(vertexType.TargetVertexType, end, Parents); } Parents = current_parents; } } foreach (IIncomingEdgeDefinition vertexType in incEdges) { if (Parents.Where(x => x.Item1 == vertexType.RelatedEdgeDefinition.SourceVertexType.ID).Count() == 0) //if (!Parents.Contains(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID))) { var current_parents = Parents.ToList(); Parents.Add(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID)); if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents)) { _path.Add(Parents); } else { DFS(vertexType.RelatedEdgeDefinition.SourceVertexType, end, Parents); } Parents = current_parents; } } }
/// <summary> /// Creates the ddl of a type. /// </summary> /// <param name="myVertexType">The vertex type.</param> private String CreateGraphDDL_VertexType(IVertexType myVertexType) { var stringBuilder = new StringBuilder(); String delimiter = ", "; stringBuilder.AppendFormat("{0} ", myVertexType.Name); #region parent type //EXTENDS ... if (myVertexType.HasParentType) { stringBuilder.AppendFormat("{0} {1} ", S_EXTENDS.ToUpperString(), myVertexType.ParentVertexType.Name); } #endregion #region attributes //are there attributes if (myVertexType.HasAttributes(false)) { #region !incomingEdges if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind != AttributeType.IncomingEdge)) { //so, there are attributes that are no incoming edges stringBuilder.Append(String.Concat(S_ATTRIBUTES.ToUpperString(), " ", S_BRACKET_LEFT)); #region properties if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.Property)) { stringBuilder.Append(String.Concat(CreateGraphDDLOfProperties(myVertexType.GetPropertyDefinitions(false)))); } #endregion #region outgoing edges if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.OutgoingEdge)) { stringBuilder.Append(String.Concat(CreateGraphDDLOfOutgoingEdges(myVertexType.GetOutgoingEdgeDefinitions(false), myVertexType))); } #endregion if (stringBuilder.ToString().EndsWith(delimiter)) stringBuilder.RemoveSuffix(delimiter); stringBuilder.Append(String.Concat(S_BRACKET_RIGHT, " ")); } #endregion #region incomingEdges if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.IncomingEdge)) { stringBuilder.Append( String.Concat(S_INCOMINGEDGES.ToUpperString(), " ", S_BRACKET_LEFT.ToUpperString(), CreateGraphDDLOfIncomingEdges( myVertexType.GetIncomingEdgeDefinitions(false)), S_BRACKET_RIGHT.ToUpperString(), " ")); } #endregion } #endregion #region Uniques if (myVertexType.HasUniqueDefinitions(false)) { if (myVertexType.GetUniqueDefinitions(false).Count() > 0) { stringBuilder.Append(S_UNIQUE.ToUpperString() + " " + S_BRACKET_LEFT.Symbol + CreateGraphDDLOfUniqueAttributes( myVertexType .GetUniqueDefinitions(false)) + S_BRACKET_RIGHT.Symbol + " "); } } #endregion #region Mandatory attributes if (myVertexType.HasProperties(false)) { if (myVertexType.GetPropertyDefinitions(false).Any(aProperty => aProperty.IsMandatory)) { stringBuilder.Append(S_MANDATORY.ToUpperString() + " " + S_BRACKET_LEFT.Symbol + CreateGraphDDLOfMandatoryAttributes( myVertexType .GetPropertyDefinitions(false) .Where(aProperty => aProperty.IsMandatory)) + S_BRACKET_RIGHT.Symbol + " "); } } #endregion #region Indices var indices = myVertexType.GetIndexDefinitions(false).Except( myVertexType.GetUniqueDefinitions(false).Select(_ => _.CorrespondingIndex)); if (indices.Count() > 0) { stringBuilder.Append(S_INDICES.ToUpperString() + " " + S_BRACKET_LEFT.Symbol + CreateGraphDDLOfIndices(indices, myVertexType) + S_BRACKET_RIGHT.Symbol); } #endregion return stringBuilder.ToString(); }
private String Recurs(String str,IVertexType StartType, List<TypeWithProperty> type_property_object, List<Tuple<long, long>> PATHShortDSF) { var hyperEdgeOut = StartType.GetOutgoingEdgeDefinitions(true); var hyperEdgeInc = StartType.GetIncomingEdgeDefinitions(true); foreach (IOutgoingEdgeDefinition value in hyperEdgeOut) { if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null) { if (type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID).Count() > 0) { var temp = str; foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID)) { _stringPath.Add(Tuple.Create(val.Type.Name+'.'+val.PropertyDefinition.Name,str + '.' + value.Name + '.' + val.PropertyDefinition.Name)); } str = temp + '.' + value.Name; Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF); str = temp; } else { var temp = str; str += '.' + value.Name; Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF); str = temp; } } } foreach (IIncomingEdgeDefinition value in hyperEdgeInc) { if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null) { if (type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID).Count() > 0) { var temp = str; foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID)) { _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name)); } str = temp + '.' + value.Name; Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF); str = temp; } else { var temp = str; str += '.' + value.Name; Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF); str = temp; } } } str = ""; return null; }
/// <summary> /// Generate an output for an type with the attributes of the types and all parent types /// </summary> /// <param name="myDBContext">The db context</param> /// <param name="myType">The db type</param> /// <param name="myDepth">If depth == 0 only the type basic attributes will be returned</param> private IVertexView GenerateOutput(IVertexType myType, Int32 myDepth = 0) { var retVal = new Dictionary<String, object>(); List<IVertexView> result = new List<IVertexView>(); var edges = new Dictionary<String, IEdgeView>(); //base output retVal.Add("VertexID", myType.ID); retVal.Add("Type", myType.GetType().Name); retVal.Add("Name", myType.Name); retVal.Add("IsUserDefined", myType.IsUserDefined); //additional output if (myDepth > 0) { retVal.Add("IsAbstract", myType.IsAbstract); edges.Add("Properties", new HyperEdgeView(null, GeneratePropertiesOutput(myType, myType.GetPropertyDefinitions(true), myDepth))); edges.Add("Edges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetOutgoingEdgeDefinitions(true)))); edges.Add("Incomingedges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetIncomingEdgeDefinitions(true)))); edges.Add("UniqueAttributes", new HyperEdgeView(null, GenerateUniquePropertiesOutput(myType, myType.GetUniqueDefinitions(true)))); edges.Add("Indices", new HyperEdgeView(null, GenerateIndicesOutput(myType))); if (myType.HasParentType) edges.Add("Extends", new SingleEdgeView(null, GenerateOutput(myType.ParentVertexType))); if (myType.HasChildTypes) { List<ISingleEdgeView> list = new List<ISingleEdgeView>(); foreach (var child in myType.ChildrenVertexTypes) list.Add(new SingleEdgeView(null, GenerateOutput(child))); edges.Add("ChildrenVertexTypes", new HyperEdgeView(null, list)); } if (!string.IsNullOrWhiteSpace(myType.Comment)) retVal.Add("Comment", myType.Comment); } return new VertexView(retVal, edges); }
/// <summary> /// This will add all attributes of <paramref name="myDBObject"/> to the /// <paramref name="myAttributes"/> reference. Reference attributes will be resolved to the <paramref name="myDepth"/> /// </summary> private void AddAttributesByDBO( SecurityToken mySecurityToken, Int64 myTransactionToken, ref Tuple<IDictionary<String, Object>, IDictionary<String, IEdgeView>> myAttributes, IVertexType myType, IVertex myDBObject, Int64 myDepth, EdgeList myEdgeList, String myReference, Boolean myUsingGraph, TypesOfSelect mySelType, Int64? myTypeID = null) { #region Get all attributes which are stored at the DBO #region properties foreach (var aProperty in myType.GetPropertyDefinitions(true)) { var tempResult = aProperty.GetValue(myDBObject); if (tempResult != null) { myAttributes.Item1.Add(aProperty.Name, tempResult); } } #endregion #region unstructured data foreach (var aUnstructuredProperty in myDBObject.GetAllUnstructuredProperties()) { myAttributes.Item1.Add(aUnstructuredProperty.PropertyName, aUnstructuredProperty.Property); } #endregion #region outgoing edges foreach (var outgoingEdgeDefinition in myType.GetOutgoingEdgeDefinitions(true)) { if (myDBObject.HasOutgoingEdge(outgoingEdgeDefinition.ID)) { // Since we can define special depth (via setting) for attributes we need to check them now myDepth = GetDepth(-1, myDepth, myType, outgoingEdgeDefinition); if ((myDepth > 0)) { myAttributes.Item2.Add( outgoingEdgeDefinition.Name, ResolveAttributeValue( outgoingEdgeDefinition, myDBObject.GetOutgoingEdge(outgoingEdgeDefinition.ID), myDepth, myEdgeList, myDBObject, myReference, myUsingGraph, mySecurityToken, myTransactionToken)); } else { myAttributes.Item2.Add(outgoingEdgeDefinition.Name, GetNotResolvedReferenceEdgeAttributeValue(myDBObject .GetOutgoingEdge(outgoingEdgeDefinition.ID) .GetTargetVertices())); } } } #endregion #region incoming foreach (var aIncomingEdgeDefinition in myType.GetIncomingEdgeDefinitions(true)) { if (myDBObject.HasIncomingVertices(aIncomingEdgeDefinition .RelatedEdgeDefinition .RelatedType.ID, aIncomingEdgeDefinition .RelatedEdgeDefinition.ID)) { if (myDepth > 0) { myAttributes.Item2.Add( aIncomingEdgeDefinition.Name, ResolveIncomingEdgeValue( aIncomingEdgeDefinition, myDBObject.GetIncomingVertices(aIncomingEdgeDefinition .RelatedEdgeDefinition .RelatedType .ID, aIncomingEdgeDefinition .RelatedEdgeDefinition.ID), myDepth, myEdgeList, myDBObject, myReference, myUsingGraph, mySecurityToken, myTransactionToken)); } else { myAttributes.Item2.Add(aIncomingEdgeDefinition.Name, GetNotResolvedReferenceEdgeAttributeValue(myDBObject.GetIncomingVertices(aIncomingEdgeDefinition .RelatedEdgeDefinition .RelatedType.ID, aIncomingEdgeDefinition .RelatedEdgeDefinition.ID))); } } } #endregion #endregion }
/// <summary> /// Generate an output for an type with the attributes of the types and all parent types /// </summary> /// <param name="myDBContext">The db context</param> /// <param name="myType">The db type</param> /// <param name="myDepth">If depth == 0 only the type basic attributes will be returned</param> private IVertexView GenerateOutput(IVertexType myType, Int32 myDepth = 0) { var retVal = new Dictionary <String, object>(); List <IVertexView> result = new List <IVertexView>(); var edges = new Dictionary <String, IEdgeView>(); //base output retVal.Add("VertexID", myType.ID); retVal.Add("Type", myType.GetType().Name); retVal.Add("Name", myType.Name); retVal.Add("IsUserDefined", myType.IsUserDefined); //additional output if (myDepth > 0) { retVal.Add("IsAbstract", myType.IsAbstract); edges.Add("Properties", new HyperEdgeView(null, GeneratePropertiesOutput(myType, myType.GetPropertyDefinitions(true), myDepth))); edges.Add("Edges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetOutgoingEdgeDefinitions(true)))); edges.Add("Incomingedges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetIncomingEdgeDefinitions(true)))); edges.Add("UniqueAttributes", new HyperEdgeView(null, GenerateUniquePropertiesOutput(myType, myType.GetUniqueDefinitions(true)))); edges.Add("Indices", new HyperEdgeView(null, GenerateIndicesOutput(myType))); if (myType.HasParentType) { edges.Add("Extends", new SingleEdgeView(null, GenerateOutput(myType.ParentVertexType))); } if (myType.HasChildTypes) { List <ISingleEdgeView> list = new List <ISingleEdgeView>(); foreach (var child in myType.ChildrenVertexTypes) { list.Add(new SingleEdgeView(null, GenerateOutput(child))); } edges.Add("ChildrenVertexTypes", new HyperEdgeView(null, list)); } if (!string.IsNullOrWhiteSpace(myType.Comment)) { retVal.Add("Comment", myType.Comment); } } return(new VertexView(retVal, edges)); }