Пример #1
0
        public void CanMatchColor()
        {
            Color c1 = new ColorRepository().Get(1);  //Black
            Color c2 = new ColorRepository().Get(8);  //Red
            Color c3 = new ColorRepository().Get(4);  //Beige
            Color c4 = new ColorRepository().Get(24); //Dark Blue Green

            HashSet <Color> colors = new HashSet <Color>();

            colors.Add(c1);
            colors.Add(c2);
            colors.Add(c3);
            colors.Add(c4);

            HashSet <ColorFamily> colorFamiliesHash = new HashSet <ColorFamily>();

            colorFamiliesHash.Add(c1.Family);
            colorFamiliesHash.Add(c2.Family);
            colorFamiliesHash.Add(c3.Family);
            colorFamiliesHash.Add(c4.Family);

            HashSet <PatternType> pt = new HashSet <PatternType>();

            pt.Add(new PatternRepository().Get(1).Type);

            HashSet <StructureType> st = new HashSet <StructureType>();

            st.Add(StructureType.Structured);

            HashSet <ShapeType> sh = new HashSet <ShapeType>();

            sh.Add(ShapeType.Fitted100);
            sh.Add(ShapeType.Fitted600Plus);

            StyleRule sr = new StyleRuleRepository().Get(8);

            Assert.IsFalse(OutfitValidationService.IsValidCombination(
                               colorFamiliesHash,
                               colors,
                               pt,
                               null,
                               sr,
                               null,
                               false,
                               false));
        }
Пример #2
0
 public override bool IsValid()
 {
     return(OutfitValidationService.IsValidCombination(this.Components));
 }
Пример #3
0
        /// <summary>
        /// Creates a new closet outfit in the system related with the current user.
        /// </summary>
        /// <param name="userId">User</param>
        /// <param name="garments">List of Garments</param>
        /// <param name="season">Season</param>
        /// <param name="visibility">Visibility</param>
        /// <exception cref="NotValidCombinationException">When a combination is not valid.</exception>
        public void CreateUserOutfit(int userId, IList <Garment> garments, Season season, ClosetOutfitVisibility visibility)
        {
            if (!OutfitValidationService.IsValidCombination(garments))
            {
                throw new NotValidCombinationException();
            }

            ClosetOutfit uo = new ClosetOutfit();

            // HACK: We need the garments saved with 0 in the non filled fields to make sure we have no duplicates.
            Garment hack = garmentRepository.Get(0);

            foreach (Garment g in garments)
            {
                uo.AddComponent(g, hack);
            }

            uo.Rating.CalculateEditorRating(uo.Components);

            BasicUser     bu = basicUserRepository.Get(userId);
            FashionFlavor ff = bu.GetPreferredFlavor();

            uo.FashionFlavor = ff;
            uo.Closet        = (bu as RegisteredUser).Closet;

            uo.SetSeason(season);
            uo.SetEventTypes(bu as RegisteredUser);
            uo.SetVisibility(visibility);

            //Agregar PreCombination
            PreCombination pc = preCombinationRepository.GetByGarments(uo.RetrieveCombinableComponents().ToList <Garment>(), ff);

            if (pc == null)
            {
                pc = new PreCombination();
                pc.FashionFlavor = ff;

                for (int j = 0; j < garments.Count; j++)
                {
                    Garment g = garments[j];
                    if (!OutfitValidationService.IsAccessory(g))
                    {
                        pc.AddPreGarment(garments[j]);
                    }
                }
            }

            uo.PreCombination = pc;
            uo.User           = bu as RegisteredUser;

            if (!uo.IsValid())
            {
                throw new NotValidCombinationException();
            }

            closetOutfitRepository.DbContext.BeginTransaction();

            // REVIEW: This may lead to orphaned records, given we cannot change the autonumeric for now because of the combination process.
            // TODO: Is better to check first if the Closet Outfit combination already exists and then proceed.
            preCombinationRepository.SaveOrUpdate(pc);

            try
            {
                closetOutfitRepository.SaveOrUpdate(uo);
                closetOutfitRepository.DbContext.BeginTransaction();
            }
            catch
            {
                closetOutfitRepository.DbContext.RollbackTransaction();
                throw new CombinationAlreadyExistsException();
            }
        }
Пример #4
0
        private IList <OutfitUpdaterByPreCombination> GetOutfitUpdatersByPreCombinations(IEnumerable <OutfitUpdater> outfitUpdaters, IEnumerable <PreCombination> lst)
        {
            IList <StyleRule> lstStyleRules = styleRuleRepository.GetAll();
            IList <OutfitUpdaterByPreCombination> result = new List <OutfitUpdaterByPreCombination>();

            // Exclude By Rules
            foreach (PreCombination pcb in lst)
            {
                var styleRule = from s in lstStyleRules
                                where s.FashionFlavor.Id == pcb.FashionFlavor.Id
                                select s;

                StyleRule sr = styleRule.First <StyleRule>();

                logger.InfoFormat("Matching PrecombinationId : {0}", pcb.Id);

                foreach (OutfitUpdater outfitUpdater in outfitUpdaters)
                {
                    HashSet <ColorFamily> colorFamiliesHash = new HashSet <ColorFamily>();
                    if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1))
                    {
                        colorFamiliesHash.Add(pcb.Garment1.ColorFamily);
                    }
                    if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2))
                    {
                        colorFamiliesHash.Add(pcb.Garment2.ColorFamily);
                    }
                    if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3))
                    {
                        colorFamiliesHash.Add(pcb.Garment3.ColorFamily);
                    }
                    if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4))
                    {
                        colorFamiliesHash.Add(pcb.Garment4.ColorFamily);
                    }
                    if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5))
                    {
                        colorFamiliesHash.Add(pcb.Garment5.ColorFamily);
                    }
                    colorFamiliesHash.Add(outfitUpdater.ColorFamily);

                    HashSet <PatternType> pt = new HashSet <PatternType>();
                    if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1))
                    {
                        pt.Add(pcb.Garment1.PatternType);
                    }
                    if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2))
                    {
                        pt.Add(pcb.Garment2.PatternType);
                    }
                    if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3))
                    {
                        pt.Add(pcb.Garment3.PatternType);
                    }
                    if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4))
                    {
                        pt.Add(pcb.Garment4.PatternType);
                    }
                    if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5))
                    {
                        pt.Add(pcb.Garment5.PatternType);
                    }
                    pt.Add(outfitUpdater.Pattern.Type);

                    HashSet <StructureType> st = new HashSet <StructureType>();
                    if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1))
                    {
                        st.Add(pcb.Garment1.Silouhette.Structure.Type);
                    }
                    if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2))
                    {
                        st.Add(pcb.Garment2.Silouhette.Structure.Type);
                    }
                    if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3))
                    {
                        st.Add(pcb.Garment3.Silouhette.Structure.Type);
                    }
                    if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4))
                    {
                        st.Add(pcb.Garment4.Silouhette.Structure.Type);
                    }
                    if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5))
                    {
                        st.Add(pcb.Garment5.Silouhette.Structure.Type);
                    }
                    if (outfitUpdater.Silouhette.Structure != null)
                    {
                        st.Add(outfitUpdater.Silouhette.Structure.Type);
                    }

                    HashSet <ShapeType> sh = new HashSet <ShapeType>();
                    if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1))
                    {
                        sh.Add(pcb.Garment1.Silouhette.Shape.Type);
                    }
                    if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2))
                    {
                        sh.Add(pcb.Garment2.Silouhette.Shape.Type);
                    }
                    if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3))
                    {
                        sh.Add(pcb.Garment3.Silouhette.Shape.Type);
                    }
                    if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4))
                    {
                        sh.Add(pcb.Garment4.Silouhette.Shape.Type);
                    }
                    if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5))
                    {
                        sh.Add(pcb.Garment5.Silouhette.Shape.Type);
                    }
                    if (outfitUpdater.Silouhette.Shape != null)
                    {
                        sh.Add(outfitUpdater.Silouhette.Shape.Type);
                    }

                    if (OutfitValidationService.IsValidCombination(
                            colorFamiliesHash,
                            null,
                            pt,
                            st,
                            sr,
                            sh,
                            pcb.Garment1.Silouhette.Layers.Contains(LayerCode.Ai),
                            OutfitValidationService.IsAccessory(outfitUpdater.Silouhette)))
                    {
                        result.Add(new OutfitUpdaterByPreCombination(outfitUpdater, pcb));
                    }
                }
            }

            return(result);
        }
Пример #5
0
        public bool ExcludeCombinations(StyleRule sr, IEnumerable <Combination> lst)
        {
            foreach (Combination cb in lst)
            {
                if (!OutfitValidationService.IsValidCombination(cb, sr))
                {
                    continue;
                }

                var fabrics = new HashSet <Fabric>();
                if (cb.GarmentA != null)
                {
                    fabrics.Add(cb.GarmentA.Tags.Fabric);
                }
                if (cb.GarmentB != null)
                {
                    fabrics.Add(cb.GarmentB.Tags.Fabric);
                }
                if (cb.GarmentC != null)
                {
                    fabrics.Add(cb.GarmentC.Tags.Fabric);
                }
                if (cb.GarmentD != null)
                {
                    fabrics.Add(cb.GarmentD.Tags.Fabric);
                }
                if (cb.GarmentE != null)
                {
                    fabrics.Add(cb.GarmentE.Tags.Fabric);
                }

                var colors = new HashSet <Color>();
                if (cb.GarmentA != null)
                {
                    colors.Add(cb.GarmentA.Tags.Colors[0]);
                }
                if (cb.GarmentB != null)
                {
                    colors.Add(cb.GarmentB.Tags.Colors[0]);
                }
                if (cb.GarmentC != null)
                {
                    colors.Add(cb.GarmentC.Tags.Colors[0]);
                }
                if (cb.GarmentD != null)
                {
                    colors.Add(cb.GarmentD.Tags.Colors[0]);
                }
                if (cb.GarmentE != null)
                {
                    colors.Add(cb.GarmentE.Tags.Colors[0]);
                }

                var pt = new HashSet <PatternType>();
                if (cb.GarmentA != null)
                {
                    pt.Add(cb.GarmentA.Tags.Pattern.Type);
                }
                if (cb.GarmentB != null)
                {
                    pt.Add(cb.GarmentB.Tags.Pattern.Type);
                }
                if (cb.GarmentC != null)
                {
                    pt.Add(cb.GarmentC.Tags.Pattern.Type);
                }
                if (cb.GarmentD != null)
                {
                    pt.Add(cb.GarmentD.Tags.Pattern.Type);
                }
                if (cb.GarmentE != null)
                {
                    pt.Add(cb.GarmentE.Tags.Pattern.Type);
                }

                cb.EditorRating = EditorRatingCalculatorService.CalculateRating(colors, fabrics, pt);

                cb.FashionFlavor = sr.FashionFlavor;
                flavorCombinations.Add(cb);
            }

            if (flavorCombinations.Count > 0)
            {
                return(ProcessFoundCombinations(sr));
            }

            return(false);
        }