private Transporter(IRepoDeviceMetadata deviceRepo) { _deviceRepo = deviceRepo; //HACK: Get this in to config! const string connectionString = "HostName=FloProUS.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=mDDgyLphcax+u2pa/Xn4DWzp/nrhia39JHjUdqqSuNg=="; const string iotHubToClientEndpoint = "messages/events"; _serviceClt = ServiceClient.CreateFromConnectionString(connectionString); var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, iotHubToClientEndpoint); foreach (var partition in eventHubClient.GetRuntimeInformation().PartitionIds) { //While debugging I found it helpful to backup the receiver a little to keep from having to constantly run the board //This allowed me to fire up the board every 15 minutes or as needed while developing the web var receiver = eventHubClient .GetDefaultConsumerGroup() .CreateReceiver(partition, DateTime.Now.AddMinutes(-15)); _sbTasks.Add(Listen(receiver)); } }
public string ToString(IRepoDeviceMetadata deviceRepo) { int cs; int.TryParse(CurrentState, out cs); if (cs > 0) { if (Enum.IsDefined(typeof(BulbStateEnum), cs)) { CurrentState = ((BulbStateEnum)cs).ToString(); } if (Enum.IsDefined(typeof(CurrentSensorStateEnum), cs)) { CurrentState = ((CurrentSensorStateEnum)cs).ToString(); } if (Enum.IsDefined(typeof(IntersectionStateEnum), cs)) { CurrentState = ((IntersectionStateEnum)cs).ToString(); } if (Enum.IsDefined(typeof(LampStateEnum), cs)) { CurrentState = ((LampStateEnum)cs).ToString(); } if (Enum.IsDefined(typeof(RightOfWayStateEnum), cs)) { CurrentState = ((RightOfWayStateEnum)cs).ToString(); } } var stream = (EventStreamEnum)EventStream; var errorNote = IsError ? " ***ERROR*** " : ""; var meta = deviceRepo.GetByDeviceId(DeviceId ?? IntersectionId ?? Guid.Empty); var msg = $"{Timestamp.ToString("yyyy-MM-dd HH:mm:ss")}Z - {errorNote}{stream}: {meta?.FriendlyName}({meta?.DeviceType})"; if (!string.IsNullOrWhiteSpace(Function)) { msg = string.Concat(msg, $" - Function: {Function}"); } if (!string.IsNullOrWhiteSpace(Description)) { msg = string.Concat(msg, $" - Description: {Description}"); } if (ParentDeviceId.HasValue) { msg = string.Concat(msg, $" - ParentDeviceId: {ParentDeviceId}"); } if (!string.IsNullOrWhiteSpace(Message)) { msg = string.Concat(msg, $" - Message: {Message}"); } if (!string.IsNullOrWhiteSpace(OldState)) { msg = string.Concat(msg, $" - OldState: {OldState}"); } if (!string.IsNullOrWhiteSpace(CurrentState)) { msg = string.Concat(msg, $" - CurrentState: {CurrentState}"); } if (UsageFactorOne != 0) { msg = string.Concat(msg, $" - UsageFactorOne: {UsageFactorOne}"); } if (UsageFactorTwo != 0) { msg = string.Concat(msg, $" - UsageFactorTwo: {UsageFactorTwo}"); } return(msg); }