private async Task SendHealthReportAsync() { try { ConditionalValue <BandActorState> BandActorStateResult = await this.StateManager.TryGetStateAsync <BandActorState>("BandActorState"); if (BandActorStateResult.HasValue) { ActorId doctorId = new ActorId(BandActorStateResult.Value.DoctorId); IDoctorActor doctor = ActorProxy.Create <IDoctorActor>(doctorId, this.doctorActorServiceUri); await doctor.ReportHealthAsync( this.Id.GetGuidId(), BandActorStateResult.Value.PatientName, BandActorStateResult.Value.HealthIndex, new HealthIndex(this.random.Next(0, 101))); ActorEventSource.Current.Message("Health info sent from band {0} to doctor {1}", this.Id, BandActorStateResult.Value.DoctorId); } } catch (Exception e) { ActorEventSource.Current.Message( "Band Actor failed to send health data to doctor. Exception: {0}", (e is AggregateException) ? e.InnerException.ToString() : e.ToString()); } return; }
private async Task GenerateAndSendHealthReportAsync() { try { ConditionalValue <HealthIndex> HeatlthInfoResult = await this.StateManager.TryGetStateAsync <HealthIndex>("HealthIndex"); ConditionalValue <string> PatientInfoResult = await this.StateManager.TryGetStateAsync <string>("PatientName"); ConditionalValue <Guid> DoctorInfoResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId"); if (HeatlthInfoResult.HasValue && PatientInfoResult.HasValue && DoctorInfoResult.HasValue) { ActorId doctorId = new ActorId(DoctorInfoResult.Value); HeartRateRecord record = new HeartRateRecord((float)this.random.NextDouble()); await this.SaveHealthDataAsync(record); IDoctorActor doctor = ActorProxy.Create <IDoctorActor>(doctorId, this.doctorActorServiceUri); await doctor.ReportHealthAsync( this.Id.GetGuidId(), PatientInfoResult.Value, HeatlthInfoResult.Value); ActorEventSource.Current.Message("Health info sent from band {0} to doctor {1}", this.Id, DoctorInfoResult.Value); } } catch (Exception e) { ActorEventSource.Current.Message( "Band Actor failed to send health data to doctor. Exception: {0}", (e is AggregateException) ? e.InnerException.ToString() : e.ToString()); } return; }