/**
  * 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 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 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"));
            }

            //TODO: Find how to validate JPath query
            // try
            // {
            //     if (!JsonPath.isPathDefinite(path))
            //     {
            //         problemReporter.Report(new Problem(this,
            //             string.Format("{0} with value '{0}' is not a definite reference path.",
            //                 propertyName, path)));
            //     }
            // }
            // catch (InvalidPathException e)
            // {
            //     problemReporter.Report(new Problem(this,
            //         string.Format("{0} with value '{0}' is not a valid JsonPath. {0}", propertyName, path,
            //             e.getMessage())));
            // }
        }
        /**
         * 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"));
            }

            //  JPath is an internal class of Newtonsoft... can't be used here
            //  JPath test = new JPath(path);
            //  TODO: Find how to validate JPath query
            // try
            // {
            //     JsonPath.compile(path);
            // }
            // catch (InvalidPathException e)
            // {
            //     problemReporter.Report(new Problem(this,
            //         string.Format("{0} with value '{1}' is not a valid JsonPath. {2}", propertyName, path,
            //             e.getMessage())));
            // }
        }
 /**
  * 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 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"));
     }
 }
Esempio n. 8
0
            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.TimeoutSeconds != null && taskState.HeartbeatSeconds != null)
                {
                    if (taskState.HeartbeatSeconds >= taskState.TimeoutSeconds)
                    {
                        _problemReporter.Report(new Problem(_currentContext, $"{PropertyNames.HEARTBEAT_SECONDS} must be smaller than {PropertyNames.TIMEOUT_SECONDS}"));
                    }
                }

                _currentContext.AssertStringNotEmpty(taskState.Resource, PropertyNames.RESOURCE);
                ValidateRetriers(taskState.Retriers);
                ValidateCatchers(taskState.Catchers);
                ValidateTransition(taskState.Transition);
                return(0);
            }