/// <summary>
        /// This method classifies an operation by setting its its operation type.
        /// </summary>
        /// <remarks>Domain operations are either explicitly marked with attributes, or they follow a naming/signature convention.</remarks>
        /// <param name="operation">The domain operation to inspect.</param>
        /// <returns>True if the operation is attributed or matches convention; false otherwise.</returns>
        private bool ClassifyDomainOperation(ReflectionDomainOperationEntry operation)
        {
            DomainOperation operationType;

            // Check if explicit attributes exist.
            QueryAttribute queryAtt = (QueryAttribute)operation.Attributes[typeof(QueryAttribute)];

            if (queryAtt != null)
            {
                // query method
                operation.Operation = DomainOperation.Query;
                return(true);
            }
            else if (operation.Attributes[typeof(InsertAttribute)] != null)
            {
                operationType = DomainOperation.Insert;
            }
            else if (operation.Attributes[typeof(UpdateAttribute)] != null)
            {
                // disable obsolete warning here
#pragma warning disable 0618
                if (((UpdateAttribute)operation.Attributes[typeof(UpdateAttribute)]).UsingCustomMethod)
#pragma warning restore 0618
                {
                    operationType = DomainOperation.Custom;
                }
                else
                {
                    operationType = DomainOperation.Update;
                }
            }
            else if (operation.Attributes[typeof(EntityActionAttribute)] != null)
            {
                operationType = DomainOperation.Custom;
            }
            else if (operation.Attributes[typeof(DeleteAttribute)] != null)
            {
                operationType = DomainOperation.Delete;
            }
            else if (operation.Attributes[typeof(InvokeAttribute)] != null)
            {
                operationType = DomainOperation.Invoke;
            }
            else
            {
                return(this.TryClassifyImplicitDomainOperation(operation));
            }

            operation.Operation = operationType;

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// This method classifies an operation by setting its its operation type.
        /// </summary>
        /// <remarks>Domain operations are either explicitly marked with attributes, or they follow a naming/signature convention.</remarks>
        /// <param name="operation">The domain operation to inspect.</param>
        /// <returns>True if the operation is attributed or matches convention; false otherwise.</returns>
        private bool ClassifyDomainOperation(ReflectionDomainOperationEntry operation)
        {
            DomainOperation operationType;

            // Check if explicit attributes exist.
            QueryAttribute queryAtt = (QueryAttribute)operation.Attributes[typeof(QueryAttribute)];

            if (queryAtt != null)
            {
                // query method
                operation.Operation = DomainOperation.Query;
                return(true);
            }
            else if (operation.Attributes[typeof(InsertAttribute)] != null)
            {
                operationType = DomainOperation.Insert;
            }
            else if (operation.Attributes[typeof(UpdateAttribute)] != null)
            {
                operationType = DomainOperation.Update;
            }
            else if (operation.Attributes[typeof(EntityActionAttribute)] != null)
            {
                operationType = DomainOperation.Custom;
            }
            else if (operation.Attributes[typeof(DeleteAttribute)] != null)
            {
                operationType = DomainOperation.Delete;
            }
            else if (operation.Attributes[typeof(InvokeAttribute)] != null)
            {
                operationType = DomainOperation.Invoke;
            }
            else
            {
                return(this.TryClassifyImplicitDomainOperation(operation));
            }

            operation.Operation = operationType;

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Based on the operation type specified, create the default corresponding attribute
        /// if it hasn't been specified explicitly, and add it to the attributes collection.
        /// </summary>
        private void InitializeOperationAttribute()
        {
            if (this._operationAttribute != null)
            {
                return;
            }

            bool attributeCreated = false;

            switch (this.Operation)
            {
            case DomainOperation.Query:
                this._operationAttribute = this._attributes[typeof(QueryAttribute)];
                if (this._operationAttribute == null)
                {
                    QueryAttribute qa = new QueryAttribute();
                    // singleton returning query methods aren't composable
                    qa.IsComposable          = TypeUtility.FindIEnumerable(this.ReturnType) != null;
                    this._operationAttribute = qa;
                    attributeCreated         = true;
                }
                break;

            case DomainOperation.Insert:
                this._operationAttribute = this._attributes[typeof(InsertAttribute)];
                if (this._operationAttribute == null)
                {
                    this._operationAttribute = new InsertAttribute();
                    attributeCreated         = true;
                }
                break;

            case DomainOperation.Update:
                this._operationAttribute = this._attributes[typeof(UpdateAttribute)];
                if (this._operationAttribute == null)
                {
                    this._operationAttribute = new UpdateAttribute();
                    attributeCreated         = true;
                }
                break;

            case DomainOperation.Delete:
                this._operationAttribute = this._attributes[typeof(DeleteAttribute)];
                if (this._operationAttribute == null)
                {
                    this._operationAttribute = new DeleteAttribute();
                    attributeCreated         = true;
                }
                break;

            case DomainOperation.Invoke:
                this._operationAttribute = this._attributes[typeof(InvokeAttribute)];
                if (this._operationAttribute == null)
                {
                    this._operationAttribute = new InvokeAttribute();
                    attributeCreated         = true;
                }
                break;

            case DomainOperation.Custom:
                this._operationAttribute = this._attributes[typeof(EntityActionAttribute)];
                if (this._operationAttribute == null)
                {
                    this._operationAttribute = new EntityActionAttribute();
                    attributeCreated         = true;
                }
                break;

            default:
                break;
            }

            if (attributeCreated)
            {
                if (this._attributes == null)
                {
                    this._attributes = new AttributeCollection(this._operationAttribute);
                }
                else
                {
                    this._attributes = AttributeCollection.FromExisting(this._attributes, this._operationAttribute);
                }
            }
        }