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);
                }
            }
        }
Beispiel #2
0
        private async Task <string> GetRandomIdsAsync()
        {
            ServiceUriBuilder serviceUri = new ServiceUriBuilder(this.GetSetting("BandActorServiceInstanceName"));
            Uri fabricServiceName        = serviceUri.ToUri();

            CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));

            CancellationToken token = cts.Token;

            FabricClient         fc         = new FabricClient();
            ServicePartitionList partitions = await fc.QueryManager.GetPartitionListAsync(fabricServiceName);

            ActorId bandActorId = null;

            try
            {
                while (!token.IsCancellationRequested && bandActorId == null)
                {
                    foreach (Partition p in partitions)
                    {
                        long partitionKey = ((Int64RangePartitionInformation)p.PartitionInformation).LowKey;
                        token.ThrowIfCancellationRequested();
                        ContinuationToken queryContinuationToken = null;
                        IActorService     proxy = ActorServiceProxy.Create(fabricServiceName, partitionKey);
                        PagedResult <ActorInformation> result = await proxy.GetActorsAsync(queryContinuationToken, token);

                        foreach (ActorInformation info in result.Items)
                        {
                            bandActorId = info.ActorId;
                            break;
                        }
                        //otherwise we will bounce around other partitions until we find an actor
                    }
                }

                IBandActor        bandActor = ActorProxy.Create <IBandActor>(bandActorId, fabricServiceName);
                BandDataViewModel data      = await bandActor.GetBandDataAsync();

                return(string.Format("{0}|{1}", bandActorId, data.DoctorId));
            }
            catch
            {
                //no actors found within timeout
                throw;
            }
        }
Beispiel #3
0
        private static async Task VerifyActors(
            HealthIndexCalculator hic, ActorId bandActorId, string doctorName, CountyRecord randomCountyRecord, BandInfo bandActorInfo, IDoctorActor docActor,
            IBandActor bandActor, CancellationToken ct)
        {
            ServiceEventSource.Current.Message("Verifying Actor {0}", bandActorId);

            bool bandVerified     = false;
            bool doctorVerified   = false;
            int  bandErrorCount   = 0;
            int  doctorErrorCount = 0;

            while (!ct.IsCancellationRequested && !bandVerified && !doctorVerified)
            {
                await Task.Delay(100);

                if (!bandVerified)
                {
                    try
                    {
                        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 (view.HealthIndexValue == bandActorInfo.HealthIndex)
                                        {
                                            bandVerified = true;
                                            ServiceEventSource.Current.Message("Band actor verified.");
                                        }
                                        else
                                        {
                                            await bandActor.NewAsync(bandActorInfo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        bandErrorCount++;
                        ServiceEventSource.Current.Message("Exception Count {0} verifying band actor, retrying. {1}", bandErrorCount, e);
                    }
                }
                else
                {
                    ServiceEventSource.Current.Message("band already verified, skipping");
                }


                if (!doctorVerified)
                {
                    try
                    {
                        Tuple <CountyRecord, string> info = await docActor.GetInfoAndNameAsync();

                        if (info.Item2 == String.Format("Dr. {0}", doctorName) &&
                            info.Item1 == randomCountyRecord)
                        {
                            doctorVerified = true;
                            ServiceEventSource.Current.Message("Doctor actor verified.");
                        }
                        else
                        {
                            await docActor.NewAsync(doctorName, randomCountyRecord);
                        }
                    }
                    catch (Exception e)
                    {
                        doctorErrorCount++;
                        ServiceEventSource.Current.Message("Exception Count {0} verifying doctor actor, retrying. {1}", doctorErrorCount, e);
                    }
                }
                else
                {
                    ServiceEventSource.Current.Message("doctor already verified, skipping");
                }
            }
        }