Skip to content

Commit

Permalink
Hygeine added to logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
anban4u committed Jul 7, 2024
1 parent 3ba5bf1 commit 30a81c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions Core/Domains/Economy/Services/PaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public async Task AddMoneyInGlobalAccountWithoutGateway(int accountId, decimal a
CreateOrUpdateDraftTransactionHistoryForAddingGlobalAccountMoney(account.Id, amount, "Internal");

await GetNew<PaymentService>().AddGlobalAccountBalance(transactionHistory.Id);

}


Expand Down
16 changes: 10 additions & 6 deletions Core/Domains/World/Services/WorldService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public WorldService(ILifetimeScope scope) : base(scope, ContextNames.World)
{
}

public async Task Init()
public async Task Start()
{
Log.Information("Running world");
var myOrg = _<Tenant>(1);
if(myOrg == null)
{
Expand All @@ -31,7 +32,7 @@ public async Task Init()
await Save(myOrg);

}

Log.Information("Got current org {o}", new { myOrg.Key, myOrg.Name, myOrg.Description });
using (var registrationService = GetTenanted<RegistrationService>(myOrg.Id))
using (var currencyService = GetTenanted<CurrencyService>(myOrg.Id))
using (var accountService = GetTenanted<AccountService>(myOrg.Id))
Expand All @@ -53,24 +54,27 @@ public async Task Init()
await currencyService.Save(currency);

}

Log.Information("Got currency {c}", new { currency.Name, currency.ShortName, currency.Type, currency.Symbol, currency.Key});
//create global payin account for marketing.
//This account is used as the central account where money can be added directly
await accountService.GetOrCreateCentralAccounts(currency.Id, AccountSponsorType.Marketing);
Log.Information("Created Central accounts for {p} purpose", AccountSponsorType.Marketing);
var centralPayinAccount = accountService.GetCentralPayinAccountBySponsorType(currency.Id, AccountSponsorType.Marketing);
await paymentService.AddMoneyInGlobalAccountWithoutGateway(centralPayinAccount.Id, 1000);

Log.Information("Added 1000 MCCs to central payin account. Current balance {b}", paymentService.GetAccountBalance(centralPayinAccount.Id));
//Create user

var me = await registrationService.SearchOrCreateRegistration("MySystemUserId", "Me", ConnectionType.Tenant);
await ShowUserAccountBalances(paymentService, me);
Log.Information("User {u} created", new { me.Username, me.Connections?.First()?.ConnectionKey });

await ShowUserAccountBalances(paymentService, me);
Log.Information("Going to transfer some cash now 😁");
//Send me some cash
await paymentService.TransferAmountFromGlobalAccount(me, 1, $"UniqueKeyForYourTransaction_{ShortId.Generate()}",
"nameof(YourEntityThatTrigerredTheTransfer)", 1, "GenericTransfer", centralPayinAccount.AccountSponsor,
purpose: "My eternal purpose to make transfers");
await ShowUserAccountBalances(paymentService, me);

Log.Information("We got money!");
}


Expand Down
19 changes: 15 additions & 4 deletions Examples/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Horde.Core.Interfaces.Data;
using Horde.Core.Services;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace Examples
{
Expand All @@ -14,11 +15,21 @@ public TestService(ILifetimeScope scope) : base(scope, ContextNames.World)

public async Task StartAsync(CancellationToken cancellationToken)
{
Task.Run(async () =>
{
GetRepository(ContextNames.World).CreateDatabase();
//run migrations as explained in readme
try
{
await Get<WorldService>().Start();
}
catch(Exception ex)
{
Log.Error(ex, "The world starter failed");
}
});
//Initialize and migrate sqlite
GetRepository(ContextNames.World).CreateDatabase();
//run migrations as explained in readme

await Get<WorldService>().Init();


}

Expand Down

0 comments on commit 30a81c0

Please sign in to comment.