public ChatModule( TVTCommentSettings settings, IEnumerable <ChatService.IChatService> chatServices, ChatCollectServiceModule collectServiceModule, IPCModule ipc, ChannelInformationModule channelInformationModule ) { Chats = new ReadOnlyObservableCollection <Chat>(chats); ChatModRules = new ReadOnlyObservableCollection <ChatModRuleEntry>(chatModRules); this.settings = settings; this.chatServices = chatServices; this.ipc = ipc; this.collectServiceModule = collectServiceModule; disposables.Add(ChatPreserveCount.Subscribe(x => onChatPreserveCountChanged())); disposables.Add(channelInformationModule.CurrentChannel.Subscribe(x => { if (ClearChatsOnChannelChange.Value) { ClearChats(); } })); collectServiceModule.NewChatProduced += collectServiceModule_NewChatProduced; loadSettings(); }
public void Dispose() { State = TVTCommentState.Disposing; if (!quickDispose) { try { //相手からCloseを要求を受けていないなら if (!isClosing) { closingResetEvent.Reset(); //CloseIPCMessageを相手に送る ipcModule.Send(new IPC.IPCMessage.CloseIPCMessage()).Wait(); //相手からCloseIPCMessageが来るまで待つ、1秒以内に来なかったら無視して進める closingResetEvent.Wait(1000); } } catch { } } foreach (var chatService in ChatServices) { chatService.Dispose(); } //メール欄例保存 this.Settings.ChatPostMailTextExamples = this.ChatPostMailTextExamples.ToArray(); //各種SubModule破棄 CommandModule?.Dispose(); ChatCollectServiceCreationPresetModule?.Dispose(); DefaultChatCollectServiceModule?.Dispose(); ChatModule?.Dispose(); ChatTrendServiceModule?.Dispose(); ChatCollectServiceModule?.Dispose(); if (ipcModule != null) { ipcModule.Disposed -= ipcManager_Disposed; ipcModule.MessageReceived -= ipcManager_MessageReceived; ipcModule.Dispose(); } // 設定保存。asyncだがawaitせずに例外は無視。 this.settingReaderWriter.Write(this.Settings).Wait(5000); State = TVTCommentState.Disposed; }
public DefaultChatCollectServiceModule( TVTCommentSettings settings, ChannelInformationModule channelInformationModule, ChatCollectServiceModule collectServiceModule, IEnumerable <ChatCollectServiceEntry.IChatCollectServiceEntry> serviceEntryList ) { this.settings = settings; this.channelInformationModule = channelInformationModule; this.collectServiceModule = collectServiceModule; this.serviceEntryList = serviceEntryList; loadSettings(); disposables.Add(channelInformationModule.CurrentTime.Subscribe(timeChanged)); disposables.Add(LiveChatCollectService.ObserveCollectionChanged(newServiceEntry => { if (IsEnabled.Value && !lastIsRecord.GetValueOrDefault(true)) { if (collectServiceModule.RegisteredServices.All(x => x.ServiceEntry != newServiceEntry)) { collectServiceModule.AddService(newServiceEntry, null); } } }, oldServiceEntry => { if (IsEnabled.Value && !lastIsRecord.GetValueOrDefault(true)) { foreach (var service in collectServiceModule.RegisteredServices.Where(x => x.ServiceEntry == oldServiceEntry)) { collectServiceModule.RemoveService(service); } } }, () => { if (IsEnabled.Value && !lastIsRecord.GetValueOrDefault(true)) { collectServiceModule.ClearServices(); } })); disposables.Add(RecordChatCollectService.ObserveCollectionChanged(newServiceEntry => { if (IsEnabled.Value && lastIsRecord.GetValueOrDefault(false)) { if (collectServiceModule.RegisteredServices.All(x => x.ServiceEntry != newServiceEntry)) { collectServiceModule.AddService(newServiceEntry, null); } } }, oldServiceEntry => { if (IsEnabled.Value && lastIsRecord.GetValueOrDefault(false)) { foreach (var service in collectServiceModule.RegisteredServices.Where(x => x.ServiceEntry == oldServiceEntry)) { collectServiceModule.RemoveService(service); } } }, () => { if (IsEnabled.Value && lastIsRecord.GetValueOrDefault(false)) { collectServiceModule.ClearServices(); } })); disposables.Add(channelInformationModule.CurrentTime.Subscribe(timeChanged)); }
private async Task initialize() { if (State != TVTCommentState.NotInitialized) { throw new InvalidOperationException("This object is already initialized"); } // プラグインの無効化→有効化を短時間で行うと // 設定ファイルがアクセス中でIOExceptionが飛ぶので時間を空けて試す for (int i = 1; ; ++i) { try { this.Settings = await this.settingReaderWriter.Read(); break; } catch (FormatException) { this.Settings = new TVTCommentSettings(); break; } catch (IOException) { const int retryCount = 6; if (i >= retryCount) { throw; } } await Task.Delay(500); } string baseDir = Path.GetDirectoryName(getExePath()); this.channelDatabase = new ChannelDatabase(Path.Combine(baseDir, "channels.txt")); this.ChatServices = new ReadOnlyCollection <ChatService.IChatService>(new ChatService.IChatService[] { new ChatService.NiconicoChatService( Settings.Niconico, this.channelDatabase, Path.Combine(baseDir, "niconicojikkyouids.txt"), Path.Combine(baseDir, "niconicoliveids.txt") ), new ChatService.NichanChatService(Settings.Nichan, this.channelDatabase, Path.Combine(baseDir, "2chthreads.txt")), new ChatService.FileChatService() }); var chatCollectServiceEntryIds = this.ChatServices.SelectMany(x => x.ChatCollectServiceEntries).Select(x => x.Id); System.Diagnostics.Debug.Assert( chatCollectServiceEntryIds.Distinct().Count() == chatCollectServiceEntryIds.Count(), "IDs of ChatCollectServiceEntries are not unique" ); //Viewerとの接続 string[] commandLine = Environment.GetCommandLineArgs(); if (commandLine.Length == 3) { ipcModule = new IPCModule(commandLine[1], commandLine[2], SynchronizationContext.Current); } else { ipcModule = new IPCModule("TVTComment_Up", "TVTComment_Down", SynchronizationContext.Current); } ipcModule.Disposed -= ipcManager_Disposed; ipcModule.Disposed += ipcManager_Disposed; try { await ipcModule.Connect(); } catch (IPCModule.ConnectException) { return; } ipcModule.MessageReceived += ipcManager_MessageReceived; //各種SubModule作成 ChannelInformationModule = new ChannelInformationModule(ipcModule); ChatCollectServiceModule = new ChatCollectServiceModule(ChannelInformationModule); ChatTrendServiceModule = new ChatTrendServiceModule(SynchronizationContext.Current); ChatModule = new ChatModule( this.Settings, ChatServices, ChatCollectServiceModule, ipcModule, ChannelInformationModule ); DefaultChatCollectServiceModule = new DefaultChatCollectServiceModule( this.Settings, ChannelInformationModule, ChatCollectServiceModule, ChatServices.SelectMany(x => x.ChatCollectServiceEntries) ); CommandModule = new CommandModule( ipcModule, SynchronizationContext.Current ); ChatCollectServiceCreationPresetModule = new ChatCollectServiceCreationPresetModule( this.Settings, ChatServices.SelectMany(x => x.ChatCollectServiceEntries) ); //コメント透過度設定処理 ChatOpacity = new ObservableValue <byte>(this.Settings.ChatOpacity); ChatOpacity.Subscribe(async opacity => { this.Settings.ChatOpacity = opacity; await ipcModule.Send(new IPC.IPCMessage.SetChatOpacityIPCMessage { Opacity = opacity }); }); //メール欄例設定 var chatPostMailTextExamples = this.Settings.ChatPostMailTextExamples; ChatPostMailTextExamples.AddRange(chatPostMailTextExamples); ipcModule.StartReceiving(); State = TVTCommentState.Working; }