Esempio n. 1
0
 public void Validate(ValidationResult result)
 {
     if (String.IsNullOrEmpty(HeaderName))
     {
         result.AddSystemError("Header Name is a Required Field.");
     }
     if (String.IsNullOrEmpty(Value))
     {
         result.AddSystemError("Header Name is a Required Field.");
     }
 }
Esempio n. 2
0
        public void Validate(ValidationResult result, Actions action)
        {
            try
            {
                if (Properties == null)
                {
                    Properties = new List <AttributeValue>();
                }

                if (PropertiesMetaData != null)
                {
                    foreach (var propertyMetaData in PropertiesMetaData)
                    {
                        var property = Properties.Where(prop => prop.Key == propertyMetaData.Key).FirstOrDefault();
                        if (property == null)
                        {
                            var prop = new AttributeValue()
                            {
                                AttributeType = propertyMetaData.FieldType,
                                Key           = propertyMetaData.Key,
                                Name          = propertyMetaData.Name,
                                Value         = String.IsNullOrEmpty(propertyMetaData.DefaultValue) ? null : propertyMetaData.DefaultValue,
                                LastUpdated   = DateTime.UtcNow.ToJSONString(),
                                LastUpdatedBy = LastUpdatedBy.Text
                            };

                            Properties.Add(prop);
                        }
                        else
                        {
                            if (property.Value == null)
                            {
                                property.Value = propertyMetaData.DefaultValue;
                            }

                            propertyMetaData.Validate(property.Value, result, action);
                        }
                    }
                }

                if (ParentDevice != null && string.IsNullOrEmpty(ParentDevice.Value))
                {
                    result.AddUserError("If parent device is set the parent device value must contain the Device Id");
                }
            }
            catch (Exception ex)
            {
                result.AddSystemError(ex.Message);
            }
        }
Esempio n. 3
0
        public ValidationResult ValidateSolution(Solution solution)
        {
            var result = new ValidationResult();

            try
            {
                if (solution.Listeners.Count == 0)
                {
                    result.Warnings.Add(Resources.DeploymentErrorCodes.NoListeners.ToErrorMessage());
                }
                if (solution.DeviceConfigurations.Count == 0)
                {
                    result.Warnings.Add(Resources.DeploymentErrorCodes.NoDeviceConfigs.ToErrorMessage());
                }

                foreach (var listner in solution.Listeners)
                {
                    if (listner.Value == null)
                    {
                        result.Errors.Add(Resources.DeploymentErrorCodes.CouldNotLoadListener.ToErrorMessage());
                    }
                    else
                    {
                        result.Concat(Validator.Validate(listner.Value));
                    }
                }

                foreach (var deviceConfigurations in solution.DeviceConfigurations)
                {
                    if (deviceConfigurations.Value == null)
                    {
                        result.Errors.Add(Resources.DeploymentErrorCodes.CouldNotLoadDeviceConfiguration.ToErrorMessage(deviceConfigurations.Text));
                    }
                    else
                    {
                        deviceConfigurations.Value.DeepValidation(result);
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddSystemError("UNHANDLED EXCEPTION:" + ex.Message);
            }

            return(result);
        }
Esempio n. 4
0
        public ValidationResult Validate(DeviceWorkflow workflow, ValidationResult result)
        {
            if (Validator.Validate(this).Successful)
            {
                result.Concat(ValidateNodeBase(workflow));
                if (Parameters.Select(param => param.Key).Distinct().Count() != Parameters.Count())
                {
                    result.Errors.Add(new ErrorMessage($"On Input Command, {Name} keys on Parameters must be unique.", true));
                    return(result);
                }

                foreach (var parameter in Parameters)
                {
                    if (EntityHeader.IsNullOrEmpty(parameter.ParameterLocation))
                    {
                        result.Errors.Add(new ErrorMessage($"On Input Command {Name}, Parameter Location is not provided.", true));
                        return(result);
                    }

                    if (parameter.ParameterType == null)
                    {
                        result.Errors.Add(new ErrorMessage($"On Input Command {Name}, Parameter {parameter.Name} parameter type is missing.", true));
                    }
                    else if (parameter.ParameterType.Value == ParameterTypes.ValueWithUnit)
                    {
                        parameter.StateSet = null;
                        if (EntityHeader.IsNullOrEmpty(parameter.UnitSet))
                        {
                            result.Errors.Add(new ErrorMessage($"On Input Command {Name}, Parameter {parameter.Name} Value with Unit is data type, but no unit type was provided.", true));
                            return(result);
                        }
                    }
                    else if (parameter.ParameterType.Value == ParameterTypes.State)
                    {
                        parameter.UnitSet = null;
                        if (EntityHeader.IsNullOrEmpty(parameter.StateSet))
                        {
                            result.Errors.Add(new ErrorMessage($"On Input Command {Name}, Parameter {parameter.Name} is a state set, but no state set was provided.", true));
                            return(result);
                        }
                    }
                    else
                    {
                        parameter.UnitSet  = null;
                        parameter.StateSet = null;
                    }

                    if (parameter.ParameterLocation.Value == PayloadTypes.Json && (EndpointType.Value == EndpointTypes.RestGet || EndpointType.Value == EndpointTypes.RestDelete))
                    {
                        result.AddSystemError("End point type of GET or DELETE was specified, however at least one of the parameters has JSON specified for the parameter location.");
                    }
                }

                if (!result.Successful)
                {
                    return(result);
                }

                foreach (var connection in OutgoingConnections)
                {
                    switch (connection.NodeType)
                    {
                    case NodeType_Input:
                    case NodeType_InputCommand:
                        result.Errors.Add(new ErrorMessage($"Mapping from an Input Command on node {Name} to a node of type {connection.NodeType} is not supported", true));
                        break;

                    case NodeType_Attribute:
                        if (connection.InputCommandKey == null)
                        {
                            result.Errors.Add(new ErrorMessage($"When Mapping from in Input Command on node {Name} to an Attribute, you must specify which parameter will be mapped", false));
                        }
                        else
                        {
                            var parameter = Parameters.Where(prm => prm.Key == connection.InputCommandKey).FirstOrDefault();
                            if (parameter == null)
                            {
                                result.Errors.Add(new ErrorMessage($"Specified Mapping Key {connection.InputCommandKey} not found on inputs from {Name}", false));
                            }
                            else
                            {
                                var attribute = workflow.Attributes.Where(attr => attr.Key == connection.NodeKey).First();
                                if (attribute.AttributeType.Value != parameter.ParameterType.Value)
                                {
                                    result.Errors.Add(new ErrorMessage($"On input command {Name}, type mismatch on mapping to {connection.NodeName} from input command {parameter.Name} to attribute of type {parameter.ParameterType.Text}.", false));
                                }
                                else
                                {
                                    if (attribute.AttributeType.Value == ParameterTypes.State &&
                                        attribute.StateSet.Id != parameter.StateSet.Id)
                                    {
                                        result.Errors.Add(new ErrorMessage($"Invalid Mapping between {Name} and {connection.NodeName} - State Sets to do not match."));
                                    }
                                    else if (attribute.AttributeType.Value == ParameterTypes.ValueWithUnit &&
                                             attribute.UnitSet.Id != parameter.UnitSet.Id)
                                    {
                                        result.Errors.Add(new ErrorMessage($"Invalid Mapping between {Name} and {connection.NodeName} - Unit Sets to do not match."));
                                    }
                                }
                            }
                        }

                        break;

                    case NodeType_StateMachine:
                        ValidateStateMachine(result, workflow, connection);
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 5
0
        public void Validate(string value, ValidationResult result, Actions action)
        {
            if (EntityHeader.IsNullOrEmpty(FieldType))
            {
                result.AddSystemError($"Custom field {Label} missing field type, invalid configuration, contact administorator");
            }

            if (IsRequired && String.IsNullOrEmpty(value))
            {
                result.AddUserError($"{Label} is a required field.");
                return;
            }

            if (String.IsNullOrEmpty(value))
            {
                return;
            }


            switch (FieldType.Value)
            {
            case ParameterTypes.DateTime:
                if (!value.SuccessfulJSONDate())
                {
                    result.AddUserError($"Date must be in ISO 8601 format YYYY-MM-DDTHH:MM:SS.SSSZ for {Label}");
                }
                break;

            case ParameterTypes.Decimal:
                if (!double.TryParse(value, out double dbl))
                {
                    result.AddUserError($"Invalid Double Value for {Label}");
                }
                break;

            case ParameterTypes.GeoLocation:
                var geo = value.ToGeoLocation();
                if (geo == null)
                {
                    result.AddUserError($"Invalid geo location on {Label}, found [value], expected [-DD.MMMMMM,-DDD.MMMMMM].");
                }
                break;

            case ParameterTypes.Integer:
                if (!int.TryParse(value, out int intValue))
                {
                    result.AddUserError($"Invalid Integer Value for {Label}");
                }
                break;

            case ParameterTypes.State:
                if (StateSet == null)
                {
                    result.AddSystemError($"Data type was State, but no state set provided, invalid configuration on {Label}");
                }
                else if (StateSet.Value == null)
                {
                    result.AddSystemError($"StateSet was present but value was not, invalid configuration on {Label}");
                }
                else
                {
                    if (!StateSet.Value.States.Where(stat => stat.Key == value).Any())
                    {
                        result.AddUserError($"Attempt to set property to invalid date {value}, possible values are [{StateSet.Value.States.Select(st => st.Key).Aggregate((cur, nxt) => cur + "," + nxt)}] for {Label}");
                    }
                }
                break;

            case ParameterTypes.TrueFalse:
                if (value != "true" && value != "false")
                {
                    result.AddUserError($"Value must be [true] or [false] for {Label}");
                }
                break;

            case ParameterTypes.ValueWithUnit:
                if (!double.TryParse(value, out double dblVal))
                {
                    result.AddUserError($"Invalid Number Value for {Label}");
                }
                break;
            }


            if (FieldType.Value == ParameterTypes.Decimal ||
                FieldType.Value == ParameterTypes.Integer ||
                FieldType.Value == ParameterTypes.ValueWithUnit)
            {
                if (Double.TryParse(value, out double outValue))
                {
                    if (MinValue.HasValue && outValue < MinValue.Value)
                    {
                        result.AddUserError($"Supplied Value {outValue} on {Label} is less then minimum allowable value {MinValue.Value}");
                    }
                    if (MaxValue.HasValue && outValue > MaxValue.Value)
                    {
                        result.AddUserError($"Supplied Value {outValue} on {Label} is greather then maximum allowable value {MaxValue.Value}");
                    }
                }
            }
        }
Esempio n. 6
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (action == Actions.Create)
            {
                if (String.IsNullOrEmpty(SharedAccessKey1))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 1 is Required.");
                }

                if (String.IsNullOrEmpty(SharedAccessKey2))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 2 is Required.");
                }
            }

            if (NuvIoTEdition?.Value == NuvIoTEditions.Container)
            {
                if (EntityHeader.IsNullOrEmpty(ContainerRepository))
                {
                    result.AddSystemError("Container Repository Is Required for NuvIoT Container Editions.");
                }

                if (EntityHeader.IsNullOrEmpty(ContainerTag))
                {
                    result.AddSystemError("Container Tag Is Required for NuvIoT Container Editions.");
                }

                if (EntityHeader.IsNullOrEmpty(Size))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }

                if (EntityHeader.IsNullOrEmpty(WorkingStorage))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }
            }
            else if (NuvIoTEdition?.Value == NuvIoTEditions.Cluster)
            {
                if (EntityHeader.IsNullOrEmpty(WorkingStorage))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }
            }

            if (action == Actions.Update)
            {
                if (String.IsNullOrEmpty(SharedAccessKey1) && String.IsNullOrEmpty(SharedAccessKeySecureId1))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 1 or Shared Access Secure Id 1 is Required.");
                }

                if (String.IsNullOrEmpty(SharedAccessKey2) && String.IsNullOrEmpty(SharedAccessKeySecureId2))
                {
                    result.AddSystemError("Upon updates, Shared Access Key 2 or Shared Access Secure Id 2 is Required.");
                }
            }

            if (!EntityHeader.IsNullOrEmpty(PrimaryCacheType) && PrimaryCacheType.Value == CacheTypes.Redis)
            {
                if (EntityHeader.IsNullOrEmpty(PrimaryCache))
                {
                    result.AddSystemError("Must provide primary cache type.");
                }
            }
        }