Esempio n. 1
0
        public PatternsMergeViewModel(List <MPattern> items)
        {
            PatternItems = new ObservableCollection <MPattern>(items);
            var strs = items.SelectMany(o => o.PATTERN.Split('/')).OrderBy(s => s).Distinct().ToList();

            PatternVariations = new BindingList <MPatternVariation>(strs.Select((s, i) => new MPatternVariation {
                Index = i + 1, Variation = s
            }).ToList());
            Action f = () => MergedItemEdit.PATTERN = string.Join("/", PatternVariations.Select(o => o.Variation).Distinct());

            PatternVariations.ListChanged += (s, e) =>
            {
                Reindex();
                f();
            };
            f();
            MergedItemEdit.NOTE = items.Select(o => o.NOTE).SplitUsingCommaAndMerge();
            MergedItemEdit.TAGS = items.Select(o => o.TAGS).SplitUsingCommaAndMerge();
            Save = ReactiveCommand.CreateFromTask(async() =>
            {
                var mergedItem = new MPattern
                {
                    IDS_MERGE = string.Join(",", PatternItems.OrderBy(o => o.ID).Select(o => o.ID.ToString())),
                    PATTERN   = MergedItemEdit.PATTERN,
                    NOTE      = MergedItemEdit.NOTE,
                    TAGS      = MergedItemEdit.TAGS,
                };
                await patternDS.MergePatterns(mergedItem);
            }, MergedItemEdit.IsValid());
        }
Esempio n. 2
0
        public async Task Create(MPattern item)
        {
            item.ID = await patternDS.Create(item);

            PatternItemsAll.Add(item);
            ApplyFilters();
        }
Esempio n. 3
0
        public PatternsSplitViewModel(MPattern item)
        {
            PatternItems = new ObservableCollection <MPattern>(new[] { item });
            var strs = item.PATTERN.Split('/').ToList();

            PatternVariations = new BindingList <MPatternVariation>(strs.Select((s, i) => new MPatternVariation {
                Index = i + 1, Variation = s
            }).ToList());
            Action f = () => SplitItemEdit.PATTERN = string.Join(",", PatternVariations.Select(o => o.Variation));

            PatternVariations.ListChanged += (s, e) =>
            {
                Reindex();
                f();
            };
            f();
            SplitItemEdit.ID = item.ID;
            Save             = ReactiveCommand.CreateFromTask(async() =>
            {
                var splitItem = new MPattern
                {
                    ID             = SplitItemEdit.ID,
                    PATTERNS_SPLIT = SplitItemEdit.PATTERN,
                };
                await patternDS.SplitPattern(splitItem);
            }, SplitItemEdit.IsValid());
        }
Esempio n. 4
0
 public PatternsWebPagesViewModel(SettingsViewModel vmSettings, bool needCopy, MPattern item)
 {
     this.vmSettings     = !needCopy ? vmSettings : vmSettings.ShallowCopy();
     SelectedPatternItem = item;
     ReloadCommand       = ReactiveCommand.CreateFromTask(async() =>
     {
         IsBusy       = true;
         WebPageItems = new ObservableCollection <MPatternWebPage>(SelectedPatternItem == null ? new List <MPatternWebPage>() : await patternWebPageDS.GetDataByPattern(SelectedPatternItem.ID));
         this.RaisePropertyChanged(nameof(WebPageItems));
         SelectedWebPageItem = WebPageItems.FirstOrDefault();
         IsBusy = false;
     });
     GetWebPages().Subscribe();
 }
Esempio n. 5
0
 public PatternsDetailViewModel(PatternsViewModel vm, MPattern item)
 {
     item.CopyProperties(ItemEdit);
     ItemEdit.Save = ReactiveCommand.CreateFromTask(async() =>
     {
         ItemEdit.CopyProperties(item);
         item.PATTERN = vm.vmSettings.AutoCorrectInput(item.PATTERN);
         if (item.ID == 0)
         {
             await vm.Create(item);
         }
         else
         {
             await vm.Update(item);
         }
     }, ItemEdit.IsValid());
 }
Esempio n. 6
0
        public static async Task AutoMergePatterns()
        {
            var storept = new PatternDataStore();
            var lst     = await storept.GetDataByLang(2);

            var dic = lst.GroupBy(o => o.PATTERN).Where(g => g.Count() > 1).ToDictionary(g => g.Key, g => g.OrderBy(o => o.ID).ToList());

            foreach (var kv in dic)
            {
                var sourceItems = kv.Value;
                var mergedItem  = new MPattern
                {
                    IDS_MERGE = string.Join(",", sourceItems.Select(o => o.ID.ToString())),
                    PATTERN   = kv.Key,
                    NOTE      = sourceItems.Select(o => o.NOTE).SplitUsingCommaAndMerge(),
                    TAGS      = sourceItems.Select(o => o.TAGS).SplitUsingCommaAndMerge()
                };
                await storept.MergePatterns(mergedItem);
            }
        }
Esempio n. 7
0
        public override async Task Step2()
        {
            var reg1 = new Regex(@"【JLPT(N\d)】文法・例文:(.+)");

            await Step2(a =>
            {
                string url = a[0], title = a[1];
                var m      = reg1.Match(title);
                string tag = m.Groups[1].Value, title2 = m.Groups[2].Value;
                var pt     = new MPattern
                {
                    LANGID  = 2,
                    PATTERN = title2,
                    TAGS    = "教師" + tag,
                };
                var wp = new MWebPage
                {
                    TITLE = $"【{tag}】{title2}",
                    URL   = url,
                };
                return(pt, wp);
            });
        }
Esempio n. 8
0
 public async Task Update(MPattern item) => await patternDS.Update(item);