public void Init(IFileManager fileManager, IBudgetSynchronizer budgetSynchronizer) { _fileManager = fileManager; _budgetSynchronizer = budgetSynchronizer; _budgetSynchronizer.DataDownloaded += UpdateData; Task.Factory.StartNew(async() => { try { if (!string.IsNullOrEmpty(Helpers.Settings.DropboxAccessToken)) { var budgetTemplate = await _budgetSynchronizer.DownloadBudgetTemplate(); if (budgetTemplate != null) { BudgetDescription = budgetTemplate; _fileManager.WriteCustomTemplate(BudgetDescription); } } if (BudgetDescription == null && _fileManager.HasCustomTemplate()) { BudgetDescription = await _fileManager.ReadCustomTemplate(); } if (BudgetDescription == null) { var assembly = typeof(MainBudget).GetTypeInfo().Assembly; //var name = assembly.GetName(); //var names = assembly.GetManifestResourceNames(); var stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{TEMPLATE_FILENAME}"); var jsonString = ""; using (var reader = new System.IO.StreamReader(stream)) { jsonString = reader.ReadToEnd(); BudgetDescription = JsonConvert.DeserializeObject <BudgetDescription>(jsonString); } } //TODO //if BudgetDescription == null budgetPlanned.Setup(BudgetDescription.Categories); if (!string.IsNullOrEmpty(Helpers.Settings.DropboxAccessToken)) { _budgetSynchronizer.Start(); LogsManager.Instance.WriteLine("Load data from cloud storage"); UpdateData(null, await _budgetSynchronizer.ForceLoad()); } else { LogsManager.Instance.WriteLine("Load data from local device"); await LoadAsync(); } } catch (Exception exc) { var msg = exc.Message; LogsManager.Instance.WriteLine(exc.Message); LogsManager.Instance.WriteLine(exc.StackTrace); } }); LogsManager.Instance.Init(fileManager); }
private void SetupCategories(List <BudgetCategoryTemplate> categoriesDesc) { BudgetPlanned.Setup(categoriesDesc); BudgetReal.Setup(categoriesDesc); }