/// <summary> /// Asks the user if they want to cancle the file fetcher process. /// </summary> /// <param name="fileFetcher"></param> /// <returns></returns> public bool cancleFileFetcher(UpdateRoutine fileFetcher) { var consoleKey = Console.ReadKey(true); if (consoleKey.Key == ConsoleKey.Escape) { fileFetcher.Pause(); UserInterface.WriteToConsole("\n\nDo you want to stop the current process? \nType s to stop or c to continue."); string input = UserInterface.ReadFromConsole(); if (input.ToUpper() == "C") { fileFetcher.Resume(); return false; // Continue } else if (input.ToUpper() == "S") { return true; // Break the loop } else { UserInterface.WriteToConsole("Error: Input was not recognized, the current process will now continue. Press Esc to stop the operation."); } } return false; }
public void Navigate(string file) { UpdateRoutine.Clear(); RenderRoutine.Clear(); RenderContext.Reset(); CurrentDocument = new Document(this, File.ReadAllText(file)); Global.InitializeJScript(CurrentDocument); CurrentDocument.ProcessRendering(); }
/// <summary> /// Runs the AutoUpdater application /// </summary> public void runNewUpdater() { UpdateRoutine fileFetcher = new UpdateRoutine(); CancellationTokenSource fileFetcher_cancelationToken = new CancellationTokenSource(); Task fileFetcherTask = Task.Factory.StartNew(() => fileFetcher.fetchFile(fileFetcher_cancelationToken)); // Check if the user wants to cancle while (!cancleFileFetcher(fileFetcher)); // Stop the file fetcher fileFetcher_cancelationToken.Cancel(); UserInterface.WriteToConsole("Canceling current process, please wait..."); while (!fileFetcher.download_finished) { }// Wait for the file fetcher to finish UserInterface.WriteToConsole("Process terminated."); restart(); }