示例#1
0
        private void Loads_Completed(object sender, EventArgs e)
        {
            CommandWatcher watcher = new CommandWatcher(filePath);

            watcher.CommandHandler += newLine;
            watcher.Start();
        }
示例#2
0
        public void ICommand_Execute_CheckReceivedEventSubscribeCalls()
        {
            var command = Substitute.For <ICommand>();
            var watcher = new CommandWatcher(command);

            command.Executed += Raise.Event();

            Assert.IsTrue(watcher.DidStuff);
        }
        public void Test_CheckReceivedCalls_CheckingEventSubscriptions()
        {
            var command = Substitute.For <ICommand>();
            var watcher = new CommandWatcher(command);

            command.Executed += Raise.Event();

            Assert.IsTrue(watcher.DidStuff);
        }
 public void Setup()
 {
     // Arrange, arguably cleaner/tidier to do this in the test(s) that uses these, but I like to use my setup, plus it saves repetition which is good
     command    = Substitute.For <ICommand>();
     something  = new SomethingThatNeedsACommand(command);
     repeater   = new CommandRepeater(command, 3);
     calculator = Substitute.For <ICalculator>();
     dictionary = Substitute.For <IDictionary <string, int> >();
     watcher    = new CommandWatcher(command);
     runner     = new OnceOffCommandRunner(command);
 }
 public void TearDown()
 {
     // break it, break it down
     command    = null;
     something  = null;
     repeater   = null;
     calculator = null;
     dictionary = null;
     watcher    = null;
     runner     = null;
 }
示例#6
0
        public void ICommand_Execute_MakeSureReceivedEventSubscribeCalls()
        {
            var command = Substitute.For <ICommand>();
            var watcher = new CommandWatcher(command);

            //不推荐此做法。
            //更好的办法是测试行为,而不是具体实现。
            command.Received().Executed += watcher.OnExecuted;
            //或者有可能事件处理器不可访问。
            command.Received().Executed += Arg.Any <EventHandler>();
        }
        public void Test_CheckReceivedCalls_MakeSureWatcherSubscribesToCommandExecuted()
        {
            var command = Substitute.For <ICommand>();
            var watcher = new CommandWatcher(command);

            // 不推荐这种方法。
            // 更好的办法是测试行为而不是具体实现。
            command.Received().Executed += watcher.OnExecuted;
            // 或者有可能事件处理器是不可访问的。
            command.Received().Executed += Arg.Any <EventHandler>();
        }
示例#8
0
        static void Main(string[] args)
        {
            args = args.Select(s => s.Trim()).ToArray();
            File.WriteAllText(args[0], string.Empty);
            File.WriteAllText(args[1], string.Empty);

            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            CommandWatcher.iPath = args[0];
            CommandWatcher.oPath = args[1];
            CommandWatcher.Start();
            Thread.Sleep(Timeout.Infinite);
        }
示例#9
0
        private void loadFile()
        {
            var t = Task.Run(() =>
            {
                filePath = AppDomain.CurrentDomain.BaseDirectory + "log\\" + fileName + ".log";
                FileStream fs;
                if (File.Exists(filePath))
                {
                    using (StreamReader sr = new StreamReader(filePath))
                    {
                        // 从文件读取并显示行,直到文件的末尾
                        while (!sr.EndOfStream)
                        {
                            string line;
                            line = sr.ReadLine();
                            if (null != line && !"".Equals(line))
                            {
                                Action action = delegate
                                {
                                    LogList.Items.Add(line);
                                    LogList.ScrollIntoView(line);
                                };
                                LogList.Dispatcher.BeginInvoke(DispatcherPriority.Background, action);
                            }
                        }
                        LogHelper.ShowLog("文件读取完成");
                    }
                }
            });

            t.GetAwaiter().OnCompleted(() =>
            {
                LogHelper.ShowLog("开始监控写入");
                CommandWatcher watcher  = new CommandWatcher(filePath);
                watcher.CommandHandler += newLine;
                watcher.Start();
            });
        }
示例#10
0
 static void CurrentDomain_ProcessExit(object sender, EventArgs e)
 {
     CommandWatcher.Stop();
 }