static void Main(string[] args) { List <TaskModel> tasksModel = new List <TaskModel>(); string comment = ""; ConsoleEx.WriteLine("Witam w Managerze Zadań ToDo".PadRight(50, '>').PadLeft(60, '<'), ConsoleColor.Red); //poprawic padleft i right ConsoleEx.WriteLine("W razie pomocy wpisz komendę HELP".PadRight(50, '>').PadLeft(60, '<'), ConsoleColor.Blue); do { ConsoleEx.Write("Wpisz komendę: ", ConsoleColor.Blue); comment = Console.ReadLine().ToLower(); if (Enum.GetNames(typeof(Comments)).Contains(comment)) { if (comment == Comments.help.ToString()) { ConsoleEx.Write("Lista dostępnych komend: ", ConsoleColor.Blue); ConsoleEx.WriteLine(string.Join("; ", Enum.GetNames(typeof(Comments))), ConsoleColor.Yellow); } if (comment == Comments.add.ToString()) { AddTask.Add(tasksModel); } if (comment == Comments.clear.ToString()) { Console.Clear(); } if (comment == Comments.remove.ToString()) { RemoveTask.Delete(tasksModel); } if (comment == Comments.load.ToString()) { LoaderTasks.Load(tasksModel); } if (comment == Comments.save.ToString()) { SaveTasks.Save(tasksModel); } if (comment == Comments.show.ToString()) { Show.ShowAll(tasksModel); } Console.WriteLine("hej"); } else { Console.WriteLine("Wpisałeś złą komendę"); } } while (comment != "exit"); }
/// <summary> /// Saves the contents of this result set to a file using the IFileStreamFactory provided /// </summary> /// <param name="saveParams">Parameters for saving the results to a file</param> /// <param name="fileFactory"> /// Factory for creating a stream reader/writer combo for writing results to disk /// </param> /// <param name="successHandler">Handler for a successful write of all rows</param> /// <param name="failureHandler">Handler for unsuccessful write of all rows</param> public void SaveAs(SaveResultsRequestParams saveParams, IFileStreamFactory fileFactory, SaveAsAsyncEventHandler successHandler, SaveAsFailureAsyncEventHandler failureHandler) { // Sanity check the save params and file factory Validate.IsNotNull(nameof(saveParams), saveParams); Validate.IsNotNull(nameof(fileFactory), fileFactory); // Make sure the resultset has finished being read if (!hasCompletedRead) { throw new InvalidOperationException(SR.QueryServiceSaveAsResultSetNotComplete); } // Make sure there isn't a task for this file already Task existingTask; if (SaveTasks.TryGetValue(saveParams.FilePath, out existingTask)) { if (existingTask.IsCompleted) { // The task has completed, so let's attempt to remove it if (!SaveTasks.TryRemove(saveParams.FilePath, out existingTask)) { throw new InvalidOperationException(SR.QueryServiceSaveAsMiscStartingError); } } else { // The task hasn't completed, so we shouldn't continue throw new InvalidOperationException(SR.QueryServiceSaveAsInProgress); } } // Create the new task Task saveAsTask = new Task(async() => { try { // Set row counts depending on whether save request is for entire set or a subset long rowEndIndex = RowCount; int rowStartIndex = 0; if (saveParams.IsSaveSelection) { // ReSharper disable PossibleInvalidOperationException IsSaveSelection verifies these values exist rowEndIndex = saveParams.RowEndIndex.Value + 1; rowStartIndex = saveParams.RowStartIndex.Value; // ReSharper restore PossibleInvalidOperationException } using (var fileReader = fileFactory.GetReader(outputFileName)) using (var fileWriter = fileFactory.GetWriter(saveParams.FilePath)) { // Iterate over the rows that are in the selected row set for (long i = rowStartIndex; i < rowEndIndex; ++i) { var row = fileReader.ReadRow(fileOffsets[i], i, Columns); fileWriter.WriteRow(row, Columns); } if (successHandler != null) { await successHandler(saveParams); } } } catch (Exception e) { fileFactory.DisposeFile(saveParams.FilePath); if (failureHandler != null) { await failureHandler(saveParams, e.Message); } } }); // Add exception handling to the save task Task taskWithHandling = saveAsTask.ContinueWithOnFaulted(async t => { if (failureHandler != null) { await failureHandler(saveParams, t.Exception.Message); } }); // If saving the task fails, return a failure if (!SaveTasks.TryAdd(saveParams.FilePath, taskWithHandling)) { throw new InvalidOperationException(SR.QueryServiceSaveAsMiscStartingError); } // Task was saved, so start up the task saveAsTask.Start(); }