private ExprType CalcExpressionType(ActivityArgument arg)
        {
            ExprType result;

            var resArg = arg.As <ResourceArgument>();

            if (resArg != null)
            {
                var resType = resArg.ConformsToType ?? Resource.Resource_Type;
                result = ExprTypeHelper.EntityOfType(resType);
            }
            else
            {
                var resListArg = arg.As <ResourceListArgument>();
                if (resListArg != null)
                {
                    var resType = resListArg.ConformsToType ?? Resource.Resource_Type;

                    result            = ExprType.EntityList.Clone();
                    result.EntityType = resType;
                }
                else
                {
                    var argType = arg.GetArgumentType();
                    result = ArgTypeAliasToExprType[argType.Alias];
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Gets the database type represented by a typed value.
        /// (Avoids unnecessarily attempting to resolve values).
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <returns>Database type.</returns>
        /// <exception cref="System.Exception">Unhandled expression result type</exception>
        public static DatabaseType GetDatabaseType(ActivityArgument argument)
        {
            if (argument == null)
            {
                return(DatabaseType.UnknownType);
            }
            else if (argument.Is <StringArgument>( ))
            {
                return(DatabaseType.StringType);
            }
            else if (argument.Is <IntegerArgument>( ))
            {
                return(DatabaseType.Int32Type);
            }
            else if (argument.Is <CurrencyArgument>( ))
            {
                return(DatabaseType.CurrencyType);
            }
            else if (argument.Is <DecimalArgument>( ))
            {
                return(DatabaseType.DecimalType);
            }
            else if (argument.Is <DateArgument>( ))
            {
                return(DatabaseType.DateType);
            }
            else if (argument.Is <TimeArgument>( ))
            {
                return(DatabaseType.TimeType);
            }
            else if (argument.Is <DateTimeArgument>( ))
            {
                return(DatabaseType.DateTimeType);
            }
            else if (argument.Is <GuidArgument>( ))
            {
                return(DatabaseType.GuidType);
            }
            else if (argument.Is <BoolArgument>( ))
            {
                return(DatabaseType.BoolType);
            }
            else if (argument.Is <ResourceArgument>( ) || argument.Is <ResourceListArgument>( ))
            {
                TypedArgument typedArgument = argument.As <TypedArgument>( );
                if (typedArgument != null && typedArgument.ConformsToType != null)
                {
                    // Interrogate to get it's base type
                    EntityType type     = Entity.Get <EntityType>(typedArgument.ConformsToType.Id);
                    EntityRef  enumType = new EntityRef("core", "enumValue");
                    if (type.GetAncestorsAndSelf( ).FirstOrDefault(a => a.Id == enumType.Id) != null)
                    {
                        return(DatabaseType.ChoiceRelationshipType);
                    }
                }
                return(DatabaseType.InlineRelationshipType);
            }

            throw new Exception("Result type is not of a recognised type.");
        }
Exemple #3
0
        private static ActivityArgument CloneArgument(ActivityArgument arg)
        {
            var newArg = Entity.Create(arg.TypeIds).As <ActivityArgument>();

            newArg.Name        = arg.Name;
            newArg.Description = arg.Description;

            // deal with type specific info.
            var resArg = arg.As <ResourceArgument>();

            if (resArg != null)
            {
                newArg.As <ResourceArgument>().ConformsToType = resArg.ConformsToType;
            }
            return(newArg);
        }
        private static void PopulateValueFromArgument(ActivityArgument argument, ReportAnalyserColumn reportColumn)
        {
            if (argument.Is <StringArgument>())
            {
                StringArgument stringArgument = argument.As <StringArgument>();
                reportColumn.Value = stringArgument.StringParameterValue;
            }
            else if (argument.Is <IntegerArgument>())
            {
                IntegerArgument integerArgument = argument.As <IntegerArgument>();
                if (integerArgument.IntParameterValue != null)
                {
                    reportColumn.Value = integerArgument.IntParameterValue.ToString();
                }
            }
            else if (argument.Is <CurrencyArgument>())
            {
                CurrencyArgument currencyArgument = argument.As <CurrencyArgument>();
                if (currencyArgument.DecimalParameterValue != null)
                {
                    reportColumn.Value = currencyArgument.DecimalParameterValue.ToString();
                }
            }
            else if (argument.Is <DecimalArgument>())
            {
                DecimalArgument decimalArgument = argument.As <DecimalArgument>();
                if (decimalArgument.DecimalParameterValue != null)
                {
                    reportColumn.Value = decimalArgument.DecimalParameterValue.ToString();
                }
            }
            else if (argument.Is <DateArgument>())
            {
                DateArgument dateArgument = argument.As <DateArgument>();

                if (dateArgument.DateParameterValue != null)
                {
                    //convert the date value to YYYY-MM-DD format
                    DateTime dateValue = (DateTime)dateArgument.DateParameterValue;
                    reportColumn.Value = dateValue.ToString("yyyy-MM-dd");
                }
            }
            else if (argument.Is <TimeArgument>())
            {
                TimeArgument timeArgument = argument.As <TimeArgument>();
                if (timeArgument.TimeParameterValue != null)
                {
                    //convert the time value to YYYY-MM-DDTHH:mm:ssZ format
                    DateTime timeValue = (DateTime)timeArgument.TimeParameterValue;
                    reportColumn.Value = timeValue.ToString("yyyy-MM-ddTHH:mm:ssZ");
                }
            }
            else if (argument.Is <DateTimeArgument>())
            {
                DateTimeArgument dateTimeArgument = argument.As <DateTimeArgument>();
                if (dateTimeArgument.DateTimeParameterValue != null)
                {
                    //convert the datetime value to YYYY-MM-DDTHH:mm:ssZ format
                    DateTime dateTimeValue = (DateTime)dateTimeArgument.DateTimeParameterValue;
                    reportColumn.Value = dateTimeValue.ToString("yyyy-MM-ddTHH:mm:ssZ");
                }
            }
            else if (argument.Is <GuidArgument>())
            {
                GuidArgument guidArgument = argument.As <GuidArgument>();
                if (guidArgument.GuidParameterValue != null)
                {
                    reportColumn.Value = guidArgument.GuidParameterValue.ToString();
                }
            }
            else if (argument.Is <BoolArgument>())
            {
                BoolArgument boolArgument = argument.As <BoolArgument>();
                if (boolArgument.BoolParameterValue != null)
                {
                    reportColumn.Value = boolArgument.BoolParameterValue.ToString();
                }
            }
            else if (argument.Is <TypedArgument>())
            {
                TypedArgument typedArgument = argument.As <TypedArgument>();
                EntityType    type          = Entity.Get <EntityType>(typedArgument.ConformsToType);
                if (type.IsOfType.FirstOrDefault(t => t.Alias == "core:enumType") != null)
                {
                    // A choice field
                    reportColumn.Type = new ChoiceRelationshipType();
                }
                else
                {
                    // Is a related resource
                    reportColumn.Type = new InlineRelationshipType();
                }
                ResourceListArgument rla = argument.As <ResourceListArgument>();
                if (rla.ResourceListParameterValues != null && rla.ResourceListParameterValues.Count > 0)
                {
                    Dictionary <long, string> values = new Dictionary <long, string>();
                    foreach (Resource resourceListParameterValue in rla.ResourceListParameterValues)
                    {
                        values[resourceListParameterValue.Id] = resourceListParameterValue.Name;
                    }
                    reportColumn.Values = values;
                }
            }
        }
        /// <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);
        }
Exemple #6
0
        public static ActivityArgument ArgumentForConditionType(ActivityArgument reportColumnExpressionType, string value)
        {
            IEntity result;

            if (reportColumnExpressionType.Is <StringArgument>())
            {
                result = new StringArgument {
                    StringParameterValue = value
                };
            }
            else if (reportColumnExpressionType.Is <IntegerArgument>())
            {
                int intValue;
                result = !int.TryParse(value, out intValue) ? new IntegerArgument() : new IntegerArgument {
                    IntParameterValue = intValue
                };
            }
            else if (reportColumnExpressionType.Is <CurrencyArgument>())
            {
                decimal currencyValue;
                result = !decimal.TryParse(value, out currencyValue) ? new CurrencyArgument() : new CurrencyArgument {
                    DecimalParameterValue = currencyValue
                };
            }
            else if (reportColumnExpressionType.Is <DecimalArgument>())
            {
                decimal decimalValue;
                result = !decimal.TryParse(value, out decimalValue) ? new DecimalArgument() : new DecimalArgument {
                    DecimalParameterValue = decimalValue
                };
            }
            else if (reportColumnExpressionType.Is <DateArgument>())
            {
                DateTime dateValue;
                result = !DateTime.TryParse(value, out dateValue) ? new DateArgument() : new DateArgument {
                    DateParameterValue = dateValue
                };
            }
            else if (reportColumnExpressionType.Is <TimeArgument>())
            {
                DateTime timeValue;
                result = !DateTime.TryParse(value, out timeValue) ? new TimeArgument() : new TimeArgument {
                    TimeParameterValue = timeValue
                };
            }
            else if (reportColumnExpressionType.Is <DateTimeArgument>())
            {
                DateTime dateTimeValue;
                result = !DateTime.TryParse(value, out dateTimeValue) ? new DateTimeArgument() : new DateTimeArgument {
                    DateTimeParameterValue = dateTimeValue
                };
            }
            else if (reportColumnExpressionType.Is <GuidArgument>())
            {
                Guid guidValue;
                result = !Guid.TryParse(value, out guidValue) ? new GuidArgument() : new GuidArgument {
                    GuidParameterValue = guidValue
                };
            }
            else if (reportColumnExpressionType.Is <BoolArgument>())
            {
                bool boolValue;
                result = !bool.TryParse(value, out boolValue) ? new BoolArgument() : new BoolArgument {
                    BoolParameterValue = boolValue
                };
            }
            else if (reportColumnExpressionType.Is <ResourceArgument>())
            {
                // Convert the value to an entityId
                TypedArgument tResult = reportColumnExpressionType.As <TypedArgument>();
                long          entityId;
                result = new ResourceArgument
                {
                    ResourceParameterValue = long.TryParse(value, out entityId) ? Entity.Get(entityId).As <Resource>() : new Resource(),
                    ConformsToType         = tResult.ConformsToType
                };
            }
            else if (reportColumnExpressionType.Is <ResourceListArgument>())
            {
                TypedArgument tResult = reportColumnExpressionType.As <TypedArgument>();
                long          entityId;
                result = new ResourceListArgument
                {
                    ResourceListParameterValues = new EntityCollection <Resource>
                    {
                        long.TryParse(value, out entityId) ? Entity.Get(entityId).As <Resource>() : new Resource()
                    },
                    ConformsToType = tResult.ConformsToType
                };
            }
            else
            {
                throw new Exception("Unhandled expression result type");
            }

            // Caller must save
            return(result.As <ActivityArgument>());
        }
Exemple #7
0
        /// <summary>
        /// Typeds the value from entity.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <returns>List{TypedValue}.</returns>
        /// <exception cref="System.Exception">Unhandled expression result type</exception>
        public static List <TypedValue> TypedValueFromEntity(ActivityArgument argument)
        {
            List <TypedValue> typedValues = new List <TypedValue>();
            TypedValue        typedValue  = new TypedValue();

            if (argument == null)
            {
                typedValue.Type = DatabaseType.UnknownType;
                typedValues.Add(typedValue);
            }
            else if (argument.Is <StringArgument>())
            {
                typedValue.Type = DatabaseType.StringType;
                StringArgument stringArgument = argument.As <StringArgument>();
                if (stringArgument.StringParameterValue != null)
                {
                    typedValue.Value = stringArgument.StringParameterValue;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <IntegerArgument>())
            {
                typedValue.Type = DatabaseType.Int32Type;
                IntegerArgument integerArgument = argument.As <IntegerArgument>();
                if (integerArgument.IntParameterValue.HasValue)
                {
                    typedValue.Value = integerArgument.IntParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <CurrencyArgument>())
            {
                typedValue.Type = DatabaseType.CurrencyType;
                CurrencyArgument currencyArgument = argument.As <CurrencyArgument>();
                if (currencyArgument.DecimalParameterValue.HasValue)
                {
                    typedValue.Value = currencyArgument.DecimalParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <DecimalArgument>())
            {
                typedValue.Type = DatabaseType.DecimalType;
                DecimalArgument decimalArgument = argument.As <DecimalArgument>();
                if (decimalArgument.DecimalParameterValue.HasValue)
                {
                    typedValue.Value = decimalArgument.DecimalParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <DateArgument>())
            {
                typedValue.Type = DatabaseType.DateType;
                DateArgument dateArgument = argument.As <DateArgument>();
                if (dateArgument.DateParameterValue.HasValue)
                {
                    typedValue.Value = dateArgument.DateParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <TimeArgument>())
            {
                typedValue.Type = DatabaseType.TimeType;
                TimeArgument timeArgument = argument.As <TimeArgument>();
                if (timeArgument.TimeParameterValue.HasValue)
                {
                    typedValue.Value = timeArgument.TimeParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <DateTimeArgument>())
            {
                typedValue.Type = DatabaseType.DateTimeType;
                DateTimeArgument dateTimeArgument = argument.As <DateTimeArgument>();
                if (dateTimeArgument.DateTimeParameterValue.HasValue)
                {
                    typedValue.Value = dateTimeArgument.DateTimeParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <GuidArgument>())
            {
                typedValue.Type = DatabaseType.GuidType;
                GuidArgument guidArgument = argument.As <GuidArgument>();
                if (guidArgument.GuidParameterValue.HasValue)
                {
                    typedValue.Value = guidArgument.GuidParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <BoolArgument>())
            {
                typedValue.Type = DatabaseType.BoolType;
                BoolArgument boolArgument = argument.As <BoolArgument>();
                if (boolArgument.BoolParameterValue.HasValue)
                {
                    typedValue.Value = boolArgument.BoolParameterValue.Value;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <ResourceArgument>())
            {
                TypedArgument typedArgument = argument.As <TypedArgument>();
                if (typedArgument != null && typedArgument.ConformsToType != null)
                {
                    // Interrogate to get it's base type
                    EntityType type     = Entity.Get <EntityType>(typedArgument.ConformsToType.Id);
                    EntityRef  enumType = new EntityRef("core", "enumValue");
                    if (type.GetAncestorsAndSelf().FirstOrDefault(a => a.Id == enumType.Id) != null)
                    {
                        typedValue.Type = DatabaseType.ChoiceRelationshipType;
                    }
                    else
                    {
                        typedValue.Type = DatabaseType.InlineRelationshipType;
                    }
                }

                ResourceArgument resourceArgument = argument.As <ResourceArgument>();
                if (resourceArgument.ResourceParameterValue != null)
                {
                    // Is this an enum type (or are any of it's base types an enum type??
                    var conformsToType = resourceArgument.ConformsToType;
                    typedValue.SourceEntityTypeId = conformsToType != null ? conformsToType.Id : 0;
                    typedValue.Value = resourceArgument.ResourceParameterValue.Id;
                }
                typedValues.Add(typedValue);
            }
            else if (argument.Is <ResourceListArgument>())
            {
                TypedArgument typedArgument = argument.As <TypedArgument>();
                if (typedArgument != null && typedArgument.ConformsToType != null)
                {
                    // Interrogate to get it's base type
                    EntityType type     = Entity.Get <EntityType>(typedArgument.ConformsToType.Id);
                    EntityRef  enumType = new EntityRef("core", "enumValue");
                    if (type.GetAncestorsAndSelf().FirstOrDefault(a => a.Id == enumType.Id) != null)
                    {
                        typedValue.Type = DatabaseType.ChoiceRelationshipType;
                    }
                    else
                    {
                        typedValue.Type = DatabaseType.InlineRelationshipType;
                    }
                }
                ResourceListArgument resourceList = argument.As <ResourceListArgument>();
                if (resourceList.ResourceListParameterValues == null || resourceList.ResourceListParameterValues.Count <= 0)
                {
                    typedValues.Add(typedValue);
                }
                else
                {
                    typedValues.AddRange(resourceList.ResourceListParameterValues.Select(parameterValue => new TypedValue
                    {
                        Type = typedValue.Type, SourceEntityTypeId = resourceList.ConformsToType.Id, Value = parameterValue.Id
                    }));
                }
            }
            else
            {
                // Throw as we cannot convert type:(
                throw new Exception("Unhandled expression result type");
            }

            return(typedValues);
        }
Exemple #8
0
        /// <summary>
        /// Given a argument holding a parameter, return the value
        /// </summary>
        /// <param name="argInst"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static object GetArgParameterValue(ActivityArgument arg)
        {
            var rla = arg.As <ResourceListArgument>();

            if (rla != null)
            {
                return(rla.ResourceListParameterValues);
            }

            var ra = arg.As <ResourceArgument>();

            if (ra != null)
            {
                return(ra.ResourceParameterValue);
            }

            var sa = arg.As <StringArgument>();

            if (sa != null)
            {
                return(sa.StringParameterValue);
            }

            var ba = arg.As <BoolArgument>();

            if (ba != null)
            {
                return(ba.BoolParameterValue);
            }

            var ia = arg.As <IntegerArgument>();

            if (ia != null)
            {
                return(ia.IntParameterValue);
            }

            var deca = arg.As <DecimalArgument>();

            if (deca != null)
            {
                return(deca.DecimalParameterValue);
            }

            var ca = arg.As <CurrencyArgument>();

            if (ca != null)
            {
                return(ca.DecimalParameterValue);
            }

            var dta = arg.As <DateTimeArgument>();

            if (dta != null)
            {
                return(dta.DateTimeParameterValue);
            }

            var da = arg.As <DateArgument>();

            if (da != null)
            {
                return(da.DateParameterValue);
            }

            var ta = arg.As <TimeArgument>();

            if (ta != null)
            {
                return(ta.TimeParameterValue);
            }

            var ga = arg.As <GuidArgument>();

            if (ga != null)
            {
                return(ga.GuidParameterValue);
            }

            throw new ArgumentException("Attempted to extract a value from an ActivityArgument for storage of a type that can not be stored: ", arg.IsOfType.First().Name);
        }