Exemple #1
0
        internal void UnselectType(string type)
        {
            // Remove types from selected types list
            var selected = SelectedList.Items.Cast <TypeWrapper>().ToList();

            selected.Remove(selected.First(t => t.TypeName.Equals(type, StringComparison.InvariantCulture)));
            SelectedList.ItemsSource = selected;

            // Unselected types list must only
            // show types compatible with all
            // the selected ones.
            var available       = wardrobe.Garments.Select(g => g.Type.ToString());
            var compatibilities = selected.Select(w => w.TypeName)
                                  .Select(t => new
            {
                TypeName    = t,
                Compatibles = ClothingTypeUtil.CompatibleWith(t)
            });

            foreach (var compatible in compatibilities)
            {
                available = available.Intersect(compatible.Compatibles);
            }
            UnselectedList.ItemsSource = available.Select(t => new TypeWrapper
            {
                TypeName            = t,
                TypeSelectCommand   = new TypeSelectCommand(this),
                TypeUnselectCommand = new TypeUnselectCommand(this)
            });
        }
Exemple #2
0
        internal static OneOf <IEnumerable <Garment>, IFailure> GarmentsFor(string user)
        {
            var result = new List <Garment>();

            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "Profiles");
            path = Path.Combine(path, $"{user}.Wardrobe.xml");

            if (!File.Exists(path))
            {
                return(new UserHasNoWardrobeFailure(user));
            }

            var config = XmlConfig.From(path);

            if (config.Read("Clothes") is null)
            {
                return(result);
            }
            foreach (var garment in config.Read("Clothes").Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                result.Add(new Garment
                {
                    ID           = garment,
                    Name         = config.Read($"{garment}:Name"),
                    Type         = ClothingTypeUtil.Parse(config.Read($"{garment}:Type")),
                    PurchaseDate = new PurchaseDate(config.Read($"{garment}:PurchaseDate")),
                    ColorTags    = new ReadOnlyCollection <string>(config.Read($"{garment}:ColorTags").Split(' ')),
                    StyleTags    = new ReadOnlyCollection <string>(config.Read($"{garment}:StyleTags").Split(' ')),
                    UserTags     = new ReadOnlyCollection <string>(config.Read($"{garment}:UserTags").Split(' '))
                });
            }

            return(result);
        }