public void SendInfo(SoundRecord soundRecord) { var eventHubClient = EventHubClient.CreateFromConnectionString(CloudConfiguration.EventHubConnString, CloudConfiguration.EventHubName); try { var jsonData = JsonConvert.SerializeObject(soundRecord); Console.WriteLine("{0} > Sending message to Event Hub: {1}", DateTime.Now, jsonData); eventHubClient.Send(new EventData(Encoding.UTF8.GetBytes(jsonData))); } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message); Console.ResetColor(); } }
public async void SendInfo(SoundRecord soundRecord) { Uri endpointUri = new Uri(CloudConfiguration.DocumentDbUri); string authorizationKey = CloudConfiguration.DocumentDbKey; _documentClient = new DocumentClient(endpointUri, authorizationKey); var collection = await GetDocumentCollection(); try { Console.WriteLine("{0} > Sending message to Document DB: {1}", DateTime.Now, soundRecord); var result = await _documentClient.CreateDocumentAsync(collection.SelfLink, soundRecord); } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message); Console.ResetColor(); } }
private static SoundRecord GetSoundLevel() { int venueId = _rnd.Next(1, 13); int sectionNumber = _rnd.Next(1, 11); int seatSectionId = ((venueId - 1)*10) + sectionNumber; // Read SeatCount from SeatSection table for calculated SectionId int seatCount = _seatSectionRepository.GetSeatCount(seatSectionId); // Generate a SeatNumber between 1 and SeatCount read above int seatNumber = _rnd.Next(1, seatCount + 1); int deviceId = seatNumber + _seatSectionRepository.CalculateSum(venueId, seatSectionId); DateTime currentDateTime = DateTime.UtcNow; int decibelLevel = GetDecibelLevel(currentDateTime.Minute, deviceId); decimal longitude = 0; decimal latitude = 0; // Get venue details from repo var venueModel = _venueRepository.GetVenueInformation(venueId); if (venueModel != null) { longitude = venueModel.Longitude; latitude = venueModel.Latitude; } SoundRecord soundRecord = new SoundRecord { DateTime = currentDateTime.ToString("o"), Location = new SoundRecord.GeoLocation() { Type = "Point", Coordinates = new List<decimal>() { longitude, latitude } }, DecibelLevel = decibelLevel, DeviceId = deviceId, VenueId = venueId, Seat = seatNumber, SeatSection = sectionNumber }; return soundRecord; }