示例#1
0
        public void TestCancelSleep()
        {
            var sc     = new SleepCommand(TimeSpan.FromMilliseconds(10000));
            var script = new Script();

            script.AddCommand(sc);
            OperationCanceledException exception = null;

            Thread scriptThread = new Thread(() =>
            {
                try
                {
                    script.Execute();
                }
                catch (OperationCanceledException e)
                {
                    exception = e;
                }
            });

            scriptThread.Start();
            script.Cancel();
            scriptThread.Join();
            Assert.IsNotNull(exception);
        }
示例#2
0
        protected override async void RunIteration()
        {
            var script   = new Script();
            var archiver = new Archiver();
            var checker  = new OrphoChecker();

            script.AddCommand(new ArchiverCommand(archiver, "extract"));
            script.AddCommand(new OrphoCheckerCommand(checker, "check"));
            script.AddCommand(new OrphoCheckerCommand(checker, "fix"));
            script.AddCommand(new ArchiverCommand(archiver, "archive"));
            script.Execute();

            Console.WriteLine("Writing to file...");
            using (var writer = new StreamWriter(File.Open(_fileName, FileMode.Create, FileAccess.Write)))
            {
                await script.Serialize(writer);
            }
            Console.WriteLine("The file was filled in successfully");

            Process.Start("notepad.exe", _fileName);
        }
示例#3
0
        public void TestCancelCopy()
        {
            string src = Path.Combine(TestConstants.TestDirectory, "a.txt");
            string dst = Path.Combine(TestConstants.TestDirectory, "b.txt");

            File.WriteAllText(src, "12345");
            var cc = new CopyCommand(src, dst);

            var script = new Script();

            script.AddCommand(cc);

            script.Progress += ((progress) =>
            {
                if (progress > 20)
                {
                    script.Cancel();
                }
            });
            Assert.Throws <OperationCanceledException>(() => script.Execute());
        }