public async Task PublishAsync() { log.Debug("Publishing.."); if (network.IsOnline) { log.Debug("Network is online."); var commands = await storage.LoadAsync(); if (commands != null && commands.Count > 0) { log.Debug($"Publishing '{commands.Count}' expenses."); foreach (CreateOutcome command in commands) { await commandDispatcher.HandleAsync(command); } await storage.DeleteAsync(); await eventDispatcher.PublishAsync(new LocallyStoredExpensesPublished()); } else { log.Debug($"Local storage is empty."); } } }
public async Task StoreAsync <TCommand>(TCommand command) { if (command is CreateOutcome expense) { var expenses = await expenseStorage.LoadAsync() ?? new List <CreateOutcome>(); expenses.Add(expense); await expenseStorage.SaveAsync(expenses); await eventDispatcher.PublishAsync(new LocallyStoredExpenseCreated()); } else { throw Ensure.Exception.InvalidOperation($"Command '{command.GetType().Name}' is not support offline yet."); } }
public async Task PublishAsync() { if (network.IsOnline) { var commands = await storage.LoadAsync(); if (commands != null && commands.Count > 0) { foreach (CreateOutcome command in commands) { await commandDispatcher.HandleAsync(command); } await storage.DeleteAsync(); await eventDispatcher.PublishAsync(new LocallyStoredExpensesPublished()); } } }