public async Task NewDoctorAsync(Guid doctorId, [FromBody] DoctorCreationRecord record)
        {
            string doctorDictionaryName         = String.Format(DoctorPatientDictionaryName, doctorId);
            string doctorMetadataDictionaryName = String.Format(DoctorMetadataDictionaryName, doctorId);

            try
            {
                //doctordictionary is just a list of GuidId to the actual doctor information
                var doctorDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, DoctorCreationRecord> >(DoctorRegistrationDictionaryName);

                //create the dictionary which holds patients for this doctor
                await this.StateManager.GetOrAddAsync <IReliableDictionary <Guid, PatientRegistrationRecord> >(doctorDictionaryName);

                //create the dictionary which holds metadata for this doctor
                await this.StateManager.GetOrAddAsync <IReliableDictionary <string, long> >(doctorMetadataDictionaryName);

                using (ITransaction tx = this.StateManager.CreateTransaction())
                {
                    if (!((await doctorDictionary.TryGetValueAsync(tx, doctorId)).HasValue))
                    {
                        //add this doctor to the list of doctors
                        await doctorDictionary.SetAsync(tx, doctorId, record);
                    }

                    await tx.CommitAsync();
                }
            }
            catch (Exception e)
            {
                // transient error. Retry.
                ServiceEventSource.Current.Message("Exception in DoctorController, NewDoctor {0}", e.ToString());
                throw;
            }

            ServiceEventSource.Current.Message("Successfully registered doctor {0}. PL: {1} D: {2}", doctorId, doctorDictionaryName, doctorMetadataDictionaryName);
            return;
        }
        private async Task CreateDeviceActorAsync(DeviceActorGenerator bag, CancellationToken cancellationToken)
        {
            //TODO: Should be able to replace this with a normal Random
            CryptoRandom random = new CryptoRandom();

            while (!cancellationToken.IsCancellationRequested && this.MaxDevicesToCreatePerService > 0)
            {
                bool created = false;
                while (!created && !cancellationToken.IsCancellationRequested)
                {
                    ActorId bandActorId;
                    Guid    doctorId;
                    int     randomCountyId = -1;
                    string  doctorName     = null;

                    randomCountyId = random.Next(0, bag.doctorsPerCounty.Keys.Count);
                    doctorName     = bag.GetRandomName(random);

                    CountyRecord randomCountyRecord = bag.doctorsPerCounty.Keys.ElementAt(randomCountyId);
                    DeviceInfo   bandActorInfo      = bag.GetRandomHealthStatus(randomCountyRecord, random);

                    try
                    {
                        bandActorId = new ActorId(Guid.NewGuid());
                        doctorId    = bandActorInfo.DoctorId;
                        //doctorId = new ActorId(bandActorInfo.DoctorId);

                        var dcr = new DoctorCreationRecord(doctorName, doctorId, randomCountyRecord);
                        ServicePartitionKey key = new ServicePartitionKey(HashUtil.getLongHashCode(bandActorInfo.DoctorId.ToString()));

                        await FabricHttpClient.MakePostRequest <DoctorCreationRecord>(
                            this.DoctorServiceUri,
                            key,
                            "DoctorEndpoint",
                            "/doctor/new/" + doctorId,
                            dcr,
                            SerializationSelector.PBUF,
                            cancellationToken
                            );

                        IDeviceActor bandActor = ActorProxy.Create <IDeviceActor>(bandActorId, ActorServiceUri);
                        await bandActor.NewAsync(bandActorInfo);

                        ServiceEventSource.Current.Message("Actor created {0} verifying...", bandActorId);

                        created = true;
                    }

                    catch (Exception e)
                    {
                        ServiceEventSource.Current.ServiceMessage(this.Context, "Failed to iniitalize device or doctor. {0}", e.ToString());
                    }
                }

                this.MaxDevicesToCreatePerService--;

                ServiceEventSource.Current.ServiceMessage(this.Context, "Created Actors, {0} remaining", this.MaxDevicesToCreatePerService);

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