public void loadLocalData() { Dictionary<string, Task> loadedTasks = null; TasksDict = null; FileStream fs = new FileStream(path, FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); loadedTasks = (Dictionary<string, Task>)formatter.Deserialize(fs); TasksDict = loadedTasks; } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { //selectedTask = TasksDict.ElementAt(0).Value; user = TasksDict.ElementAt(0).Value.executor; fs.Close(); } }
// обновляет данные об исполнителе private void updateExecutor(Executor currentExecutor) { int tasksCompleted = 0; int tasksInWork = 0; int tasksCorrecting = 0; foreach (KeyValuePair<string, Task> task in TasksDict) { if (task.Value.status == Task.Statuses.Completed.ToString()) tasksCompleted++; if (task.Value.status == Task.Statuses.InWork.ToString()) tasksInWork++; if (task.Value.status == Task.Statuses.Correcting.ToString()) tasksCorrecting++; } currentExecutor.correctingTime = new TimeSpan(0); currentExecutor.workTime = new TimeSpan(0); foreach (Task task in TasksDict.Values) { currentExecutor.correctingTime += task.correctingTime; currentExecutor.workTime += task.workTime; } currentExecutor.inWorkTasks = tasksInWork; currentExecutor.completedTasks = tasksCompleted; currentExecutor.correctingTasks = tasksCorrecting; user = currentExecutor; }