public override void OnOpened()
{
base.OnOpened();
// On opening the socket connection:
// - We subscribe to changes in our person grain in orleans, so we can easily publish these to the client
if (this.ConnectionContext.User.Identity is ClaimsIdentity && this.ConnectionContext.User.Identity.IsAuthenticated)
{
var identity = this.ConnectionContext.User.Identity as ClaimsIdentity;
var cid = identity.FindFirstValue("client");
if (!String.IsNullOrWhiteSpace(cid))
{
this.clientId = cid;
}
// get the currently impersonated person
this.clientGrain = ClientGrainFactory.GetGrain(this.clientId);
// set the personGrain and subscribe for changes
AsyncHelper.RunSync(() => this.SetSubscribedPerson(this.AuthenticatedUserId));
// Checkin with the clientgrain, this retuns possible impersonation
var impersonatedUserSetting = AsyncHelper.RunSync(() => this.clientGrain.CheckIn(this.ConnectionId.ToString(), this.AuthenticatedUserId));
if (impersonatedUserSetting.HasValue && impersonatedUserSetting.Value != this.AuthenticatedUserId)
{
AsyncHelper.RunSync(() => this.Impersonate(impersonatedUserSetting.Value)); // will subscribe and set personGrain
}
}
}