public async Task GrantAccess() { // Look up Patient record DataStore <Patient> patientStore = DataStore <Patient> .Collection("Patients", DataStoreType.NETWORK); var query = from patient in patientStore where patient.UserID == Patient.Id select patient; List <Patient> results = await patientStore.FindAsync(query); var activePatient = results.FirstOrDefault(); if (activePatient != null) { // Grant permission for Bob's doctor to follow Bob (feed communication) var aclForBob = new StreamAccessControlList(); aclForBob.Publishers.Add(activePatient.UserID); // Give Bob permission to publish to himself aclForBob.Subscribers.Add(activePatient.DoctorID); // Give Bob's doctor permission to follow his updates await streamStatus.GrantStreamAccess(Patient.Id, aclForBob); } }
//public async Task<User> LoginCharlie() //{ // try // { // await User.LoginAsync("Charlie", "charlie"); // var alreadyLoggedInController = new PatientViewController(); // var navController = new UINavigationController(alreadyLoggedInController); // Window.RootViewController = navController; // // REALTIME REGISTRATION // // Register for realtime // await Client.SharedClient.ActiveUser.RegisterRealtimeAsync(); // // Create stream object corresponding to "meddevcmds" stream created on the backend // streamCommand = new Stream<MedicalDeviceCommand>("device_command"); // streamStatus = new Stream<MedicalDeviceStatus>("device_status"); // } // catch (KinveyException e) // { // if (e.ErrorCategory == EnumErrorCategory.ERROR_REALTIME) // { // Console.WriteLine("VRG (exception caught) Exception from Realtime operation"); // } // Console.WriteLine("VRG (exception caught) Exception Error -> " + e.Error); // Console.WriteLine("VRG (exception caught) Exception Description -> " + e.Description); // Console.WriteLine("VRG (exception caught) Exception Debug -> " + e.Debug); // Console.WriteLine("VRG (exception caught) Exception Request ID -> " + e.RequestID); // } // return Client.SharedClient.ActiveUser; //} public async Task <User> LoginAdmin() { try { await User.LoginAsync("Admin", "admin"); var alreadyLoggedInController = new PatientViewController(); var navController = new UINavigationController(alreadyLoggedInController); Window.RootViewController = navController; // REALTIME REGISTRATION // Register for realtime await Client.SharedClient.ActiveUser.RegisterRealtimeAsync(); // Create stream object corresponding to "meddevcmds" stream created on the backend var streamCommand = new Stream <MedicalDeviceCommand>("device_command"); var streamStatus = new Stream <MedicalDeviceStatus>("device_status"); // Get user IDs for granting stream access var criteria = new UserDiscovery(); // Alice criteria.FirstName = "Alice"; var lookup = await Client.SharedClient.ActiveUser.LookupAsync(criteria); User alice = lookup[0]; // Bob criteria.FirstName = "Bob"; lookup = await Client.SharedClient.ActiveUser.LookupAsync(criteria); User bob = lookup[0]; //// Charlie //criteria.FirstName = "Charlie"; //lookup = await Client.SharedClient.ActiveUser.LookupAsync(criteria); //User charlie = lookup[0]; // Grant stream access for the device stream var streamACLDeviceAlice = new StreamAccessControlList(); streamACLDeviceAlice.Publishers.Add(alice.Id); streamACLDeviceAlice.Subscribers.Add(bob.Id); bool resultGrantDevice = await streamCommand.GrantStreamAccess(bob.Id, streamACLDeviceAlice); //var streamACLDeviceBob = new StreamAccessControlList(); //streamACLDeviceBob.Subscribers.Add(bob.Id); //bool resultGrantDeviceBob = await streamCommand.GrantStreamAccess(alice.Id, streamACLDeviceBob); // Grant stream access for the status stream var streamACLStatusBob = new StreamAccessControlList(); streamACLStatusBob.Publishers.Add(bob.Id); streamACLStatusBob.Publishers.Add(alice.Id); streamACLStatusBob.Subscribers.Add(alice.Id); streamACLStatusBob.Subscribers.Add(bob.Id); bool resultGrantStatusBob = await streamStatus.GrantStreamAccess(bob.Id, streamACLStatusBob); var streamACLStatusAlice = new StreamAccessControlList(); streamACLStatusAlice.Subscribers.Add(alice.Id); streamACLStatusAlice.Subscribers.Add(bob.Id); streamACLStatusAlice.Publishers.Add(bob.Id); streamACLStatusAlice.Publishers.Add(alice.Id); bool resultGrantStatusAlice = await streamStatus.GrantStreamAccess(alice.Id, streamACLStatusAlice); } catch (KinveyException e) { if (e.ErrorCategory == EnumErrorCategory.ERROR_REALTIME) { Console.WriteLine("VRG (exception caught) Exception from Realtime operation"); } Console.WriteLine("VRG (exception caught) Exception Error -> " + e.Error); Console.WriteLine("VRG (exception caught) Exception Description -> " + e.Description); Console.WriteLine("VRG (exception caught) Exception Debug -> " + e.Debug); Console.WriteLine("VRG (exception caught) Exception Request ID -> " + e.RequestID); } return(Client.SharedClient.ActiveUser); }