public Guid GetDynamicID(string originalPath)
        {
            Guid id = Guid.Empty;

            string relativePath = Converter.ToRelative(originalPath);

            string[] parts = relativePath.Trim('/').Split('/');

            if (parts.Length >= 2)
            {
                string idString = parts[1];

                // If the id string contains a dot then it's a file name and needs to be fixed
                if (idString.IndexOf('.') > -1)
                {
                    idString = Path.GetFileNameWithoutExtension(idString);
                }

                if (GuidValidator.IsValidGuid(idString))
                {
                    id = GuidValidator.ParseGuid(idString);
                }
            }
            return(id);
        }
		/// <summary>
		/// Constructs and configures an <see cref="IValidator"/>
		/// instance based on the properties set on the attribute instance.
		/// </summary>
		/// <returns></returns>
		public override IValidator Build()
		{
			IValidator validator = new GuidValidator(acceptEmptyGuid);

			ConfigureValidatorMessage(validator);

			return validator;
		}
Beispiel #3
0
        /// <summary>
        /// Constructs and configures an <see cref="IValidator"/>
        /// instance based on the properties set on the attribute instance.
        /// </summary>
        /// <returns></returns>
        public override IValidator Build()
        {
            IValidator validator = new GuidValidator(acceptEmptyGuid);

            ConfigureValidatorMessage(validator);

            return(validator);
        }
Beispiel #4
0
        public ImportListExclusionController(IImportListExclusionService importListExclusionService,
                                             ImportListExclusionExistsValidator importListExclusionExistsValidator,
                                             GuidValidator guidValidator)
        {
            _importListExclusionService = importListExclusionService;

            SharedValidator.RuleFor(c => c.ForeignId).NotEmpty().SetValidator(guidValidator).SetValidator(importListExclusionExistsValidator);
            SharedValidator.RuleFor(c => c.AuthorName).NotEmpty();
        }
		private void setup(bool acceptEmptyGuid)
		{
			Thread.CurrentThread.CurrentCulture =
				Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

			validator = new GuidValidator(acceptEmptyGuid);
			
			validator.Initialize(new CachedValidationRegistry(), typeof (TestTarget).GetProperty("TargetField"));
			target = new TestTarget();
		}
        private void setup(bool acceptEmptyGuid)
        {
            Thread.CurrentThread.CurrentCulture       =
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

            validator = new GuidValidator(acceptEmptyGuid);

            validator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField"));
            target = new TestTarget();
        }
Beispiel #7
0
        public static bool IsValidGuid(this string guidCandidate)
        {
            if (string.IsNullOrWhiteSpace(guidCandidate))
            {
                return(false);
            }

            var result = new GuidValidator().Validate(guidCandidate).IsValid;

            return(result);
        }
        public void ValidateGuidToBeEmpty()
        {
            // Given
            var validator = new GuidValidator(Guid.Empty);

            // When
            validator.BeEmpty();

            // Then
            Assert.True(true);
        }
            public void ShouldBeDirtyOnceValidated()
            {
                // Arrange
                string value     = "Test";
                var    validator = new GuidValidator();

                // Act
                validator.Validate(value);

                // Assert
                validator.IsDirty.ShouldBe(true);
            }
            public void ShouldBeValidIfGuidType()
            {
                // Arrange
                var value     = Guid.NewGuid();
                var validator = new GuidValidator();

                // Act
                validator.Validate(value);

                // Assert
                validator.IsInvalid.ShouldBe(false);
            }
            public void ShouldBeValidIfStringGuid()
            {
                // Arrange
                var value     = "f39bc65d-dcb5-47f1-a3ba-51fb5f584fd9";
                var validator = new GuidValidator();

                // Act
                validator.Validate(value);

                // Assert
                validator.IsInvalid.ShouldBe(false);
            }
            public void ShouldBeInvalidIfNotGuid()
            {
                // Arrange
                const string value     = "Test";
                var          validator = new GuidValidator();

                // Act
                validator.Validate(value);

                // Assert
                validator.IsInvalid.ShouldBe(true);
            }
        public ImportListExclusionModule(IImportListExclusionService importListExclusionService,
                                         ImportListExclusionExistsValidator importListExclusionExistsValidator,
                                         GuidValidator guidValidator)
        {
            _importListExclusionService = importListExclusionService;

            GetResourceById = GetImportListExclusion;
            GetResourceAll  = GetImportListExclusions;
            CreateResource  = AddImportListExclusion;
            UpdateResource  = UpdateImportListExclusion;
            DeleteResource  = DeleteImportListExclusionResource;

            SharedValidator.RuleFor(c => c.ForeignId).NotEmpty().SetValidator(guidValidator).SetValidator(importListExclusionExistsValidator);
            SharedValidator.RuleFor(c => c.ArtistName).NotEmpty();
        }
        public async Task <ActionResult <GuidDataResponse> > GetGuidData(string guid)
        {
            GuidValidator.EnsureValid(guid);

            var response = await _provider.GetGuidData(guid);

            if (response != null)
            {
                return(Ok(response));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <ActionResult> DeleteGuidData(string guid)
        {
            GuidValidator.EnsureValid(guid);

            var success = await _provider.DeleteGuidData(guid);

            if (success)
            {
                return(NoContent());
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <ActionResult <GuidDataResponse> > UpsertGuidData(string guid, GuidDataRequest request)
        {
            GuidValidator.EnsureValid(guid);
            GuidDataRequestValidator.EnsureValid(request);

            var(response, isUpdated) = await _provider.UpsertGuidData(guid, request);

            if (isUpdated)
            {
                return(Ok(response));
            }
            else
            {
                return(Created(UriHelper.GetEncodedUrl(Request), response));
            }
        }
        public void ValidateGuidToBeEmptyViolated()
        {
            // Given
            var guid      = Guid.NewGuid();
            var validator = new GuidValidator(guid);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeEmpty(because: "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"{guid}\"{rn}but was expected to be empty{rn}because that's the bottom line",
                exception.UserMessage);
        }
        /// <summary>
        /// Selects the appropriate items depending on the SelectedEntityIDs.
        /// </summary>
        protected void SelectItems()
        {
            using (LogGroup logGroup = LogGroup.Start("Selecting the items that match the info specified.", NLog.LogLevel.Debug))
            {
                Guid[] selectedEntityIDs = new Guid[] {};

                if (ViewState["SelectedEntityIDs"] != null)
                {
                    LogWriter.Debug("ViewState[\"SelectedEntityIDs\"] != null");

                    selectedEntityIDs = (Guid[])ViewState["SelectedEntityIDs"];
                }
                else
                {
                    LogWriter.Debug("ViewState[\"SelectedEntityIDs\"] == null");
                }


                LogWriter.Debug("# of selected entities: " + selectedEntityIDs.Length.ToString());

                foreach (ListItem item in Items)
                {
                    using (LogGroup logGroup2 = LogGroup.Start("Selecting/deselecting item.", NLog.LogLevel.Debug))
                    {
                        Guid id = Guid.Empty;

                        if (GuidValidator.IsValidGuid(item.Value))
                        {
                            id = GuidValidator.ParseGuid(item.Value);
                        }

                        LogWriter.Debug("item.Text: " + item.Text);
                        LogWriter.Debug("item.Value: " + item.Value);
                        item.Selected = (Array.IndexOf(selectedEntityIDs, id) > -1);
                        LogWriter.Debug("item.Selected: " + item.Selected.ToString());
                    }
                }
            }
        }
 public void Init()
 {
     _validator = new GuidValidator();
 }