Пример #1
0
        public void addLine(Pso2LogEventArgs msg)
        {
            // Callback
            if (this.txtLog.InvokeRequired)
            {
                addLineCallback d = new addLineCallback(addLine);
                this.Invoke(d, new object[] { msg });
            }
            else
            {
                // Let's pick a color to print
                Color msgColor;
                switch (msg.SendTo)
                {
                case "PARTY": msgColor = Properties.Settings.Default.ColorParty; break;

                case "GUILD": msgColor = Properties.Settings.Default.ColorGuild; break;

                case "REPLY": msgColor = Properties.Settings.Default.ColorReply; break;

                case "GROUP": msgColor = Properties.Settings.Default.ColorGroup; break;

                default: msgColor = Properties.Settings.Default.ColorDefault; break;
                }

                TranslatorService tr = AvailableTranslationServices.Active;

                // Which language is it?
                string msgLang = tr.DetectLanguage(msg.Message);

                // If not EN, translate
                string transText = "";
                if (msgLang != "en")
                {
                    transText = tr.Translate(msg.Message, ref msgLang);
                }

                // Let's add whatever
                txtLog.AppendText(msg.From + "\r\n", msgColor, 0, true);
                string[] a_Message = msg.Message.Split('\n');
                foreach (string line in a_Message)
                {
                    txtLog.AppendText(line + "\r\n", msgColor, 15);                                 // Adding one line at a time solves multi-laguage/multi-line formatting issue
                }
                if ((msgLang != "en") && (msg.Message != transText.Trim()))                         // Sometimes gibberish gets translated because it's detected as some other language
                {
                    txtLog.AppendText(transText + "\r\n", msgColor, 15, false, true, 0.7F);
                }
            }
        }
Пример #2
0
        public void CavetubeMainTest2_RoomIdNotFound()
        {
            var clientFactory = new MockCavetubeClientFactory();
            var mockClient    = clientFactory.MockCavetubeClient;
            var authFactory   = new MockCavetubeAuthFactory();
            var mockAuth      = authFactory.MockCavetubeAuth;
            var pso2Factory   = new MockPso2LogWatcherFactory();
            var mockPso2      = pso2Factory.MockPso2LogWatcher;

            var summary = new SummaryWrapper();
            //summary.RoomId = "roomid";
            var manualEvent = new ManualResetEvent(false);
            var check       = true;

            mockAuth.Setup(a => a.Login(It.IsAny <string>(), It.IsAny <string>())).Returns("apikey");
            mockClient.Setup(cl => cl.JoinRoom(It.IsAny <string>())).Raises(m => m.OnJoin += null, "roomid");
            mockClient.Setup(cl => cl.LeaveRoom()).Raises(m => m.OnLeave += null, "roomid");
            mockClient.Setup(cl => cl.GetSummary(It.IsAny <string>())).Returns(summary);
            mockClient.Setup(cl => cl.PostComment(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string, string>((name, message, apikey) =>
            {
                check = false;
                manualEvent.Set();
                Assert.AreEqual("someone", name);
                Assert.AreEqual("message", message);
                Assert.AreEqual("apikey", apikey);
            });

            var msg = new Pso2LogEventArgs();

            msg.From    = "someone";
            msg.SendTo  = "GUILD";
            msg.Message = "message";
            mockPso2.Setup(pso2 => pso2.Start()).Raises(pso2 => pso2.Pso2LogEvent += null, msg);

            var ex = Assert.Throws <ApplicationException>(() =>
            {
                Pso2LogSender.CavetubeMain(authFactory, clientFactory, pso2Factory, () =>
                {
                    check = false;
                    manualEvent.WaitOne();
                });
            });

            Assert.AreEqual("部屋IDの取得に失敗しました", ex.Message);

            Assert.True(check);
        }
Пример #3
0
        public void LivetubeMainTest3_StreamIdNotFound()
        {
            var clientFactory = new MockLivetubeClientFactory();
            var mockClient    = clientFactory.MockLivetubeClient;
            var pso2Factory   = new MockPso2LogWatcherFactory();
            var mockPso2      = pso2Factory.MockPso2LogWatcher;

            var manualEvent = new ManualResetEvent(false);
            var check       = true;

            mockClient.Setup(cl => cl.FindCurrentBroadcasting(It.IsAny <string>())).Returns("http://livetube.cc/someone/sometitle");
            mockClient.Setup(cl => cl.FindStream(It.IsAny <string>())).Returns((String)null);
            mockClient.Setup(cl => cl.PostComment(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string, string>((stream, user, comment) =>
            {
                check = false;
                manualEvent.Set();
                Assert.AreEqual("stream_id", stream);
                Assert.AreEqual("someone", user);
                Assert.AreEqual("message", comment);
            });

            var msg = new Pso2LogEventArgs();

            msg.From    = "someone";
            msg.SendTo  = "GUILD";
            msg.Message = "message";
            mockPso2.Setup(pso2 => pso2.Start()).Raises(pso2 => pso2.Pso2LogEvent += null, msg);

            var ex = Assert.Throws <ApplicationException>(() =>
            {
                Pso2LogSender.LivetubeMain(clientFactory, pso2Factory, () =>
                {
                    check = false;
                    manualEvent.WaitOne();
                });
            });

            Assert.AreEqual("ストリームの取得に失敗しました", ex.Message);

            Assert.True(check);
        }