Beispiel #1
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.");
        }
Beispiel #2
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);
        }
Beispiel #3
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
            });
        }
Beispiel #4
0
        private void InitializeArguments(ExpressionCollection arguments)
        {
            _typedArguments = new TypedArgument[arguments.Count];
            CallableSignature methodSignature = GenericMethod.CallableType.GetSignature();
            int   count      = Math.Min(arguments.Count, methodSignature.Parameters.Length);
            IType formalType = null;

            for (int i = 0; i < count; i++)
            {
                formalType = methodSignature.Parameters[i].Type;
                if (GenericMethod.AcceptVarArgs && i == count - 1)
                {
                    formalType = formalType.ElementType;
                }
                _typedArguments[i] = new TypedArgument(arguments[i], formalType);
            }

            for (int i = count; i < arguments.Count; i++)
            {
                _typedArguments[i] = new TypedArgument(arguments[i], GenericMethod.AcceptVarArgs ? formalType : null);
            }
        }
        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);
        }
        private void InitializeArguments(ExpressionCollection arguments)
        {
            _typedArguments = new TypedArgument[arguments.Count];
            CallableSignature methodSignature = GenericMethod.CallableType.GetSignature();
            int count = Math.Min(arguments.Count, methodSignature.Parameters.Length);
            IType formalType = null;

            for (int i = 0; i < count; i++)
            {
                formalType = methodSignature.Parameters[i].Type;
                if (GenericMethod.AcceptVarArgs && i == count - 1)
                    formalType = formalType.ElementType;
                _typedArguments[i] = new TypedArgument(arguments[i], formalType);
            }

            for (int i = count; i < arguments.Count; i++)
            {
                _typedArguments[i] = new TypedArgument(arguments[i], GenericMethod.AcceptVarArgs ? formalType : null);
            }
        }
Beispiel #8
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>());
        }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// Method for creating typed values from DatabaseType.
        /// Caller must save.
        /// </summary>
        /// <param name="typedValue"></param>
        /// <param name="forceResourceLists"></param>
        /// <returns></returns>
        public static ActivityArgument CreateTypedValueEntity(TypedValue typedValue, bool forceResourceLists = false)
        {
            DatabaseType dbType = typedValue.Type;
            IEntity      result;

            if (dbType is UnknownType || dbType == null)
            {
                return(null);
            }
            if (dbType is StringType || dbType is XmlType)
            {
                result = new StringArgument {
                    StringParameterValue = (string)typedValue.Value
                };
            }
            else if (dbType is Int32Type) // includes autonumber
            {
                result = new IntegerArgument {
                    IntParameterValue = (int?)typedValue.Value
                };
            }
            else if (dbType is CurrencyType)
            {
                result = new CurrencyArgument {
                    DecimalParameterValue = (decimal?)typedValue.Value
                };
            }
            else if (dbType is DecimalType)
            {
                result = new DecimalArgument {
                    DecimalParameterValue = (decimal?)typedValue.Value
                };
            }
            else if (dbType is DateType)
            {
                result = new DateArgument {
                    DateParameterValue = (DateTime?)typedValue.Value
                };
            }
            else if (dbType is TimeType)
            {
                result = new TimeArgument {
                    TimeParameterValue = (DateTime?)typedValue.Value
                };
            }
            else if (dbType is DateTimeType)
            {
                result = new DateTimeArgument {
                    DateTimeParameterValue = (DateTime?)typedValue.Value
                };
            }
            else if (dbType is GuidType)
            {
                result = new GuidArgument {
                    GuidParameterValue = (Guid?)typedValue.Value
                };
            }
            else if (dbType is BoolType)
            {
                result = new BoolArgument {
                    BoolParameterValue = (bool?)typedValue.Value
                };
            }
            else if (dbType is ChoiceRelationshipType || dbType is InlineRelationshipType || dbType is IdentifierType)
            {
                // Hmm.. not sure if this is a good idea for identifier types..

                long targetId;
                if (typedValue.Value == null || !long.TryParse(typedValue.Value.ToString(), out targetId))
                {
                    targetId = 0;
                }

                IEntity target = targetId > 0 ? Entity.Get(targetId) : null;

                if (forceResourceLists)
                {
                    var resourceListArgument = new ResourceListArgument();
                    if (target != null)
                    {
                        resourceListArgument.ResourceListParameterValues.Add(target.As <Resource>());
                    }
                    result = resourceListArgument;
                }
                else
                {
                    var resourceArgument = new ResourceArgument();
                    if (target != null)
                    {
                        resourceArgument.ResourceParameterValue = target.As <Resource>();
                    }
                    result = resourceArgument;
                }

                TypedArgument tResult = result.As <TypedArgument>();
                if (typedValue.SourceEntityTypeId > 0)
                {
                    var targetType = Entity.Get <EntityType>(typedValue.SourceEntityTypeId);
                    tResult.ConformsToType = targetType;
                }
            }
            else
            {
                // IdentifierType
                // BinaryType
                // StructureLevelsType
                throw new Exception("Unhandled expression result type: " + dbType.GetType().Name);
            }

            // Caller must save
            return(result.As <ActivityArgument>());
        }