コード例 #1
0
        private async Task OnFFChatMessageArrived(ChatMessageArrivedEventArgs ea)
        {
            bool        logged  = false;
            ChatMsgType msgType = new ChatMsgType();

            if (_ChatCodesTypes != null)
            {
                if (_ChatCodesTypes.TryGetValue(ea.ChatMessage.Code, out msgType))
                {
                    if (!MsgBlackList.Contains(ea.ChatMessage.Text))
                    {
                        await ProcessChatMsg(ea.ChatMessage, msgType);
                    }

                    if (CmdArgsStatus.LogPlotChat)
                    {
                        Logger.WriteChatLog(String.Format("{0} {1}: {2}", ea.ChatMessage.TimeStamp, ea.ChatMessage.Code, ea.ChatMessage.Text));
                        logged = true;
                    }
                }

                if (CmdArgsStatus.LogAllChat && !logged)
                {
                    Logger.WriteChatLog(String.Format("{0} {1}: {2}", ea.ChatMessage.TimeStamp, ea.ChatMessage.Code, ea.ChatMessage.Text));
                }
            }
        }
コード例 #2
0
        private void ChatMessageEvetRiser()
        {
            Task.Factory.StartNew(async() =>
            {
                if (_FFChatMessageArrived.HandlersCount == 0)
                {
                    SpinWait.SpinUntil(() => _FFChatMessageArrived.HandlersCount > 0);
                }

                while (_KeepWorking)
                {
                    try
                    {
                        FFChatMsg ffChatMsg = new FFChatMsg();
                        if (_FFxivChat.TryDequeue(out ffChatMsg))
                        {
                            var ea = new ChatMessageArrivedEventArgs(this)
                            {
                                ChatMessage = ffChatMsg
                            };

                            await _FFChatMessageArrived.InvokeAsync(ea);
                        }
                        else
                        {
                            SpinWait.SpinUntil(() => _FFxivChat.IsEmpty == false && _KeepWorking == true);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.WriteLog(e);
                    }
                }
            }, TaskCreationOptions.LongRunning);
        }
コード例 #3
0
        public async Task OnFFChatMessageArrived(ChatMessageArrivedEventArgs ea)
        {
            ChatMsgType msgType = new ChatMsgType();

            if (!MsgBlackList.Contains(ea.ChatMessage.Text))
            {
                await ProcessChatMsg(ea, msgType);
            }

            if (CmdArgsStatus.LogAllChat || CmdArgsStatus.LogPlotChat)
            {
                Logger.WriteChatLog(String.Format("{0} {1}: {2}", ea.ChatMessage.TimeStamp, ea.ChatMessage.Code, ea.ChatMessage.Text));
            }
        }
コード例 #4
0
        private async Task ProcessChatMsg(ChatMessageArrivedEventArgs ea, ChatMsgType msgType)
        {
            switch (msgType.MsgType)
            {
            default:
            {
                var translation = new ChatMessageArrivedEventArgs(ea);

                await _TextArrivedArrived.InvokeAsync(translation);

                break;
            }
            }
        }
コード例 #5
0
        protected async Task OnTextArrived(ChatMessageArrivedEventArgs ea)
        {
            string            text      = "";
            Color             textColor = Color.FromArgb(255, 255, 255, 255);
            ChatCodeViewModel chatCode;

            chatCode = _ChatWindowViewModel.ChatCodes.FirstOrDefault(x => x.Code == ea.ChatMessage.Code);

            if (chatCode == null)
            {
                return;
            }
            if (!chatCode.IsChecked)
            {
                return;
            }

            textColor = chatCode.Color;

            int  translateTryCount = 0;
            bool notTransalted     = true;

            while (translateTryCount < GlobalSettings.MaxTranslateTryCount && notTransalted)
            {
                var    translationEngines = _TataruModel.ChatProcessor.TranslationEngines;
                string translation        = string.Empty;
                Task.Run(async() =>
                {
                    translation = await _TataruModel.ChatProcessor.Translate(ea.ChatMessage.Text, _ChatWindowViewModel.CurrentTransaltionEngine,
                                                                             _ChatWindowViewModel.CurrentTranslateFromLanguague, _ChatWindowViewModel.CurrentTranslateToLanguague, chatCode.Code);
                }).Wait(GlobalSettings.TranslatorWaitTime);
                translateTryCount++;

                if (translation.Length < 1)
                {
                    var engineIndex = translationEngines.IndexOf(_ChatWindowViewModel.CurrentTransaltionEngine);
                    if (engineIndex < 0)
                    {
                        engineIndex = translationEngines.Count - 1;
                    }

                    bool supported = false;

                    int iterCount = 0;
                    do
                    {
                        engineIndex++;
                        iterCount++;
                        if (engineIndex >= translationEngines.Count)
                        {
                            engineIndex = 0;
                        }

                        var tmpEngine = translationEngines[engineIndex];
                        if (tmpEngine.SupportedLanguages.Contains(_ChatWindowViewModel.CurrentTranslateFromLanguague) &&
                            tmpEngine.SupportedLanguages.Contains(_ChatWindowViewModel.CurrentTranslateToLanguague))
                        {
                            supported = true;

                            UiWindow.Window.UIThread(() =>
                            {
                                _ChatWindowViewModel.TranslationEngines.MoveCurrentToPosition(engineIndex);
                            });
                        }
                    } while (!supported && iterCount <= translationEngines.Count);

                    UiWindow.Window.UIThread(() =>
                    {
                        ShowErorrText(1, _ChatWindowViewModel.CurrentTransaltionEngine.Name, textColor);
                    });
                }
                else
                {
                    text          = translation;
                    notTransalted = false;
                }
            }

            text = await _TataruModel.ChatProcessor.Translate(ea.ChatMessage.Text, _ChatWindowViewModel.CurrentTransaltionEngine,
                                                              _ChatWindowViewModel.CurrentTranslateFromLanguague, _ChatWindowViewModel.CurrentTranslateToLanguague, chatCode.Code);

            await this.UIThreadAsync(() =>
            {
                ShowWindow();

                if (_ChatWindowViewModel.IsHiddenByUser == false)
                {
                    _TextArrivedTime = DateTime.UtcNow;
                }

                ShowTransaltedText(text, textColor);

                if (_ChatWindowViewModel.IsHiddenByUser == false)
                {
                    _TextArrivedTime = DateTime.UtcNow;
                }
            });
        }