Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously processes all documents in the project in a comprehensive manner.
        /// </summary>
        /// <returns>A System.Threading.Tasks.Task representing the asynchronous processing operation.</returns>
        public async Task ParseDocuments()
        {
            var resourceLoadingNotifier = new ResourceNotifier();
            var analysisOrchestrator    = new AnalysisOrchestrator(FileManager.TxtFiles);

            var loadingEvents        = ConfigureLoadingEvents(resourceLoadingNotifier);
            var loadedEvents         = ConfigureLoadedEventStream(resourceLoadingNotifier);
            var analysisUpdateEvents = ConfigureAnalysisUpdateEvents(analysisOrchestrator);

            Observable.Merge(
                loadingEvents.Select(pattern => pattern.EventArgs),
                loadedEvents.Select(pattern => pattern.EventArgs),
                analysisUpdateEvents.Select(pattern => pattern.EventArgs)
                )
            .Select(pattern => new
            {
                pattern.Message,
                Progress = pattern.PercentWorkRepresented
            })
            .SubscribeOn(System.Threading.SynchronizationContext.Current)
            .Subscribe(onNext: async e =>
            {
                progressLabel.Content = e.Message;
                progressBar.ToolTip   = e.Message;
                var animateStep       = 0.028 * e.Progress;
                for (var i = 0; i < 33; ++i)
                {
                    progressBar.Value += animateStep;
                    await Task.Yield();
                }
            });
            var timer = System.Diagnostics.Stopwatch.StartNew();

            ResultsScreen.Documents = await analysisOrchestrator.ProcessAsync();

            progressBar.Value = 100;
            var completetionMessage = $"Processing Complete. Time: {timer.ElapsedMilliseconds / 1000f} seconds";

            progressLabel.Content             = completetionMessage;
            progressBar.ToolTip               = completetionMessage;
            proceedtoResultsButton.Visibility = Visibility.Visible;
            NativeMethods.StartFlashing(this);
            await Task.WhenAll(ResultsScreen.CreateWeightViewsForAllDocumentsAsync(), ResultsScreen.BuildTextViewsForAllDocumentsAsync());

            ProcessingCompleted(this, new EventArgs());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var fragment      = new RawTextFragment(rawText, "Test");
            var percent       = 0d;
            var notfier       = new ResourceNotifier();
            var setsProcessed = 0;

            notfier.ResourceLoading += (s, e) =>
            {
                Logger.Log($"Sets Processed {++setsProcessed}");
            };
            notfier.ResourceLoaded += (s, e) =>
            {
                percent = Math.Min(100, percent + e.PercentWorkRepresented);
                Logger.Log($"Update : {e.Message} Percent : {percent += e.PercentWorkRepresented} MS : {e.ElapsedMiliseconds}");
            };
            var orchestrator =
                new AnalysisOrchestrator(new RawTextFragment(
                                             File.ReadAllLines(@".\..\..\testDocs\testDoc1.txt"), "testDoc1")
                                         );

            orchestrator.ProgressChanged += (s, e) =>
            {
                percent = Math.Min(100, percent + e.PercentWorkRepresented);
                Logger.Log($"Update : {e.Message} Percent : {percent}");
            };

            var document = orchestrator.ProcessAsync().Result.First();

            var x = document.Entities.FirstOrDefault();

            x.Match()
            .Case((IReferencer r) => r.Referencers != null ? r.RefersTo.Text : r.Text)
            .Result(x.Text);
            Logger.Log(document);
            foreach (var phrase in document.Phrases)
            {
                Logger.Log(phrase);
            }
            Input.WaitForKey(ConsoleKey.Escape);
        }
Ejemplo n.º 3
0
 private IObservable <EventPattern <ResourceLoadEventArgs> > ConfigureLoadedEventStream(ResourceNotifier loadedNotifier) =>
 Observable.FromEventPattern <ResourceLoadEventArgs>(
     addHandler: h => loadedNotifier.ResourceLoaded    += h,
     removeHandler: h => loadedNotifier.ResourceLoaded -= h
     );
Ejemplo n.º 4
0
 private IObservable <EventPattern <ResourceLoadEventArgs> > ConfigureLoadingEvents(ResourceNotifier loadingNotifier) =>
 Observable.FromEventPattern <ResourceLoadEventArgs>(
     addHandler: h => loadingNotifier.ResourceLoading    += h,
     removeHandler: h => loadingNotifier.ResourceLoading -= h
     );