예제 #1
0
        /// <summary>
        /// Initializes important members of this application.
        /// </summary>
        /// <param name="mainWindow">
        /// A static instance of <see cref="MainWindow"/> which will be provided for other classes.
        /// </param>
        /// <param name="scheduler">
        /// A <see cref="TaskScheduler"/> used to start the start <see cref="Task"/>s.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The parameter was passed as null.
        /// </exception>
        public static async void StartAsync(MainWindow mainWindow, TaskScheduler scheduler)
        {
            if (mainWindow == null)
            {
                throw new ArgumentNullException("mainWindow");
            }

            Io.CreateFiles();

            var loadFilesTask = LoadFilesAsync();

            MainWindow = mainWindow;

            // ToDo: C# 6.0 auto-initialization of properties
            NoTextChangedPlox = false;

            cancellationToken   = new CancellationTokenSource();
            highlightSyntaxTask = new Task(() => FacilitateCoding.HighlightSyntaxAsync(RecognitionEngine.AllWordsInCode, CurrentProgrammingLanguage), CancellationToken.None, TaskCreationOptions.LongRunning);
            pseudoSenseTask     = new Task(() => FacilitateCoding.PseudoSenseAsync(RecognitionEngine.PreviousWord, RecognitionEngine.AllWordsInCode, CurrentProgrammingLanguage, MainWindow.CodeListBox), CancellationToken.None, TaskCreationOptions.LongRunning);
            errorSearchTask     =
                new Task(
                    () =>
                    MistakeEngine.MistakeSearchAsync(
                        RecognitionEngine.AllWordsInCode,
                        mainWindow.ErrorListView,
                        TaskScheduler.FromCurrentSynchronizationContext()),
                    CancellationToken.None,
                    TaskCreationOptions.LongRunning);

            await Task.Factory.StartNew(() => Gui.FillProgrammingLanguageComboBoxAsync(ProgrammingLanguages, MainWindow.ProgrammingLanguageComboBox), CancellationToken.None, TaskCreationOptions.None, scheduler);

            await loadFilesTask.ContinueWith(task => Gui.FillLocalizationLanguageComboBoxAsync(LocalizationLanguages, MainWindow.LocalizationLanguageComboBox), scheduler);

            MainWindow.LocalizationLanguageComboBox.SelectedItem = currentLocalizationLanguage["language"];
            MainWindow.ProgrammingLanguageComboBox.SelectedItem  = currentProgrammingLanguage.Name;
            mainWindow.Show();
            mainWindow.CodeTextBox.Focus();
        }
예제 #2
0
        /// <summary>
        /// Starts the performance intensive <see cref="Task"/>s which round up <see cref="MainClass.CodeAlteredAsync"/>.
        /// </summary>
        /// <param name="scheduler">
        /// The <see cref="TaskScheduler"/> containing GUI-context.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The parameter was passed as null.
        /// </exception>
        public static async void StartPerformanceIntensiveCodeAlteredTasksAsync(TaskScheduler scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }

            switch (highlightSyntaxTask.Status)
            {
            case TaskStatus.Created:
                highlightSyntaxTask.Start(scheduler);
                break;

            case TaskStatus.RanToCompletion:
            case TaskStatus.Canceled:
            case TaskStatus.Faulted:
                highlightSyntaxTask.Dispose();
                highlightSyntaxTask =
                    new Task(
                        () => FacilitateCoding.HighlightSyntaxAsync(RecognitionEngine.AllWordsInCode, CurrentProgrammingLanguage),
                        cancellationToken.Token,
                        TaskCreationOptions.LongRunning);
                highlightSyntaxTask.Start(scheduler);
                break;
            }

            switch (errorSearchTask.Status)
            {
            case TaskStatus.Created:
                errorSearchTask.Start(scheduler);
                break;

            case TaskStatus.RanToCompletion:
            case TaskStatus.Faulted:
                errorSearchTask.Dispose();
                errorSearchTask = new Task(
                    () => MistakeEngine.MistakeSearchAsync(RecognitionEngine.AllWordsInCode, MainWindow.ErrorListView, scheduler),
                    cancellationToken.Token,
                    TaskCreationOptions.LongRunning);
                errorSearchTask.Start(scheduler);
                break;
            }

            try
            {
                highlightSyntaxTask.Wait();
            }
            catch (AggregateException)
            {
                if (highlightSyntaxTask.Exception != null)
                {
                    Console.WriteLine(@"AggregateException thrown by {0}: {1}", highlightSyntaxTask.Id, highlightSyntaxTask.Exception.Message);
                    foreach (var innerException in highlightSyntaxTask.Exception.InnerExceptions)
                    {
                        Console.WriteLine(@"InnerException:{0}", innerException.Message);
                    }
                }
            }

            try
            {
                errorSearchTask.Wait();
            }
            catch (AggregateException)
            {
                if (errorSearchTask.Exception != null)
                {
                    Console.WriteLine(@"AggregateException thrown by {0}: {1}", errorSearchTask.Id, errorSearchTask.Exception.Message);
                    foreach (var innerException in errorSearchTask.Exception.InnerExceptions)
                    {
                        Console.WriteLine(@"InnerException:{0}", innerException.Message);
                    }
                }
            }
        }