/// <summary> /// Refresh or clear the log by reloading the default page /// </summary> /// <param name="pages"></param> /// <returns></returns> private async Task UpdateLog(IDictionary <string, string> pages) { string loc = await lp.GetLocation(); loc = "Device Location: " + loc; string html = pages[NavConstants.DEFAULT_PAGE].Replace(devloc, loc); devloc = loc; htmlPages[NavConstants.DEFAULT_PAGE] = html; }
/// <summary> /// sends a number of messages to the cloud /// </summary> /// <param name="numMsg">The number of messages to send</param> /// <returns></returns> private async Task SendMessages(int numMsg) { sendMsg = true; string listElements = ""; string postStatus = Constants.READY_AZURE; for (int i = 0; i < numMsg; i++) { if (sendMsg) { string msg = await lp.GetLocation(); string[] parsedmsg = msg.Split(','); var coords = new { type = "coordinates", latitude = parsedmsg[0], longitude = parsedmsg[1], deviceName = msgHub.GetDeviceId(), version = Constants.VERSION }; var str = new { message = coords, time = DateTime.Now.ToString() }; var fullMsg = JsonConvert.SerializeObject(str); try { await msgHub.SendDeviceToCloudMessageAsync(fullMsg); } catch (Exception) { postStatus = Constants.ERROR_AZURE; break; } await Task.Delay(TimeSpan.FromSeconds(1)); string newElement = "<li class='msg'>" + fullMsg + "</li>\n"; listElements = newElement + listElements; } else { Debug.WriteLine("MESSAGES STOPPED"); break; } } listElements = Constants.LIST_HEADER + "\n" + listElements; string html = await LoadandUpdateStatus(Constants.LIST_HEADER, listElements, NavConstants.DEFAULT_PAGE); html = await LoadandUpdateStatus(status, postStatus, NavConstants.DEFAULT_PAGE); status = postStatus; }
private async Task <string> GenerateCoordinateMessage(string device) { string coords = await lp.GetLocation(); Debug.WriteLine(coords); string[] parsedmsg = coords.Split(','); var update = new { type = "pinUpdate", latitude = parsedmsg[0], longitude = parsedmsg[1], pin = BlinkyController.PinNumber(), pinStatus = BlinkyController.PinStatus() }; var str = new { message = update, time = DateTime.Now.ToString(), receiver = device, sender = msgHub.GetDeviceId(), version = Constants.VERSION }; var fullMsg = JsonConvert.SerializeObject(str); Debug.WriteLine(fullMsg); return(fullMsg); }