private InArgument CreateNewValueDynamic(string value) { double dvalue = 0.0; if (Double.TryParse(value, out dvalue)) { return(DynamicLiteral.CreateArgument(dvalue)); } int ivalue = 0; if (Int32.TryParse(value, out ivalue)) { return(DynamicLiteral.CreateArgument(ivalue)); } bool bvalue = false; if (Boolean.TryParse(value, out bvalue)) { return(DynamicLiteral.CreateArgument(bvalue)); } return(DynamicStringLiteral.CreateArgument(value)); }
private static void BinaryOperationCreationCallback <T>(Activity activity, ModelProperty itemProperty) { InArgument <T> left = null, right = null; ModelItem modelItem = itemProperty != null ? itemProperty.Value : null; if (modelItem != null && modelItem.Properties[Constants.ExpressionPropertyName] != null) { ModelItem oldActivity = modelItem.Properties[Constants.ExpressionPropertyName].Value; if (oldActivity.Properties[Constants.LeftOperandPropertyName] != null && oldActivity.Properties[Constants.RightOperandPropertyName] != null) { left = oldActivity.Properties[Constants.LeftOperandPropertyName].ComputedValue as InArgument <T>; right = oldActivity.Properties[Constants.RightOperandPropertyName].ComputedValue as InArgument <T>; oldActivity.Properties[Constants.LeftOperandPropertyName].SetValue(null); oldActivity.Properties[Constants.RightOperandPropertyName].SetValue(null); } } dynamic binaryOperation = activity; if (left != null && right != null) { binaryOperation.Left = left; binaryOperation.Right = right; } else { if (modelItem != null) { var originalItem = modelItem.GetCurrentValue() as InArgument <T>; if (originalItem != null) { // Clear the Expression result as the operator will have the output result. // If the result is not clear, exception will throw in this case. if (originalItem.Expression != null) { originalItem.Expression.Result = null; } binaryOperation.Left = originalItem; } } // Assign default value if (typeof(T) == typeof(DynamicValue)) { // Specify default values of DynamicValue as it does not have proper default value. binaryOperation.Left = binaryOperation.Left ?? DynamicLiteral.CreateArgument(Constants.DefaultNumberValue); binaryOperation.Right = binaryOperation.Right ?? DynamicLiteral.CreateArgument(Constants.DefaultNumberValue); } else { binaryOperation.Left = binaryOperation.Left ?? new InArgument <T>(default(T)); binaryOperation.Right = binaryOperation.Right ?? new InArgument <T>(default(T)); } } }
/// <summary> /// Creates a new value. /// </summary> /// <typeparam name="T">The type of value.</typeparam> /// <returns>The new instance.</returns> protected object CreateNewValue <T>() { if (typeof(T) == typeof(DynamicValue)) { return(DynamicLiteral <int> .CreateArgument(0)); } else { T tvalue = default(T); return(new InArgument <T>(tvalue)); } }
private static void DynamicIfCreationCallback(Activity activity, ModelProperty itemProperty) { If ifActivity = activity as If; ifActivity.Condition = new InArgument <DynamicValue>( new Equal() { Left = DynamicLiteral.CreateArgument(Constants.DefaultNumberValue), Right = DynamicLiteral.CreateArgument(Constants.DefaultNumberValue) }); ifActivity.Then = new sas.Sequence(); ifActivity.Else = new sas.Sequence(); }
private static void DynamicNotOperationCreationCallback(Activity activity, ModelProperty itemProperty) { InArgument <DynamicValue> inArg = GetOldItemArgument <DynamicValue>(itemProperty); dynamic unaryOperation = activity; if (inArg != null) { unaryOperation.Operand = inArg; } else { unaryOperation.Operand = DynamicLiteral <bool> .CreateArgument(true);//so the default is 'if ... is not true' } }
void ModelItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { // If left-hand operand changed, check if it become a feature property having valid values, e.g. Domain Attribute if (e.PropertyName == IMConstants.LeftOperandPropertyName) { IEnumerable <DynamicValue> validValues = ModelItem.Properties[IMConstants.RightOperandPropertyName].Value.GetValidValues(); ModelProperty rightOperand = ModelItem.Properties[IMConstants.RightOperandPropertyName]; // if expression like "1 equals 1" becomes "status equals 1", the right-hand operand should be refresh. // if expression like "Status equals new" becomes "1 equals new", the right-hand operand should be refresh, too. if (validValues.Any()) { // TODO: refactor to remove redundant code. DynamicValue dv = validValues.First(); rightOperand.SetValue(DynamicLiteral.CreateArgument(dv.Value)); _hasValidValues = true; } else if (_hasValidValues) { rightOperand.SetValue(DynamicLiteral.CreateArgument(IMConstants.DefaultNumberValue)); _hasValidValues = false; } } }
public override object CreateNewInstance(SelectItem item) { object value = item.Value; return(new InArgument <DynamicValue>(DynamicLiteral.Create(value))); }