public static async Task sendMessage(BrokeredMessage message) { try { Console.ForegroundColor = ConsoleColor.DarkYellow; Stream stream = message.GetBody <Stream>(); StreamReader reader = new StreamReader(stream, Encoding.ASCII); string s = reader.ReadToEnd(); s = String.Format("Message from hospital<br/><br/>{0}", s); Console.WriteLine(s); Console.WriteLine("Connecting emergency services... Sending Message to Patient..\n{0}", s); MessageToDevice.SendMessageToPatient(s); bool isSuccess = await sendToNotificationHub("gcm", s, string.Empty); if (!isSuccess) { Console.WriteLine("Sending notification failed"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private static void HandleHospitalMessages() { var connectionString = "Endpoint=sb://patientmr.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=TycKNyOj7Zn0l6hQ4QWLY3qaxhZOm1ErGb925FERKDI="; var queueName = "bpcriticalqueue"; var client = QueueClient.CreateFromConnectionString(connectionString, queueName); client.OnMessage(message => { try { Console.ForegroundColor = ConsoleColor.Red; Stream stream = message.GetBody <Stream>(); StreamReader reader = new StreamReader(stream, Encoding.ASCII); string s = reader.ReadToEnd(); s = String.Format("Pulse: {0}..<br/><br/>", s); Console.WriteLine(s); Console.WriteLine("Connecting emergency services... Sending Message to Doctor..\n"); string strmessage = String.Concat(s, "<font color='Red'> Patient pulse critically went down.</font><br/> <br/> All systems activated. <br/> <br/>Message sent to hospital emergency service and family members.<br/> <br/>Please be available for all communications.<br/>----------EOM----------<br/> <br/>"); MessageToDevice.SendMessageToHospital(strmessage); } catch (Exception e) { Console.WriteLine(e.Message); } }); Console.WriteLine("Receive critical messages. Ctrl-C to exit.\n"); }
public async Task NotifyPhotoArrivedToDeviceAsync(string deviceId, string blobUri) { MessageToDevice message = new MessageToDevice() { Action = Action.BLOB_UPLOADED, TextMessage = "Foto ricevuta con successo e presente al link: { blobUri}", SendMessageDate = DateTimeOffset.UtcNow }; byte[] messagePayload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); await _serviceClient.SendAsync(deviceId, new Message(messagePayload)).ConfigureAwait(false); }