Exemplo n.º 1
0
        protected virtual IQueryable <TEntity> CheckSpecifications(SpecificationList <TEntity, TFilter> specifications, IQueryable <TEntity> source, TFilter filter)
        {
            AppliedFilters = 0;
            AppliedOrders  = 0;

            foreach (var specification in specifications.Items)
            {
                if (specification.Condition(filter))
                {
                    AppliedFilters++;
                    source = source.Where(specification.Predicate);
                }
            }

            foreach (var item in specifications.Order)
            {
                if (item.Condition(filter))
                {
                    AppliedOrders++;
                    source = item.Sort(source);
                }
            }

            if (specifications.PageNumber > 0 && specifications.PageSize > 0)
            {
                source = source.Skip((specifications.PageNumber - 1) * specifications.PageSize).Take(specifications.PageSize);
            }

            return(source);
        }
        public override WAVSound GenerateWord(string word)
        {
            int      wordIndex = wordToSoundMappingList.FindIndex(m => m.Word == word);
            WAVSound wordSound = null;

            if (wordIndex >= 0)
            {
                WordToSoundMapping wordToSoundMapping = wordToSoundMappingList[wordIndex];
                List <WAVSound>    wavSoundList       = new List <WAVSound>();
                foreach (string soundName in wordToSoundMapping.SoundNameList)
                {
                    FormantSpecification formantSpecification = SpecificationList.Find(s => s.Name == soundName);
                    if (formantSpecification != null)
                    {
                        formantSpecification.GenerateSettingsSequence();
                        WAVSound sound = GenerateSound(formantSpecification);
                        wavSoundList.Add(sound);
                    }
                }
                if (wavSoundList.Count > 0)
                {
                    wordSound = WAVSound.Join(wavSoundList, null);
                }
            }
            return(wordSound);
        }
        protected SpecificationList <TEntity> NewSpecificationList(bool addCheckNullObject = true)
        {
            var result = new SpecificationList <TEntity>();

            if (addCheckNullObject)
            {
                ISpecificationValidation <TEntity> basicSpecification = new AndIsNotEmpty <TEntity, object>(c => c, AndIsNotEmptyType.Object, true, "Entity {0} can't be null", typeof(TEntity).Name);
                result.Add(basicSpecification, true);
            }

            return(result);
        }
Exemplo n.º 4
0
        protected virtual bool CheckSpecifications(SpecificationList <TEntity> specifications, TEntity entity, Execute execute)
        {
            var result = true;

            foreach (var item in specifications.Items)
            {
                if (!item.Condition(entity))
                {
                    continue;
                }

                var satisfied = item.Specification.IsSatisfiedBy(entity, execute);
                result = result && satisfied;

                if (!result && item.StopIfInvalid)
                {
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public static SpecificationList <TEntity, TFilter> OrderBy <TEntity, TFilter, TProperty>(this SpecificationList <TEntity, TFilter> specification, Expression <Func <TEntity, TProperty> > property, Func <TFilter, bool> condition, bool descending)
        {
            if (descending)
            {
                specification.Order.Add(new SpecificationOrder <TEntity, TFilter>(items => items.OrderByDescending(property), condition));
            }
            else
            {
                specification.Order.Add(new SpecificationOrder <TEntity, TFilter>(items => items.OrderBy(property), condition));
            }

            return(specification);
        }
Exemplo n.º 6
0
 public static SpecificationList <TEntity, TFilter> OrderBy <TEntity, TFilter, TProperty>(this SpecificationList <TEntity, TFilter> specification, Expression <Func <TEntity, TProperty> > property)
 => specification.OrderBy(property, f => true, false);
Exemplo n.º 7
0
 public static SpecificationList <TEntity, TFilter> OrderBy <TEntity, TFilter, TProperty>(this SpecificationList <TEntity, TFilter> specification, Expression <Func <TEntity, TProperty> > property, bool condition = true, bool descending = false)
 => specification.OrderBy(property, f => condition, descending);
Exemplo n.º 8
0
 public static SpecificationList <TEntity, TFilter> OrderByDesc <TEntity, TFilter, TProperty>(this SpecificationList <TEntity, TFilter> specification, Expression <Func <TEntity, TProperty> > property, bool condition)
 => specification.OrderBy(property, f => condition, true);
Exemplo n.º 9
0
 public static SpecificationList <TEntity> Or <TEntity>(this SpecificationList <TEntity> specification, ISpecificationValidation <TEntity> spec1, ISpecificationValidation <TEntity> spec2, bool stopIfInvalid = false)
 => specification.Or(spec1, spec2, c => true, stopIfInvalid);
Exemplo n.º 10
0
 public static SpecificationList <TEntity, TFilter> Take <TEntity, TFilter>(this SpecificationList <TEntity, TFilter> specification, int pageNumber, int pageSize)
 {
     specification.PageNumber = pageNumber;
     specification.PageSize   = pageSize;
     return(specification);
 }
Exemplo n.º 11
0
 public static SpecificationList <TEntity, TFilter> Take <TEntity, TFilter>(this SpecificationList <TEntity, TFilter> specification, FilterBase filter)
 {
     specification.PageNumber = filter?.PageNumber ?? 0;
     specification.PageSize   = filter?.PageSize ?? 0;
     return(specification);
 }
Exemplo n.º 12
0
 public static SpecificationList <TEntity> AndIsNotEmpty <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector)
 => specification.AndIsNotEmpty(selector, c => true, false, "Property value is empty", null);
Exemplo n.º 13
0
 public static SpecificationList <TEntity> AndIsUrl <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, string message, params object[] args)
 => specification.AndIsUrl(selector, c => true, false, message, args);
Exemplo n.º 14
0
 public static SpecificationList <TEntity> AndIsUrl <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, Func <TEntity, bool> condition, bool stopIfInvalid, string message, params object[] args)
 {
     return(specification.AndRegexValid(selector, LibraryRegex.URL, condition, stopIfInvalid, message, args));
 }
Exemplo n.º 15
0
 public static SpecificationList <TEntity> AndIsEmail <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, bool condition, bool stopIfInvalid, string message, params object[] args)
 => specification.AndIsEmail(selector, c => condition, stopIfInvalid, message, args);
 public static SpecificationList <TEntity> AndIsValidAsync <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, Task <bool> > selector, Func <TEntity, bool> condition, bool stopIfInvalid, string message = "", params object[] args)
 {
     specification.Add(new AndIsValidAsync <TEntity>(selector, condition, message, args), stopIfInvalid);
     return(specification);
 }
 public static SpecificationList <TEntity> AndIsValidAsync <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, Task <bool> > selector, string message, params object[] args)
 => specification.AndIsValidAsync(selector, c => true, false, message, args);
Exemplo n.º 18
0
 public static SpecificationList <TEntity> AndIsNotEmpty <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, Func <TEntity, bool> condition, string message, params object[] args)
 => specification.AndIsNotEmpty(selector, condition, false, message, args);
Exemplo n.º 19
0
 public static SpecificationList <TEntity> AndIsValid <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, bool> selector)
 => specification.AndIsValid(selector, c => true, false, "Invalid value", null);
Exemplo n.º 20
0
 public static SpecificationList <TEntity> AndIsNotEmpty <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, Func <TEntity, bool> condition, bool stopIfInvalid, string message = "", params object[] args)
 {
     specification.Add(new AndIsNotEmpty <TEntity, string>(selector, AndIsNotEmptyType.String, condition, message, args), stopIfInvalid);
     return(specification);
 }
Exemplo n.º 21
0
 public static SpecificationList <TEntity> AndRegexValid <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, string expression, Func <TEntity, bool> condition, bool stopIfInvalid, string message, params object[] args)
 {
     specification.Add(new AndIsValidRegex <TEntity>(selector, expression, condition, message, args), stopIfInvalid);
     return(specification);
 }
Exemplo n.º 22
0
 public static SpecificationList <TEntity> AndMerge <TEntity>(this SpecificationList <TEntity> specification, SpecificationList <TEntity> specificationList, bool condition, bool stopIfInvalid = false)
 => specification.AndMerge(specificationList, c => condition, stopIfInvalid);
Exemplo n.º 23
0
 public static SpecificationList <TEntity> Or <TEntity>(this SpecificationList <TEntity> specification, ISpecificationValidation <TEntity> spec1, ISpecificationValidation <TEntity> spec2, Func <TEntity, bool> condition, bool stopIfInvalid = false)
 {
     specification.Add(new Or <TEntity>(spec1, spec2, condition), stopIfInvalid);
     return(specification);
 }
Exemplo n.º 24
0
 public static SpecificationList <TEntity> AndIsValid <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, bool> selector, bool condition, string message, params object[] args)
 => specification.AndIsValid(selector, c => condition, false, message, args);
Exemplo n.º 25
0
 public static SpecificationList <TEntity> AndMerge <TEntity>(this SpecificationList <TEntity> specification, SpecificationList <TEntity> specificationList, Func <TEntity, bool> condition, bool stopIfInvalid = false)
 {
     specification.Add(new AndMerge <TEntity>(specificationList, condition), stopIfInvalid);
     return(specification);
 }
Exemplo n.º 26
0
 public static SpecificationList <TEntity> AndRegexValid <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, string expression, bool condition, bool stopIfInvalid, string message, params object[] args)
 => specification.AndRegexValid(selector, expression, c => condition, stopIfInvalid, message, args);
Exemplo n.º 27
0
 public static SpecificationList <TEntity> AndIsEmail <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector)
 => specification.AndIsEmail(selector, c => true, false, "Invalid email", new object[] { });
Exemplo n.º 28
0
 public static SpecificationList <TEntity> AndRegexValid <TEntity>(this SpecificationList <TEntity> specification, Func <TEntity, string> selector, string expression, string message, params object[] args)
 => specification.AndRegexValid(selector, expression, c => true, false, message, args);
Exemplo n.º 29
0
 public static SpecificationList <TEntity, TFilter> And <TEntity, TFilter>(this SpecificationList <TEntity, TFilter> specification, Expression <Func <TEntity, bool> > predicate, bool condition = true)
 {
     specification.Items.Add(new SpecificationItem <TEntity, TFilter>(predicate, x => condition));
     return(specification);
 }