Skip to content

Commit

Permalink
Using stateful grains in client app
Browse files Browse the repository at this point in the history
  • Loading branch information
Kritner committed Oct 17, 2018
1 parent baa88e9 commit e6b3705
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Kritner.OrleansGettingStarted.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static async Task<int> RunMainAsync()
using (var client = await StartClientWithRetries())
{
await DoClientWork(client);
await DoStatefulWork(client);
Console.ReadKey();
}

Expand Down Expand Up @@ -85,6 +86,52 @@ private static async Task DoClientWork(IClusterClient client)
Console.WriteLine($"{await grain.SayHello("1")}");
Console.WriteLine($"{await grain2.SayHello("2")}");
Console.WriteLine($"{await grain.SayHello("3")}");

PrintSeparatorThing();
}

private static async Task DoStatefulWork(IClusterClient client)
{
var kritnerGrain = client.GetGrain<IVisitTracker>("[email protected]");
var notKritnerGrain = client.GetGrain<IVisitTracker>("[email protected]");

await PrettyPrintGrainVisits(kritnerGrain);
await PrettyPrintGrainVisits(notKritnerGrain);

PrintSeparatorThing();
Console.WriteLine("Ayyy some people are visiting!");

await kritnerGrain.Visit();
await kritnerGrain.Visit();
await notKritnerGrain.Visit();

PrintSeparatorThing();

await PrettyPrintGrainVisits(kritnerGrain);
await PrettyPrintGrainVisits(notKritnerGrain);

PrintSeparatorThing();
Console.Write("ayyy kritner's visiting even more!");

for (int i = 0; i < 5; i++)
{
await kritnerGrain.Visit();
}

PrintSeparatorThing();

await PrettyPrintGrainVisits(kritnerGrain);
await PrettyPrintGrainVisits(notKritnerGrain);
}

private static async Task PrettyPrintGrainVisits(IVisitTracker grain)
{
Console.WriteLine($"{grain.GetPrimaryKeyString()} has visited {await grain.GetNumberOfVisits()} times");
}

private static void PrintSeparatorThing()
{
Console.WriteLine($"{Environment.NewLine}-----{Environment.NewLine}");
}
}
}

0 comments on commit e6b3705

Please sign in to comment.