public override void Validate(string value) { base.Validate(value); int parsedValue; if (!Int32.TryParse(value, out parsedValue)) { throw new FormatException("Value cannot be parsed as an integer."); } if (AlwaysAllowZero && parsedValue == 0) { return; } if (MinValue != int.MinValue && parsedValue < MinValue) { throw new FormatException(String.Format("Value is too low ({0}); expected at least {1}.", parsedValue, MinValue)); } if (MaxValue != int.MaxValue && parsedValue > MaxValue) { throw new FormatException(String.Format("Value is too high ({0}); expected at most {1}.", parsedValue, MaxValue)); } if (MultipleOf != 0 && (parsedValue % MultipleOf != 0)) { throw new FormatException(String.Format("Value ({0}) is not a multiple of {1}.", parsedValue, MultipleOf)); } if (PowerOfTwo) { bool found = false; for (int i = 0; i < 31; i++) { if (parsedValue == (1 << i)) { found = true; break; } } if (!found && parsedValue != 0) { throw new FormatException(String.Format("Value ({0}) is not a power of two.", parsedValue)); } } if (ValidValues != null) { if (!ValidValues.Any(t => parsedValue == t)) { throw new FormatException(String.Format("Value ({0}) is not on the list of valid values.", parsedValue)); } } if (InvalidValues != null) { if (!InvalidValues.All(t => parsedValue != t)) { throw new FormatException(String.Format("Value ({0}) is on the list of invalid values.", parsedValue)); } } }
private PropertySetResult PopulateNumberPropertyLite() { if (ValidValues != null && ValidValues.Any()) { return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now number property. Property change action is currently invalid.")); } if (String.IsNullOrEmpty(PropertyValue)) { PropertyLiteValue = new PropertyLite() { PropertyTypeId = InstancePropertyTypeId, NumberValue = null }; } else { decimal value; if ( !Decimal.TryParse(PropertyValue, NumberStyles.Number, CultureInfo.InvariantCulture, out value)) { return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now number property. Property change action is currently invalid.")); } PropertyLiteValue = new PropertyLite() { PropertyTypeId = InstancePropertyTypeId, NumberValue = value }; } return(null); }
public override bool TryGetTokenFromInput(ITextCursor textCursor, out string token) { var match = false; token = null; if (ValidValues != null && ValidValues.Length > 0) { string matchText = null; var queryText = string.Empty; while (string.IsNullOrEmpty(matchText) && ValidValues.Any(v => v.Length >= queryText.Length)) { var tokenPeek = textCursor.Next(); if (string.IsNullOrWhiteSpace(tokenPeek)) { break; } queryText = textCursor.RightToLeftParsing ? $"{tokenPeek} {queryText}" : $"{queryText} {tokenPeek}"; matchText = TryGetMatchText(ValidValues, queryText.Trim()); } if (!string.IsNullOrEmpty(matchText)) { token = matchText; match = true; } } else { var queryText = textCursor.All(); if (!string.IsNullOrEmpty(queryText)) { token = queryText; match = true; } } return(match); }
protected virtual PropertySetResult PopulatePropertyLite(WorkflowPropertyType propertyType) { switch (propertyType?.PrimitiveType) { case PropertyPrimitiveType.Text: PropertyLiteValue = new PropertyLite() { PropertyTypeId = InstancePropertyTypeId, TextOrChoiceValue = PropertyValue }; break; case PropertyPrimitiveType.Number: return(PopulateNumberPropertyLite()); case PropertyPrimitiveType.Date: return(PopulateDatePropertyLite()); case PropertyPrimitiveType.Choice: PropertyLiteValue = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, }; if (!ValidValues.Any() && !propertyType.Validate.GetValueOrDefault(false)) { PropertyLiteValue.TextOrChoiceValue = PropertyValue; } else { PropertyLiteValue.ChoiceIds.AddRange(ValidValues); } break; case PropertyPrimitiveType.User: return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now user, but does not contain user and group change actions")); default: PropertyLiteValue = new PropertyLite() { PropertyTypeId = InstancePropertyTypeId }; break; } return(null); }
public override bool TryGetTokenFromContext(IRequestContext context, out string token) { var match = false; token = null; var variableName = Name; if (!string.IsNullOrWhiteSpace(ContextVariableName)) { variableName = ContextVariableName; } var objTokenValue = context.GetVariable(variableName); if (objTokenValue != null) { var tokenValue = (string)objTokenValue; if (ValidValues != null && ValidValues.Length > 0) { if ( ValidValues.Any( w => w.ToString().Equals(tokenValue.ToString(), StringComparison.OrdinalIgnoreCase))) { token = tokenValue; match = true; } } else { token = tokenValue; match = true; } } return(match); }
private PropertySetResult PopulateDatePropertyLite() { // was Choice property if (ValidValues != null && ValidValues.Any()) { return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now date property. Property change action is currently invalid.")); } // is null if (string.IsNullOrEmpty(PropertyValue)) { PropertyLiteValue = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, DateValue = null }; return(null); } DateTime date; try { date = PropertyHelper.ParseDateValue(PropertyValue, new TimeProvider()); } catch (Exception ex) { // invalid date format return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, $"Property type is now date property. Property change action is currently invalid. {ex.Message}")); } // valid date format PropertyLiteValue = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, DateValue = date }; return(null); }