private async Task ProcessAction(ActionModel eventData) { if (eventData == null) { Trace.TraceWarning("Action event is null"); return; } try { // NOTE: all column names from ASA come out as lowercase; see // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics string deviceId = eventData.DeviceID; string ruleOutput = eventData.RuleOutput; if (ruleOutput.Equals("AlarmTemp", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: temperature rule triggered!"); double tempReading = eventData.Reading; string tempActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(tempActionId)) { await _actionLogic.ExecuteLogicAppAsync( tempActionId, deviceId, "Temperature", tempReading); } else { Trace.TraceError("ActionProcessor: tempActionId value is empty for temperatureRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmWaterLevel", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: water level rule triggered!"); double waterLevelReading = eventData.Reading; string waterLevelActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(waterLevelActionId)) { await _actionLogic.ExecuteLogicAppAsync( waterLevelActionId, deviceId, "Humidity", waterLevelReading); } else { Trace.TraceError("ActionProcessor: waterLevelActionId value is empty for waterLevelRuleOutput '{0}'", ruleOutput); } } } catch (Exception e) { Trace.TraceError("ActionProcessor: exception in ProcessAction:"); Trace.TraceError(e.ToString()); } }
private async Task ProcessAction(ActionModel eventData) { if (eventData == null) { Trace.TraceWarning("Action event is null"); return; } try { // NOTE: all column names from ASA come out as lowercase; see // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics string deviceId = eventData.DeviceID; string ruleOutput = eventData.RuleOutput; if (ruleOutput.Equals("AlarmTemp", StringComparison.OrdinalIgnoreCase)) { //MDS bae 2017.0626 string iotHubConnectionString = "HostName=soulbrainsuite03c80.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=imdKYODaeMsTQVqE3Z/rrHUC4Lne8Azg8I7Grf4fBU8="; iotHubServiceClient = ServiceClient.CreateFromConnectionString(iotHubConnectionString); string commandParameterNew = "{\"Name\":\"CaptureImage\",\"Parameters\":{}}"; await iotHubServiceClient.SendAsync(deviceId, new Message(Encoding.UTF8.GetBytes(commandParameterNew))); //MDS bae 2017.0626 var appSettingsReader = new AppSettingsReader(); var connectionString = "DefaultEndpointsProtocol=https;AccountName=soulbrainsuite;AccountKey=40ke5Jv9rIwl+FXeJ6XHseP9xTwe6+0Dz6x1WlVwoitCm1nY05UUEwhne4WRcOT6RtFcPf4YWvZisdL9gjsKZA==;EndpointSuffix=core.windows.net"; CloudStorageAccount storageaccount = CloudStorageAccount.Parse(connectionString); blobClient = storageaccount.CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference(blobContainerName); await blobContainer.CreateIfNotExistsAsync(); await blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(deviceId); foreach (IListBlobItem blob in blobDirectory.ListBlobs()) { if (blob.GetType() == typeof(CloudBlockBlob)) { flirimageurl = blob.Uri.ToString(); } } Trace.TraceInformation("ProcessAction: temperature rule triggered!"); double tempReading = eventData.Reading; string tempActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(tempActionId)) { await _actionLogic.ExecuteLogicAppAsync( tempActionId, deviceId, flirimageurl, //MDS bae 2017.0626 add imageurl parameter "Temperature", tempReading); } else { Trace.TraceError("ActionProcessor: tempActionId value is empty for temperatureRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmHumidity", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: humidity rule triggered!"); double humidityReading = eventData.Reading; string humidityActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(humidityActionId)) { await _actionLogic.ExecuteLogicAppAsync( humidityActionId, deviceId, flirimageurl, //MDS bae 2017.0626 add imageurl parameter "Humidity", humidityReading); } else { Trace.TraceError("ActionProcessor: humidityActionId value is empty for humidityRuleOutput '{0}'", ruleOutput); } } } catch (Exception e) { Trace.TraceError("ActionProcessor: exception in ProcessAction:"); Trace.TraceError(e.ToString()); } }
private async Task ProcessAction(dynamic eventData) { if (eventData == null) { Trace.TraceWarning("Action event is null"); return; } try { // NOTE: all column names from ASA come out as lowercase; see // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics string deviceId = eventData.deviceid; string temperatureRuleOutput = eventData.temperatureruleoutput; if (!string.IsNullOrWhiteSpace(temperatureRuleOutput)) { Trace.TraceInformation("ProcessAction: temperature rule triggered!"); double tempReading = ExtractDouble(eventData.tempreading); string tempActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(temperatureRuleOutput); if (!string.IsNullOrWhiteSpace(tempActionId)) { await _actionLogic.ExecuteLogicAppAsync( tempActionId, deviceId, "Temperature", tempReading); } else { Trace.TraceError("ActionProcessor: tempActionId value is empty for temperatureRuleOutput '{0}'", temperatureRuleOutput); } } string humidityRuleOutput = eventData.humidityruleoutput; if (!string.IsNullOrWhiteSpace(humidityRuleOutput)) { Trace.TraceInformation("ProcessAction: humidity rule triggered!"); double humidityReading = ExtractDouble(eventData.humidityreading); string humidityActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(humidityRuleOutput); if (!string.IsNullOrWhiteSpace(humidityActionId)) { await _actionLogic.ExecuteLogicAppAsync( humidityActionId, deviceId, "Humidity", humidityReading); } else { Trace.TraceError("ActionProcessor: humidityActionId value is empty for humidityRuleOutput '{0}'", humidityRuleOutput); } } } catch (Exception e) { Trace.TraceError("ActionProcessor: exception in ProcessAction:"); Trace.TraceError(e.ToString()); } }
private async Task ProcessAction(ActionModel eventData) { if (eventData == null) { Trace.TraceWarning("Action event is null"); return; } try { // NOTE: all column names from ASA come out as lowercase; see // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics string deviceId = eventData.DeviceID; string ruleOutput = eventData.RuleOutput; if (ruleOutput.Equals("AlarmTEMP", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: temperature rule triggered!"); double tempReading = eventData.Reading; string tempActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(tempActionId)) { await _actionLogic.ExecuteLogicAppAsync( tempActionId, deviceId, "TEMP", tempReading); } else { Trace.TraceError("ActionProcessor: tempActionId value is empty for temperatureRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmREAR_TPM", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: REAR_TPM rule triggered!"); double REAR_TPMReading = eventData.Reading; string REAR_TPMActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(REAR_TPMActionId)) { await _actionLogic.ExecuteLogicAppAsync( REAR_TPMActionId, deviceId, "REAR_TPM", REAR_TPMReading); } else { Trace.TraceError("ActionProcessor: REAR_TPM value is empty for REAR_TPMRuleOutput '{0}'", ruleOutput); } } //insert DATA FIELD if (ruleOutput.Equals("AlarmFRONT_TPM", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: FRONT_TPM rule triggered!"); double FRONT_TPMReading = eventData.Reading; string FRONT_TPMActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(FRONT_TPMActionId)) { await _actionLogic.ExecuteLogicAppAsync( FRONT_TPMActionId, deviceId, "FRONT_TPM", FRONT_TPMReading); } else { Trace.TraceError("ActionProcessor: FRONT_TPM ActionId value is empty for FRONT_TPMRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmBETTERY_VOLT", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: BETTERY_VOLT rule triggered!"); double BETTERY_VOLTReading = eventData.Reading; string BETTERY_VOLTActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(BETTERY_VOLTActionId)) { await _actionLogic.ExecuteLogicAppAsync( BETTERY_VOLTActionId, deviceId, "BETTERY_VOLT", BETTERY_VOLTReading); } else { Trace.TraceError("ActionProcessor: BETTERY_VOLT ActionId value is empty for BETTERY_VOLTRuleOutput '{0}'", ruleOutput); } } } catch (Exception e) { Trace.TraceError("ActionProcessor: exception in ProcessAction:"); Trace.TraceError(e.ToString()); } }
private async Task ProcessAction(dynamic eventData) { if (eventData == null) { Trace.TraceWarning("Action event is null"); return; } try { // NOTE: all column names from ASA come out as lowercase; see // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics string deviceId = eventData.deviceid; string ruleOutput = eventData.ruleoutput; if (ruleOutput.Equals("AlarmTemp", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: temperature rule triggered!"); double tempReading = ExtractDouble(eventData.reading); string tempActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(tempActionId)) { await _actionLogic.ExecuteLogicAppAsync( tempActionId, deviceId, "Temperature", tempReading); } else { Trace.TraceError("ActionProcessor: tempActionId value is empty for temperatureRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmSpeed", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: speed rule triggered!"); double speedReading = ExtractDouble(eventData.reading); string speedActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(speedActionId)) { await _actionLogic.ExecuteLogicAppAsync( speedActionId, deviceId, "Speed", speedReading); } else { Trace.TraceError("ActionProcessor: speedActionId value is empty for speedRuleOutput '{0}'", ruleOutput); } } if (ruleOutput.Equals("AlarmObstacle", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("ProcessAction: obstacle rule triggered!"); bool obstacleReading = ExtractBoolean(eventData.reading); string obstacleActionId = await _actionMappingLogic.GetActionIdFromRuleOutputAsync(ruleOutput); if (!string.IsNullOrWhiteSpace(obstacleActionId)) { //await _actionLogic.ExecuteLogicAppAsync( // obstacleActionId, // deviceId, // "IsObstacleDetected", // obstacleReading); } else { Trace.TraceError("ActionProcessor: speedActionId value is empty for obstacleRuleOutput '{0}'", ruleOutput); } } } catch (Exception e) { Trace.TraceError("ActionProcessor: exception in ProcessAction:"); Trace.TraceError(e.ToString()); } }