public override int Visit(TaskState taskState) { _currentContext.AssertIsValidInputPath(taskState.InputPath); _currentContext.AssertIsValidOutputPath(taskState.OutputPath); _currentContext.AssertIsValidResultPath(taskState.ResultPath); _currentContext.AssertIsPositiveIfPresent(taskState.TimeoutSeconds, PropertyNames.TIMEOUT_SECONDS); _currentContext.AssertIsPositiveIfPresent(taskState.HeartbeatSeconds, PropertyNames.HEARTBEAT_SECONDS); if (taskState.HeartbeatSeconds != null) { if (taskState.HeartbeatSeconds >= taskState.TimeoutSeconds) { _problemReporter.Report(new Problem(_currentContext, $"{PropertyNames.HEARTBEAT_SECONDS} must be smaller than {PropertyNames.TIMEOUT_SECONDS}")); } } if (taskState.HeartbeatSeconds.HasValue && !string.IsNullOrEmpty(taskState.HeartbeatSecondsPath)) { _problemReporter.Report(new Problem(_currentContext, "TaskState cannot contain HeartbeatSecondsPath and HeartbeatSecond property")); } if (taskState.TimeoutSeconds.HasValue && !string.IsNullOrEmpty(taskState.TimeoutSecondPath)) { _problemReporter.Report(new Problem(_currentContext, "TaskState cannot contain TimeoutSecondPath and TimeoutSeconds property")); } _currentContext.AssertStringNotEmpty(taskState.Resource, PropertyNames.RESOURCE); ValidateRetriers(taskState.Retriers); ValidateCatchers(taskState.Catchers); ValidateTransition(taskState.Transition); return(0); }
/** * Asserts the value is not null, reporting to {@link ProblemReporter} with this context if it is. * * @param propertyValue Value to Assert on. * @param propertyName Name of property. */ public void AssertNotNull(object propertyValue, string propertyName) { if (propertyValue == null) { ProblemReporter.Report(new Problem(this, $"{propertyName} is a required property.")); } }
/** * Asserts that the string represents a valid JsonPath expression. * * @param path Path expression to validate. * @param propertyName Name of property. */ public void AssertIsValidJsonPath(string path, string propertyName) { if (path == null) { return; } if (string.IsNullOrEmpty(path)) { ProblemReporter.Report(new Problem(this, $"{propertyName} cannot be empty")); } // Newtonsoft.Json seems to allow JsonPath to not start with $ if (path[0] != '$') { ProblemReporter.Report(new Problem(this, $"{propertyName} with value '{path}' is not a valid JsonPath. Must Start with '$'")); } try { var token = JToken.Parse("{}").SelectTokens(path); } catch (Exception e) { ProblemReporter.Report(new Problem(this, $"{propertyName} with value '{path}' is not a valid JsonPath. {e.Message}")); } }
/** * Asserts the integer is either null or non-negative, reporting to {@link ProblemReporter} with this context if it is. * * @param integer Value to Assert on. * @param propertyName Name of property. */ public void AssertIsNotNegativeIfPresent(int?integer, string propertyName) { if (integer.HasValue && integer < 0) { ProblemReporter.Report(new Problem(this, $"{propertyName} must be non negative")); } }
/** * Asserts the string is not null and not empty, reporting to {@link ProblemReporter} with this context if it is. * * @param propertyValue Value to Assert on. * @param propertyName Name of property. */ public void AssertStringNotEmpty(string propertyValue, string propertyName) { if (string.IsNullOrEmpty(propertyValue)) { ProblemReporter.Report(new Problem(this, $"{propertyName} is a required property.")); } }
/** * Asserts the map is not null and not empty, reporting to {@link ProblemReporter} with this context if it is. * * @param map Map to Assert on. * @param propertyName Name of property. */ public void AssertNotEmpty(IDictionary map, string propertyName) { if (map == null || map.Count == 0) { ProblemReporter.Report(new Problem(this, $"{propertyName} requires one or more entries")); } }
/** * Asserts the collection is not null and not empty, reporting to {@link ProblemReporter} with this context if it is. * * @param collection Collection to Assert on. * @param propertyName Name of property. */ public void AssertNotEmpty(IEnumerable collection, string propertyName) { if (!collection.GetEnumerator().MoveNext()) { ProblemReporter.Report(new Problem(this, $"{propertyName} requires one or more items")); } }
/** * Asserts that the string represents a valid reference path expression. * * @param path Path expression to validate. * @param propertyName Name of property. */ public void AssertIsValidReferencePath(string path, string propertyName) { if (path == null) { return; } if (string.IsNullOrEmpty(path)) { ProblemReporter.Report(new Problem(this, $"{propertyName} cannot be empty")); } try { var r = ReferencePath.Parse(path); } catch (InvalidReferencePathException e) { ProblemReporter.Report(new Problem(this, $"{propertyName} with value '{path}' is not a valid ReferencePath. {e.Message}")); } }