Ejemplo n.º 1
0
        /// <summary>
        /// Builds the resource expression.
        /// </summary>
        /// <param name="resourceExpression">The resource expression.</param>
        /// <returns>ResourceExpression.</returns>
        /// <param name="context"></param>
        private static ResourceExpression BuildResourceExpression(Model.ResourceExpression resourceExpression, FromEntityContext context)
        {
            //resourceExpression entity node's followRelationship must not be null
            RelationshipReportNode relationshipReportNode =
                resourceExpression.SourceNode.As <RelationshipReportNode>();

            if (relationshipReportNode != null)
            {
                if (relationshipReportNode.FollowRelationship == null)
                {
                    EventLog.Application.WriteWarning(context.DebugInfo + "relationshipReportNode.FollowRelationship was null");
                    return(null);
                }
            }

            //resourceExpression sourceNode is null means that the source entity is removed
            if (resourceExpression.SourceNode == null)
            {
                EventLog.Application.WriteWarning(context.DebugInfo + "resourceExpression.SourceNode was null");
                return(null);
            }

            long          targetTypeId = 0;
            TypedArgument ta           = resourceExpression.ReportExpressionResultType.As <TypedArgument>();

            if (ta != null && ta.ConformsToType != null)
            {
                targetTypeId = ta.ConformsToType.Id;
            }

            DatabaseType castType = null;

            if (ta != null && ta.Name != null)
            {
                if (ta.Name == "ChoiceRelationship")
                {
                    castType = new ChoiceRelationshipType();
                }
                else
                {
                    castType = new InlineRelationshipType();
                }
            }


            return(new ResourceExpression {
                FieldId = new EntityRef("core:name"), SourceNodeEntityId = resourceExpression.SourceNode.Id, TargetTypeId = targetTypeId, CastType = castType
            });
        }
        /// <summary>
        /// Interrogates the expression instance populating the report column that is exposed to the Report API service.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <param name="reportColumn">The report column.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool PopulateTypeFromArgument(ActivityArgument argument, out DatabaseType type, out EntityType resourceType)
        {
            resourceType = null;

            if (argument.Is <StringArgument>())
            {
                type = new StringType();
            }
            else if (argument.Is <IntegerArgument>())
            {
                type = new Int32Type();
            }
            else if (argument.Is <CurrencyArgument>())
            {
                type = new CurrencyType();
            }
            else if (argument.Is <DecimalArgument>())
            {
                type = new DecimalType();
            }
            else if (argument.Is <DateArgument>())
            {
                type = new DateType();
            }
            else if (argument.Is <TimeArgument>())
            {
                type = new TimeType();
            }
            else if (argument.Is <DateTimeArgument>())
            {
                type = new DateTimeType();
            }
            else if (argument.Is <GuidArgument>())
            {
                type = new GuidType();
            }
            else if (argument.Is <BoolArgument>())
            {
                type = new BoolType();
            }
            else if (argument.Is <TypedArgument>())
            {
                TypedArgument rla = argument.As <TypedArgument>();
                resourceType = Entity.Get <EntityType>(rla.ConformsToType);
                if (resourceType == null)
                {
                    type = null;
                    return(false);
                }
                if (resourceType.IsOfType.FirstOrDefault(t => t.Alias == "core:enumType") != null)
                {
                    // A choice field
                    type = new ChoiceRelationshipType();
                }
                else
                {
                    // Is a related resource
                    type = new InlineRelationshipType();
                }
            }
            else
            {
                type = null;
                return(false);
            }
            return(true);
        }