Example #1
0
        /// <summary>
        /// Generate an output for an index
        /// </summary>
        /// <param name="myIndex">The index</param>
        /// <param name="myName">The index name</param>
        /// <returns>List of readouts which contain the index information</returns>
        private IEnumerable <IVertexView> GenerateOutput(IEnumerable <IIndexDefinition> myIndices, String myName)
        {
            var _Index = new Dictionary <String, Object>();
            var result = new List <IVertexView>();

            foreach (var index in myIndices)
            {
                _Index.Add("Name", index.Name);
                _Index.Add("ID", index.ID);
                _Index.Add("Edition", index.Edition);
                _Index.Add("IndexTypeName", index.IndexTypeName);
                _Index.Add("IsUserDefinied", index.IsUserdefined);

                ListCollectionWrapper list = new ListCollectionWrapper();

                foreach (var prop in index.IndexedProperties)
                {
                    list.Add(prop.Name);
                }

                _Index.Add("IndexedProperties", list);

                result.Add(new VertexView(new Dictionary <String, Object>(_Index), new Dictionary <String, IEdgeView>()));
                _Index.Clear();
            }

            return(result);
        }
        /// <summary>
        /// output for the type indices
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable <ISingleEdgeView> GenerateIndicesOutput(IVertexType myType)
        {
            var _AttributeReadout = new List <ISingleEdgeView>();

            foreach (var idx in myType.GetIndexDefinitions(true))
            {
                var Attributes = new Dictionary <String, Object>();

                Attributes.Add("ID", idx.ID);
                Attributes.Add("Type", idx.IndexTypeName);
                Attributes.Add("Name", idx.Name);
                Attributes.Add("Edition", idx.Edition);

                var list = new ListCollectionWrapper();
                foreach (var item in idx.IndexedProperties)
                {
                    list.Add(item.Name);
                }

                Attributes.Add("IndexedProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary <String, IEdgeView>())));
            }

            return(_AttributeReadout);
        }
Example #3
0
        /// <summary>
        /// generates an output for an edgetype
        /// </summary>
        /// <param name="myEdge">the edge</param>
        /// <param name="myEdgeName">edge name</param>
        /// <returns>list of readouts with the information</returns>
        private IVertexView GenerateOutput(IEdgeType myEdge, String myEdgeName)
        {
            var Edge = new Dictionary <String, Object>();

            Edge.Add("ID", myEdge.ID);
            Edge.Add("Type", myEdge.GetType().Name);
            Edge.Add("Name", myEdge.Name);
            Edge.Add("IsUserDefined", myEdge.IsUserDefined);
            Edge.Add("IsSealed", myEdge.IsSealed);
            Edge.Add("ParentEdgeType", myEdge.ParentEdgeType.Name);

            var list = new ListCollectionWrapper();

            foreach (var child in myEdge.ChildrenEdgeTypes)
            {
                list.Add(child.Name);
            }

            Edge.Add("ChildrenEdgeTypes", list);
            Edge.Add("Comment", myEdge.Comment);

            return(new VertexView(Edge, new Dictionary <String, IEdgeView>()));
        }
        /// <summary>
        /// output for the type uniques
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <param name="myUniques">The uniqueDefinitions</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable <ISingleEdgeView> GenerateUniquePropertiesOutput(IVertexType myType, IEnumerable <IUniqueDefinition> myUniques)
        {
            var _AttributeReadout = new List <ISingleEdgeView>();

            foreach (var unique in myUniques)
            {
                var Attributes = new Dictionary <String, Object>();

                Attributes.Add("CorrespondingIndex", unique.CorrespondingIndex.Name);
                Attributes.Add("DefiningVertexType", unique.DefiningVertexType.Name);

                var list = new ListCollectionWrapper();
                foreach (var item in unique.UniquePropertyDefinitions)
                {
                    list.Add(item.Name);
                }

                Attributes.Add("UniqueProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary <String, IEdgeView>())));
            }

            return(_AttributeReadout);
        }
Example #5
0
        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;
            }
        }
Example #6
0
        private void ProcessAttributeRemoveList(IVertexType vertexType,
                                                GQLPluginManager myPluginManager,
                                                IGraphDB myGraphDB,
                                                SecurityToken mySecurityToken,
                                                Int64 myTransactionToken,
                                                AttributeRemoveList attributeRemoveList,
                                                ref RequestUpdate result)
        {
            if (attributeRemoveList.TupleDefinition is VertexTypeVertexIDCollectionNode)
            {
                #region setofUUIDs

                var edgedef = new EdgePredefinition(attributeRemoveList.AttributeName);

                List <EdgePredefinition> toBeRemovedEdges = new List <EdgePredefinition>();

                foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeRemoveList.TupleDefinition).Elements)
                {
                    foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                    {
                        var innerEdge = new EdgePredefinition();

                        innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                        edgedef.AddEdge(innerEdge);
                    }
                }

                result.RemoveElementsFromCollection(attributeRemoveList.AttributeName, edgedef);

                #endregion
            }
            else if (attributeRemoveList.TupleDefinition is TupleDefinition)
            {
                if (((TupleDefinition)attributeRemoveList.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();
                    Type myRequestedType;
                    if (vertexType.HasProperty(attributeRemoveList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeRemoveList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeRemoveList.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.RemoveElementsFromCollection(attributeRemoveList.AttributeIDChain.ContentString, listWrapper);

                    #endregion
                }
                else
                {
                    #region binaryExpression

                    Dictionary <String, EdgePredefinition> toBeRemovedEdges = new Dictionary <String, EdgePredefinition>();

                    foreach (var aTupleElement in ((TupleDefinition)attributeRemoveList.TupleDefinition))
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            if (!vertexType.HasAttribute(attributeRemoveList.AttributeName))
                            {
                                throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeRemoveList.AttributeName));
                            }

                            IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeRemoveList.AttributeName);

                            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));
                            }

                            EdgePredefinition outValue = null;

                            if (toBeRemovedEdges.TryGetValue(attributeRemoveList.AttributeName, out outValue))
                            {
                                foreach (var aVertex in vertexIDs)
                                {
                                    outValue.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }
                            }
                            else
                            {
                                EdgePredefinition edge = new EdgePredefinition(attributeRemoveList.AttributeName);

                                foreach (var aVertex in vertexIDs)
                                {
                                    edge.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }

                                toBeRemovedEdges.Add(attributeRemoveList.AttributeName, edge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    foreach (var item in toBeRemovedEdges)
                    {
                        result.RemoveElementsFromCollection(item.Key, item.Value);
                    }

                    #endregion
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #7
0
        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
        }
Example #8
0
		public override FuncParameter ExecFunc(IAttributeDefinition myAttributeDefinition,
												Object myCallingObject,
												IVertex myDBObject, 
												IGraphDB myGraphDB, 
												SecurityToken mySecurityToken,
												Int64 myTransactionToken, 
												params FuncParameter[] myParams)
        {
            #region initialisation

            List<TypeWithProperty> ObjectList = new List<TypeWithProperty>();
			 
			var str =  myParams[0].Value.ToString();
			var method = Convert.ToBoolean(myParams[1].Value);

			if (str == "")
				throw new InvalidFunctionParameterException("Input String", "Input String is leer", "null");

			ObjectList = new TypeWithProperty().StringParser(str, myGraphDB, mySecurityToken, myTransactionToken);

			if (ObjectList.Count<2)
				throw new InvalidFunctionParameterException("Input String", "Input String has insufficient quantity objects", "null");

			List<Tuple<double, List<Tuple<long,long>>, IVertexType, IVertexType>> all = new List<Tuple<double, List<Tuple<long,long>>, IVertexType, IVertexType>>();
			Dictionary<Tuple<long, long>, List<List<Tuple<long, long>>>> allPath = new Dictionary<Tuple<long, long>, List<List<Tuple<long, long>>>>();
            #endregion
            #region search Path between two any VertexTypes
            foreach (TypeWithProperty vertexStart in ObjectList)
			{
				foreach (TypeWithProperty vertexEnd in ObjectList)
				{

					if (vertexStart != vertexEnd && vertexStart.Type.ID!=vertexEnd.Type.ID)
					{
						if (method)
						{
							var output = this.ShortPath(vertexStart.Type, vertexEnd.Type);
							if (output != null)
								all.Add(output);
						}
						else
						{
							List<Tuple<long, long>> value = new List<Tuple<long, long>>();
							value.Add(Tuple.Create(vertexStart.Type.ID, 0L));
							this.DFS(vertexStart.Type, vertexEnd.Type, value);
						}


						
					}

				}
			}
			#endregion
           
			
			if (!method)
			{ 
                #region DFS
                #region path->allPath->PATH for better representation
				foreach (List<Tuple<long, long>> value in _path)
				{
					if (!allPath.ContainsKey(Tuple.Create(value.First().Item1, value.Last().Item1)))
					{
						List<List<Tuple<long, long>>> temp = new List<List<Tuple<long, long>>>();
						temp.Add(value);
						allPath.Add(Tuple.Create(value.First().Item1, value.Last().Item1), temp);
					}
					else
					{
						allPath[Tuple.Create(value.First().Item1, value.Last().Item1)].Add(value);
					}
				}

				List<List<Tuple<long, long>>> PATH = new List<List<Tuple<long, long>>>();

				foreach (KeyValuePair<Tuple<long, long>, List<List<Tuple<long, long>>>> value in allPath)
				{
					var paths = value.Value;
					foreach (List<Tuple<long, long>> abc in paths)
					{
						PATH.Add(abc);
					}
				}

				if (PATH.Count < 1)
					throw new InvalidFunctionParameterException("PATH", "PATH with DFS not found", "null");

			#endregion
				#region all paths merge
				foreach (KeyValuePair<Tuple<long, long>, List<List<Tuple<long, long>>>> value in allPath)
				{
					var paths = value.Value;
					foreach (List<Tuple<long, long>> abc in paths)
					{
						var flag_ends = false;
						var iCount = 0;
						do
						{


							if (PATH.Count > 0)
							{
								var detekt = (PATH[iCount].Where(x => x.Item1 == value.Key.Item1).Count() > 0) && (PATH[iCount].Where(x => x.Item1 == value.Key.Item2).Count() > 0); //PATH[iCount].Contains(value.Key.Item2);

								if (!detekt)
								{

									var test = 0;
									foreach (long wert in ObjectList.Select(x => x.Type.ID))
									{
										if (PATH[iCount].Where(x => x.Item1 == wert).Count() > 0)
											test++;
									}


									if (test == ObjectList.Count)
										flag_ends = true;
									else
									{

										if (PATH[iCount].Contains(abc.Where(x => x.Item2 == 0).First()))
											PATH.Add(PATH[iCount].Union(abc).ToList());


									}
								}

							}
							else
							{
								flag_ends = true;
							}
							if (PATH.Count - 1 > iCount)
								iCount++;
							else
								flag_ends = true;
						}
						while (!flag_ends);

					}
				}

				#endregion
				#region redundance kill zone


				var jCount = 0;
				var flag_ends2 = false;
				do
				{


					var test = 0;
					test = 0;
					foreach (long value in ObjectList.Select(x => x.Type.ID))
					{
						if (PATH[jCount].Where(x => x.Item1 == value).Count() > 0)
							test++;
					}


					if (test < ObjectList.Count)
					{
						PATH.Remove(PATH[jCount]);
                        if (PATH.Count == 0 || PATH.Count == jCount)
							flag_ends2 = true;
					}
					else
					{
						if (PATH.Count - 1 > jCount)
							jCount++;
						else
							flag_ends2 = true;
					}
				}
				while (!flag_ends2);

				flag_ends2 = false;
				var iCount2 = 0;
				do
				{

					List<List<Tuple<long, long>>> delete = new List<List<Tuple<long, long>>>();

					foreach (List<Tuple<long, long>> wert in PATH)
					{
						var flag = true;
						var flagEnd = true;
						var jCountB = 0;
						if (PATH[iCount2].Count == wert.Count)
						{
							do
							{
								if (!wert.Contains(PATH[iCount2][jCountB]))
								{
									flag = false;
									flagEnd = false;
								}

								if (PATH[iCount2].Count - 1 > jCountB)
									jCountB++;
								else
									flagEnd = false;

							}
							while (flagEnd);
							if (flag)
								if (flag && !PATH[iCount2].Equals(wert))
									delete.Add(wert);
						}
					}
					
					if (delete.Count > 0)//(test > 1)
					{
						foreach (List<Tuple<long, long>> value in delete)
							PATH.Remove(value);
                        if (PATH.Count == 0 || PATH.Count == iCount2)
							flag_ends2 = true;
					}
					else
					{
						if (PATH.Count - 1 > iCount2)
							iCount2++;
						else
							flag_ends2 = true;
					}
				}
				while (!flag_ends2);

				if (PATH.Count < 1)
					throw new InvalidFunctionParameterException("PATH", "PATH with DFS not found", "null");

				var minPATH = PATH.Min(x => x.Count);
				var indexPATH = PATH.First(x => x.Count == minPATH);
			    this.Helper(myGraphDB, mySecurityToken, myTransactionToken, ObjectList, indexPATH);

			}
				#endregion
            #endregion
            else
            {
                #region Dijkstra
                #region all shortest paths between two any VertexTypes to PATHShort for better representation
                List<List<Tuple<long, long>>> PATHShort = new List<List<Tuple<long, long>>>();

				foreach (Tuple<double, List<Tuple<long, long>>, IVertexType, IVertexType> value in all)
				{

					PATHShort.Add(value.Item2);

				}
				if (PATHShort.Count < 1)
					throw new InvalidFunctionParameterException("PATH", "PATH with Dijkstra not found", "null");

				#endregion
				#region shortest paths merge

				foreach (Tuple<double, List<Tuple<long, long>>, IVertexType, IVertexType> value in all)
				{
					var abc = value.Item2;

					bool flag_ends = false;
					int iCount = 0;
					do
					{


						if (PATHShort.Count > 0)
						{
							var detekt = (PATHShort[iCount].Where(x => x.Item1 == value.Item3.ID).Count() > 0) && (PATHShort[iCount].Where(x => x.Item1 == value.Item4.ID).Count() > 0); //PATH[iCount].Contains(value.Key.Item2);

							if (!detekt)
							{

								var test = 0;
								foreach (long wert in ObjectList.Select(x => x.Type.ID))
								{
									if (PATHShort[iCount].Where(x => x.Item1 == wert).Count() > 0)
										test++;
								}


								if (test == ObjectList.Count)
									flag_ends = true;
								else
								{


									if (PATHShort[iCount].Contains(abc.Where(x => x.Item2 == 0).First()))
										PATHShort.Add(PATHShort[iCount].Union(abc).ToList());


								}
							}

						}
						else
						{
							flag_ends = true;
						}
						if (PATHShort.Count - 1 > iCount)
							iCount++;
						else
							flag_ends = true;
					}
					while (!flag_ends);

				}
				#endregion
				#region redudance kill zone for shortest paths
				var jCount = 0;
				var flag_ends2 = false;
				do
				{


					var test = 0;
					test = 0;
					foreach (long value in ObjectList.Select(x => x.Type.ID))
					{
						if (PATHShort[jCount].Where(x => x.Item1 == value).Count() > 0)
							test++;
					}


					if (test < ObjectList.Count)
					{
						PATHShort.Remove(PATHShort[jCount]);
						if (PATHShort.Count == 0||PATHShort.Count==jCount)
							flag_ends2 = true;

					}
					else
					{
						if (PATHShort.Count - 1 > jCount)
							jCount++;
						else
							flag_ends2 = true;
					}
				}
				while (!flag_ends2);


				flag_ends2 = false;
				var iCount2 = 0;
				do
				{

					List<List<Tuple<long, long>>> delete = new List<List<Tuple<long, long>>>();
					foreach (List<Tuple<long, long>> wert in PATHShort)
					{
						var flag = true;
						var flagEnd = true;
						var jCountB = 0;
						if (PATHShort[iCount2].Count == wert.Count)
						{
							do
							{
								if (!wert.Contains(PATHShort[iCount2][jCountB]))
								{
									flag = false;
									flagEnd = false;
								}

								if (PATHShort[iCount2].Count - 1 > jCountB)
									jCountB++;
								else
									flagEnd = false;

							}
							while (flagEnd);
							if (flag && !PATHShort[iCount2].Equals(wert))
								delete.Add(wert);
						}

				
					}
					if (delete.Count > 0)//(test > 1)
					{
						foreach (List<Tuple<long, long>> value in delete)
							PATHShort.Remove(value);
                        if (PATHShort.Count == 0 || PATHShort.Count == iCount2)
							flag_ends2 = true;
					}
					else
					{
						if (PATHShort.Count - 1 > iCount2)
							iCount2++;
						else
							flag_ends2 = true;
					}
				}
				while (!flag_ends2);

                if (PATHShort.Count < 1)
                    throw new InvalidFunctionParameterException("PATH", "PATH with Dijkstra not found", "null");

				var minPATHShort = PATHShort.Min(x => x.Count);
				var indexPATHShort = PATHShort.First(x => x.Count == minPATHShort);
			       this.Helper(myGraphDB, mySecurityToken, myTransactionToken, ObjectList,indexPATHShort);
			}
			#endregion
                #endregion
            #region Output
           
		
           var result = new ListCollectionWrapper(_stringPath.Select(x => x.Item1+" = "+ x.Item2));
            this._path.Clear();
            this._stringPath.Clear();
			return new FuncParameter(result);
			 #endregion
		}
Example #9
0
        /// <summary>
        /// output for the type uniques
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <param name="myUniques">The uniqueDefinitions</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable<ISingleEdgeView> GenerateUniquePropertiesOutput(IVertexType myType, IEnumerable<IUniqueDefinition> myUniques)
        {
            var _AttributeReadout = new List<ISingleEdgeView>();

            foreach (var unique in myUniques)
            {

                var Attributes = new Dictionary<String, Object>();

                Attributes.Add("CorrespondingIndex", unique.CorrespondingIndex.Name);
                Attributes.Add("DefiningVertexType", unique.DefiningVertexType.Name);

                var list = new ListCollectionWrapper();
                foreach (var item in unique.UniquePropertyDefinitions)
                    list.Add(item.Name);

                Attributes.Add("UniqueProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary<String, IEdgeView>())));

            }

            return _AttributeReadout;
        }
Example #10
0
        /// <summary>
        /// output for the type indices
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable<ISingleEdgeView> GenerateIndicesOutput(IVertexType myType)
        {
            var _AttributeReadout = new List<ISingleEdgeView>();

            foreach (var idx in myType.GetIndexDefinitions(true))
            {

                var Attributes = new Dictionary<String, Object>();

                Attributes.Add("ID", idx.ID);
                Attributes.Add("Type", idx.IndexTypeName);
                Attributes.Add("Name", idx.Name);
                Attributes.Add("Edition", idx.Edition);

                var list = new ListCollectionWrapper();
                foreach (var item in idx.IndexedProperties)
                    list.Add(item.Name);

                Attributes.Add("IndexedProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary<String, IEdgeView>())));

            }

            return _AttributeReadout;
        }
Example #11
0
        /// <summary>
        /// generates an output for an edgetype
        /// </summary>
        /// <param name="myEdge">the edge</param>
        /// <param name="myEdgeName">edge name</param>
        /// <returns>list of readouts with the information</returns>
        private IVertexView GenerateOutput(IEdgeType myEdge, String myEdgeName)
        {
            var Edge = new Dictionary<String, Object>();

            Edge.Add("ID", myEdge.ID);
            Edge.Add("Type", myEdge.GetType().Name);
            Edge.Add("Name", myEdge.Name);
            Edge.Add("IsAbstract", myEdge.IsAbstract);
            Edge.Add("IsUserDefined", myEdge.IsUserDefined);
            Edge.Add("IsSealed", myEdge.IsSealed);
            Edge.Add("ParentEdgeType", myEdge.ParentEdgeType.Name);

            var list = new ListCollectionWrapper();
            foreach (var child in myEdge.ChildrenEdgeTypes)
                list.Add(child.Name);

            Edge.Add("ChildrenEdgeTypes", list);
            Edge.Add("Comment", myEdge.Comment);

            return new VertexView(Edge, new Dictionary<String,IEdgeView>());
        }
Example #12
0
        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>
        /// Generate an output for an index
        /// </summary>
        /// <param name="myIndex">The index</param>
        /// <param name="myName">The index name</param>
        /// <returns>List of readouts which contain the index information</returns>
        private IEnumerable<IVertexView> GenerateOutput(IEnumerable<IIndexDefinition> myIndices, String myName)
        {

            var _Index = new Dictionary<String, Object>();
            var result = new List<IVertexView>();

            foreach (var index in myIndices)
            {

                _Index.Add("Name", index.Name);
                _Index.Add("ID", index.ID);
                _Index.Add("Edition", index.Edition);
                _Index.Add("IndexTypeName", index.IndexTypeName);
                _Index.Add("IsUserDefinied", index.IsUserdefined);

                ListCollectionWrapper list = new ListCollectionWrapper();

                foreach (var prop in index.IndexedProperties)
                {
                    list.Add(prop.Name);
                }

                _Index.Add("IndexedProperties", list);
                
                result.Add(new VertexView(new Dictionary<String, Object>(_Index), new Dictionary<String, IEdgeView>()));
                _Index.Clear();
            }

            return result;
        }
Example #14
0
        public override FuncParameter ExecFunc(IAttributeDefinition myAttributeDefinition,
                                               Object myCallingObject,
                                               IVertex myDBObject,
                                               IGraphDB myGraphDB,
                                               SecurityToken mySecurityToken,
                                               Int64 myTransactionToken,
                                               params FuncParameter[] myParams)
        {
            #region initialisation

            List <TypeWithProperty> ObjectList = new List <TypeWithProperty>();

            var str    = myParams[0].Value.ToString();
            var method = Convert.ToBoolean(myParams[1].Value);

            if (str == "")
            {
                throw new InvalidFunctionParameterException("Input String", "Input String is leer", "null");
            }

            ObjectList = new TypeWithProperty().StringParser(str, myGraphDB, mySecurityToken, myTransactionToken);

            if (ObjectList.Count < 2)
            {
                throw new InvalidFunctionParameterException("Input String", "Input String has insufficient quantity objects", "null");
            }

            List <Tuple <double, List <Tuple <long, long> >, IVertexType, IVertexType> > all     = new List <Tuple <double, List <Tuple <long, long> >, IVertexType, IVertexType> >();
            Dictionary <Tuple <long, long>, List <List <Tuple <long, long> > > >         allPath = new Dictionary <Tuple <long, long>, List <List <Tuple <long, long> > > >();
            #endregion
            #region search Path between two any VertexTypes
            foreach (TypeWithProperty vertexStart in ObjectList)
            {
                foreach (TypeWithProperty vertexEnd in ObjectList)
                {
                    if (vertexStart != vertexEnd && vertexStart.Type.ID != vertexEnd.Type.ID)
                    {
                        if (method)
                        {
                            var output = this.ShortPath(vertexStart.Type, vertexEnd.Type);
                            if (output != null)
                            {
                                all.Add(output);
                            }
                        }
                        else
                        {
                            List <Tuple <long, long> > value = new List <Tuple <long, long> >();
                            value.Add(Tuple.Create(vertexStart.Type.ID, 0L));
                            this.DFS(vertexStart.Type, vertexEnd.Type, value);
                        }
                    }
                }
            }
            #endregion


            if (!method)
            {
                #region DFS
                #region path->allPath->PATH for better representation
                foreach (List <Tuple <long, long> > value in _path)
                {
                    if (!allPath.ContainsKey(Tuple.Create(value.First().Item1, value.Last().Item1)))
                    {
                        List <List <Tuple <long, long> > > temp = new List <List <Tuple <long, long> > >();
                        temp.Add(value);
                        allPath.Add(Tuple.Create(value.First().Item1, value.Last().Item1), temp);
                    }
                    else
                    {
                        allPath[Tuple.Create(value.First().Item1, value.Last().Item1)].Add(value);
                    }
                }

                List <List <Tuple <long, long> > > PATH = new List <List <Tuple <long, long> > >();

                foreach (KeyValuePair <Tuple <long, long>, List <List <Tuple <long, long> > > > value in allPath)
                {
                    var paths = value.Value;
                    foreach (List <Tuple <long, long> > abc in paths)
                    {
                        PATH.Add(abc);
                    }
                }

                if (PATH.Count < 1)
                {
                    throw new InvalidFunctionParameterException("PATH", "PATH with DFS not found", "null");
                }

                #endregion
                #region all paths merge
                foreach (KeyValuePair <Tuple <long, long>, List <List <Tuple <long, long> > > > value in allPath)
                {
                    var paths = value.Value;
                    foreach (List <Tuple <long, long> > abc in paths)
                    {
                        var flag_ends = false;
                        var iCount    = 0;
                        do
                        {
                            if (PATH.Count > 0)
                            {
                                var detekt = (PATH[iCount].Where(x => x.Item1 == value.Key.Item1).Count() > 0) && (PATH[iCount].Where(x => x.Item1 == value.Key.Item2).Count() > 0);                                 //PATH[iCount].Contains(value.Key.Item2);

                                if (!detekt)
                                {
                                    var test = 0;
                                    foreach (long wert in ObjectList.Select(x => x.Type.ID))
                                    {
                                        if (PATH[iCount].Where(x => x.Item1 == wert).Count() > 0)
                                        {
                                            test++;
                                        }
                                    }


                                    if (test == ObjectList.Count)
                                    {
                                        flag_ends = true;
                                    }
                                    else
                                    {
                                        if (PATH[iCount].Contains(abc.Where(x => x.Item2 == 0).First()))
                                        {
                                            PATH.Add(PATH[iCount].Union(abc).ToList());
                                        }
                                    }
                                }
                            }
                            else
                            {
                                flag_ends = true;
                            }
                            if (PATH.Count - 1 > iCount)
                            {
                                iCount++;
                            }
                            else
                            {
                                flag_ends = true;
                            }
                        }while (!flag_ends);
                    }
                }

                #endregion
                #region redundance kill zone


                var jCount     = 0;
                var flag_ends2 = false;
                do
                {
                    var test = 0;
                    test = 0;
                    foreach (long value in ObjectList.Select(x => x.Type.ID))
                    {
                        if (PATH[jCount].Where(x => x.Item1 == value).Count() > 0)
                        {
                            test++;
                        }
                    }


                    if (test < ObjectList.Count)
                    {
                        PATH.Remove(PATH[jCount]);
                        if (PATH.Count == 0 || PATH.Count == jCount)
                        {
                            flag_ends2 = true;
                        }
                    }
                    else
                    {
                        if (PATH.Count - 1 > jCount)
                        {
                            jCount++;
                        }
                        else
                        {
                            flag_ends2 = true;
                        }
                    }
                }while (!flag_ends2);

                flag_ends2 = false;
                var iCount2 = 0;
                do
                {
                    List <List <Tuple <long, long> > > delete = new List <List <Tuple <long, long> > >();

                    foreach (List <Tuple <long, long> > wert in PATH)
                    {
                        var flag    = true;
                        var flagEnd = true;
                        var jCountB = 0;
                        if (PATH[iCount2].Count == wert.Count)
                        {
                            do
                            {
                                if (!wert.Contains(PATH[iCount2][jCountB]))
                                {
                                    flag    = false;
                                    flagEnd = false;
                                }

                                if (PATH[iCount2].Count - 1 > jCountB)
                                {
                                    jCountB++;
                                }
                                else
                                {
                                    flagEnd = false;
                                }
                            }while (flagEnd);
                            if (flag)
                            {
                                if (flag && !PATH[iCount2].Equals(wert))
                                {
                                    delete.Add(wert);
                                }
                            }
                        }
                    }

                    if (delete.Count > 0)                    //(test > 1)
                    {
                        foreach (List <Tuple <long, long> > value in delete)
                        {
                            PATH.Remove(value);
                        }
                        if (PATH.Count == 0 || PATH.Count == iCount2)
                        {
                            flag_ends2 = true;
                        }
                    }
                    else
                    {
                        if (PATH.Count - 1 > iCount2)
                        {
                            iCount2++;
                        }
                        else
                        {
                            flag_ends2 = true;
                        }
                    }
                }while (!flag_ends2);

                if (PATH.Count < 1)
                {
                    throw new InvalidFunctionParameterException("PATH", "PATH with DFS not found", "null");
                }

                var minPATH   = PATH.Min(x => x.Count);
                var indexPATH = PATH.First(x => x.Count == minPATH);
                this.Helper(myGraphDB, mySecurityToken, myTransactionToken, ObjectList, indexPATH);
            }
            #endregion
            #endregion
            else
            {
                #region Dijkstra
                #region all shortest paths between two any VertexTypes to PATHShort for better representation
                List <List <Tuple <long, long> > > PATHShort = new List <List <Tuple <long, long> > >();

                foreach (Tuple <double, List <Tuple <long, long> >, IVertexType, IVertexType> value in all)
                {
                    PATHShort.Add(value.Item2);
                }
                if (PATHShort.Count < 1)
                {
                    throw new InvalidFunctionParameterException("PATH", "PATH with Dijkstra not found", "null");
                }

                #endregion
                #region shortest paths merge

                foreach (Tuple <double, List <Tuple <long, long> >, IVertexType, IVertexType> value in all)
                {
                    var abc = value.Item2;

                    bool flag_ends = false;
                    int  iCount    = 0;
                    do
                    {
                        if (PATHShort.Count > 0)
                        {
                            var detekt = (PATHShort[iCount].Where(x => x.Item1 == value.Item3.ID).Count() > 0) && (PATHShort[iCount].Where(x => x.Item1 == value.Item4.ID).Count() > 0);                             //PATH[iCount].Contains(value.Key.Item2);

                            if (!detekt)
                            {
                                var test = 0;
                                foreach (long wert in ObjectList.Select(x => x.Type.ID))
                                {
                                    if (PATHShort[iCount].Where(x => x.Item1 == wert).Count() > 0)
                                    {
                                        test++;
                                    }
                                }


                                if (test == ObjectList.Count)
                                {
                                    flag_ends = true;
                                }
                                else
                                {
                                    if (PATHShort[iCount].Contains(abc.Where(x => x.Item2 == 0).First()))
                                    {
                                        PATHShort.Add(PATHShort[iCount].Union(abc).ToList());
                                    }
                                }
                            }
                        }
                        else
                        {
                            flag_ends = true;
                        }
                        if (PATHShort.Count - 1 > iCount)
                        {
                            iCount++;
                        }
                        else
                        {
                            flag_ends = true;
                        }
                    }while (!flag_ends);
                }
                #endregion
                #region redudance kill zone for shortest paths
                var jCount     = 0;
                var flag_ends2 = false;
                do
                {
                    var test = 0;
                    test = 0;
                    foreach (long value in ObjectList.Select(x => x.Type.ID))
                    {
                        if (PATHShort[jCount].Where(x => x.Item1 == value).Count() > 0)
                        {
                            test++;
                        }
                    }


                    if (test < ObjectList.Count)
                    {
                        PATHShort.Remove(PATHShort[jCount]);
                        if (PATHShort.Count == 0 || PATHShort.Count == jCount)
                        {
                            flag_ends2 = true;
                        }
                    }
                    else
                    {
                        if (PATHShort.Count - 1 > jCount)
                        {
                            jCount++;
                        }
                        else
                        {
                            flag_ends2 = true;
                        }
                    }
                }while (!flag_ends2);


                flag_ends2 = false;
                var iCount2 = 0;
                do
                {
                    List <List <Tuple <long, long> > > delete = new List <List <Tuple <long, long> > >();
                    foreach (List <Tuple <long, long> > wert in PATHShort)
                    {
                        var flag    = true;
                        var flagEnd = true;
                        var jCountB = 0;
                        if (PATHShort[iCount2].Count == wert.Count)
                        {
                            do
                            {
                                if (!wert.Contains(PATHShort[iCount2][jCountB]))
                                {
                                    flag    = false;
                                    flagEnd = false;
                                }

                                if (PATHShort[iCount2].Count - 1 > jCountB)
                                {
                                    jCountB++;
                                }
                                else
                                {
                                    flagEnd = false;
                                }
                            }while (flagEnd);
                            if (flag && !PATHShort[iCount2].Equals(wert))
                            {
                                delete.Add(wert);
                            }
                        }
                    }
                    if (delete.Count > 0)                    //(test > 1)
                    {
                        foreach (List <Tuple <long, long> > value in delete)
                        {
                            PATHShort.Remove(value);
                        }
                        if (PATHShort.Count == 0 || PATHShort.Count == iCount2)
                        {
                            flag_ends2 = true;
                        }
                    }
                    else
                    {
                        if (PATHShort.Count - 1 > iCount2)
                        {
                            iCount2++;
                        }
                        else
                        {
                            flag_ends2 = true;
                        }
                    }
                }while (!flag_ends2);

                if (PATHShort.Count < 1)
                {
                    throw new InvalidFunctionParameterException("PATH", "PATH with Dijkstra not found", "null");
                }

                var minPATHShort   = PATHShort.Min(x => x.Count);
                var indexPATHShort = PATHShort.First(x => x.Count == minPATHShort);
                this.Helper(myGraphDB, mySecurityToken, myTransactionToken, ObjectList, indexPATHShort);
            }
            #endregion
            #endregion
            #region Output


            var result = new ListCollectionWrapper(_stringPath.Select(x => x.Item1 + " = " + x.Item2));
            this._path.Clear();
            this._stringPath.Clear();
            return(new FuncParameter(result));

            #endregion
        }
Example #15
0
        /// <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));
        }
Example #16
0
        private void ProcessAttributeAssignOrUpdateList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken 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;
            }
        }
Example #17
0
        private void ProcessAttributeRemoveList(IVertexType vertexType, GQLPluginManager myPluginManager, IGraphDB myGraphDB, SecurityToken mySecurityToken, TransactionToken myTransactionToken, AttributeRemoveList attributeRemoveList, ref RequestUpdate result)
        {
            if (attributeRemoveList.TupleDefinition is VertexTypeVertexIDCollectionNode)
            {
                #region setofUUIDs

                var edgedef = new EdgePredefinition(attributeRemoveList.AttributeName);

                List<EdgePredefinition> toBeRemovedEdges = new List<EdgePredefinition>();

                foreach (var aTupleElement in ((VertexTypeVertexIDCollectionNode)attributeRemoveList.TupleDefinition).Elements)
                {
                    foreach (var aVertexIDTuple in aTupleElement.VertexIDs)
                    {
                        var innerEdge = new EdgePredefinition();

                        innerEdge.AddVertexID(aTupleElement.ReferencedVertexTypeName, aVertexIDTuple.Item1);

                        edgedef.AddEdge(innerEdge);
                    }
                }

                result.RemoveElementsFromCollection(attributeRemoveList.AttributeName, edgedef);

                #endregion
            }
            else if (attributeRemoveList.TupleDefinition is TupleDefinition)
            {
                if (((TupleDefinition)attributeRemoveList.TupleDefinition).All(_ => _.Value is ValueDefinition))
                {
                    #region base-set

                    //has to be list of comparables
                    ListCollectionWrapper listWrapper = new ListCollectionWrapper();
                    Type myRequestedType;
                    if (vertexType.HasProperty(attributeRemoveList.AttributeIDChain.ContentString))
                    {
                        myRequestedType = ((IPropertyDefinition)vertexType.GetAttributeDefinition(attributeRemoveList.AttributeIDChain.ContentString)).BaseType;
                    }
                    else
                    {
                        myRequestedType = typeof(String);
                    }

                    foreach (var aTupleElement in (TupleDefinition)attributeRemoveList.TupleDefinition)
                    {
                        listWrapper.Add(((ValueDefinition)aTupleElement.Value).Value.ConvertToIComparable(myRequestedType));
                    }

                    result.RemoveElementsFromCollection(attributeRemoveList.AttributeIDChain.ContentString, listWrapper);

                    #endregion
                }
                else
                {
                    #region binaryExpression

                    Dictionary<String, EdgePredefinition> toBeRemovedEdges = new Dictionary<String, EdgePredefinition>();

                    foreach (var aTupleElement in ((TupleDefinition)attributeRemoveList.TupleDefinition))
                    {
                        if (aTupleElement.Value is BinaryExpressionDefinition)
                        {
                            #region BinaryExpressionDefinition

                            if (!vertexType.HasAttribute(attributeRemoveList.AttributeName))
                            {
                                throw new InvalidVertexAttributeException(String.Format("The vertex type {0} has no attribute named {1}.", vertexType.Name, attributeRemoveList.AttributeName));
                            }

                            IAttributeDefinition attribute = vertexType.GetAttributeDefinition(attributeRemoveList.AttributeName);

                            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));
                            }

                            EdgePredefinition outValue = null;

                            if (toBeRemovedEdges.TryGetValue(attributeRemoveList.AttributeName, out outValue))
                            {
                                foreach (var aVertex in vertexIDs)
                                {
                                    outValue.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }
                            }
                            else
                            {
                                EdgePredefinition edge = new EdgePredefinition(attributeRemoveList.AttributeName);

                                foreach (var aVertex in vertexIDs)
                                {
                                    edge.AddEdge(new EdgePredefinition().AddVertexID(aVertex.VertexTypeID, aVertex.VertexID));
                                }

                                toBeRemovedEdges.Add(attributeRemoveList.AttributeName, edge);
                            }

                            #endregion
                        }
                        else
                        {
                            throw new NotImplementedQLException("");
                        }
                    }

                    foreach (var item in toBeRemovedEdges)
                    {
                        result.RemoveElementsFromCollection(item.Key, item.Value);
                    }

                    #endregion
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #18
0
        /// <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);
        }