예제 #1
0
        private static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                PrintUsage();
                return(1);
            }
            string sourcePath = args[0];

            if (!File.Exists(sourcePath))
            {
                Console.WriteLine(string.Format("Cannot find file {0})", sourcePath));
                return(1);
            }

            Console.WriteLine("SampleDataProcessor is processing " + sourcePath);

            var progress = new ConsoleProgressState();

            progress.Log += progress_Log;

            new WeSayWordsProject();
            WeSayWordsProject.Project.LoadFromLiftLexiconPath(sourcePath);
            //todo this should be re-implemented if needed with SynchronicRepository
            //CacheBuilder builder = new CacheBuilder(sourcePath);
            BackgroundWorker cacheBuildingWork = new BackgroundWorker();

            //cacheBuildingWork.DoWork += builder.OnDoWork;
            cacheBuildingWork.RunWorkerAsync(progress);
            while (true)
            {
                switch (progress.State)
                {
                case ProgressState.StateValue.NotStarted:
                    break;

                case ProgressState.StateValue.Busy:
                    break;

                case ProgressState.StateValue.Finished:
                    Console.WriteLine(string.Empty);
                    Console.WriteLine("Done.");
                    return(0);

                case ProgressState.StateValue.StoppedWithError:
                    Console.Error.WriteLine(string.Empty);
                    Console.Error.WriteLine("Error. Unable to complete import.");
                    return(3);

                default:
                    break;
                }
                Thread.Sleep(100);
            }
        }
예제 #2
0
        private void WaitForFinish(ConsoleProgressState progress, ProgressState.StateValue expectedResult)
        {
            DateTime giveUpTime = DateTime.Now.AddSeconds(5);

            while (progress.State != expectedResult)
            {
                if (DateTime.Now > giveUpTime)
                {
                    Assert.Fail("Didn't get expected result");
                }
                Thread.Sleep(10);
            }
        }
예제 #3
0
        public void LongRunningMethodUsingConsoleHandler_ProducesLog()
        {
            Assert.IsFalse((_logBuilder.ToString().Contains("99")));
            var progress = new ConsoleProgressState();

            progress.Log += new EventHandler <ProgressState.LogEvent>(OnProgressStateLog);
            BackgroundWorker cacheBuildingWork = new BackgroundWorker();

            cacheBuildingWork.DoWork += new DoWorkEventHandler(OnDoBackgroundWorkerWork);
            cacheBuildingWork.RunWorkerAsync(progress);

            WaitForFinish(progress, ProgressState.StateValue.Finished);
            Assert.IsTrue(_logBuilder.ToString().Contains("99"));
        }
예제 #4
0
        public void LongRunningMethodUsingConsoleHandler_ProducesLog()
        {
            Assert.IsFalse((_logBuilder.ToString().Contains("99")));
            var progress = new ConsoleProgressState();

            progress.Log += new EventHandler <ProgressState.LogEvent>(OnProgressStateLog);
            BackgroundWorker cacheBuildingWork = new BackgroundWorker();

            cacheBuildingWork.DoWork += new DoWorkEventHandler(OnDoBackgroundWorkerWork);
            cacheBuildingWork.RunWorkerAsync(progress);

            WaitForFinish(progress, ProgressState.StateValue.Finished);
            // Fails about 2% of the time on TC Windows agents, likely due to the Asynchronous aspects of this test
            Assert.IsTrue(_logBuilder.ToString().Contains("99"));
        }