示例#1
0
        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();
        }
示例#2
0
        public CommandModule(IPCModule ipcModule, SynchronizationContext synchronizationContext)
        {
            this.ipcModule = ipcModule;
            this.SynchronizationContext = synchronizationContext;

            ipcModule.MessageReceived += ipcModule_MessageReceived;
        }
示例#3
0
        public ChannelInformationModule(IPCModule ipc)
        {
            CurrentTime    = new ReadOnlyObservableValue <DateTime?>(currentTime);
            ChannelList    = new ReadOnlyObservableCollection <ChannelInfo>(channelList);
            CurrentChannel = new ReadOnlyObservableValue <ChannelInfo>(currentChannel);
            CurrentEvent   = new ReadOnlyObservableValue <EventInfo>(currentEvent);

            this.ipc             = ipc;
            ipc.MessageReceived += ipc_MessageReceived;
        }
示例#4
0
        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;
        }