public async Task LoadAsync() { try { LogsManager.Instance.WriteLine("Load data"); var data = await _fileManager.Load(); if (data != null) { if (data.BudgetPlanned != null) { budgetPlanned = data.BudgetPlanned; } if (data.Months != null) { _months = data.Months; foreach (var month in _months) { month.Setup(); } } } IsDataLoaded = true; //onBudgetLoaded?.Invoke(); BudgetDataChanged?.Invoke(false); } catch (Exception exc) { LogsManager.Instance.WriteLine(exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } }
public void UpdateBudgetCategories(List <BudgetCategoryForEdit> updatedCategories) { try { BudgetDescription.UpdateCategories(updatedCategories); budgetPlanned.Setup(BudgetDescription.Categories); _fileManager.WriteCustomTemplate(BudgetDescription); if (!string.IsNullOrEmpty(Helpers.Settings.DropboxAccessToken)) { _budgetSynchronizer.UploadBudgetTemplate(BudgetDescription); } GetCurrentMonthData().UpdateBudgetCategories(updatedCategories); Task.Factory.StartNew(async() => await Save()); BudgetDataChanged?.Invoke(false); } catch (Exception exc) { LogsManager.Instance.WriteLine($"Update template failed: {exc.Message}"); } }
private void UpdateData(object sender, BudgetData data) { try { if (data == null) { LogsManager.Instance.WriteLine("Cloud UpdateData == null"); Task.Run(() => LoadAsync()); } else { lock (_updateLock) { _months.Clear(); if (data.Months != null) { _months = data.Months; foreach (var month in _months) { month.Setup(); } } if (data.BudgetPlanned != null) { budgetPlanned = data.BudgetPlanned; } } IsDataLoaded = true; BudgetDataChanged?.Invoke(true); Task.Factory.StartNew(async() => await Save(false)); } } catch (Exception exc) { LogsManager.Instance.WriteLine("SynchronizeData exception: " + exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } }