Exemplo n.º 1
0
        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);
        }
Exemplo n.º 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.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update any arguments on the workflow with the resolved expressions
        /// </summary>
        private void UpdateWorkflowArguments(IRunState context, Dictionary <WfExpression, object> resolvedExpressions)
        {
            foreach (var kvp in resolvedExpressions)
            {
                var expression = kvp.Key;

                ActivityArgument arg = context.Metadata.GetArgumentPopulatedByExpression(expression);

                context.SetArgValue(arg, kvp.Value);
            }
        }
Exemplo n.º 4
0
        private ExprType GetExpressionType(ActivityArgument arg)
        {
            ExprType result;

            if (!_expressionArgumentTypeCache.TryGetValue(arg.Id, out result))
            {
                throw new ArgumentException("Tried to get an expression type for an uncached expression.");
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a new activity argument describing the argument type based on the column expression type and condition.
        /// </summary>
        /// <param name="reportColumnExpressionType">Type of the report column expression.</param>
        /// <param name="conditionType">Type of the condition.</param>
        /// <returns>ActivityArgument.</returns>
        public static ActivityArgument ArgumentForConditionType(ActivityArgument reportColumnExpressionType, ConditionType conditionType)
        {
            switch (conditionType)
            {
            case ConditionType.Equal:
            case ConditionType.NotEqual:
            case ConditionType.Contains:
            case ConditionType.StartsWith:
            case ConditionType.EndsWith:
                if (reportColumnExpressionType.Is <ResourceArgument>() || reportColumnExpressionType.Is <ResourceListArgument>())
                {
                    return(new StringArgument().As <ActivityArgument>());
                }
                return(reportColumnExpressionType);

            case ConditionType.LastNDays:
            case ConditionType.LastNDaysTillNow:
            case ConditionType.NextNDaysFromNow:
            case ConditionType.NextNDays:
            case ConditionType.LastNWeeks:
            case ConditionType.NextNWeeks:
            case ConditionType.LastNMonths:
            case ConditionType.NextNMonths:
            case ConditionType.LastNQuarters:
            case ConditionType.NextNQuarters:
            case ConditionType.LastNYears:
            case ConditionType.NextNYears:
            case ConditionType.LastNFinancialYears:
            case ConditionType.NextNFinancialYears:
                return(new IntegerArgument().As <ActivityArgument>());

            case ConditionType.DateEquals:
                return(new DateArgument().As <ActivityArgument>());

            case ConditionType.FullTextSearch:
                return(new StringArgument().As <ActivityArgument>());

            case ConditionType.AnyOf:
            case ConditionType.AnyExcept:
            case ConditionType.CurrentUser:
                if (reportColumnExpressionType.Is <ResourceArgument>() || reportColumnExpressionType.Is <ResourceListArgument>())
                {
                    return(reportColumnExpressionType);
                }
                return(new StringArgument().As <ActivityArgument>());

            case ConditionType.Unspecified:
                return(new StringArgument().As <ActivityArgument>());

            default:
                return(new StringArgument().As <ActivityArgument>());
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a variable to be used within a windows activity based upon a model variable.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public static Variable CreateVariable(ActivityArgument argument)
        {
            Variable result;

            var argumentTypes = argument.IsOfType.Select(t => t.Id);

            // This is ugly, but it works
            if (argumentTypes.Contains(StringArgument.StringArgument_Type.Id))
            {
                result = new Variable <string>();
            }
            else
            if (argumentTypes.Contains(IntegerArgument.IntegerArgument_Type.Id))
            {
                result = new Variable <int>();
            }
            else
            if (argumentTypes.Contains(BoolArgument.BoolArgument_Type.Id))
            {
                result = new Variable <bool>();
            }
            else
            if (argumentTypes.Contains(DecimalArgument.DecimalArgument_Type.Id))
            {
                result = new Variable <decimal>();
            }
            else
            if (argumentTypes.Contains(CurrencyArgument.CurrencyArgument_Type.Id))
            {
                result = new Variable <decimal>();
            }
            else
            if (argumentTypes.Contains(ResourceArgument.ResourceArgument_Type.Id))
            {
                result = new Variable <EntityRef>();
            }
            else
            if (argumentTypes.Contains(ObjectArgument.ObjectArgument_Type.Id))
            {
                result = new Variable <object>();
            }
            else
            {
                throw new ArgumentException(string.Format("Unsupported result type "));
            }

            result.Name = argument.Name;

            //TODO: Add in default values

            return(result);
        }
Exemplo n.º 7
0
        private static ReportCondition ReportConditionFromRule(ReportConditionalFormatRule rule, ReportColumn column)
        {
            ReportCondition reportCondition = new ReportCondition();

            if (rule.Operator.HasValue && rule.Operator != ConditionType.Unspecified)
            {
                string alias = "oper" + rule.Operator.ToString();
                reportCondition.Operator = Entity.Get <OperatorEnum>(new EntityRef(alias));
            }

            Parameter parameter = reportCondition.ConditionParameter != null?reportCondition.ConditionParameter.AsWritable <Parameter>() : new Parameter();

            // Clear the old parameter
            if (parameter.ParamTypeAndDefault != null)
            {
                parameter.ParamTypeAndDefault.AsWritable().Delete();
            }
            // Force entity resource list for argument if we have entities
            ActivityArgument activityArgument = null;

            if (rule.Values != null && rule.Values.Count > 0)
            {
                ResourceListArgument resourceList = new ResourceListArgument();
                foreach (KeyValuePair <long, string> valuePair in rule.Values)
                {
                    Resource resource = Entity.Get <Resource>(valuePair.Key);
                    if (resource != null)
                    {
                        resourceList.ResourceListParameterValues.Add(resource);
                    }
                }
                TypedArgument argumentType = column.ColumnExpression.ReportExpressionResultType.As <TypedArgument>();
                resourceList.ConformsToType = argumentType.ConformsToType;
                activityArgument            = resourceList.As <ActivityArgument>();
                activityArgument.Save();
            }
            else if (rule.Operator.HasValue)
            {
                int operatorCount = ConditionTypeHelper.GetArgumentCount(rule.Operator.Value);
                if (operatorCount > 0)
                {
                    activityArgument = ReportConditionHelper.ArgumentForConditionType(column.ColumnExpression.ReportExpressionResultType, rule.Operator.Value, rule.Value);
                    activityArgument.Save();
                }
            }
            parameter.ParamTypeAndDefault = activityArgument;
            parameter.Save();
            reportCondition.ConditionParameter = parameter;
            return(reportCondition);
        }
Exemplo n.º 8
0
        public WfExpression GetPopulatedBy(WfActivity activity, ActivityArgument argument)
        {
            WfExpression result;
            var          key = new Tuple <long, long>(activity.Id, argument.Id);

            if (_populatedByCache.TryGetValue(key, out result))
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Add an expression parameter, return the parameters substitution name
        /// </summary>
        /// <param name="wf"></param>
        /// <param name="from"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public static string CreateArgumentInstance(Workflow wf, WfActivity from, ActivityArgument argument)
        {
            var uniqueName     = GeneratetUniqueNameForExpressionParameter(wf, from, argument);
            var sourceInstance = new WfArgumentInstance {
                Name = uniqueName, ArgumentInstanceActivity = @from, ArgumentInstanceArgument = argument
            };

            if (@from.IsReadOnly)
            {
                @from = @from.AsWritable <WfActivity>();
            }
            @from.ArgumentInstanceFromActivity.Add(sourceInstance);
            wf.ExpressionParameters.Add(sourceInstance);

            return(uniqueName);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public WfArgumentInstance GetArgInstance(ActivityArgument targetArg, WfActivity activity)
        {
            WfArgumentInstance targetArgInst = null;
            var key = new Tuple <long, long>(activity.Id, targetArg.Id);

            if (_argInstCache.TryGetValue(key, out targetArgInst))
            {
                return(targetArgInst);
            }

            targetArgInst = targetArg.GetArgInstance(activity);

            _argInstCache.Add(key, targetArgInst);

            return(targetArgInst);
        }
Exemplo n.º 12
0
        public static WfArgumentInstance GetArgInstance(this ActivityArgument targetArg, WfActivity activity)
        {
            WfArgumentInstance targetArgInst = null;
            var key = new Tuple <long, long>(activity.Id, targetArg.Id);


            targetArgInst =
                activity.ArgumentInstanceFromActivity.First(ai => ai.ArgumentInstanceArgument.Id == targetArg.Id);

            //var targetArgInst =
            //    targetArg.ArgumentInstanceFromArgument.First(ai => ai.ArgumentInstanceActivity.Id == activity.Id);        // this is probably less efficient



            return(targetArgInst);
        }
 /// <summary>
 /// Defaults the type of the operator for.
 /// </summary>
 /// <param name="dataType">Type of the data.</param>
 /// <returns>ConditionType.</returns>
 private static Structured.ConditionType DefaultOperatorForType(ActivityArgument dataType)
 {
     Structured.ConditionType conditionType = Structured.ConditionType.Contains;
     if (dataType.Is <BoolArgument>())
     {
         conditionType = Structured.ConditionType.Unspecified;
     }
     else if (dataType.Is <DateArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <DateTimeArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <DecimalArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <IntegerArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <CurrencyArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <StringArgument>())
     {
         conditionType = Structured.ConditionType.Contains;
     }
     else if (dataType.Is <TimeArgument>())
     {
         conditionType = Structured.ConditionType.GreaterThan;
     }
     else if (dataType.Is <TypedArgument>())
     {
         conditionType = Structured.ConditionType.AnyOf;
     }
     return(conditionType);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Get the type of an argument.
        /// </summary>
        public static EntityType GetArgumentType(this ActivityArgument argument)
        {
            var argumentType = new List <EntityType>
            {
                StringArgument.StringArgument_Type,
                IntegerArgument.IntegerArgument_Type,
                BoolArgument.BoolArgument_Type,
                DecimalArgument.DecimalArgument_Type,
                CurrencyArgument.CurrencyArgument_Type,
                ResourceArgument.ResourceArgument_Type,
                DateTimeArgument.DateTimeArgument_Type,
                DateArgument.DateArgument_Type,
                TimeArgument.TimeArgument_Type,
                ObjectArgument.ObjectArgument_Type,
                ResourceListArgument.ResourceListArgument_Type,
                GuidArgument.GuidArgument_Type
            };


            EntityType result = null;

            var resultTypes = argument.IsOfType.Intersect(argumentType, new EntityIdComparer()).ToList();

            if (resultTypes.Count == 0)
            {
                throw new ArgumentException("Was asked to evaluate an expression with an argument that can not be evaluated. This should never occur.");
            }

            if (resultTypes.Count > 1)
            {
                throw new ArgumentException("Was asked to evaluate and expression with more than one argument type. This should never occur.");
            }

            result = resultTypes[0];

            return(result);
        }
        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);
        }
        /// <summary>
        /// Analysers the column for condition.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="reportCondition">The report condition.</param>
        /// <returns>
        /// ReportAnalyserColumn.
        /// </returns>
        internal static ReportAnalyserColumn AnalyserColumnForCondition(Report report, ReportCondition reportCondition)
        {
            if (reportCondition.ConditionIsHidden ?? false)
            {
                // Do not include analyser conditions when they are hidden
                return(null);
            }
            ReportAnalyserColumn reportAnalyserColumn = new ReportAnalyserColumn
            {
                Title             = reportCondition.Name,
                Ordinal           = reportCondition.ConditionDisplayOrder ?? 0,
                IsConditionLocked = reportCondition.ConditionIsLocked ?? false
            };

            if (reportCondition.Operator != null && reportCondition.Operator.ToString().Length > 4)
            {
                string[] conditionOperatorParts = reportCondition.Operator.Alias.Split(':');
                string   operatorString         = conditionOperatorParts.Length == 2 ? conditionOperatorParts[1].Substring(4) : conditionOperatorParts[0].Substring(4);
                Structured.ConditionType conditionType;
                reportAnalyserColumn.Operator = Enum.TryParse(operatorString, true, out conditionType) ? conditionType : Structured.ConditionType.Unspecified;
            }
            else
            {
                reportAnalyserColumn.Operator = Structured.ConditionType.Unspecified;
            }
            if (reportCondition.ColumnForCondition != null)
            {
                reportAnalyserColumn.ReportColumnId = reportCondition.ColumnForCondition.Id;
            }

            if (reportCondition.ConditionExpression == null)
            {
                return(null);
            }

            // Get the argument
            ActivityArgument reportExpressionResultType = reportCondition.ConditionExpression.Is <ColumnReferenceExpression>() ?
                                                          reportCondition.ConditionExpression.As <ColumnReferenceExpression>().ExpressionReferencesColumn.ColumnExpression.ReportExpressionResultType :
                                                          reportCondition.ConditionExpression.ReportExpressionResultType;
            // Process the expression result associated to this condition
            DatabaseType type;         // scalar type of analyser expression
            EntityType   resourceType; // resource type of analyser expression

            if (reportExpressionResultType == null || !PopulateTypeFromArgument(reportExpressionResultType, out type, out resourceType))
            {
                return(null);
            }
            reportAnalyserColumn.Type = type;
            if (resourceType != null)
            {
                reportAnalyserColumn.TypeId = resourceType.Id;
            }
            reportAnalyserColumn.DefaultOperator = DefaultOperatorForType(reportExpressionResultType);

            // Get the column expression for the analysable field. If this is a referenced column then use it's referenced column's expression.
            ReportExpression reportExpression = reportCondition.ConditionExpression.Is <ColumnReferenceExpression>() ?
                                                reportCondition.ConditionExpression.As <ColumnReferenceExpression>().ExpressionReferencesColumn.ColumnExpression : reportCondition.ConditionExpression;

            // Track current user for a 'core:UserAccount' or any derivatives and 'core:Person' or any derivatives and if the source node
            // is one of these and the report expression's field type is 'core:name' then fudge the analyser type to be 'UserString' which includes all
            // string analyser operator definitions in addition to the 'Current User' operator.
            PopulateAnalyserTypeForColumn(report, resourceType, reportExpression, reportAnalyserColumn);

            // Process any values associated to this condition.
            if (reportCondition.ConditionParameter != null && reportCondition.ConditionParameter.ParamTypeAndDefault != null)
            {
                ActivityArgument activityArgument = reportCondition.ConditionParameter.ParamTypeAndDefault;
                PopulateValueFromArgument(activityArgument, reportAnalyserColumn);
            }

            // resource picker for condition parameter
            if (reportCondition.ConditionParameterPicker != null)
            {
                reportAnalyserColumn.ConditionParameterPickerId = reportCondition.ConditionParameterPicker.Id;
            }

            return(reportAnalyserColumn);
        }
Exemplo n.º 18
0
 public override void SetArgValue(WfActivity activity, ActivityArgument targetArg, object value)
 {
     _storage[GetKey(activity, targetArg)] = value;
 }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
 public override T GetArgValue <T>(ActivityArgument targetArg)
 {
     return((T)_storage[GetKey(null, targetArg)]);
 }
Exemplo n.º 21
0
 public override void SetArgValue(ActivityArgument targetArg, object value)
 {
     _storage[GetKey(null, targetArg)] = value;
 }
Exemplo n.º 22
0
 private Tuple <long, long, string> GetKey(WfActivity activity, ActivityArgument targetArg)
 {
     return(new Tuple <long, long, string>(activity != null ? activity.Id : 0, targetArg.Id, targetArg.Name));
 }
Exemplo n.º 23
0
 public override T GetArgValue <T>(WfActivity activity, ActivityArgument targetArg)
 {
     return((T)_storage[GetKey(activity, targetArg)]);
 }
Exemplo n.º 24
0
 public abstract T GetArgValue <T>(ActivityArgument targetArg);
Exemplo n.º 25
0
 public abstract void SetArgValue(ActivityArgument targetArg, object value);
Exemplo n.º 26
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>());
        }
Exemplo n.º 27
0
        public static Workflow AddUpdateExpressionToArgument(this Workflow wf, WfActivity activity, ActivityArgument arg, string expressionString, bool isTemplate)
        {
            if (isTemplate)
            {
                expressionString = ConvertTemplateToExpressionString(expressionString);
            }

            if (expressionString == null)
            {
                throw new ArgumentNullException("expressionString");
            }

            var exp = activity.ExpressionMap.FirstOrDefault(x => x.ArgumentToPopulate?.Id == arg.Id);

            if (exp == null)
            {
                var newExp = new WfExpression()
                {
                    ExpressionString     = expressionString,
                    ArgumentToPopulate   = arg,
                    ExpressionInActivity = activity,
                    IsTemplateString     = false
                };

                activity.ExpressionMap.Add(newExp.As <WfExpression>());
            }
            else
            {
                var wrExp = exp.AsWritable <WfExpression>();
                wrExp.ExpressionString = expressionString;
                wrExp.Save();
            }

            return(wf);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Returns a new activity argument describing the argument type based on the column expression type and condition.
        /// Also populates the value for the argument prior to returning.
        /// </summary>
        /// <param name="reportColumnExpressionType">Type of the report column expression.</param>
        /// <param name="conditionType">Type of the condition.</param>
        /// <param name="value">The value.</param>
        /// <returns>ActivityArgument.</returns>
        public static ActivityArgument ArgumentForConditionType(ActivityArgument reportColumnExpressionType, ConditionType conditionType, string value)
        {
            ActivityArgument targetArgumentType = ArgumentForConditionType(reportColumnExpressionType, conditionType);

            return(ArgumentForConditionType(targetArgumentType, value));
        }
Exemplo n.º 29
0
        public static Workflow AddUpdateEntityExpression(this Workflow wf, WfActivity activity, ActivityArgument arg, EntityRef entityRef)
        {
            var exp = activity.ExpressionMap.FirstOrDefault(x => x.ArgumentToPopulate?.Id == arg.Id);
            var r   = Entity.Get(entityRef).As <Resource>();

            var expName = r.Id.ToString();

            if (!string.IsNullOrEmpty(r.Name))
            {
                expName = r.Name;
            }

            if (exp == null)
            {
                exp = new WfExpression {
                    ArgumentToPopulate = arg, ExpressionInActivity = activity, ExpressionString = string.Format("[{0}]", expName)
                };
                exp.WfExpressionKnownEntities.Add(new NamedReference {
                    Name = expName, ReferencedEntity = r
                });
                activity.ExpressionMap.Add(exp);
            }
            else
            {
                var wrExp = exp.AsWritable <WfExpression>();
                wrExp.ExpressionString = string.Format("[{0}]", expName);
                wrExp.WfExpressionKnownEntities.Clear();
                wrExp.WfExpressionKnownEntities.Add(new NamedReference {
                    Name = expName, ReferencedEntity = r
                });
                wrExp.Save();
            }

            return(wf);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Update the provided run with the cached values in the runstate
        /// </summary>
        /// <param name="writableRun"></param>
        public void SyncToRun(WorkflowRun writableRun)
        {
            using (Profiler.Measure("RunStateBase.SyncToRun"))
            {
                writableRun.WorkflowRunExitPoint = ExitPointId != null?Entity.Get <ExitPoint>(ExitPointId) : null;

                writableRun.HasTimeout      = HasTimeout;
                writableRun.PendingActivity = PendingActivity;
                writableRun.RunStepCounter  = writableRun.RunStepCounter.HasValue
                    ? writableRun.RunStepCounter.Value + StepsTakenInSession
                    : StepsTakenInSession;
                writableRun.TotalTimeMs            = (writableRun.TotalTimeMs.HasValue ? writableRun.TotalTimeMs.Value : 0) + (int)TimeTakenInSession.ElapsedMilliseconds;
                writableRun.WorkflowRunStatus_Enum = RunStatus;
                writableRun.RunCompletedAt         = CompletedAt;

                StepsTakenInSession = 0;
                TimeTakenInSession.Reset();

                var stateInfo  = writableRun.StateInfo;
                var deleteList = stateInfo.Select(e => e.Id).ToList();

                stateInfo.Clear();

                Entity.Delete(deleteList);

                // write a message to the log
                var sb = new StringBuilder();

                sb.AppendLine("Saving state to workflow run. Values: ");

                foreach (var cacheValue in GetArgValues())
                {
                    WfActivity       activity = cacheValue.Item1;
                    ActivityArgument arg      = cacheValue.Item2;
                    object           value    = cacheValue.Item3;

                    ActivityArgument valueArg = ActivityArgumentHelper.ConvertArgInstValue(activity, arg, value);

                    stateInfo.Add(new StateInfoEntry
                    {
                        Name = valueArg.Name,
                        StateInfoActivity = activity.Id != writableRun.WorkflowBeingRun.Id ? activity : null,
                        // Don't store the workflow as an activity
                        StateInfoArgument = arg,
                        StateInfoValue    = valueArg
                    });

                    sb.Append(valueArg.Name);
                    sb.Append(": \t");
                    if (value is IEntity)
                    {
                        sb.AppendFormat("Resource {0}\n", ((IEntity)value).Id);
                    }
                    else if (value == null)
                    {
                        sb.AppendLine("[Null]");
                    }
                    else
                    {
                        sb.AppendLine(value.ToString());
                    }
                }

                EventLog.Application.WriteInformation(sb.ToString());
            }
        }