示例#1
0
        private String Recurs(String str, IVertexType StartType, List <TypeWithProperty> type_property_object, List <Tuple <long, long> > PATHShortDSF)
        {
            var hyperEdgeOut = StartType.GetOutgoingEdgeDefinitions(true);
            var hyperEdgeInc = StartType.GetIncomingEdgeDefinitions(true);

            foreach (IOutgoingEdgeDefinition value in hyperEdgeOut)
            {
                if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null)
                {
                    if (type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID).Count() > 0)
                    {
                        var temp = str;
                        foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID))
                        {
                            _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name));
                        }
                        str = temp + '.' + value.Name;
                        Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF);
                        str = temp;
                    }
                    else
                    {
                        var temp = str;
                        str += '.' + value.Name;
                        Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF);
                        str = temp;
                    }
                }
            }

            foreach (IIncomingEdgeDefinition value in hyperEdgeInc)
            {
                if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null)
                {
                    if (type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID).Count() > 0)
                    {
                        var temp = str;
                        foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID))
                        {
                            _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name));
                        }
                        str = temp + '.' + value.Name;
                        Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF);
                        str = temp;
                    }
                    else
                    {
                        var temp = str;
                        str += '.' + value.Name;
                        Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF);
                        str = temp;
                    }
                }
            }
            str = "";
            return(null);
        }
示例#2
0
		void DFS(IVertexType start, IVertexType end, List<Tuple<long,long>> Parents)
		{
		
		  var outEdges =  start.GetOutgoingEdgeDefinitions(true);
		  var incEdges = start.GetIncomingEdgeDefinitions(true);
		  
		  foreach (IOutgoingEdgeDefinition vertexType in outEdges)
		  {
			  if (Parents.Where(x=>x.Item1 == vertexType.TargetVertexType.ID).Count()==0)//(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID)))
			  {
				  
					 var current_parents =  Parents.ToList();
					 Parents.Add(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID));

					 if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents))
						 _path.Add(Parents);
					 else
					 {
						 DFS(vertexType.TargetVertexType, end, Parents);
					 }
				  Parents = current_parents;
			  }
		  }
		  foreach (IIncomingEdgeDefinition vertexType in incEdges)
		  {
			  if (Parents.Where(x => x.Item1 == vertexType.RelatedEdgeDefinition.SourceVertexType.ID).Count() == 0) //if (!Parents.Contains(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID)))
			  {
				  var current_parents = Parents.ToList();
				  Parents.Add(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID,vertexType.ID));

				 
				  if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents))
				  {
					  _path.Add(Parents);
				  }
				  else
				  {
					 DFS(vertexType.RelatedEdgeDefinition.SourceVertexType, end, Parents);
				  }
				  Parents = current_parents;
			  }
		  }
		}
示例#3
0
        void DFS(IVertexType start, IVertexType end, List <Tuple <long, long> > Parents)
        {
            var outEdges = start.GetOutgoingEdgeDefinitions(true);
            var incEdges = start.GetIncomingEdgeDefinitions(true);

            foreach (IOutgoingEdgeDefinition vertexType in outEdges)
            {
                if (Parents.Where(x => x.Item1 == vertexType.TargetVertexType.ID).Count() == 0)      //(Tuple.Create(vertexType.TargetVertexType.ID,vertexType.ID)))
                {
                    var current_parents = Parents.ToList();
                    Parents.Add(Tuple.Create(vertexType.TargetVertexType.ID, vertexType.ID));

                    if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents))
                    {
                        _path.Add(Parents);
                    }
                    else
                    {
                        DFS(vertexType.TargetVertexType, end, Parents);
                    }
                    Parents = current_parents;
                }
            }
            foreach (IIncomingEdgeDefinition vertexType in incEdges)
            {
                if (Parents.Where(x => x.Item1 == vertexType.RelatedEdgeDefinition.SourceVertexType.ID).Count() == 0)           //if (!Parents.Contains(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID)))
                {
                    var current_parents = Parents.ToList();
                    Parents.Add(Tuple.Create(vertexType.RelatedEdgeDefinition.SourceVertexType.ID, vertexType.ID));


                    if (Parents.Last().Item1 == end.ID && !_path.Contains(Parents))
                    {
                        _path.Add(Parents);
                    }
                    else
                    {
                        DFS(vertexType.RelatedEdgeDefinition.SourceVertexType, end, Parents);
                    }
                    Parents = current_parents;
                }
            }
        }
示例#4
0
        private Dictionary <IOutgoingEdgeDefinition, Tuple <bool, long> > AllEdgeWithTargetVertex(IVertexType vertexType)
        {
            Dictionary <IOutgoingEdgeDefinition, Tuple <bool, long> > idList = new Dictionary <IOutgoingEdgeDefinition, Tuple <bool, long> >();
            var temp = vertexType.GetOutgoingEdgeDefinitions(true);

            foreach (IOutgoingEdgeDefinition vertex in temp)
            {
                if (vertex.TargetVertexType.ID == vertexType.ID)
                {
                    var hasProperty = vertex.InnerEdgeType.HasProperty("Weight");


                    long myPropertyID = 0;

                    if (hasProperty == true)
                    {
                        myPropertyID = vertex.InnerEdgeType.GetPropertyDefinition("Weight").ID;
                    }

                    idList.Add(vertex, Tuple.Create(hasProperty, myPropertyID));
                }
            }
            return(idList);
        }
示例#5
0
        private Tuple<long?, String, VertexUpdateDefinition> CreateVertexUpdateDefinition(
                                                                IVertex myVertex,
                                                                IVertexType myVertexType,
                                                                RequestUpdate myUpdate,
                                                                IPropertyProvider myPropertyCopy,
                                                                Int64 myTransaction,
                                                                SecurityToken mySecurity)
        {

            #region get removes

            List<long> toBeDeletedSingle = null;
            List<long> toBeDeletedHyper = null;
            List<long> toBeDeletedStructured = null;
            List<String> toBeDeletedUnstructured = null;
            List<long> toBeDeletedBinaries = null;

            if (myUpdate.RemovedAttributes != null)
            {
                #region remove each defined attribute

                foreach (var name in myUpdate.RemovedAttributes)
                {
                    if (myVertexType.HasAttribute(name))
                    {
                        var attr = myVertexType.GetAttributeDefinition(name);

                        switch (attr.Kind)
                        {
                            case AttributeType.Property:

                                if ((attr as IPropertyDefinition).IsMandatory)
                                    throw new MandatoryConstraintViolationException(attr.Name);

                                toBeDeletedStructured = toBeDeletedStructured ?? new List<long>();
                                toBeDeletedStructured.Add(attr.ID);
                                break;

                            case AttributeType.BinaryProperty:
                                toBeDeletedBinaries = toBeDeletedBinaries ?? new List<long>();
                                toBeDeletedBinaries.Add(attr.ID);
                                break;

                            case AttributeType.IncomingEdge:
                                //TODO: a better exception here.
                                throw new Exception("The edges on an incoming edge attribute can not be removed.");

                            case AttributeType.OutgoingEdge:
                                switch ((attr as IOutgoingEdgeDefinition).Multiplicity)
                                {
                                    case EdgeMultiplicity.HyperEdge:
                                    case EdgeMultiplicity.MultiEdge:
                                        toBeDeletedHyper = toBeDeletedHyper ?? new List<long>();
                                        toBeDeletedHyper.Add(attr.ID);
                                        break;
                                    case EdgeMultiplicity.SingleEdge:
                                        toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                        toBeDeletedSingle.Add(attr.ID);
                                        break;
                                    default:
                                        //TODO a better exception here
                                        throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                                }
                                break;

                            default:
                                //TODO: a better exception here.
                                throw new Exception("The enumeration AttributeType was updated, but not this switch statement.");
                        }
                    }
                    else
                    {
                        toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>();
                        toBeDeletedUnstructured.Add(name);
                    }
                }

                #endregion
            }

            if (myUpdate.RemovedUnstructuredProperties != null)
            {
                #region remove each unstructured property

                foreach (var name in myUpdate.RemovedUnstructuredProperties)
                {
                    if ((myVertexType.HasAttribute(name)) && (myVertexType.GetAttributeDefinition(name).Kind == AttributeType.Property))
                    {
                        toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>();
                        toBeDeletedUnstructured.Add(name);
                    }
                }

                #endregion
            }

            #endregion

            #region get update definitions

            IDictionary<Int64, HyperEdgeUpdateDefinition> toBeUpdatedHyper = null;
            IDictionary<Int64, SingleEdgeUpdateDefinition> toBeUpdatedSingle = null;
            IDictionary<Int64, IComparable> toBeUpdatedStructured = null;
            IDictionary<String, Object> toBeUpdatedUnstructured = null;
            IDictionary<Int64, StreamAddDefinition> toBeUpdatedBinaries = null;
            long? revision = null;
            string edition = myUpdate.UpdatedEdition;
            string comment = myUpdate.UpdatedComment;

            #region property copy things

            if (myPropertyCopy.StructuredProperties != null)
            {
                toBeUpdatedStructured = new Dictionary<long, IComparable>();
                foreach (var prop in myPropertyCopy.StructuredProperties)
                {
                    var propDef = myVertexType.GetPropertyDefinition(prop.Key);
                    CheckPropertyType(myVertexType.Name, prop.Value, propDef);
                    toBeUpdatedStructured.Add(propDef.ID, prop.Value);
                }
            }

            toBeUpdatedUnstructured = myPropertyCopy.UnstructuredProperties;

            #endregion

            #region binary properties
            if (myUpdate.UpdatedBinaryProperties != null)
            {
                foreach (var prop in myUpdate.UpdatedBinaryProperties)
                {
                    var propDef = myVertexType.GetBinaryPropertyDefinition(prop.Key);

                    toBeUpdatedBinaries = toBeUpdatedBinaries ?? new Dictionary<long, StreamAddDefinition>();
                    toBeUpdatedBinaries.Add(propDef.ID, new StreamAddDefinition(propDef.ID, prop.Value));
                }
            }
            #endregion

            #region collections

            if (myUpdate.AddedElementsToCollectionProperties != null || myUpdate.RemovedElementsFromCollectionProperties != null)
            {
                if (myUpdate.AddedElementsToCollectionProperties != null && myUpdate.RemovedElementsFromCollectionProperties != null)
                {
                    var keys = myUpdate.AddedElementsToCollectionProperties.Keys.Intersect(myUpdate.RemovedElementsFromCollectionProperties.Keys);
                    if (keys.CountIsGreater(0))
                    {
                        //TOTO a better exception here
                        throw new Exception("You can not add and remove items simultaneously on a collection attribute.");
                    }

                    if (myUpdate.AddedElementsToCollectionProperties != null)
                    {
                        foreach (var added in myUpdate.AddedElementsToCollectionProperties)
                        {
                            var propDef = myVertexType.GetPropertyDefinition(added.Key);

                            var hasValue = (propDef == null)
                                ? myVertex.HasUnstructuredProperty(added.Key)
                                : myVertex.HasProperty(propDef.ID);

                            //if it is not ICollectionWrapper something wrong with deserialization
                            var extractedValue = (!hasValue)
                                ? null
                                : (propDef == null)
                                    ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(added.Key)
                                    : (ICollectionWrapper)propDef.GetValue(myVertex);

                            PropertyMultiplicity mult;
                            if (propDef != null)
                            {
                                //check types only for structured properties
                                foreach (var element in added.Value)
                                {
                                    CheckPropertyType(myVertexType.Name, element, propDef);
                                }
                                mult = propDef.Multiplicity;
                            }
                            else
                                mult = (added.Value is SetCollectionWrapper)
                                    ? PropertyMultiplicity.Set
                                    : PropertyMultiplicity.List;


                            var newValue = CreateNewCollectionWrapper(
                                (hasValue)
                                    ? extractedValue.Union(added.Value)
                                    : added.Value,
                                 mult);

                            if (propDef == null)
                            {
                                toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>();
                                toBeUpdatedUnstructured.Add(added.Key, newValue);
                            }
                            else
                            {
                                toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>();
                                toBeUpdatedStructured.Add(propDef.ID, newValue);
                            }

                        }
                    }
                    if (myUpdate.RemovedElementsFromCollectionProperties != null)
                    {
                        foreach (var remove in myUpdate.RemovedElementsFromCollectionProperties)
                        {
                            var propDef = myVertexType.GetPropertyDefinition(remove.Key);

                            var hasValue = (propDef == null)
                                ? myVertex.HasUnstructuredProperty(remove.Key)
                                : myVertex.HasProperty(propDef.ID);

                            //no value, nothing to remove
                            if (!hasValue)
                                continue;

                            //if it is not ICollectionWrapper something wrong with deserialization
                            var extractedValue = (propDef == null)
                                ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(remove.Key)
                                : (ICollectionWrapper)propDef.GetValue(myVertex);

                            PropertyMultiplicity mult = (propDef != null)
                                ? propDef.Multiplicity
                                : (extractedValue is SetCollectionWrapper)
                                    ? PropertyMultiplicity.Set
                                    : PropertyMultiplicity.List;

                            var newValue = CreateNewCollectionWrapper(extractedValue.Except(remove.Value), mult);

                            toBeUpdatedStructured.Add(propDef.ID, newValue);

                            if (propDef == null)
                            {
                                toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>();
                                toBeUpdatedUnstructured.Add(remove.Key, newValue);
                            }
                            else
                            {
                                toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>();
                                toBeUpdatedStructured.Add(propDef.ID, newValue);
                            }

                        }
                    }
                }
            }

            #endregion

            #region extract vertex properties
            #region will be ignored
            long vertexID = 0L;
            long creationDate = 0L;
            long modificationDate = 0L;
            #endregion

            ExtractVertexProperties(ref edition, ref revision, ref comment, ref vertexID, ref creationDate, ref modificationDate, toBeUpdatedStructured);
            #endregion

            #region edge magic

            if (myUpdate.AddedElementsToCollectionEdges != null ||
                myUpdate.RemovedElementsFromCollectionEdges != null ||
                myUpdate.UpdateOutgoingEdges != null ||
                myUpdate.UpdateOutgoingEdgesProperties != null)
            {
                VertexInformation source = new VertexInformation(myVertex.VertexTypeID, myVertex.VertexID);

                #region update outgoing edges

                if (myUpdate.UpdateOutgoingEdges != null)
                {
                    foreach (var edge in myUpdate.UpdateOutgoingEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(edge.EdgeName);

                        switch (edgeDef.Multiplicity)
                        {
                            case EdgeMultiplicity.SingleEdge:
                                {
                                    #region SingleEdge
                                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);
                                    if (targets == null || !targets.CountIsGreater(0))
                                    {
                                        toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                        toBeDeletedSingle.Add(edgeDef.ID);
                                    }
                                    else if (targets.CountIsGreater(1))
                                    {
                                        throw new Exception("Single edge can not have more than one target.");
                                    }
                                    else
                                    {
                                        ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                        var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                        var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                        toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>();

                                        toBeUpdatedSingle.Add(edgeDef.ID,
                                                                new SingleEdgeUpdateDefinition(source,
                                                                                                targets.First(),
                                                                                                edgeDef.EdgeType.ID,
                                                                                                edge.Comment,
                                                                                                structured,
                                                                                                unstructured));
                                    }
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.MultiEdge:
                                {
                                    #region MultiEdge
                                    // Why deleting the edge instances ???
                                    // they will never be inserted inside the update !!!
                                    // After delete the update will be needless because the edges are deleted !!!

                                    //List<SingleEdgeDeleteDefinition> internSingleDelete = null;
                                    //if (myVertex.HasOutgoingEdge(edgeDef.ID))
                                    //{
                                    //    internSingleDelete = new List<SingleEdgeDeleteDefinition>();
                                    //    foreach (var edgeInstance in myVertex.GetOutgoingHyperEdge(edgeDef.ID).GetTargetVertices())
                                    //    {
                                    //        internSingleDelete.Add(
                                    //            new SingleEdgeDeleteDefinition(source,
                                    //                                            new VertexInformation(edgeInstance.VertexTypeID,
                                    //                                                                    edgeInstance.VertexID)));
                                    //    }
                                    //}

                                    List<SingleEdgeUpdateDefinition> internSingleUpdate = null;
                                    var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);

                                    if (targets != null)
                                    {
                                        foreach (var target in targets)
                                        {
                                            internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();
                                            internSingleUpdate.Add(new SingleEdgeUpdateDefinition(source, target, edgeDef.InnerEdgeType.ID));
                                        }
                                    }
                                    if (edge.ContainedEdges != null)
                                    {
                                        foreach (var innerEdge in edge.ContainedEdges)
                                        {
                                            targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType);
                                            if (targets != null && targets.CountIsGreater(0))
                                            {
                                                ConvertUnknownProperties(innerEdge, edgeDef.InnerEdgeType);
                                                var structured = CreateStructuredUpdate(innerEdge.StructuredProperties, edgeDef.InnerEdgeType);
                                                var unstructured = CreateUnstructuredUpdate(innerEdge.UnstructuredProperties);

                                                foreach (var target in targets)
                                                {
                                                    internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();

                                                    internSingleUpdate.Add(
                                                        new SingleEdgeUpdateDefinition(source,
                                                                                        target,
                                                                                        edgeDef.InnerEdgeType.ID,
                                                                                        innerEdge.Comment,
                                                                                        structured,
                                                                                        unstructured));
                                                }
                                            }

                                        }
                                    }
                                    ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                    var outerStructured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                    var outerUnstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                    toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();

                                    toBeUpdatedHyper.Add(edgeDef.ID,
                                                            new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID,
                                                                                            edge.Comment,
                                                                                            outerStructured,
                                                                                            outerUnstructured,
                                                                                            null,//internSingleDelete,
                                                                                            internSingleUpdate));
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.HyperEdge:
                                break;

                            default:
                                throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                        }
                    }
                }

                #endregion

                #region update outgoing edges properties

                if (myUpdate.UpdateOutgoingEdgesProperties != null)
                {
                    foreach (var edge in myUpdate.UpdateOutgoingEdgesProperties)
                    {
                        var edgeDef = myVertexType
                                        .GetOutgoingEdgeDefinitions(true)
                                        .Where(_ => _.ID.Equals(edge.EdgeTypeID) ||
                                                _.InnerEdgeType.ID.Equals(edge.EdgeTypeID)).FirstOrDefault();

                        switch (edgeDef.Multiplicity)
                        {
                            case EdgeMultiplicity.SingleEdge:
                                {
                                    #region SingleEdge
                                    //var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType);

                                    //if (targets == null || !targets.CountIsGreater(0))
                                    //{
                                    //    toBeDeletedSingle = toBeDeletedSingle ?? new List<long>();
                                    //    toBeDeletedSingle.Add(edgeDef.ID);
                                    //}
                                    //else if (targets.CountIsGreater(1))
                                    //{
                                    //    throw new Exception("Single edge can not have more than one target.");
                                    //}
                                    //else
                                    //{
                                    //    ConvertUnknownProperties(edge, edgeDef.EdgeType);
                                    //    var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType);
                                    //    var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties);

                                    //    toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>();

                                    //    toBeUpdatedSingle.Add(edgeDef.ID,
                                    //                            new SingleEdgeUpdateDefinition(source,
                                    //                                                            targets.First(),
                                    //                                                            edgeDef.EdgeType.ID,
                                    //                                                            edge.Comment,
                                    //                                                            structured,
                                    //                                                            unstructured));
                                    //}
                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.MultiEdge:
                                {
                                    #region MultiEdge
                                    List<SingleEdgeUpdateDefinition> internSingleUpdate = null;

                                    var targets =
                                        myVertex
                                        .GetOutgoingEdge(edgeDef.ID)
                                        .GetTargetVertices()
                                        .Select(_ => new VertexInformation(_.VertexTypeID,
                                                                            _.VertexID));

                                    if (targets != null && targets.CountIsGreater(0))
                                    {
                                        var structured = edge.UpdatedStructuredProperties;
                                        var unstructured = edge.UpdatedUnstructuredProperties;

                                        foreach (var target in targets)
                                        {
                                            internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>();

                                            internSingleUpdate.Add(
                                                new SingleEdgeUpdateDefinition(source,
                                                                                target,
                                                                                edgeDef.InnerEdgeType.ID,
                                                                                edge.CommentUpdate,
                                                                                structured,
                                                                                unstructured));
                                        }
                                    }

                                    toBeUpdatedHyper = toBeUpdatedHyper ??
                                                        new Dictionary<long, HyperEdgeUpdateDefinition>();

                                    if (toBeUpdatedHyper.ContainsKey(edgeDef.ID))
                                    {
                                        var temp = toBeUpdatedHyper[edgeDef.ID];
                                        toBeUpdatedHyper.Remove(edgeDef.ID);
                                        toBeUpdatedHyper.Add(edgeDef.ID,
                                                            MergeToBeAddedHyperEdgeUpdates(temp,
                                                                                            internSingleUpdate));
                                    }
                                    else
                                        toBeUpdatedHyper.Add(edgeDef.ID,
                                                                new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID,
                                                                                                null,
                                                                                                null,
                                                                                                null,
                                                                                                null,
                                                                                                internSingleUpdate));

                                    #endregion
                                }
                                break;

                            case EdgeMultiplicity.HyperEdge:
                                break;

                            default:
                                throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement.");
                        }
                    }
                }

                #endregion

                #region update AddedElementsToCollectionEdges

                if (myUpdate.AddedElementsToCollectionEdges != null)
                {
                    foreach (var hyperEdge in myUpdate.AddedElementsToCollectionEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key);

                        if (edgeDef == null)
                            //TODO a better exception here
                            throw new Exception("edge attribute not defined.");

                        if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge)
                            //TODO a better exception here
                            throw new Exception("Add edges is only defined on hyper/multi edges.");

                        var edgeTypeID = edgeDef.ID;
                        StructuredPropertiesUpdate structuredUpdate;
                        UnstructuredPropertiesUpdate unstructuredUpdate;
                        IEnumerable<SingleEdgeUpdateDefinition> singleUpdate;

                        CheckIfToBeAddedElementAlreadyExist(myVertex, 
                                                            edgeDef, 
                                                            hyperEdge.Value,
                                                            myTransaction,
                                                            mySecurity);

                        CreateSingleEdgeUpdateDefinitions(source,
                                                            myTransaction,
                                                            mySecurity,
                                                            hyperEdge.Value,
                                                            edgeDef,
                                                            out structuredUpdate,
                                                            out unstructuredUpdate,
                                                            out singleUpdate);

                        toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();

                        toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, structuredUpdate, unstructuredUpdate, null, singleUpdate));
                    }
                }

                #endregion

                #region update RemovedElementsFromCollectionEdges

                if (myUpdate.RemovedElementsFromCollectionEdges != null)
                {
                    foreach (var hyperEdge in myUpdate.RemovedElementsFromCollectionEdges)
                    {
                        var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key);

                        if (edgeDef == null)
                            //TODO a better exception here
                            throw new Exception("Edge attribute not defined.");

                        if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge)
                            //TODO a better exception here
                            throw new Exception("Removing edges is only defined on hyper/multi edges.");

                        var edgeTypeID = edgeDef.ID;

                        var del = CreateSingleEdgeDeleteDefinitions(source, myTransaction, mySecurity, hyperEdge.Value, edgeDef);

                        toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>();
                        toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, null, null, del, null));

                    }
                }

                #endregion
            }

            #endregion

            #region create updates

            var updateSingle = (toBeUpdatedSingle != null || toBeDeletedSingle != null)
                ? new SingleEdgeUpdate(toBeUpdatedSingle, toBeDeletedSingle)
                : null;

            var updateHyper = (toBeUpdatedHyper != null || toBeDeletedHyper != null)
                ? new HyperEdgeUpdate(toBeUpdatedHyper, toBeDeletedHyper)
                : null;

            var updateStructured = (toBeUpdatedStructured != null || toBeDeletedStructured != null)
                ? new StructuredPropertiesUpdate(toBeUpdatedStructured, toBeDeletedStructured)
                : null;

            var updateUnstructured = (toBeUpdatedUnstructured != null || toBeDeletedUnstructured != null)
                ? new UnstructuredPropertiesUpdate(toBeUpdatedUnstructured, toBeDeletedUnstructured)
                : null;

            var updateBinaries = (toBeUpdatedBinaries != null || toBeDeletedBinaries != null)
                ? new BinaryPropertiesUpdate(toBeUpdatedBinaries, toBeDeletedBinaries)
                : null;

            #endregion

            return Tuple.Create(revision,
                                edition,
                                new VertexUpdateDefinition(comment,
                                                            updateStructured,
                                                            updateUnstructured,
                                                            updateBinaries,
                                                            updateSingle,
                                                            updateHyper));
        }
示例#6
0
        private string CreateGraphDMLforIVertex(
            IVertexType myVertexType,
            IVertex myVertex,
            Dictionary<long, IPropertyDefinition> myPropertyDefinitions)
        {
            var stringBuilder = new StringBuilder();
            var delimiter = ", ";

            //INSERT INTO ... VALUES (VertexID = ...,
            stringBuilder.Append(String.Concat(S_INSERT.ToUpperString(),
                                                " ",
                                                S_INTO.ToUpperString(),
                                                " ",
                                                myVertexType.Name,
                                                " ",
                                                S_VALUES.ToUpperString(),
                                                " ",
                                                S_BRACKET_LEFT));

            stringBuilder.Append(String.Concat(S_UUID, " = ", myVertex.VertexID.ToString(), delimiter));

            #region standard attributes (creationDate, ...)

            string standardProperties = CreateGraphDMLforVertexStandardProperties(myVertex);

            stringBuilder.Append(standardProperties);

            #endregion

            #region properties (age, list<String>, ...)

            string defAttrsDML = CreateGraphDMLforDefinedProperties(myVertex.GetAllProperties(),
                                                                    myPropertyDefinitions);

            stringBuilder.Append(defAttrsDML);

            #endregion

            #region unstructured data

            string unstrProperties = CreateGraphDMLforVertexUnstructuredProperties(
                                        myVertex.GetAllUnstructuredProperties(),
                                        myPropertyDefinitions);

            stringBuilder.Append(unstrProperties);

            #endregion

            #region outgoing edges

            #region singleEdge

            string outgoingSingleEdges = CreateGraphDMLforVertexOutgoingSingleEdges(
                                            myVertexType,
                                            myVertex.GetAllOutgoingSingleEdges(),
                                            myVertexType.GetOutgoingEdgeDefinitions(true)
                                                .ToDictionary(key => key.ID, value => value));

            stringBuilder.Append(outgoingSingleEdges);

            #endregion

            #region hyperEdge

            string outgoingHyperEdges = CreateGraphDMLforVertexOutgoingHyperEdges
                                        (myVertexType,
                                        myVertex.GetAllOutgoingHyperEdges(),
                                        myVertexType.GetOutgoingEdgeDefinitions(true)
                                            .ToDictionary(key => key.ID, value => value));

            stringBuilder.Append(outgoingHyperEdges);

            #endregion

            #endregion

            if (stringBuilder.ToString().EndsWith(delimiter))
                stringBuilder.RemoveSuffix(delimiter);

            stringBuilder.Append(S_BRACKET_RIGHT);

            return stringBuilder.ToString();
        }
示例#7
0
        /// <summary>
        /// Creates the ddl of a type.
        /// </summary>
        /// <param name="myVertexType">The vertex type.</param>
        private String CreateGraphDDL_VertexType(IVertexType myVertexType)
        {
            var stringBuilder = new StringBuilder();
            String delimiter = ", ";
            stringBuilder.AppendFormat("{0} ", myVertexType.Name);

            #region parent type

            //EXTENDS ...
            if (myVertexType.HasParentType)
            {
                stringBuilder.AppendFormat("{0} {1} ", S_EXTENDS.ToUpperString(), myVertexType.ParentVertexType.Name);
            }

            #endregion

            #region attributes
            //are there attributes
            if (myVertexType.HasAttributes(false))
            {
                #region !incomingEdges

                if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind != AttributeType.IncomingEdge))
                {
                    //so, there are attributes that are no incoming edges
                    stringBuilder.Append(String.Concat(S_ATTRIBUTES.ToUpperString(), " ", S_BRACKET_LEFT));

                    #region properties

                    if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.Property))
                    {
                        stringBuilder.Append(String.Concat(CreateGraphDDLOfProperties(myVertexType.GetPropertyDefinitions(false))));
                    }

                    #endregion

                    #region outgoing edges

                    if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.OutgoingEdge))
                    {
                        stringBuilder.Append(String.Concat(CreateGraphDDLOfOutgoingEdges(myVertexType.GetOutgoingEdgeDefinitions(false), myVertexType)));
                    }

                    #endregion

                    if (stringBuilder.ToString().EndsWith(delimiter))
                        stringBuilder.RemoveSuffix(delimiter);

                    stringBuilder.Append(String.Concat(S_BRACKET_RIGHT, " "));

                }

                #endregion

                #region incomingEdges

                if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.IncomingEdge))
                {
                    stringBuilder.Append(
                        String.Concat(S_INCOMINGEDGES.ToUpperString(),
                                        " ",
                                        S_BRACKET_LEFT.ToUpperString(),
                                        CreateGraphDDLOfIncomingEdges(
                                            myVertexType.GetIncomingEdgeDefinitions(false)),
                                        S_BRACKET_RIGHT.ToUpperString(), " "));
                }

                #endregion
            }

            #endregion

            #region Uniques

            if (myVertexType.HasUniqueDefinitions(false))
            {
                if (myVertexType.GetUniqueDefinitions(false).Count() > 0)
                {
                    stringBuilder.Append(S_UNIQUE.ToUpperString() +
                                            " " +
                                            S_BRACKET_LEFT.Symbol +
                                            CreateGraphDDLOfUniqueAttributes(
                                                myVertexType
                                                    .GetUniqueDefinitions(false)) +
                                            S_BRACKET_RIGHT.Symbol + " ");
                }
            }

            #endregion

            #region Mandatory attributes

            if (myVertexType.HasProperties(false))
            {
                if (myVertexType.GetPropertyDefinitions(false).Any(aProperty => aProperty.IsMandatory))
                {
                    stringBuilder.Append(S_MANDATORY.ToUpperString() +
                                            " " +
                                            S_BRACKET_LEFT.Symbol +
                                            CreateGraphDDLOfMandatoryAttributes(
                                                myVertexType
                                                    .GetPropertyDefinitions(false)
                                                    .Where(aProperty => aProperty.IsMandatory)) +
                                            S_BRACKET_RIGHT.Symbol + " ");
                }
            }

            #endregion

            #region Indices

            var indices =
                myVertexType.GetIndexDefinitions(false).Except(
                    myVertexType.GetUniqueDefinitions(false).Select(_ => _.CorrespondingIndex));

            if (indices.Count() > 0)
            {
                stringBuilder.Append(S_INDICES.ToUpperString() +
                                        " " +
                                        S_BRACKET_LEFT.Symbol +
                                        CreateGraphDDLOfIndices(indices, myVertexType) +
                                        S_BRACKET_RIGHT.Symbol);
            }

            #endregion

            return stringBuilder.ToString();
        }
示例#8
0
        private Dictionary<IOutgoingEdgeDefinition, Tuple<bool, long>> AllEdgeWithTargetVertex(IVertexType vertexType)
        {
            Dictionary<IOutgoingEdgeDefinition, Tuple<bool, long>> idList = new Dictionary<IOutgoingEdgeDefinition, Tuple<bool, long>>();
            var temp =   vertexType.GetOutgoingEdgeDefinitions(true);
            foreach (IOutgoingEdgeDefinition vertex in temp)
            {
                if (vertex.TargetVertexType.ID == vertexType.ID)
                {
                    var hasProperty = vertex.InnerEdgeType.HasProperty("Weight");

                    long myPropertyID = 0;

                    if (hasProperty == true)
                    {
                        myPropertyID = vertex.InnerEdgeType.GetPropertyDefinition("Weight").ID;
                    }

                    idList.Add(vertex,Tuple.Create(hasProperty,myPropertyID));
                }
            }
            return idList;
        }
示例#9
0
		private String Recurs(String str,IVertexType StartType, List<TypeWithProperty> type_property_object, List<Tuple<long, long>> PATHShortDSF)
		{
			var hyperEdgeOut = StartType.GetOutgoingEdgeDefinitions(true);
			var hyperEdgeInc = StartType.GetIncomingEdgeDefinitions(true);

			foreach (IOutgoingEdgeDefinition value in hyperEdgeOut)
			{
				if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null)
				{
					if (type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID).Count() > 0)
					{
						var temp = str;
						foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.TargetVertexType.ID))
						{
							_stringPath.Add(Tuple.Create(val.Type.Name+'.'+val.PropertyDefinition.Name,str + '.' + value.Name + '.' + val.PropertyDefinition.Name));
						}
						 str = temp + '.' + value.Name;
						Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF);
						str = temp;
					}
					else
					{
						var temp = str;
						str += '.' + value.Name;
						Recurs(str, value.TargetVertexType, type_property_object, PATHShortDSF);
						str = temp;
					}
				}
			}

			foreach (IIncomingEdgeDefinition value in hyperEdgeInc)
			{
				if (PATHShortDSF.Find(x => x.Item2 == value.ID) != null)
				{
					if (type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID).Count() > 0)
					{
						var temp = str;
						foreach (TypeWithProperty val in type_property_object.Where(x => x.Type.ID == value.RelatedEdgeDefinition.SourceVertexType.ID))
						{
				          _stringPath.Add(Tuple.Create(val.Type.Name + '.' + val.PropertyDefinition.Name, str + '.' + value.Name + '.' + val.PropertyDefinition.Name));
                        }
					str = temp + '.' + value.Name;
						Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF);
						str = temp;
					}
					else
					{
						var temp = str;
						str += '.' + value.Name;
						Recurs(str, value.RelatedEdgeDefinition.SourceVertexType, type_property_object, PATHShortDSF);
						str = temp;
					}
				}
			}
			str = "";
			return null;
		} 
示例#10
0
        /// <summary>
        /// Generate an output for an type with the attributes of the types and all parent types
        /// </summary>         
        /// <param name="myDBContext">The db context</param>
        /// <param name="myType">The db type</param>
        /// <param name="myDepth">If depth == 0 only the type basic attributes will be returned</param>
        private IVertexView GenerateOutput(IVertexType myType, Int32 myDepth = 0)
        {
            var retVal = new Dictionary<String, object>();

            List<IVertexView> result = new List<IVertexView>();
            var edges = new Dictionary<String, IEdgeView>();

            //base output
            retVal.Add("VertexID", myType.ID);
            retVal.Add("Type", myType.GetType().Name);
            retVal.Add("Name", myType.Name);
            retVal.Add("IsUserDefined", myType.IsUserDefined);

            //additional output
            if (myDepth > 0)
            {
                retVal.Add("IsAbstract", myType.IsAbstract);

                edges.Add("Properties", new HyperEdgeView(null, GeneratePropertiesOutput(myType, myType.GetPropertyDefinitions(true), myDepth)));

                edges.Add("Edges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetOutgoingEdgeDefinitions(true))));

                edges.Add("Incomingedges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetIncomingEdgeDefinitions(true))));

                edges.Add("UniqueAttributes", new HyperEdgeView(null, GenerateUniquePropertiesOutput(myType, myType.GetUniqueDefinitions(true))));

                edges.Add("Indices", new HyperEdgeView(null, GenerateIndicesOutput(myType)));

                if (myType.HasParentType)
                    edges.Add("Extends", new SingleEdgeView(null, GenerateOutput(myType.ParentVertexType)));

                if (myType.HasChildTypes)
                {
                    List<ISingleEdgeView> list = new List<ISingleEdgeView>();

                    foreach (var child in myType.ChildrenVertexTypes)
                        list.Add(new SingleEdgeView(null, GenerateOutput(child)));

                    edges.Add("ChildrenVertexTypes", new HyperEdgeView(null, list));
                }

                if (!string.IsNullOrWhiteSpace(myType.Comment))
                    retVal.Add("Comment", myType.Comment);
            }

            return new VertexView(retVal, edges);
        }
示例#11
0
        /// <summary>
        /// This will add all attributes of <paramref name="myDBObject"/> to the 
        /// <paramref name="myAttributes"/> reference. Reference attributes will be resolved to the <paramref name="myDepth"/>
        /// </summary>
        private void AddAttributesByDBO(
            SecurityToken mySecurityToken,
            Int64 myTransactionToken,
            ref Tuple<IDictionary<String, Object>, IDictionary<String, IEdgeView>> myAttributes,
            IVertexType myType,
            IVertex myDBObject,
            Int64 myDepth,
            EdgeList myEdgeList,
            String myReference,
            Boolean myUsingGraph,
            TypesOfSelect mySelType,
            Int64? myTypeID = null)
        {

            #region Get all attributes which are stored at the DBO

            #region properties

            foreach (var aProperty in myType.GetPropertyDefinitions(true))
            {
                var tempResult = aProperty.GetValue(myDBObject);

                if (tempResult != null)
                {
                    myAttributes.Item1.Add(aProperty.Name, tempResult);
                }
            }

            #endregion

            #region unstructured data

            foreach (var aUnstructuredProperty in myDBObject.GetAllUnstructuredProperties())
            {
                myAttributes.Item1.Add(aUnstructuredProperty.PropertyName, aUnstructuredProperty.Property);
            }

            #endregion

            #region outgoing edges

            foreach (var outgoingEdgeDefinition in myType.GetOutgoingEdgeDefinitions(true))
            {
                if (myDBObject.HasOutgoingEdge(outgoingEdgeDefinition.ID))
                {
                    // Since we can define special depth (via setting) for attributes we need to check them now
                    myDepth = GetDepth(-1, myDepth, myType, outgoingEdgeDefinition);
                    if ((myDepth > 0))
                    {
                        myAttributes.Item2.Add(
                            outgoingEdgeDefinition.Name,
                            ResolveAttributeValue(
                                outgoingEdgeDefinition,
                                myDBObject.GetOutgoingEdge(outgoingEdgeDefinition.ID),
                                myDepth,
                                myEdgeList,
                                myDBObject,
                                myReference,
                                myUsingGraph,
                                mySecurityToken,
                                myTransactionToken));
                    }
                    else
                    {
                        myAttributes.Item2.Add(outgoingEdgeDefinition.Name, 
                                                GetNotResolvedReferenceEdgeAttributeValue(myDBObject
                                                                                            .GetOutgoingEdge(outgoingEdgeDefinition.ID)
                                                                                            .GetTargetVertices()));
                    }
                }
            }

            #endregion

            #region incoming

            foreach (var aIncomingEdgeDefinition in myType.GetIncomingEdgeDefinitions(true))
            {
                if (myDBObject.HasIncomingVertices(aIncomingEdgeDefinition
                                                    .RelatedEdgeDefinition
                                                    .RelatedType.ID, 
                                                   aIncomingEdgeDefinition
                                                    .RelatedEdgeDefinition.ID))
                {
                    if (myDepth > 0)
                    {
                        myAttributes.Item2.Add(
                            aIncomingEdgeDefinition.Name,
                            ResolveIncomingEdgeValue(
                                aIncomingEdgeDefinition,
                                myDBObject.GetIncomingVertices(aIncomingEdgeDefinition
                                                                .RelatedEdgeDefinition
                                                                .RelatedType
                                                                .ID, 
                                                               aIncomingEdgeDefinition
                                                                .RelatedEdgeDefinition.ID),
                                myDepth,
                                myEdgeList,
                                myDBObject,
                                myReference,
                                myUsingGraph,
                                mySecurityToken,
                                myTransactionToken));
                    }
                    else
                    {
                        myAttributes.Item2.Add(aIncomingEdgeDefinition.Name, 
                                                GetNotResolvedReferenceEdgeAttributeValue(myDBObject.GetIncomingVertices(aIncomingEdgeDefinition
                                                                                                                            .RelatedEdgeDefinition
                                                                                                                            .RelatedType.ID, 
                                                                                                                          aIncomingEdgeDefinition
                                                                                                                            .RelatedEdgeDefinition.ID)));
                    }
                }
            }

            #endregion

            #endregion
        }
示例#12
0
        /// <summary>
        /// Generate an output for an type with the attributes of the types and all parent types
        /// </summary>
        /// <param name="myDBContext">The db context</param>
        /// <param name="myType">The db type</param>
        /// <param name="myDepth">If depth == 0 only the type basic attributes will be returned</param>
        private IVertexView GenerateOutput(IVertexType myType, Int32 myDepth = 0)
        {
            var retVal = new Dictionary <String, object>();

            List <IVertexView> result = new List <IVertexView>();
            var edges = new Dictionary <String, IEdgeView>();

            //base output
            retVal.Add("VertexID", myType.ID);
            retVal.Add("Type", myType.GetType().Name);
            retVal.Add("Name", myType.Name);
            retVal.Add("IsUserDefined", myType.IsUserDefined);

            //additional output
            if (myDepth > 0)
            {
                retVal.Add("IsAbstract", myType.IsAbstract);

                edges.Add("Properties", new HyperEdgeView(null, GeneratePropertiesOutput(myType, myType.GetPropertyDefinitions(true), myDepth)));

                edges.Add("Edges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetOutgoingEdgeDefinitions(true))));

                edges.Add("Incomingedges", new HyperEdgeView(null, GenerateEdgesOutput(myType, myType.GetIncomingEdgeDefinitions(true))));

                edges.Add("UniqueAttributes", new HyperEdgeView(null, GenerateUniquePropertiesOutput(myType, myType.GetUniqueDefinitions(true))));

                edges.Add("Indices", new HyperEdgeView(null, GenerateIndicesOutput(myType)));

                if (myType.HasParentType)
                {
                    edges.Add("Extends", new SingleEdgeView(null, GenerateOutput(myType.ParentVertexType)));
                }

                if (myType.HasChildTypes)
                {
                    List <ISingleEdgeView> list = new List <ISingleEdgeView>();

                    foreach (var child in myType.ChildrenVertexTypes)
                    {
                        list.Add(new SingleEdgeView(null, GenerateOutput(child)));
                    }

                    edges.Add("ChildrenVertexTypes", new HyperEdgeView(null, list));
                }

                if (!string.IsNullOrWhiteSpace(myType.Comment))
                {
                    retVal.Add("Comment", myType.Comment);
                }
            }

            return(new VertexView(retVal, edges));
        }