Beispiel #1
0
        public void StartTest3_StartWhileStart()
        {
            String dir = Path.GetRandomFileName();

            // まあ確率的に例外とかないだろう
            Directory.CreateDirectory(dir);
            try
            {
                using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                    using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                    {
                        watcher.Pso2LogEvent += (s, e) =>
                        {
                        };
                        watcher.Start(dir);
                        Assert.Throws <InvalidOperationException>(() =>
                        {
                            watcher.Start(dir);
                        });
                        watcher.Stop();
                    }
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }
Beispiel #2
0
        private void fMain_Load(object sender, EventArgs e)
        {
            // Title label
            lblAppTitle.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            // Populate translation menu
            AvailableTranslationServices.List().ForEach(
                delegate(TranslatorService tr)
            {
                var ttb    = new ToolStripMenuItem(tr.Name);
                ttb.Click += new EventHandler(tsddbGenericHandler);
                tsddbServices.DropDownItems.Add(ttb);

                if ((Properties.Settings.Default.TranslatorEngine == tr.Name) || (AvailableTranslationServices.Active == tr))
                {
                    ActivateService(tr.Name);
                }
            });

            // Load settings
            toggleAlwaysOnTop(Properties.Settings.Default.AlwaysOnTop);
            SetOpacity(Properties.Settings.Default.Opacity);
            this.Size        = Properties.Settings.Default.FormSize;
            this.Location    = Properties.Settings.Default.FormPos;
            txtLog.BackColor = Properties.Settings.Default.ColorBackground;
            this.OnResize(e);

            // Start the log watcher
            using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                {
                    watcher.Pso2LogEvent += (sndr, ev) =>
                    {
                        // That's a command, let's quit
                        if (ParsingSupport.isPSO2ChatCommand(ev.Message))
                        {
                            return;
                        }

                        // Let's remove all crap
                        ev.Message = ParsingSupport.chatCleanUp(ev.Message);

                        // If message didn't turned out all crap, let's display
                        if (ev.Message != "")
                        {
                            addLine(ev);
                        }
                    };
                    watcher.Start();
                }
        }
Beispiel #3
0
 private static void LogWatch(
     Action <string, string> postAction,
     Action waitAction,
     IPso2LogWatcherFactory pso2Factory)
 {
     using (IPso2LogWatcher watcher = pso2Factory.CreatePso2LogWatcher())
     {
         watcher.Pso2LogEvent += (sender, e) =>
         {
             if (e.SendTo == "GUILD")
             {
                 _logger.Debug("{0}: <{1}>{2}", e.From, e.SendTo, e.Message);
                 string person = e.From;
                 if (person == PSO2USER)
                 {
                     person = USER;
                 }
                 postAction(person, e.Message);
             }
         };
         watcher.Start();
         waitAction();
     }
 }
Beispiel #4
0
        public void StartTest5_NotepadLikeCreateFile()
        {
            String dir = Path.GetRandomFileName();

            // まあ確率的に例外とかないだろう
            Directory.CreateDirectory(dir);
            try
            {
                String[][] expectedRows = new String[][] {
                    new String[] { "2013-05-17T20:07:49", "10", "PUBLIC", "12133621", "白 菜2", "テスト2" },
                    new String[] { "2013-05-17T20:07:50", "11", "PARTY", "12133622", "白 菜3", "テスト3" }
                };
                int row = 0;

                using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                    using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                    {
                        StartTestState5[] state = new StartTestState5[] { StartTestState5.WaitingAssertRow1 };
                        watcher.Pso2LogEvent += (s, e) =>
                        {
                            string[] expectedCols = expectedRows[row++];
                            int      col          = 0;
                            Assert.AreEqual(expectedCols[col++], e.Time);
                            Assert.AreEqual(expectedCols[col++], e.MessageID);
                            Assert.AreEqual(expectedCols[col++], e.SendTo);
                            Assert.AreEqual(expectedCols[col++], e.FromID);
                            Assert.AreEqual(expectedCols[col++], e.From);
                            Assert.AreEqual(expectedCols[col++], e.Message);

                            lock (state)
                            {
                                state[0]++;
                                Monitor.Pulse(state);
                            }
                        };
                        using (TextWriter log =
                                   new StreamWriter(
                                       new FileStream(
                                           Path.Combine(dir, "ChatLog20130519_00.txt"),
                                           FileMode.CreateNew,
                                           FileAccess.Write,
                                           FileShare.Delete | FileShare.ReadWrite
                                           ),
                                       Encoding.Unicode
                                       )
                               )
                        {
                            log.WriteLine("2013-05-17T20:07:48\t9\tGUILD\t12133620\t白 菜\tテスト");
                            log.Flush();

                            watcher.Start(dir);

                            Thread.Sleep(1000); // これを入れないと読み込みの終端シークより前に書き込みが終わってしまう

                            log.WriteLine("2013-05-17T20:07:49\t10\tPUBLIC\t12133621\t白 菜2\tテスト2");
                            log.Flush();
                        }
                        lock (state)
                        {
                            if (state[0] != StartTestState5.AssertedRow1)
                            {
                                Monitor.Wait(state, 3000);
                            }
                            Assert.AreEqual(StartTestState5.AssertedRow1, state[0]);
                        }
                        File.Create(Path.Combine(dir, "ChatLog20130520_00.txt")).Close();
                        File.Delete(Path.Combine(dir, "ChatLog20130520_00.txt"));
                        Thread.Sleep(100);
                        using (TextWriter log =
                                   new StreamWriter(
                                       new FileStream(
                                           Path.Combine(dir, "ChatLog20130520_00.txt"),
                                           FileMode.CreateNew,
                                           FileAccess.Write,
                                           FileShare.Delete | FileShare.ReadWrite
                                           ),
                                       Encoding.Unicode
                                       )
                               )
                        {
                            log.WriteLine("2013-05-17T20:07:50\t11\tPARTY\t12133622\t白 菜3\tテスト3");
                            log.Flush();
                        }
                        lock (state)
                        {
                            if (state[0] != StartTestState5.AssertedRow2)
                            {
                                Monitor.Wait(state, 3000);
                            }
                            Assert.AreEqual(StartTestState5.AssertedRow2, state[0]);
                        }
                        watcher.Stop();
                    }
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }
Beispiel #5
0
        public void StartTest2_Twice()
        {
            String dir = Path.GetRandomFileName();

            // まあ確率的に例外とかないだろう
            Directory.CreateDirectory(dir);
            try
            {
                String[][] expectedRows = new String[][] {
                    new String[] { "2013-05-17T20:07:48", "9", "GUILD", "12133620", "白 菜", "テスト" },
                };
                int row = 0;

                using (IPso2LogWatcherFactory factory = new Pso2LogWatcherFactory())
                    using (IPso2LogWatcher watcher = factory.CreatePso2LogWatcher())
                    {
                        StartTestState2[] state = new StartTestState2[] { StartTestState2.WaitingAssertRow1 };
                        watcher.Pso2LogEvent += (s, e) =>
                        {
                            string[] expectedCols = expectedRows[row++];
                            int      col          = 0;
                            Assert.AreEqual(expectedCols[col++], e.Time);
                            Assert.AreEqual(expectedCols[col++], e.MessageID);
                            Assert.AreEqual(expectedCols[col++], e.SendTo);
                            Assert.AreEqual(expectedCols[col++], e.FromID);
                            Assert.AreEqual(expectedCols[col++], e.From);
                            Assert.AreEqual(expectedCols[col++], e.Message);

                            lock (state)
                            {
                                state[0]++;
                                Monitor.Pulse(state);
                            }
                        };
                        watcher.Start(dir);
                        using (TextWriter log =
                                   new StreamWriter(
                                       new FileStream(
                                           Path.Combine(dir, "ChatLog20130519_00.txt"),
                                           FileMode.CreateNew,
                                           FileAccess.Write,
                                           FileShare.Delete | FileShare.ReadWrite
                                           ),
                                       Encoding.Unicode
                                       )
                               )
                        {
                            log.WriteLine("2013-05-17T20:07:48\t9\tGUILD\t12133620\t白 菜\tテスト");
                            log.Flush();
                        }
                        lock (state)
                        {
                            if (state[0] != StartTestState2.AssertedRow1)
                            {
                                Monitor.Wait(state, 3000);
                            }
                            Assert.AreEqual(StartTestState2.AssertedRow1, state[0]);
                        }
                        watcher.Stop();
                        Assert.Throws <ObjectDisposedException>(() =>
                        {
                            watcher.Start(dir);
                        });
                        watcher.Stop();
                    }
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }