예제 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrWhiteSpace(Content))
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Content)));
            }

            var jsonString = Content.Trim();

            if (!jsonString.StartsWith("{") || !jsonString.EndsWith("}"))
            {
                yield return(BusinessErrors.ClientConfigurations.InvalidJson);
            }

            var parseSucceeded = false;

            try
            {
                JToken.Parse(Content);
                parseSucceeded = true;
            }
            catch (Exception)
            {
                // ignored
            }

            if (!parseSucceeded)
            {
                yield return(BusinessErrors.ClientConfigurations.InvalidJson);
            }
        }
예제 #2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Name)));
            }

            if (Id == Guid.Empty)
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Id)));
            }

            if (RestartOnFailInterval != null && RestartOnFailInterval <= TimeSpan.Zero)
            {
                yield return(TaskErrors.RestartOnFailIntervalMustBePositive);
            }

            if (RestartOnFailInterval == null && MaximumRestarts < 1)
            {
                yield return(TaskErrors.MaximumRestartsMustBeGreaterThanZero);
            }

            if (!Audience.IncludesServer && !Audience.IsAll && !Audience.Any())
            {
                yield return(TaskErrors.NoAudienceGiven);
            }

            if (!Commands.Any())
            {
                yield return(TaskErrors.NoCommandsGiven);
            }
        }
예제 #3
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (string.IsNullOrWhiteSpace(Name))
     {
         yield return(BusinessErrors.FieldNullOrEmpty(nameof(Name)));
     }
 }
예제 #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrWhiteSpace(Username))
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(Username)));
            }

            if (string.IsNullOrWhiteSpace(OperatingSystem))
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(OperatingSystem)));
            }

            if (string.IsNullOrWhiteSpace(SystemLanguage))
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(SystemLanguage)));
            }
            else if (!CultureInfoExtensions.TryGet(SystemLanguage, out _))
            {
                yield return(BusinessErrors.InvalidCultureName.ValidateOnMember(nameof(SystemLanguage)));
            }

            if (string.IsNullOrWhiteSpace(ClientPath))
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(ClientPath)));
            }

            if (string.IsNullOrWhiteSpace(HardwareId))
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(HardwareId)));
            }
            else if (!Hash.TryParse(HardwareId, out _))
            {
                yield return(BusinessErrors.InvalidSha256Hash.ValidateOnMember(nameof(HardwareId)));
            }

            if (MacAddress == null)
            {
                yield return(BusinessErrorHelper.FieldNullOrEmpty(nameof(MacAddress)));
            }
            else if (MacAddress.Length != 6)
            {
                yield return(BusinessErrors.InvalidMacAddress.ValidateOnMember(nameof(MacAddress)));
            }

            if (ClientVersion == null)
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(ClientVersion)));
            }

            if (Framework == null)
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Framework)));
            }
        }
예제 #5
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            foreach (var validationResult in base.Validate(validationContext))
            {
                yield return(validationResult);
            }

            if (string.IsNullOrWhiteSpace(Password))
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Password)));
            }
        }
예제 #6
0
        public async Task <TaskTransmission> BizActionAsync(TaskTransmission inputData)
        {
            if (inputData.TaskReferenceId == Guid.Empty)
            {
                return(ReturnError <TaskTransmission>(BusinessErrors.FieldNullOrEmpty("TaskReferenceId")));
            }

            if (inputData.CreatedOn == default)
            {
                return(ReturnError <TaskTransmission>(BusinessErrors.FieldNullOrEmpty("CreatedOn")));
            }

            await _dbAccess.CreateAsync(inputData);

            return(inputData);
        }
예제 #7
0
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Username))
            {
                yield return(BusinessErrors.FieldNullOrEmpty(nameof(Username)));
            }
            else
            {
                if (Username.Length > LengthConsts.AccountUsernameMaxLength)
                {
                    yield return(BusinessErrors.Account.UsernameTooLong);
                }

                if (!Regex.IsMatch(Username, "^[a-zA-Z0-9]+$"))
                {
                    yield return(BusinessErrors.Account.InvalidCharsInUsername);
                }
            }
        }
예제 #8
0
 public static ValidationResult FieldNullOrEmpty(string name)
 {
     return(BusinessErrors.FieldNullOrEmpty(name).ValidateOnMember(name));
 }