internal static ServiceBaseExpression ToServiceExpression(IExpression myExpression) { ServiceBaseExpression expression = null; if (myExpression is BinaryExpression) { expression = new ServiceBinaryExpression((BinaryExpression)myExpression); } else if (myExpression is PropertyExpression) { expression = new ServicePropertyExpression((PropertyExpression)myExpression); } else if (myExpression is SingleLiteralExpression) { expression = new ServiceSingleLiteralExpression((SingleLiteralExpression)myExpression); } else if (myExpression is CollectionLiteralExpression) { expression = new ServiceCollectionLiteralExpression((CollectionLiteralExpression)myExpression); } else if (myExpression is RangeLiteralExpression) { expression = new ServiceRangeLiteralExpression((RangeLiteralExpression)myExpression); } else if (myExpression is UnaryExpression) { expression = new ServiceUnaryExpression((UnaryExpression)myExpression); } return(expression); }
private void GatherData() { #region Get VertexType from DB by Name //how to get a type from the DB var TagDBType = _GraphDS_Service.GetVertexTypeByName(SecToken, TransToken, "Tag"); var WebsiteDBType = _GraphDS_Service.GetVertexTypeByName(SecToken, TransToken, "Website"); #endregion #region Get VertexType definition information with VertexTypeService //read informations from type Console.WriteLine("Got vertex type name " + TagDBType.Name + " with ID " + TagDBType.ID); Console.WriteLine("Got vertex type name " + WebsiteDBType.Name + " with ID " + WebsiteDBType.ID); //are there other types wich extend the type "Tag" or "Website" var hasChildTypes = _VertexTypeService.HasChildTypeByVertexType(SecToken,TransToken,TagDBType); Console.WriteLine(TagDBType.Name + " HasChildTypes: " + hasChildTypes.ToString()); hasChildTypes = _VertexTypeService.HasChildTypeByVertexType(SecToken, TransToken, WebsiteDBType); Console.WriteLine(WebsiteDBType.Name + " HasChildTypes: " + hasChildTypes.ToString()); #region collect all Properties on VertexType "Tag" and "Website" var TagPropertyList = _VertexTypeService.GetPropertyDefinitionsByVertexType(SecToken, TransToken,TagDBType.Name, false); var WebsitePropertyList = _VertexTypeService.GetPropertyDefinitionsByVertexType(SecToken, TransToken, WebsiteDBType.Name, false); Console.WriteLine(Environment.NewLine); Console.WriteLine("Properties of VertexType 'Tag'"); foreach (var Property in TagPropertyList) { Console.WriteLine(Property.Name + " : " + Property.BaseType.Substring(0, Property.BaseType.IndexOf(',')) + "| IsMandatory: " + Property.IsMandatory.ToString() + "| ID: " + Property.ID.ToString()); } Console.WriteLine(Environment.NewLine); Console.WriteLine("Properties of VertexType 'Website'"); foreach (var Property in WebsitePropertyList) { Console.WriteLine(Property.Name + " : " + Property.BaseType.Substring(0, Property.BaseType.IndexOf(',')) + "| IsMandatory: " + Property.IsMandatory.ToString() + "| ID: " + Property.ID.ToString()); } Console.WriteLine(Environment.NewLine); #endregion //are there any IncomingEdges var TagIncoming = _VertexTypeService.HasIncomingEdges(SecToken, TransToken, TagDBType, false); var WebsiteIncoming = _VertexTypeService.HasIncomingEdges(SecToken, TransToken, WebsiteDBType, false); Console.WriteLine(TagDBType.Name + " HasIncomingEdges: " + TagIncoming); Console.WriteLine(WebsiteDBType.Name + " HasIncomingEdges: " + WebsiteIncoming); Console.WriteLine(Environment.NewLine); //todo add some VertexTypeService functions #endregion #region Get Vertex Instance information with VertexInstanceService //get a specific property definition var TagPropName = _VertexTypeService.GetPropertyDefinitionByVertexType(SecToken, TransToken, TagDBType.Name, "Name"); var WebPropName = _VertexTypeService.GetPropertyDefinitionByVertexType(SecToken, TransToken, WebsiteDBType.Name, "Name"); var WebPropURL = _VertexTypeService.GetPropertyDefinitionByVertexType(SecToken, TransToken, WebsiteDBType.Name, "URL"); var TagWebsite = _VertexTypeService.GetOutgoingEdgeDefinitionByVertexType(SecToken, TransToken, TagDBType, "TaggedWebsites"); #region Get all instances of the VertexTypes //how to get all instances of a type from the DB Stopwatch watch1 = Stopwatch.StartNew(); var TagInstances = _GraphDS_Service.GetVerticesByType(SecToken, TransToken, TagDBType); watch1.Stop(); Console.WriteLine(watch1.Elapsed.TotalMilliseconds); watch1.Reset(); watch1.Start(); TagInstances = _GraphDS_Service.GetVerticesByType(SecToken, TransToken, TagDBType); watch1.Stop(); Console.WriteLine(watch1.Elapsed.TotalMilliseconds); var WebsiteInstances = _GraphDS_Service.GetVerticesByType(SecToken, TransToken, WebsiteDBType); #endregion #region Iterate over all instances Console.WriteLine("Collect all vertex instances of type " + WebsiteDBType.Name + ":"); foreach (var item in WebsiteInstances) { //to get the value of a property of an instance, you need the property ID //(that's why we fetched the type from DB an read out the property definition of property "Name") var name = _VertexInstanceService.GetPropertyAsStringByVertexInstance(SecToken, TransToken, item, WebPropName.ID); var url = _VertexInstanceService.GetPropertyAsStringByVertexInstance(SecToken, TransToken, item, WebPropURL.ID); Console.WriteLine("Vertex instance: " + name + " | URL: " + url); } Console.WriteLine(Environment.NewLine); Console.WriteLine("Collect all vertex instances of type " + TagDBType.Name + ":"); foreach (var item in TagInstances) { var vertexname = _VertexInstanceService.GetPropertyAsStringByVertexInstance(SecToken, TransToken, item, TagPropName.ID); var edges = _VertexInstanceService.GetOutgoingHyperEdge(SecToken, TransToken, item, TagWebsite.ID).SingleEdges; Console.Write(vertexname + " points to: "); foreach (var edge in edges) { var name = _VertexInstanceService.GetPropertyAsStringByVertexInstance(SecToken, TransToken, edge.TargetVertex, WebPropName.ID); Console.Write(" |-->" + name + " "); } Console.Write(Environment.NewLine); } #endregion #region How to use Expressions to filter like a 'Where' //We want to search through an property var PropExpression = new ServicePropertyExpression(); PropExpression.NameOfProperty = "Name"; PropExpression.NameOfVertexType = "Website"; //Single Constances are SingleLiteralExpression, there are also Range and Multiple Literals var SingleExpression = new ServiceSingleLiteralExpression(); SingleExpression.Constant = "CNN"; //BinaryExpression With a Left Statement, an Operator and a Right Statement var BinExpression = new ServiceBinaryExpression(); BinExpression.Right = PropExpression; BinExpression.Left = SingleExpression; BinExpression.Operator = ServiceBinaryOperator.Equals; //In this case we query the Vertices "Where Name = 'CNN'". That's just one vertex ;) var a = _GraphDS_Service.GetVerticesByExpression(SecToken, TransToken, BinExpression); Console.WriteLine("\r\nExpression was: Name(Property) = (Equals) 'CNN'"); Console.WriteLine("Expression Result: " + a.Count + " affected Vertices"); #endregion #endregion }