コード例 #1
0
        public Parameter AddParameter(Parameter parameter)
        {
            parameter.Name = NameValidation.ValidateName(parameter.Name, validationName => !Parameters.ContainsKey(validationName));
            Parameters.Add(parameter.Name, parameter);

            return(parameter);
        }
コード例 #2
0
        public Parameter AddParameter(string name)
        {
            var parameter = new Parameter {
                Name = NameValidation.ValidateName(name, validationName => !Parameters.ContainsKey(validationName))
            };

            Parameters.Add(parameter.Name, parameter);

            return(parameter);
        }
コード例 #3
0
        public void ValidExercise()
        {
            var exercises = new IExerciseDefinition[]
            {
                new ValidExercise()
            };

            var errors = NameValidation.GetErrors(exercises);

            Assert.AreEqual(0, errors.Count, string.Join(",", errors));
        }
コード例 #4
0
 public IActionResult Validate(ValidationModel model)
 {
     if (ModelState.IsValid)
     {
         model.isValidEmail = NameValidation.ValidateEmail(model.Input);
         return(View(model));
     }
     else
     {
         return(View(model));
     }
 }
コード例 #5
0
        public IActionResult Registration(Models.RegistrationModel model)
        {
            //Проверка правильности переданной модели
            if (ModelState.IsValid)
            {
                //проверка эл. ящика
                if (!NameValidation.ValidateEmail(model.Email))
                {
                    ModelState.AddModelError("", "Введённый почтовый адрес не прошёл валидацию.");
                    return(RedirectToAction("Registration", model));
                }
                //добавление пользователя в бд
                db.Users.Add(new Data.User()
                {
                    Email    = NameValidation.idn.GetAscii(model.Email),
                    Login    = Utils.GetHash(model.Email),
                    Password = Utils.GetHash(model.Password),
                    Person   = new Person()
                    {
                        DateOfBirth = DateTime.Now,
                        FirstName   = "Тест",
                        LastName    = "Кейсов",
                        Patronymic  = "Тестович"
                    },
                    Role       = Roles.Ученик,
                    UniqueCode = new UniqueKey()
                    {
                        UniqueKeyString = Utils.GetHash(DateTime.Now.ToShortTimeString())
                    }
                });
                db.SaveChanges();
                //отправка письма
                MailAddress from = new MailAddress("unnamed2@тестовая-зона.рф");
                MailAddress to   = new MailAddress(model.Email);

                MailMessage message = new MailMessage(from, to);
                message.Subject    = "Благодарим за регистрацию на сайте ИТ-Дневник!" + DateTime.Now;
                message.Body       = $"Вы зарегистрировались по уникальному ключу {model.UniqueKey}";
                message.IsBodyHtml = true;
                //настройка smtp-клиента
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                //пока что используется аккаунт почты гугла
                smtp.Credentials    = new NetworkCredential("*****@*****.**", "bfd20380a6");
                smtp.EnableSsl      = true;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Send(message);
                //вход под пользователем
                Authenticate(model.Email, model.Password);
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Registration", model));
        }
コード例 #6
0
        public State AddState(State state)
        {
            state.Name = NameValidation.ValidateName(state.Name, validationName => !States.ContainsKey(validationName));

            if (States.Count == 0)
            {
                CurrentState = state;

                state.InputPort = CreateBaseInputPort(1f);
            }
            else
            {
                state.InputPort = CreateBaseInputPort(0f);
            }

            States.Add(state.Name, state);

            return(state);
        }
コード例 #7
0
ファイル: ReferenceNameBuilder.cs プロジェクト: am11/runner
 internal Boolean TryAddKnownName(
     String value,
     out String error)
 {
     if (!NameValidation.IsValid(value, allowHyphens: true) && value.Length < PipelineConstants.MaxNodeNameLength)
     {
         error = $"The identifier '{value}' is invalid. IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and and must be less than {PipelineConstants.MaxNodeNameLength} characters.";
         return(false);
     }
     else if (!m_distinctNames.Add(value))
     {
         error = $"The identifier '{value}' may not be used more than once within the same scope.";
         return(false);
     }
     else
     {
         error = null;
         return(true);
     }
 }
コード例 #8
0
        private bool ValidateSave()
        {
            if (this.CurrentlySelectedFieldId == Guid.Empty)
            {
                return(true);
            }

            if (this.NameField.Text.Contains(" "))
            {
                Baloon(this.NameField, GetString("SpaceInNameError"));
                return(false);
            }

            if (string.IsNullOrEmpty(this.NameField.Text))
            {
                Baloon(this.NameField, GetString("NameEmptyError"));
                return(false);
            }

            if (this.CurrentFields.Any(f => f.Name == this.NameField.Text && f.Id != this.CurrentlySelectedFieldId))
            {
                Baloon(this.NameField, GetString("NameAlreadyInUseError"));
                return(false);
            }

            string toValidate = this.NameField.Text.StartsWith("@") ? this.NameField.Text.Substring(1) : this.NameField.Text;
            string err;

            if (!NameValidation.TryValidateName(toValidate, out err))
            {
                Baloon(this.NameField, err);
                return(false);
            }

            return(true);
        }
コード例 #9
0
        //public ScriptNode<T> Script<T>(string nodeName) where T: struct, IScriptNodeJob => this[nodeName] as ScriptNode<T>;

        #endregion Access

        #region Utility

        public string ValidateNodeName(string name) => NameValidation.ValidateName(name, validationName => !Nodes.ContainsKey(validationName));
コード例 #10
0
        private void okayBtn_OnClick(object sender, EventArgs e)
        {
            NameValidation nameResult = validateNameCriteria();

            switch (nameResult)
            {
            case NameValidation.BadRegex:
                warningLabel.Text    = "Warning: A bad regular expression was provided for the name criteria";
                warningLabel.Visible = true;
                return;
            }

            DateValidation modifiedResult = validateModifiedCriteria();

            switch (modifiedResult)
            {
            case DateValidation.AfterNow:
                warningLabel.Text    = "Warning: The modified date criteria is in the future";
                warningLabel.Visible = true;
                return;

            case DateValidation.NegativeSpan:
                warningLabel.Text    = "Warning: The modified date criteria has inverted begin and end dates";
                warningLabel.Visible = true;
                return;
            }

            DateValidation creationResult = validateCreationCriteria();

            switch (creationResult)
            {
            case DateValidation.AfterNow:
                warningLabel.Text    = "Warning: The creation date criteria is in the future";
                warningLabel.Visible = true;
                return;

            case DateValidation.NegativeSpan:
                warningLabel.Text    = "Warning: The creation date criteria has inverted begin and end dates";
                warningLabel.Visible = true;
                return;
            }

            SizeValidation sizeResult = validateSizeCriteria();

            switch (sizeResult)
            {
            case SizeValidation.SizeBad:
                warningLabel.Text    = "Warning: The size criteria is not a valid number";
                warningLabel.Visible = true;
                return;

            case SizeValidation.FirstSizeBad:
                warningLabel.Text    = "Warning: The size criteria minimum is not a valid number";
                warningLabel.Visible = true;
                return;

            case SizeValidation.SecondSizeBad:
                warningLabel.Text    = "Warning: The size criteria maximum is not a valid number";
                warningLabel.Visible = true;
                return;

            case SizeValidation.NegativeSpan:
                warningLabel.Text    = "Warning: The size criteria has inverted miniumum and maximum values";
                warningLabel.Visible = true;
                return;

            case SizeValidation.LessThanZero:
                warningLabel.Text    = "Warning: The size criteria is less than zero";
                warningLabel.Visible = true;
                return;
            }

            warningLabel.Visible = false;
            DialogResult         = DialogResult.OK;
        }
 private static string ValidateEventName(string name, SerializedProperty events) => NameValidation.ValidateName(name, validationName => !events.Exists(evtAsset => evtAsset.FindPropertyRelative(nameof(StateEventAsset.Name)).stringValue.Equals(validationName)));
コード例 #12
0
ファイル: NameConverterTest.cs プロジェクト: hadoan/solid
        public void Name_3GivenNames_Valid_Converter()
        {
            var nameValidation = new NameValidation();

            nameValidation.IsValidName("This is valid name").ShouldBeTrue();
        }
コード例 #13
0
ファイル: NameConverterTest.cs プロジェクト: hadoan/solid
        public void Name_4GivenNames_Not_Valid_Converter()
        {
            var nameValidation = new NameValidation();

            nameValidation.IsValidName("This is not valid name").ShouldBeFalse();
        }
コード例 #14
0
ファイル: NameConverterTest.cs プロジェクト: hadoan/solid
        public void Name_SingleName_Not_Valid_Converter()
        {
            var nameValidation = new NameValidation();

            nameValidation.IsValidName("Ha").ShouldBeFalse();
        }
コード例 #15
0
 public DataMember(string lastName, string firstName)
 {
     FirstNameState = ValidateName(firstName);
     LastNameState  = ValidateName(lastName);
 }
コード例 #16
0
ファイル: NameConverterTest.cs プロジェクト: hadoan/solid
        public void Name_Blank_Not_Valid_Converter()
        {
            var nameValidation = new NameValidation();

            nameValidation.IsValidName("").ShouldBeFalse();
        }
コード例 #17
0
        public IAzureBlobContainer GetContainerReference(string containerName)
        {
            NameValidation.Container(containerName, "containerName");

            return(new StandaloneAzureBlobContainer(_blobStorageDirectory, containerName));
        }
 private string ValidateStateName(string name) => NameValidation.ValidateName(name, validationName => !_asset.StatesEvents.Exists(state => state.Name.Equals(validationName)));
コード例 #19
0
 public void ValidateNames()
 {
     nameButton = NameValidation.CheckIfNameUnique();
 }
コード例 #20
0
        public IAzureBlobContainer GetContainerReference(string containerName)
        {
            NameValidation.Container(containerName, "containerName");

            return(new HostedAzureBlobContainer(_cloudBlobClient.GetContainerReference(containerName)));
        }
コード例 #21
0
ファイル: Name.cs プロジェクト: snico-dev/sample-store-cqrs
 public override bool IsValid()
 {
     ValidationResult = new NameValidation().Validate(this);
     return(ValidationResult.IsValid);
 }
コード例 #22
0
        /// <exclude />
        public bool ValidateNewTypeNamespace(string typeNamespace, out string message)
        {
            Verify.ArgumentNotNullOrEmpty(typeNamespace, "typeNamespace");

            return(NameValidation.TryValidateNamespace(typeNamespace, out message));
        }
コード例 #23
0
        private static ActionStep ConvertToStep(
            TemplateContext context,
            TemplateToken stepsItem)
        {
            var step            = stepsItem.AssertMapping($"{PipelineTemplateConstants.Steps} item");
            var continueOnError = default(ScalarToken);
            var env             = default(TemplateToken);
            var id             = default(StringToken);
            var ifCondition    = default(String);
            var ifToken        = default(ScalarToken);
            var name           = default(ScalarToken);
            var run            = default(ScalarToken);
            var scope          = default(StringToken);
            var timeoutMinutes = default(ScalarToken);
            var uses           = default(StringToken);
            var with           = default(TemplateToken);
            var workingDir     = default(ScalarToken);
            var path           = default(ScalarToken);
            var clean          = default(ScalarToken);
            var fetchDepth     = default(ScalarToken);
            var lfs            = default(ScalarToken);
            var submodules     = default(ScalarToken);
            var shell          = default(ScalarToken);

            foreach (var stepProperty in step)
            {
                var propertyName = stepProperty.Key.AssertString($"{PipelineTemplateConstants.Steps} item key");

                switch (propertyName.Value)
                {
                case PipelineTemplateConstants.Clean:
                    clean = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Clean}");
                    break;

                case PipelineTemplateConstants.ContinueOnError:
                    ConvertToStepContinueOnError(context, stepProperty.Value, allowExpressions: true);     // Validate early if possible
                    continueOnError = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} {PipelineTemplateConstants.ContinueOnError}");
                    break;

                case PipelineTemplateConstants.Env:
                    ConvertToStepEnvironment(context, stepProperty.Value, StringComparer.Ordinal, allowExpressions: true);     // Validate early if possible
                    env = stepProperty.Value;
                    break;

                case PipelineTemplateConstants.FetchDepth:
                    fetchDepth = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.FetchDepth}");
                    break;

                case PipelineTemplateConstants.Id:
                    id = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Id}");
                    if (!NameValidation.IsValid(id.Value, true))
                    {
                        context.Error(id, $"Step id {id.Value} is invalid. Ids must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'");
                    }
                    break;

                case PipelineTemplateConstants.If:
                    ifToken = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.If}");
                    break;

                case PipelineTemplateConstants.Lfs:
                    lfs = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Lfs}");
                    break;

                case PipelineTemplateConstants.Name:
                    name = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Name}");
                    break;

                case PipelineTemplateConstants.Path:
                    path = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Path}");
                    break;

                case PipelineTemplateConstants.Run:
                    run = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Run}");
                    break;

                case PipelineTemplateConstants.Shell:
                    shell = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Shell}");
                    break;

                case PipelineTemplateConstants.Scope:
                    scope = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Scope}");
                    break;

                case PipelineTemplateConstants.Submodules:
                    submodules = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Submodules}");
                    break;

                case PipelineTemplateConstants.TimeoutMinutes:
                    ConvertToStepTimeout(context, stepProperty.Value, allowExpressions: true);     // Validate early if possible
                    timeoutMinutes = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.TimeoutMinutes}");
                    break;

                case PipelineTemplateConstants.Uses:
                    uses = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Uses}");
                    break;

                case PipelineTemplateConstants.With:
                    ConvertToStepInputs(context, stepProperty.Value, allowExpressions: true);     // Validate early if possible
                    with = stepProperty.Value;
                    break;

                case PipelineTemplateConstants.WorkingDirectory:
                    workingDir = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.WorkingDirectory}");
                    break;

                default:
                    propertyName.AssertUnexpectedValue($"{PipelineTemplateConstants.Steps} item key");     // throws
                    break;
                }
            }

            // Fixup the if-condition
            var isDefaultScope = String.IsNullOrEmpty(scope?.Value);

            ifCondition = ConvertToIfCondition(context, ifToken, false, isDefaultScope);

            if (run != null)
            {
                var result = new ActionStep
                {
                    ScopeName        = scope?.Value,
                    ContextName      = id?.Value,
                    ContinueOnError  = continueOnError,
                    DisplayNameToken = name,
                    Condition        = ifCondition,
                    TimeoutInMinutes = timeoutMinutes,
                    Environment      = env,
                    Reference        = new ScriptReference(),
                };

                var inputs = new MappingToken(null, null, null);
                inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Script), run);

                if (workingDir != null)
                {
                    inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.WorkingDirectory), workingDir);
                }

                if (shell != null)
                {
                    inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Shell), shell);
                }

                result.Inputs = inputs;

                return(result);
            }
            else
            {
                uses.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Uses}");
                var result = new ActionStep
                {
                    ScopeName        = scope?.Value,
                    ContextName      = id?.Value,
                    ContinueOnError  = continueOnError,
                    DisplayNameToken = name,
                    Condition        = ifCondition,
                    TimeoutInMinutes = timeoutMinutes,
                    Inputs           = with,
                    Environment      = env,
                };

                if (uses.Value.StartsWith("docker://", StringComparison.Ordinal))
                {
                    var image = uses.Value.Substring("docker://".Length);
                    result.Reference = new ContainerRegistryReference {
                        Image = image
                    };
                }
                else if (uses.Value.StartsWith("./") || uses.Value.StartsWith(".\\"))
                {
                    result.Reference = new RepositoryPathReference
                    {
                        RepositoryType = PipelineConstants.SelfAlias,
                        Path           = uses.Value
                    };
                }
                else
                {
                    var usesSegments = uses.Value.Split('@');
                    var pathSegments = usesSegments[0].Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                    var gitRef       = usesSegments.Length == 2 ? usesSegments[1] : String.Empty;

                    if (usesSegments.Length != 2 ||
                        pathSegments.Length < 2 ||
                        String.IsNullOrEmpty(pathSegments[0]) ||
                        String.IsNullOrEmpty(pathSegments[1]) ||
                        String.IsNullOrEmpty(gitRef))
                    {
                        // todo: loc
                        context.Error(uses, $"Expected format {{org}}/{{repo}}[/path]@ref. Actual '{uses.Value}'");
                    }
                    else
                    {
                        var repositoryName = $"{pathSegments[0]}/{pathSegments[1]}";
                        var directoryPath  = pathSegments.Length > 2 ? String.Join("/", pathSegments.Skip(2)) : String.Empty;

                        result.Reference = new RepositoryPathReference
                        {
                            RepositoryType = RepositoryTypes.GitHub,
                            Name           = repositoryName,
                            Ref            = gitRef,
                            Path           = directoryPath,
                        };
                    }
                }

                return(result);
            }
        }