Exemple #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();
        }
Exemple #2
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;
        }
Exemple #3
0
        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));
        }
Exemple #4
0
 public ChatCollectServiceModule(ChannelInformationModule channelInformationManager)
 {
     this.channelInformationManager = channelInformationManager;
     timer = new Timer(timerCallback, null, 100, 50);
     RegisteredServices = new ReadOnlyObservableCollection <ChatCollectService.IChatCollectService>(registeredServices);
 }