Пример #1
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);
        }