예제 #1
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (action == Actions.Create)
            {
                if (String.IsNullOrEmpty(AppAuthKeyPrimary))
                {
                    result.AddUserError("AppAuthKeyPrimary is required when creating a client app.");
                }

                if (String.IsNullOrEmpty(AppAuthKeySecondary))
                {
                    result.AddUserError("AppAuthKeySecondary is required when creating a client app.");
                }
            }
            else if (action == Actions.Update)
            {
                if (String.IsNullOrEmpty(AppAuthKeyPrimary) && String.IsNullOrEmpty(AppAuthKeyPrimarySecureId))
                {
                    result.AddUserError("AppAuthKeyPrimary or AppAuthKeyPrimarySecureId is required when creating a client app.");
                }

                if (String.IsNullOrEmpty(AppAuthKeySecondary) && String.IsNullOrEmpty(AppAuthKeySecondarySecureId))
                {
                    result.AddUserError("AppAuthKeySecondary or AppAuthKeySecondarySecureId is required when creating a client app.");
                }
            }
        }
예제 #2
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (EntityHeader.IsNullOrEmpty(RepositoryType))
            {
                result.AddUserError("Respository Type is a Required Field.");
                return;
            }

            if (RepositoryType.Value == RepositoryTypes.AzureIoTHub)
            {
                if (String.IsNullOrEmpty(ResourceName))
                {
                    result.AddUserError("Resource name which is the name of our Azure IoT Hub is a required field.");
                }
                if (String.IsNullOrEmpty(AccessKeyName))
                {
                    result.AddUserError("Access Key name is a Required field.");
                }
                if (action == Actions.Create && String.IsNullOrEmpty(AccessKey))
                {
                    result.AddUserError("Access Key is a Required field.");
                }
                if (!String.IsNullOrEmpty(AccessKey))
                {
                    if (!AccessKey.IsBase64String())
                    {
                        result.AddUserError("Access Key does not appear to be a Base 64 String.");
                    }
                }
            }
        }
예제 #3
0
        public static ValidationResult ValidateSQLSeverMetaData(this DataStream stream, List <SQLFieldMetaData> sqlMetaData)
        {
            var result = new ValidationResult();

            var timeStampColumn = sqlMetaData.Where(strFld => strFld.ColumnName.ToLower() == stream.TimestampFieldName.ToLower()).FirstOrDefault();
            var deviceIdColumn  = sqlMetaData.Where(strFld => strFld.ColumnName.ToLower() == stream.DeviceIdFieldName.ToLower()).FirstOrDefault();

            if (timeStampColumn == null)
            {
                result.AddUserError($"SQL Server Table must contain the time stamp field [{stream.TimestampFieldName}] but it does not.");
            }
            else if (!_sqlServerDateTypes.Contains(timeStampColumn.DataType))
            {
                result.AddUserError($"Data Type on SQL Server Table for field [{stream.TimestampFieldName}] (the time stamp field) must be one of the following: datetime, datetime2, datetimeoffset.");
            }
            else
            {
                /* Already validated it so we don't want to look for it on the data stream fields */
                sqlMetaData.Remove(timeStampColumn);
            }

            if (deviceIdColumn == null)
            {
                result.AddUserError($"SQL Server Table must contain the device id field [{stream.DeviceIdFieldName}] but it does not.");
            }
            else if (!_sqlServerStringDataTypes.Contains(deviceIdColumn.DataType))
            {
                result.AddUserError($"Data Type on SQL Server Table for field [{stream.DeviceIdFieldName}] (the device id field) must be one of the following: char, varchar, nchar or nvarchar.");
            }
            else
            {
                /* Already validated it so we don't want to look for it on the data stream fields */
                sqlMetaData.Remove(deviceIdColumn);
            }

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

            foreach (var fld in stream.Fields)
            {
                var sqlField = sqlMetaData.Where(sqlFld => sqlFld.ColumnName.ToLower() == fld.FieldName.ToLower()).FirstOrDefault();
                result.Concat(fld.ValidatioRDBMSMetaDataField(sqlField));
            }

            foreach (var fld in sqlMetaData)
            {
                var dsFld = stream.Fields.Where(strFld => strFld.FieldName.ToLower() == fld.ColumnName.ToLower()).FirstOrDefault();
                if (dsFld == null && fld.IsRequired && !fld.IsIdentity && (fld.DefaultValue == null || !fld.DefaultValue.ToLower().Contains("newid")))
                {
                    result.AddUserError($"{fld.ColumnName} is required on the SQL Server table but it is not present on the data stream field.");
                }
            }

            return(result);
        }
예제 #4
0
        public static ValidationResult ValidatePostSQLSeverMetaData(this DataStream stream, List <SQLFieldMetaData> sqlMetaData)
        {
            var result = new ValidationResult();

            var timeStampColumn = sqlMetaData.Where(strFld => strFld.ColumnName.ToLower() == stream.TimestampFieldName.ToLower()).FirstOrDefault();
            var deviceIdColumn  = sqlMetaData.Where(strFld => strFld.ColumnName.ToLower() == stream.DeviceIdFieldName.ToLower()).FirstOrDefault();

            if (timeStampColumn == null)
            {
                result.AddUserError($"Postgress Server Table must contain the time stamp field [{stream.TimestampFieldName}] but it does not.");
            }
            else if (!timeStampColumn.DataType.Contains("time") && !timeStampColumn.DataType.Contains("date"))
            {
                result.AddUserError($"Data Type on SQL Server Table for field [{stream.TimestampFieldName}] (the time stamp field) must time based field.");
            }
            else
            {
                /* Already validated it so we don't want to look for it on the data stream fields */
                sqlMetaData.Remove(timeStampColumn);
            }

            if (deviceIdColumn == null)
            {
                result.AddUserError($"SQL Server Table must contain the device id field [{stream.DeviceIdFieldName}] but it does not.");
            }
            else if (!deviceIdColumn.DataType.Contains("text") && !deviceIdColumn.DataType.Contains("char"))
            {
                result.AddUserError($"Data Type on SQL Server Table for field [{stream.DeviceIdFieldName}] (the device id field) must be a text based field.");
            }
            else
            {
                /* Already validated it so we don't want to look for it on the data stream fields */
                sqlMetaData.Remove(deviceIdColumn);
            }

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

            foreach (var fld in stream.Fields)
            {
                var sqlField = sqlMetaData.Where(sqlFld => sqlFld.ColumnName.ToLower() == fld.FieldName.ToLower()).FirstOrDefault();
                if (sqlField == null)
                {
                    result.AddUserError($"Missing field [{fld.Name}] of data type [{fld.FieldType.Text}] on the postgress table.");
                }
            }

            return(result);
        }
예제 #5
0
 public void Validate(ValidationResult result)
 {
     if (EntityHeader.IsNullOrEmpty(ParameterType))
     {
         result.AddUserError($"Parameter Type on Parameter {Name} is a required field.");
     }
     else if (ParameterType.Value == ParameterTypes.State && EntityHeader.IsNullOrEmpty(StateSet))
     {
         result.AddUserError($"Parameter Type on Parameter {Name} is a Value with Unit but no State Set has been provided.");
     }
     else if (ParameterType.Value == ParameterTypes.ValueWithUnit && EntityHeader.IsNullOrEmpty(UnitSet))
     {
         result.AddUserError($"Parameter Type on Parameter {Name} is a Value with Unit but no Unit Set has been provided.");
     }
 }
예제 #6
0
파일: Model.cs 프로젝트: LagoVista/ai
 public void Validate(ValidationResult result)
 {
     if (Revisions.GroupBy(rev => new { rev.VersionNumber, rev.MinorVersionNumber }).Count() != Revisions.Count)
     {
         result.AddUserError("Revision Indexes must be unique.");
     }
 }
 public void Validate(ValidationResult res)
 {
     if (PeriodMS < 100)
     {
         res.AddUserError("Please provide a number larger then 100ms for the period.");
     }
 }
예제 #8
0
 public void Validate(ValidationResult result, Actions action)
 {
     if (AppUsers.Count == 0)
     {
         result.AddUserError("Must have at least one person on the distribution list.");
     }
 }
        public void Validate(ValidationResult result)
        {
            if (WatchdogEnabledDefault && !WatchdogSeconds.HasValue)
            {
                result.AddUserError("Watchdog Internal is required.");
            }
            else if (!WatchdogEnabledDefault)
            {
                WatchdogSeconds = null;
            }

            if (ErrorCodes.Count != ErrorCodes.GroupBy(err => err.Key).Count())
            {
                result.AddUserError("Error codes for a device configuration must be unique..");
            }
        }
        public void Validate(ValidationResult result)
        {
            if (Items.Count() == 0)
            {
                result.AddUserError("Must provide at least one status item.");
            }

            if (Items.Where(itm => itm.IsDefault).Count() == 0)
            {
                result.AddUserError("Must provide at least one item that is set as the default value.");
            }
            else if (Items.Where(itm => itm.IsDefault).Count() > 1)
            {
                result.AddUserError("Can only have one item that is set as the default status.");
            }
        }
예제 #11
0
 public void Validate(ValidationResult result, Actions action)
 {
     if (action == Actions.Update && Key == SubscriptionKey_Trial)
     {
         result.AddUserError("Can not update trial subscription.");
     }
 }
예제 #12
0
 public void Validate(ValidationResult result)
 {
     if (TimeToCompleteTimeSpan.Value != TimeSpanIntervals.NotApplicable && !TimeToCompleteQuantity.HasValue)
     {
         result.AddUserError("Time to complete quantity is required.");
     }
 }
예제 #13
0
        //TODO: Need to add localization
        public static ValidationResult ValidatioRDBMSMetaDataField(this DataStreamField field, SQLFieldMetaData metaData)
        {
            var result = new ValidationResult();

            if (metaData == null)
            {
                result.AddUserError($"{field.FieldName} is present on data stream, but not on SQL table.");
                return(result);
            }

            if (metaData.IsRequired && !field.IsRequired)
            {
                result.AddUserError($"{field.FieldName} on database is required, but it is not required on the data stream.");
            }

            List <string> validColumnTypes = null;

            switch (field.FieldType.Value)
            {
            case DeviceAdmin.Models.ParameterTypes.DateTime: validColumnTypes = _sqlServerDateTypes; break;

            case DeviceAdmin.Models.ParameterTypes.Decimal: validColumnTypes = _sqlServerDecimalTypes; break;

            case DeviceAdmin.Models.ParameterTypes.GeoLocation: validColumnTypes = _sqlServerLocationDateTypes; break;

            case DeviceAdmin.Models.ParameterTypes.Integer: validColumnTypes = _sqlServerIntegerDateTypes; break;

            case DeviceAdmin.Models.ParameterTypes.State: validColumnTypes = _sqlServerStatesAndEnums; break;

            case DeviceAdmin.Models.ParameterTypes.String: validColumnTypes = _sqlServerStringDataTypes; break;

            case DeviceAdmin.Models.ParameterTypes.TrueFalse: validColumnTypes = _sqlServerBooleanDataTypes; break;

            case DeviceAdmin.Models.ParameterTypes.ValueWithUnit: validColumnTypes = _sqlServerDecimalTypes; break;
            }

            if (!validColumnTypes.Contains(metaData.DataType))
            {
                result.AddUserError($"Type mismatch on field [{field.Name}], Data Stream Type: {field.FieldType.Text} - SQL Data Type: {metaData.DataType}.");
            }

            return(result);
        }
예제 #14
0
 public void Validate(ValidationResult res, Actions action)
 {
     if (ValueType.Value == CacheValueDataTypes.Number)
     {
         if (!Double.TryParse(Value, out _))
         {
             res.AddUserError($"Value provided for {Name} must be a number, it currently is {Value}.");
         }
     }
 }
예제 #15
0
 public void Validate(ValidationResult result)
 {
     if (!String.IsNullOrEmpty(InputShape))
     {
         var regEx = new Regex(@"^[0-9,]+$");
         if (!regEx.Match(InputShape).Success)
         {
             result.AddUserError("Please enter a valid input shape, this should be a comma delimited set of integers that represent the dimmensions of the input.");
         }
     }
 }
예제 #16
0
        public void Validate(ValidationResult result)
        {
            if (States.Count() < 2)
            {
                result.AddUserError("State Sets require at least 2 States.");
            }
            else
            {
                if (States.Select(state => state.Key).Distinct().Count() != States.Count())
                {
                    result.AddUserError("Duplicate Keys found on States.");
                }
                if (States.Where(state => state.IsInitialState).Count() == 0)
                {
                    result.AddUserError("Could not find initial state on State Set.  Please add one.");
                }
                if (States.Where(state => state.IsInitialState).Count() > 1)
                {
                    result.AddUserError("Found multiple Initial States on State Set.  Please ensure you have only one.");
                }
            }

            if (RequireEnum)
            {
                if (States.Where(state => !state.EnumValue.HasValue).Any())
                {
                    result.AddUserError("This State requires that each state has an enumeration value, but not all do.");
                }
                else if (States.Select(state => state.EnumValue.Value).Distinct().Count() != States.Count())
                {
                    result.AddUserError("Enum values on States must be Unique.");
                }
            }
        }
예제 #17
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (EntityHeader.IsNullOrEmpty(FieldType))
            {
                result.AddUserError("Field Type is Required.");
            }

            if (FieldType.Value == ParameterTypes.ValueWithUnit)
            {
                if (EntityHeader.IsNullOrEmpty(UnitSet))
                {
                    result.AddUserError("If Value with Unit is selected for the Field Type, you must specify a Unit Set.");
                }
            }
            else if (FieldType.Value == ParameterTypes.State)
            {
                if (EntityHeader.IsNullOrEmpty(StateSet))
                {
                    result.AddUserError("If State Set is selected for the Field Type, you must specify a State Set.");
                }
            }
        }
예제 #18
0
 public void Validate(ValidationResult result)
 {
     if (Units == null || Units.Count() == 0)
     {
         result.AddUserError("Unit Sets require at least 1 Unit.");
     }
     else
     {
         if (Units.Select(unit => unit.Key).Distinct().Count() != Units.Count())
         {
             result.AddUserError("Duplicate Keys found on Unit Set.");
         }
         if (Units.Where(unit => unit.IsDefault).Count() == 0)
         {
             result.AddUserError("Could not find Default Unit on Unit Set.  Please add one.");
         }
         if (Units.Where(unit => unit.IsDefault).Count() > 1)
         {
             result.AddUserError("Found multiple Default Units on Unit Set.  Please ensure you have only one.");
         }
     }
 }
예제 #19
0
        public void Validate(ValidationResult result)
        {
            if (Timers == null)
            {
                Timers = new List <Timer>();
            }


            if (Inputs.Select(param => param.Key).Distinct().Count() != Inputs.Count())
            {
                result.AddUserError("Duplicate Keys found on Inputs.");
            }
            if (Attributes.Select(param => param.Key).Distinct().Count() != Attributes.Count())
            {
                result.AddUserError("Duplicate Keys found on Attributes.");
            }
            if (InputCommands.Select(param => param.Key).Distinct().Count() != InputCommands.Count())
            {
                result.AddUserError("Duplicate Keys found on Input Commands.");
            }
            if (StateMachines.Select(param => param.Key).Distinct().Count() != StateMachines.Count())
            {
                result.AddUserError("Duplicate Keys found on State Machines.");
            }
            if (OutputCommands.Select(param => param.Key).Distinct().Count() != OutputCommands.Count())
            {
                result.AddUserError("Duplicate Keys found on Output Commands.");
            }
            if (Timers.Select(param => param.Key).Distinct().Count() != Timers.Count())
            {
                result.AddUserError("Duplicate Keys found on Timers.");
            }

            foreach (var input in Inputs)
            {
                input.Validate(this, result);
            }
            foreach (var attribute in Attributes)
            {
                attribute.Validate(this, result);
            }
            foreach (var inputCommand in InputCommands)
            {
                inputCommand.Validate(this, result);
            }
            foreach (var stateMachine in StateMachines)
            {
                stateMachine.Validate(this, result);
            }
            foreach (var outputCommand in OutputCommands)
            {
                outputCommand.Validate(this, result);
            }
            foreach (var timer in Timers)
            {
                timer.Validate(this, result);
            }
        }
예제 #20
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);
            }
        }
 public void Validate(ValidationResult result)
 {
     if (TimeAllowedInStatusTimeSpan.Value != TimeSpanIntervals.NotApplicable)
     {
         if (!TimeAllowedInStatusQuantity.HasValue)
         {
             result.AddUserError($"{FSResources.Status_TimeAllowedInStatus_Quantity} is a required field.");
         }
     }
     else
     {
         TimeAllowedInStatusQuantity = null;
     }
 }
예제 #22
0
        public void Validate(ValidationResult result)
        {
            if (EntityHeader.IsNullOrEmpty(DistroList))
            {
                NotificationIntervalTimeSpan = EntityHeader <TimeSpanIntervals> .Create(TimeSpanIntervals.NotApplicable);

                NotificationIntervalQuantity = null;
            }
            else
            {
                if (NotificationIntervalTimeSpan != EntityHeader <TimeSpanIntervals> .Create(TimeSpanIntervals.NotApplicable) &&
                    (!NotificationIntervalQuantity.HasValue || NotificationIntervalQuantity.Value <= 0))
                {
                    result.AddUserError("You must specify a notification interval quantity.");
                }
            }

            if (AutoexpireTimespan.Value != TimeSpanIntervals.NotApplicable &&
                (!AutoexpireTimespanQuantity.HasValue || AutoexpireTimespanQuantity.Value < 0))
            {
                result.AddUserError("You must specify a positive, non-zero auto expire value.");
            }
        }
예제 #23
0
        public void Validate(DeviceWorkflow workflow, ValidationResult result)
        {
            if (Validator.Validate(this).Successful)
            {
                if (States.Select(param => param.Key).Distinct().Count() != States.Count())
                {
                    result.AddUserError($"Duplicate Keys found in States on State Machine: {Name}.");
                }
                if (Events.Select(param => param.Key).Distinct().Count() != Events.Count())
                {
                    result.AddUserError($"Duplicate Keys found in Events on State Machine: {Name}.");
                }
                if (Variables.Select(param => param.Key).Distinct().Count() != Variables.Count())
                {
                    result.AddUserError($"Duplicate Keys found in Variables on State Machine: {Name}.");
                }

                result.Concat(ValidateNodeBase(workflow));
                foreach (var connection in OutgoingConnections)
                {
                    if (connection.NodeType == NodeType_Input || connection.NodeType == NodeType_InputCommand)
                    {
                        result.Errors.Add(new ErrorMessage($"Mapping from an Input to a node of type: {NodeType} is not supported", true));
                    }
                }

                foreach (var variable in Variables)
                {
                    variable.Validate(result);
                }

                foreach (var state in States)
                {
                    state.Validate(result);
                }
            }
        }
예제 #24
0
        public void Validate(ValidationResult result)
        {
            if (IsFileUpload)
            {
                Link = String.Empty;

                if (String.IsNullOrEmpty(FileName))
                {
                    result.AddUserError("Must provide file.");
                }
                else
                {
                    if (String.IsNullOrEmpty(MimeType))
                    {
                        result.AddUserError("Mime Type is a Required Field.");
                    }

                    if (String.IsNullOrEmpty(StorageReferenceName))
                    {
                        result.AddUserError("Storage Reference Name is a Required Field.");
                    }
                }
            }
            else
            {
                ContentSize          = null;
                MimeType             = null;
                FileName             = null;
                StorageReferenceName = null;

                if (String.IsNullOrEmpty(Link))
                {
                    result.AddUserError("Must provide link.");
                }
            }
        }
예제 #25
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (PropertiesMetaData != null)
            {
                foreach (var propertyMetaData in PropertiesMetaData)
                {
                    var property = Properties.Where(prop => prop.Key == propertyMetaData.Key).FirstOrDefault();
                    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");
            }
        }
예제 #26
0
        public void Validate(ValidationResult result)
        {
            if (EntityHeader.IsNullOrEmpty(Transport))
            {
                result.AddUserError("Transport is a Required Field.");
                return;
            }

            switch (Transport.Value)
            {
            case TransportTypes.MQTT:
                if (String.IsNullOrEmpty(Topic))
                {
                    result.AddUserError("Topic is a Required Field.");
                }
                if (EntityHeader.IsNullOrEmpty(QualityOfServiceLevel))
                {
                    result.AddUserError("QOS Must Be Defined");
                }
                break;

            case TransportTypes.AzureServiceBus:
                if (String.IsNullOrEmpty(QueueName))
                {
                    result.AddUserError("Queue Name a Required Field.");
                }
                break;

            case TransportTypes.RestHttp:
            case TransportTypes.RestHttps:
                if (String.IsNullOrEmpty(HttpVerb))
                {
                    result.AddUserError("HTTP Verb is a Required Field.");
                }
                else
                {
                    HttpVerb = HttpVerb.ToUpper();
                    if (HttpVerb != HttpVerb_GET &&
                        HttpVerb != HttpVerb_PUT &&
                        HttpVerb != HttpVerb_POST &&
                        HttpVerb != HttpVerb_DELETE)
                    {
                        result.AddUserError("Currently only the HTTP Verbs GET, POST, PUT and DELETE are supported.");
                    }
                }

                break;
            }

            foreach (var hdr in MessageHeaders)
            {
                hdr.Validate(result);
            }
        }
예제 #27
0
파일: Unit.cs 프로젝트: lulzzz/DeviceAdmin
        public void Validate(ValidationResult result)
        {
            if (IsDefault)
            {
                ConversionType       = null;
                ConversionFactor     = null;
                ConversionToScript   = null;
                ConversionFromScript = null;
            }
            else
            {
                if (EntityHeader.IsNullOrEmpty(ConversionType))
                {
                    result.AddUserError($"For non-default Units, on unit {Name} you must provide a conversion type.");
                }
                else
                {
                    switch (ConversionType.Value)
                    {
                    case ConversionTypes.Factor:
                        if (!ConversionFactor.HasValue)
                        {
                            result.AddUserError($"For Units that specify a Conversion Type of a Conversion Factor, a Conversion Factor must be Provided on unit {Name}");
                        }
                        break;

                    case ConversionTypes.Script:
                        if (String.IsNullOrEmpty(ConversionToScript))
                        {
                            result.AddUserError($"Since you are using a conversion script on unit {Name}, you must provide the Conversion To Script");
                        }
                        if (String.IsNullOrEmpty(ConversionFromScript))
                        {
                            result.AddUserError($"Since you are using a conversion script on unit {Name}, you must provide the Conversion From Script");
                        }

                        //TODO: Should probably provide some sort of validation on the scripts, JInt, requires dotnetstandard 1.3 and need to think it through first, for now, just ensure it's not empty and contains the name of the method
                        /* For now, just make sure the script contains the name of the function, that will be called, the run time engine will handle and report invalid scripts */
                        if (!String.IsNullOrEmpty(ConversionToScript) && !ConversionToScript.Contains("convertToDefaultUnit"))
                        {
                            result.AddUserError($"Convertion From Script on unit {Name} must contain an implementation of the function [convertToDefaultUnit]");
                        }
                        if (!String.IsNullOrEmpty(ConversionFromScript) && !ConversionFromScript.Contains("convertFromDefaultUnit"))
                        {
                            result.AddUserError($"Convertion From Script on unit {Name} must contain an implementation of the function [convertFromDefaultUnit]");
                        }

                        break;
                    }
                }
            }
        }
예제 #28
0
        public void Validate(ValidationResult result)
        {
            var startHours   = Start / 100;
            var startMinutes = Start - ((Start / 100) * 100);

            if (startHours > 23)
            {
                result.AddUserError($"Start hours must not be greater then 23, Start={Start / 100}:{Start % 100:00}");
            }

            if (startMinutes > 59)
            {
                result.AddUserError($"Minutes portion of start time must not be greater then 59, Start={Start / 100}:{Start % 100:00}");
            }

            var endHours   = End / 100;
            var endMinutes = End - ((End / 100) * 100);

            if (endHours > 23)
            {
                result.AddUserError($"End hours must not be greater then 23, Start={End / 100}:{End % 100:00}");
            }

            if (endMinutes > 59)
            {
                result.AddUserError($"Minutes portion of end time must not be greater then 59, End={End / 100}:{End % 100:00}");
            }

            if (Start == End)
            {
                result.AddUserError($"Start time for exclusion must not equal end time, Start={Start / 100}:{Start % 100:00} End={End / 100}:{End % 100:00}.");
            }

            if (End < Start)
            {
                result.AddUserError($"Start time for exclusion must not be greather then the end time, Start={Start / 100}:{Start % 100:00} End={End / 100}:{End % 100:00}.");
            }
        }
예제 #29
0
        public void Validate(ValidationResult result, Actions action)
        {
            //TODO: Needs localizations on error messages
            if (EntityHeader.IsNullOrEmpty(RepositoryType))
            {
                result.AddUserError("Respository Type is a Required Field.");
                return;
            }

            if (RepositoryType?.Value == RepositoryTypes.NuvIoT)
            {
                if (action == Actions.Create)
                {
                    if (DeviceArchiveStorageSettings == null)
                    {
                        result.AddUserError("Device Archive Storage Settings are Required on Insert.");
                    }
                    if (PEMStorageSettings == null)
                    {
                        result.AddUserError("PEM Storage Settings Are Required on Insert.");
                    }
                    if (DeviceStorageSettings == null)
                    {
                        result.AddUserError("Device Storage Settings are Required on Insert.");
                    }
                }
                else if (action == Actions.Update)
                {
                    if (DeviceArchiveStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("Device Archive Storage Settings Or SecureId are Required when updating.");
                    }
                    if (PEMStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("PEM Storage Settings or Secure Id Are Required when updating.");
                    }
                    if (DeviceStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("Device Storage Settings Or Secure Id are Required when updating.");
                    }
                }
            }

            if (RepositoryType.Value == RepositoryTypes.AzureIoTHub)
            {
                if (String.IsNullOrEmpty(ResourceName))
                {
                    result.AddUserError("Resource name which is the name of our Azure IoT Hub is a required field.");
                }
                if (String.IsNullOrEmpty(AccessKeyName))
                {
                    result.AddUserError("Access Key name is a Required field.");
                }

                if (action == Actions.Create && String.IsNullOrEmpty(AccessKey))
                {
                    result.AddUserError("Access Key is a Required field when adding a repository of type Azure IoT Hub");
                }
                if (action == Actions.Update && String.IsNullOrEmpty(AccessKey) && String.IsNullOrEmpty(SecureAccessKeyId))
                {
                    result.AddUserError("Access Key or ScureAccessKeyId is a Required when updating a repo of Azure IoT Hub.");
                }


                if (!String.IsNullOrEmpty(AccessKey))
                {
                    if (!AccessKey.IsBase64String())
                    {
                        result.AddUserError("Access Key does not appear to be a Base 64 String.");
                    }
                }
            }
        }
        public void Validate(ValidationResult result)
        {
            if (EntityHeader.IsNullOrEmpty(ListenerType))
            {
                result.AddUserError("Listener Type is a Required Field.");
                return;
            }

            switch (ListenerType.Value)
            {
            case ListenerTypes.AMQP:
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for Connecting to an AMQP Server.");
                }
                if (!Anonymous)
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        result.AddUserError("User Name is Required to connect to your AMQP server for non-anonymous connections.");
                    }
                    if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(SecurePasswordId))
                    {
                        result.AddUserError("Password is Required to connect to your AMQP server for non-anonymous connections.");
                    }
                }
                else
                {
                    UserName = null;
                    Password = null;
                }

                if (!AmqpSubscriptions.Any())
                {
                    result.AddUserError("Please ensure you provide at least one subscription (including wildcards * and #) that will be monitored for incoming messages.");
                }
                break;

            case ListenerTypes.AzureEventHub:
                if (HostName != null && HostName.ToLower().StartsWith("sb://"))
                {
                    HostName = HostName.Substring(5);
                }
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for Azure Event Hubs, this is the host name of your Event Hub without the sb:// protocol.");
                }
                if (string.IsNullOrEmpty(HubName))
                {
                    result.AddUserError("Hub Name is Required for an Azure Event Hub Listener.");
                }
                if (string.IsNullOrEmpty(AccessKey) && string.IsNullOrEmpty(SecureAccessKeyId))
                {
                    result.AddUserError("Access Key is Required for an Azure Event Hub listener.");
                }
                if (!string.IsNullOrEmpty(AccessKey) && !Utils.StringValidationHelper.IsBase64String(AccessKey))
                {
                    result.AddUserError("Access Key does not appear to be a Base 64 string and is likely incorrect.");
                }
                break;

            case ListenerTypes.AzureIoTHub:
                if (HostName != null && HostName.ToLower().StartsWith("sb://"))
                {
                    HostName = HostName.Substring(5);
                }
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for Azure IoT Hub, this is found in the Event Hub-compatible endpoint field on the Azure Portal.");
                }
                if (string.IsNullOrEmpty(ResourceName))
                {
                    result.AddUserError("Resource Name is require for Azure IoT Hub, this is found in the Event Hub-compatible name field on the Azure Portal.");
                }
                if (string.IsNullOrEmpty(AccessKeyName))
                {
                    result.AddUserError("Access Key Name is a required field for an Azure Serice Bus Listener.");
                }
                if (string.IsNullOrEmpty(AccessKey) && string.IsNullOrEmpty(SecureAccessKeyId))
                {
                    result.AddUserError("Access Key is Required for Azure IoT Event Hub.");
                }
                if (!string.IsNullOrEmpty(AccessKey) && !Utils.StringValidationHelper.IsBase64String(AccessKey))
                {
                    result.AddUserError("Access Key does not appear to be a Base 64 string and is likely incorrect.");
                }
                break;

            case ListenerTypes.AzureServiceBus:
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for an Azure Service Bus Listener, this is the host name of your Event Hub without the sb:// protocol.");
                }
                if (HostName != null && HostName.ToLower().StartsWith("sb://"))
                {
                    HostName = HostName.Substring(5);
                }
                if (string.IsNullOrEmpty(Queue))
                {
                    result.AddUserError("Queue Name is required for an Azure Service Bus Listener.");
                }
                if (string.IsNullOrEmpty(AccessKeyName))
                {
                    result.AddUserError("Access Key Name is a required field for an Azure Serice Bus Listener.");
                }
                if (string.IsNullOrEmpty(AccessKey) && string.IsNullOrEmpty(SecureAccessKeyId))
                {
                    result.AddUserError("Access Key is Required for an Azure IoT Service Bus Listener.");
                }
                if (!string.IsNullOrEmpty(AccessKey) && !Utils.StringValidationHelper.IsBase64String(AccessKey))
                {
                    result.AddUserError("Access Key does not appear to be a Base 64 string and is likely incorrect.");
                }

                break;

            case ListenerTypes.MQTTClient:
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for Connecting to an MQTT Server.");
                }
                if (!Anonymous)
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        result.AddUserError("User Name is Required to connect to your MQTT Broker for non-anonymous connections.");
                    }
                    if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(SecurePasswordId))
                    {
                        result.AddUserError("Password is Required to connect to your MQTT Broker for non-anonymous connections.");
                    }
                }
                else
                {
                    UserName = null;
                    Password = null;
                }
                if (!ConnectToPort.HasValue)
                {
                    result.AddUserError("Please provide a port that your MQTT Client will connect, usually 1883 or 8883 (SSL).");
                }
                MqttSubscriptions.RemoveAll(sub => string.IsNullOrEmpty(sub.Topic));
                if (!MqttSubscriptions.Any())
                {
                    result.AddUserError("Please ensure you provide at least one subscription (including wildcards + and #) that will be monitored for incoming messages.");
                }

                break;

            case ListenerTypes.WebSocket:
                if (string.IsNullOrEmpty(HostName))
                {
                    result.AddUserError("Host Name is required for an Azure Service Bus Listener, this is the host name of your Event Hub without the sb:// protocol.");
                }
                if (HostName != null && HostName.ToLower().StartsWith("wss://"))
                {
                    HostName = HostName.Substring(5);
                }
                if (HostName != null && HostName.ToLower().StartsWith("ws://"))
                {
                    HostName = HostName.Substring(4);
                }
                if (!string.IsNullOrEmpty(Path) && !Path.StartsWith("/"))
                {
                    Path = "/" + Path;
                }

                if (!Anonymous)
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        result.AddUserError("User Name is Required to be used to authenticate with your Web Socket Server.");
                    }
                    if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(SecurePasswordId))
                    {
                        result.AddUserError("Password is Required to be used to authenticate with your Web Socket Server..");
                    }
                }
                else
                {
                    UserName = null;
                    Password = null;
                }

                break;

            case ListenerTypes.MQTTListener:
                if (!Anonymous)
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        result.AddUserError("User Name is Required to be used to authenticate MQTT clients authenticating with your broker.");
                    }
                    if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(SecurePasswordId))
                    {
                        result.AddUserError("Password is Required to be used to authenticate MQTT clients authenticating with your broker.");
                    }
                }
                else
                {
                    UserName = null;
                    Password = null;
                }
                if (!ListenOnPort.HasValue)
                {
                    result.AddUserError("Please provide a port that your MQTT listenr will listen for incoming messages, usually 1883.");
                }
                break;

            /*
             * case ListenerTypes.MQTTBroker:
             * break;
             * case ListenerTypes.RabbitMQ:
             * break;
             * case ListenerTypes.RabbitMQClient:
             * break;*/
            case ListenerTypes.RawTCP:
                if (!ListenOnPort.HasValue)
                {
                    result.AddUserError("Please provide a port that your TCP listenr will listen for incoming messages.");
                }
                break;

            case ListenerTypes.RawUDP:
                if (!ListenOnPort.HasValue)
                {
                    result.AddUserError("Please provide a port that your UDP listenr will listen for incoming messages.");
                }
                break;

            case ListenerTypes.Rest:
                if (!ListenOnPort.HasValue)
                {
                    result.AddUserError("Please provide a port that your REST listenr will listen for incoming messages, this is usually port 80 for HTTP and 443 for HTTPS.");
                }
                if (EntityHeader.IsNullOrEmpty(RestServerType))
                {
                    result.AddUserError("Allowable Connection Type is required for an REST Listener.");
                }
                if (!Anonymous)
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        result.AddUserError("Anonymous connections are not enabled, you must provide a user name that will be used to connect to your REST endpoint.");
                    }
                    if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(SecurePasswordId))
                    {
                        result.AddUserError("Anonymous connections are not enabled, you must provide a password that will be used to connect to your REST endpoint.");
                    }
                }
                else
                {
                    UserName = null;
                    Password = null;
                }


                break;
            }
        }