private async Task initializeInternal() { if (initialized) { return; } initialized = true; // モデルの初期化 try { await model.Initialize(); await BasicSettingControlViewModel.Initialize(); //await ChatPostControlViewModel.Initialize(); } catch (Exception e) { AlertRequest.Raise(new Notification { Title = "TVTCommentエラー", Content = $"初期化で予期しないエラーが発生しました\n{e.ToString()}" }); CloseApplication(); return; } if (model.State != Model.TVTCommentState.Working) { AlertRequest.Raise(new Notification { Title = "TVTCommentエラー", Content = "Viewer側(TVTestプラグイン側)と接続できませんでした" }); CloseApplication(); return; } // 表示関係の設定復元 Model.Serialization.WindowPositionEntity rect = model.Settings.View.MainWindowPosition; this.WindowPosition.X = rect.X; this.WindowPosition.Y = rect.Y; this.WindowPosition.Width = rect.Width; this.WindowPosition.Height = rect.Height; ChatListColumnInfos = model.Settings.View.ChatListViewColumns?.Select( x => new Views.AttachedProperties.GridViewColumnSettingsBinder.ColumnInfo(x.Id, x.Width) ).ToArray(); this.SelectedTab.Value = model.Settings.View.MainWindowTab; // ウィンドウの位置を復元したら最小化を解除 Window window = Application.Current.MainWindow; window.WindowState = WindowState.Normal; // モデルのイベントハンドラを登録 model.ChatCollectServiceModule.ErrorOccurredInChatCollecting += model_ErrorOccurredInChatCollecting; model.ChatCollectServiceModule.ErrorOccurredInChatPosting += model_ErrorOccurredInChatPosting; model.ChatCollectServiceModule.ErrorOccurredInServiceCreation += model_ErrorOccurredAtChatCollectServiceCreation; // モデルのプロパティを結びつける CurrentPlayTime = model.ChannelInformationModule.CurrentTime; CurrentChannel = model.ChannelInformationModule.CurrentChannel; CurrentEvent = model.ChannelInformationModule.CurrentEvent; disposables.Add(CurrentPlayTime.Subscribe(_ => updateWindowTitle())); disposables.Add(CurrentChannel.Subscribe(_ => updateWindowTitle())); disposables.Add(CurrentEvent.Subscribe(_ => updateWindowTitle())); // 旧ニコニコ実況が廃止されたので現状常にnull // 今後対応するときのためにとって置いてる forceValueData = new ReadOnlyObservableValue <Model.IForceValueData>(Observable.Return <Model.IForceValueData>(null)); UseDefaultChatCollectService = model.DefaultChatCollectServiceModule.IsEnabled; model.CommandModule.ShowWindowCommandInvoked += commandModule_ShowWindowCommandInvoked; // コマンド生成 ChangeChannelCommand = new DelegateCommand <Model.ChannelInfo>(channel => { if (channel != null) { model.ChannelInformationModule.SetCurrentChannel(channel); } }); AddChatCollectServiceCommand = new DelegateCommand <ShellContents.ChatCollectServiceAddListItemViewModel>( async x => { if (x != null) { await addChatCollectService(x); } }, _ => !UseDefaultChatCollectService.Value ); RemoveChatCollectServiceCommand = new DelegateCommand <Model.ChatCollectService.IChatCollectService>( service => { if (service != null) { model.ChatCollectServiceModule.RemoveService(service); } }, _ => !UseDefaultChatCollectService.Value ); UseDefaultChatCollectService.Subscribe(x => { AddChatCollectServiceCommand.RaiseCanExecuteChanged(); RemoveChatCollectServiceCommand.RaiseCanExecuteChanged(); }); ClearChatsCommand = new DelegateCommand(() => model.ChatModule.ClearChats()); AddWordNgCommand = new DelegateCommand <Model.Chat>(chat => { if (chat == null) { return; } model.ChatModule.AddChatModRule(new Model.ChatModRules.WordNgChatModRule(model.ChatServices.SelectMany(x => x.ChatCollectServiceEntries), chat.Text)); }); AddUserNgCommand = new DelegateCommand <Model.Chat>(chat => { if (chat == null) { return; } model.ChatModule.AddChatModRule(new Model.ChatModRules.UserNgChatModRule(chat.SourceService.Owner.ChatCollectServiceEntries, chat.UserId)); }); CopyCommentCommand = new DelegateCommand <Model.Chat>(chat => { if (chat == null) { return; } Clipboard.SetText(chat.Text); }); CopyUserCommand = new DelegateCommand <Model.Chat>(chat => { if (chat == null) { return; } Clipboard.SetText(chat.UserId); }); OnPropertyChanged(null); }
public NgSettingWindowViewModel(Model.TVTComment model) { this.model = model; Model.Serialization.WindowPositionEntity rect = model.Settings.View.NgSettingWindowPosition; WindowLeft = rect.X; WindowTop = rect.Y; WindowWidth = rect.Width; WindowHeight = rect.Height; TargetChatCollectServiceEntries = new List <Contents.SelectableViewModel <Model.ChatCollectServiceEntry.IChatCollectServiceEntry> >( model.ChatServices.SelectMany(service => service.ChatCollectServiceEntries) .Select(x => new Contents.SelectableViewModel <Model.ChatCollectServiceEntry.IChatCollectServiceEntry>(x, true))); var updateTimer = Observable.Interval(TimeSpan.FromSeconds(3)); disposables.Add((IDisposable)(Rules = model.ChatModule.ChatModRules.MakeOneWayLinkedCollection(x => new Contents.ChatModRuleListItemViewModel(x, updateTimer.Select(_ => new Unit()))))); AddWordNgCommand = new DelegateCommand(() => { if (string.IsNullOrWhiteSpace(NgText)) { return; } model.ChatModule.AddChatModRule(new Model.ChatModRules.WordNgChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value), NgText)); }); AddUserNgCommand = new DelegateCommand(() => { if (string.IsNullOrWhiteSpace(NgText)) { return; } model.ChatModule.AddChatModRule(new Model.ChatModRules.UserNgChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value), NgText)); }); AddIroKomeNgCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.IroKomeNgChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value))); }); AddJyougeKomeNgCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.JyougeKomeNgChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value))); }); AddJyougeIroKomeNgCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.JyougeIroKomeNgChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value))); }); AddRandomizeColorRuleCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.RandomizeColorChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value))); }); AddSmallOnMultiLineRuleCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.SmallOnMultiLineChatModRule(TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value), SmallOnMultiLineRuleLineCount.Value)); }); AddSetColorRuleCommand = new DelegateCommand(() => { model.ChatModule.AddChatModRule(new Model.ChatModRules.SetColorChatModRule( TargetChatCollectServiceEntries.Where(x => x.IsSelected).Select(x => x.Value), SetColorRuleColor.Value )); }); RemoveRuleCommand = new DelegateCommand(() => { if (SelectedRule == null) { return; } model.ChatModule.RemoveChatModRule(SelectedRule.ChatModRule); }); }