public static RequestAlterVertexType MakeRequestAlterVertexType(ServiceVertexType myVertexType, ServiceAlterVertexChangeset myChangeset)
        {
            var Request = new RequestAlterVertexType(myVertexType.Name);

            #region Add Attributes

            if (myChangeset.ToBeAddedProperties != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedProperties)
                {
                    Request.AddProperty(toAdd.ToPropertyPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIncomingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIncomingEdges)
                {
                    Request.AddIncomingEdge(toAdd.ToIncomingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedOutgoingEdges != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedOutgoingEdges)
                {
                    Request.AddOutgoingEdge(toAdd.ToOutgoingEdgePredefinition());
                }
            }

            if (myChangeset.ToBeAddedUniques != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedUniques)
                {
                    Request.AddUnique(toAdd.ToUniquePredefinition());
                }
            }

            if (myChangeset.ToBeAddedMandatories != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedMandatories)
                {
                    Request.AddMandatory(toAdd.ToMandatoryPredefinition());
                }
            }

            if (myChangeset.ToBeAddedIndices != null)
            {
                foreach (var toAdd in myChangeset.ToBeAddedIndices)
                {
                    Request.AddIndex(toAdd.ToIndexPredefinition());
                }
            }


            #endregion

            #region Remove Attributes

            if (myChangeset.ToBeRemovedProperties != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedProperties)
                {
                    Request.RemoveProperty(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIncomingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIncomingEdges)
                {
                    Request.RemoveIncomingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedOutgoingEdges != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedOutgoingEdges)
                {
                    Request.RemoveOutgoingEdge(toDel);
                }
            }

            if (myChangeset.ToBeRemovedUniques != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedUniques)
                {
                    Request.RemoveUnique(toDel);
                }
            }

            if (myChangeset.ToBeRemovedMandatories != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedMandatories)
                {
                    Request.RemoveMandatory(toDel);
                }
            }

            if (myChangeset.ToBeRemovedIndices != null)
            {
                foreach (var toDel in myChangeset.ToBeRemovedIndices)
                {
                    Request.RemoveIndex(toDel.Key, toDel.Value);
                }
            }

            #endregion

            #region define / undefine

            if (myChangeset.ToBeDefinedAttributes != null)
            {
                foreach (var toDefine in myChangeset.ToBeDefinedAttributes)
                {
                    Request.DefineAttribute(toDefine.ToUnknownAttributePredefinition());
                }
            }

            if (myChangeset.ToBeUndefinedAttributes != null)
            {
                foreach (var toUndefine in myChangeset.ToBeUndefinedAttributes)
                {
                    Request.UndefineAttribute(toUndefine);
                }
            }

            #endregion

            #region Rename Task

            if (myChangeset.ToBeRenamedProperties != null)
            {
                foreach (var toRename in myChangeset.ToBeRenamedProperties)
                {
                    Request.RenameAttribute(toRename.Key, toRename.Value);
                }
            }

            #endregion

            if (myChangeset.Comment != null)
            {
                Request.SetComment(myChangeset.Comment);
            }

            if (myChangeset.NewTypeName != null)
            {
                Request.RenameType(myChangeset.NewTypeName);
            }

            //todo add unknown attribute

            return(Request);
        }
示例#2
0
        public override IVertexType AlterType(IRequestAlterType myAlterTypeRequest,
                                              Int64 myTransactionToken,
                                              SecurityToken mySecurityToken,
                                              out RequestUpdate myUpdateRequest)
        {
            CheckRequestType(myAlterTypeRequest);

            RequestAlterVertexType myRequest = myAlterTypeRequest as RequestAlterVertexType;

            var vertexType = _TypeManager.GetType(myRequest.TypeName,
                                                  myTransactionToken,
                                                  mySecurityToken);

            #region check to be added

            if (myRequest.ToBeAddedUnknownAttributes != null)
            {
                var toBeConverted = myRequest.ToBeAddedUnknownAttributes.ToArray();

                foreach (var unknown in toBeConverted)
                {
                    if (BinaryPropertyPredefinition.TypeName.Equals(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToBinaryProperty(unknown);

                        myRequest.AddBinaryProperty(prop);
                    }
                    else if (_baseTypeManager.IsBaseType(unknown.AttributeType))
                    {
                        var prop = ConvertUnknownToProperty(unknown);

                        myRequest.AddProperty(prop);
                    }
                    else if (unknown.AttributeType.Contains(IncomingEdgePredefinition.TypeSeparator))
                    {
                        var prop = ConvertUnknownToIncomingEdge(unknown);
                        myRequest.AddIncomingEdge(prop);
                    }
                    else
                    {
                        var prop = ConvertUnknownToOutgoingEdge(unknown);
                        myRequest.AddOutgoingEdge(prop);
                    }
                }

                myRequest.ResetUnknown();
            }

            #endregion

            #region check to be removed

            if (myRequest.ToBeRemovedUnknownAttributes != null)
            {
                foreach (var unknownProp in myRequest.ToBeRemovedUnknownAttributes)
                {
                    var attrDef = vertexType.GetAttributeDefinition(unknownProp);

                    if (attrDef == null)
                    {
                        throw new AttributeDoesNotExistException(unknownProp);
                    }

                    switch (attrDef.Kind)
                    {
                    case AttributeType.Property:
                        myRequest.RemoveProperty(unknownProp);
                        break;

                    case AttributeType.OutgoingEdge:
                        myRequest.RemoveOutgoingEdge(unknownProp);
                        break;

                    case AttributeType.IncomingEdge:
                        myRequest.RemoveIncomingEdge(unknownProp);
                        break;

                    case AttributeType.BinaryProperty:
                        myRequest.RemoveBinaryProperty(unknownProp);
                        break;

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

                myRequest.ClearToBeRemovedUnknownAttributes();
            }

            #endregion

            #region check attributes to be defined
            if (myRequest.ToBeDefinedAttributes != null)
            {
                foreach (var unknownProp in myRequest.ToBeDefinedAttributes)
                {
                    var toBeDefined = myRequest.ToBeDefinedAttributes.ToArray();

                    foreach (var unknown in toBeDefined)
                    {
                        if (BinaryPropertyPredefinition.TypeName.Equals(unknown.AttributeType))
                        {
                            throw new InvalidDefineAttributeTypeException(BinaryPropertyPredefinition.TypeName, vertexType.Name);
                        }
                        else if (unknown.AttributeType.Contains(IncomingEdgePredefinition.TypeSeparator))
                        {
                            throw new InvalidDefineAttributeTypeException("incoming edge", vertexType.Name);
                        }
                        else if (!_baseTypeManager.IsBaseType(unknown.AttributeType))
                        {
                            throw new InvalidDefineAttributeTypeException("user defined", vertexType.Name);
                        }
                    }
                }
            }
            #endregion

            #region check attributes to be undefined

            if (myRequest.ToBeUndefinedAttributes != null)
            {
                foreach (var attr in myRequest.ToBeUndefinedAttributes)
                {
                    var attrDef = vertexType.GetAttributeDefinition(attr);

                    if (attrDef == null)
                    {
                        throw new AttributeDoesNotExistException(attr);
                    }

                    switch (attrDef.Kind)
                    {
                    case AttributeType.Property:
                        break;

                    case AttributeType.OutgoingEdge:
                        throw new InvalidUndefineAttributeTypeException("Outgoing Edge", vertexType.Name);

                    case AttributeType.IncomingEdge:
                        throw new InvalidUndefineAttributeTypeException("Incoming Edge", vertexType.Name);

                    case AttributeType.BinaryProperty:
                        throw new InvalidUndefineAttributeTypeException(BinaryPropertyPredefinition.TypeName, vertexType.Name);

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

            #endregion

            #region checks

            CallCheckFunctions(myAlterTypeRequest, vertexType, myTransactionToken, mySecurityToken);

            #endregion

            myUpdateRequest = new RequestUpdate();

            return(null);
        }