Esempio n. 1
0
        public async Task <BandDataViewModel> GetBandDataAsync()
        {
            try
            {
                ConditionalValue <BandActorState> BandActorStateResult = await this.StateManager.TryGetStateAsync <BandActorState>("BandActorState");

                if (BandActorStateResult.HasValue)
                {
                    BandActorState state = BandActorStateResult.Value;

                    HealthIndexCalculator ic = this.indexCalculator;
                    HealthIndex           hi = state.HealthIndex;

                    int healthIndex = ic.ComputeIndex(hi);

                    return(new BandDataViewModel(
                               state.DoctorId,
                               this.Id.GetGuidId(),
                               state.PatientName,
                               state.CountyInfo,
                               healthIndex,
                               state.HeartRateHistory));
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException(string.Format("Exception inside band actor {0}|{1}|{2}", this.Id, this.Id.Kind, e));
            }

            throw new ArgumentException(string.Format("No band actor state {0}|{1}|{2}", this.Id, this.Id.Kind));
        }
        private static async Task VerifyActors(
            HealthIndexCalculator hic, ActorId bandActorId, string doctorName, CountyRecord randomCountyRecord, BandInfo bandActorInfo, IDoctorActor docActor,
            IBandActor bandActor)
        {
            while (true)
            {
                BandDataViewModel view = await bandActor.GetBandDataAsync();

                if (view.PersonName == bandActorInfo.PersonName)
                {
                    if (view.CountyInfo == bandActorInfo.CountyInfo)
                    {
                        if (view.DoctorId == bandActorInfo.DoctorId)
                        {
                            if (view.PersonId == bandActorId.GetGuidId())
                            {
                                if (hic.ComputeIndex(bandActorInfo.HealthIndex) == view.HealthIndex)
                                {
                                    break;
                                }
                                else
                                {
                                    await bandActor.NewAsync(bandActorInfo);

                                    await Task.Delay(100);
                                }
                            }
                        }
                    }
                }
            }

            while (true)
            {
                Tuple <CountyRecord, string> info = await docActor.GetInfoAndNameAsync();

                if (info.Item2 == String.Format("Dr. {0}", doctorName) &&
                    info.Item1 == randomCountyRecord)
                {
                    break;
                }
                else
                {
                    await docActor.NewAsync(doctorName, randomCountyRecord);

                    await Task.Delay(100);
                }
            }
        }
        public async Task <DeviceDataViewModel> GetDeviceDataAsync()
        {
            try
            {
                //check to see if the patient name is set
                //if not this actor object hasn't been initialized
                //and we can skip the rest of the checks
                ConditionalValue <string> PatientInfoResult = await this.StateManager.TryGetStateAsync <string>("PatientName");

                if (PatientInfoResult.HasValue)
                {
                    ConditionalValue <CountyRecord> CountyInfoResult = await this.StateManager.TryGetStateAsync <CountyRecord>("CountyInfo");

                    ConditionalValue <Guid> DoctorInfoResult = await this.StateManager.TryGetStateAsync <Guid>("DoctorId");

                    ConditionalValue <HealthIndex> HeatlthInfoResult = await this.StateManager.TryGetStateAsync <HealthIndex>("HealthIndex");

                    ConditionalValue <List <HeartRateRecord> > HeartRateRecords =
                        await this.StateManager.TryGetStateAsync <List <HeartRateRecord> >("HeartRateRecords");

                    HealthIndexCalculator ic = this.indexCalculator;

                    HealthIndex healthIndex = ic.ComputeIndex(HeatlthInfoResult.Value);

                    return(new DeviceDataViewModel(
                               DoctorInfoResult.Value,
                               this.Id.GetGuidId(),
                               PatientInfoResult.Value,
                               CountyInfoResult.Value,
                               healthIndex,
                               HeartRateRecords.Value));
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException(string.Format("Exception inside band actor {0}|{1}|{2}", this.Id, this.Id.Kind, e));
            }

            throw new ArgumentException(string.Format("No band actor state {0}|{1}", this.Id, this.Id.Kind));
        }