Friday, March 6, 2015

What is category in Event Store?

 If put dash into stream name, the first part will be saved as category name

Source code from Event Store 

  _handler = new CategorizeEventsByStreamPath("-", Console.WriteLine);

        public override string GetCategoryByStreamId(string streamId)
        {
            string category = null;
            if (!streamId.StartsWith("$"))
            {
                var lastSeparatorPosition = streamId.IndexOf(_separator);
                if (lastSeparatorPosition > 0)
                    category = streamId.Substring(0, lastSeparatorPosition);
            }
            return category;

        }



http://codeofrob.com/entries/creating-a-projection-per-stream-in-the-eventstore.html

How to add Multiple Regular Expression Validation attribute into one Property in ASP.Net MVC?



Create another new attribute and inherit from RegularExpressionAttribute

    public class RegularExpressionAttribute : ValidationAttribute
    {
        private string _pattern;
        public RegularExpressionAttribute(string pattern)
        {
            _pattern = pattern;
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null) return null;
            if (!System.Text.RegularExpressions.Regex.IsMatch(value.ToString(), _pattern))
            {
                return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
            }
            return null;
        }

    public class RegularExpression2ndAttribute : RegularExpressionAttribute {}


So in view model:
        [ValidURL(ErrorMessage = "Invalid URL")]
        [RegularExpression(@"^.*\.(jpg|JPG|gif|GIF|jpeg)$", ErrorMessage = "Not a image URL")]
        public string LogoUrl { get; set; }