private void UpdateBasedOnTemporaryDessychronized(Data data) { if (app.TemporaryDesynchronized.Count > 0) { var addProjects = app.TemporaryDesynchronized.Where(x => (x["type"] as string).Contains("project_add")).ToList(); var removeProjects = app.TemporaryDesynchronized.Where(x => (x["type"] as string).Contains("project_delete")).ToList(); if (addProjects.Count > 0) { foreach (var addProject in addProjects) { Project Project = new Project { name = (string)(addProject["args"] as Dictionary<string, object>)["name"], color = (int)(addProject["args"] as Dictionary<string, object>)["color"], }; string tempKey = (addProject["temp_id"]).ToString(); if (data.TempIdMapping.ContainsKey(tempKey)) Project.id = data.TempIdMapping[tempKey]; data.Projects.Add(Project); } } if (removeProjects.Count > 0) { foreach (var removeProject in removeProjects) { var dicTempArgs = removeProject["args"] as Dictionary<string, object>; var tempStringIdProjects = (dicTempArgs["ids"] as string).Replace("[", string.Empty).Replace("]", string.Empty).Split(','); List<int> idProjects = new List<int>(); foreach (var itemStringID in tempStringIdProjects) { idProjects.Add(Int32.Parse(itemStringID)); } if (idProjects.Count > 1) { throw new Exception("Multiple deletions is not implemented yet."); } var realProjectToRemove = data.Projects.Where(x => x.id == idProjects.First()).FirstOrDefault(); if (realProjectToRemove != null) { data.Projects.Remove(realProjectToRemove); } else { //Project was already remove at server, another words, do nothing :) } } } } }
public static void updateAll(Data fullData) { App app = Application.Current as App; app.projects = fullData.Projects; app.items = fullData.Items; app.notes = fullData.Notes; }