상속: INotifyPropertyChanged
예제 #1
0
        private void LoadClicked(object sender, RoutedEventArgs e)
        {
            if (setsCombo.SelectedItem == null)
            {
                return;
            }
            if (propertyCombo.SelectedItem == null)
            {
                return;
            }
            if (!Directory.Exists(FolderDir))
            {
                return;
            }
            Items.Clear();
            var selectedSet = setsCombo.SelectedItem as Set;

            var selectedProperty = propertyCombo.SelectedItem as PropertyDef;

            ImagePaths = new ObservableCollection <string>(Directory.EnumerateFiles(FolderDir).Where(file => Regex.IsMatch(file, @"^.+\.(jpg|jpeg|png)$")));

            foreach (var c in selectedSet.Cards)
            {
                foreach (var alternate in c.PropertySets)
                {
                    var card = new Card(c);
                    card.Alternate = alternate.Key;
                    string cardPropertyValue;
                    if (selectedProperty.Name == "Name")
                    {
                        cardPropertyValue = card.PropertySets[card.Alternate].Name;
                    }
                    else
                    {
                        cardPropertyValue = card.PropertySets[card.Alternate].Properties[selectedProperty].ToString();
                    }
                    var sanitizedValue = SanitizeString(cardPropertyValue);

                    // first check for exact matches, then if none show up we check for partial matches
                    var matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)) == sanitizedValue).ToList();
                    if (matchedImages.Count < 1)
                    {
                        matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)).Contains(sanitizedValue)).ToList();
                    }

                    var ret = new ImportImagesItem()
                    {
                        Path = null, Card = card, Filter = sanitizedValue, PossiblePaths = null
                    };

                    if (matchedImages.Count < 1)
                    {
                    }
                    else if (matchedImages.Count > 1)
                    {
                        ret.PossiblePaths = new ObservableCollection <string>(matchedImages);
                    }
                    else
                    {
                        var singleImage = matchedImages.First();
                        ret.Path = singleImage;
                        ImagePaths.Remove(singleImage);
                        ret.PossiblePaths = new ObservableCollection <string>(matchedImages);
                    }
                    Items.Add(ret);
                }
            }
            OnPropertyChanged("Items");
        }
예제 #2
0
        private void LoadClicked(object sender, RoutedEventArgs e)
        {
            if (setsCombo.SelectedItem == null) return;
            if (propertyCombo.SelectedItem == null) return;
            if (!Directory.Exists(FolderDir)) return;
            Items.Clear();
            var selectedSet = setsCombo.SelectedItem as Set;

            var selectedProperty = propertyCombo.SelectedItem as PropertyDef;
            ImagePaths = new ObservableCollection<string>(Directory.EnumerateFiles(FolderDir).Where(file => Regex.IsMatch(file, @"^.+\.(jpg|jpeg|png)$")));

            foreach (var c in selectedSet.Cards)
            {
                foreach (var alternate in c.Properties)
                {
                    Card card = new Card(c);
                    card.Alternate = alternate.Key;
                    var cardPropertyValue = card.Properties[card.Alternate].Properties[selectedProperty].ToString();
                    var sanitizedValue = SanitizeString(cardPropertyValue);

                    // first check for exact matches, then if none show up we check for partial matches
                    var matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)) == sanitizedValue).ToList();
                    if (matchedImages.Count() < 1) matchedImages = ImagePaths.Where(x => SanitizeString(Path.GetFileNameWithoutExtension(x)).Contains(sanitizedValue)).ToList();

                    var ret = new ImportImagesItem() { Path = null, Card = card, Filter = sanitizedValue, PossiblePaths = null };

                    if (matchedImages.Count() < 1)
                    {
                    }
                    else if (matchedImages.Count() > 1)
                    {
                        ret.PossiblePaths = new ObservableCollection<string>(matchedImages);
                    }
                    else
                    {
                        var singleImage = matchedImages.First();
                        ret.Path = singleImage;
                        ImagePaths.Remove(singleImage);
                        ret.PossiblePaths = new ObservableCollection<string>(matchedImages);
                    }
                    Items.Add(ret);
                }
            }
            OnPropertyChanged("Items");
        }