コード例 #1
0
        private async void DoAnalyze()
        {
            Debug.Assert(TargetPath != null);

            // set the view title
            ViewTitle = "Analyzing " + TargetPath + "...";

            try
            {
                   // start the analyzer
                DirectoryAnalyzer analyzer = new DirectoryAnalyzer();
                var results = await Task.Run(() => analyzer.Analyze(TargetPath, new Progress<int>(ReportProgress), m_cancellationToken.Token));

                // at this point, we close ourselves and open the resuls view
                var resultsVm = new ResultsVm(results, TargetPath + " results");

                // add the results Vm to our application resources in order to pass it to the 
                // ResultsView.
                // yes, I know, this is terrible design. But for the time being, I 
                // don't have time to learn ModernUI well enough to understand how to do this 
                // correctly. 
                Application.Current.Resources.Add("ResultsVm", resultsVm);

                Close();
            }
            catch (OperationCanceledException)
            {
                Application.Current.Shutdown();
            }
         
        }
コード例 #2
0
        public void TestAnalyze()
        {
            string testPath = @"C:\temp\test";
            DirectoryAnalyzer analyzer = new DirectoryAnalyzer();
            CancellationTokenSource ctSource = new CancellationTokenSource();

            IList< DirectoryAnalyzer.DirectoryEntry> results = analyzer.Analyze(testPath, new Progress<int>(), ctSource.Token);

            Assert.AreEqual(results.Count, 3);
            Assert.AreEqual(results[0].Name.ToLower(), @"subdir1");
            Assert.AreEqual(results[1].Name.ToLower(), @"subdir3");
            Assert.AreEqual(results[2].Name.ToLower(), @"subdir2");
        }