public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { var azureToken = request.DataStore.GetJson("AzureToken", "access_token"); var subscription = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId"); var resourceGroup = request.DataStore.GetValue("SelectedResourceGroup"); var logicAppName = request.DataStore.GetValue("LogicAppName"); var requestUri = request.DataStore.GetValue("RequestUri"); AzureHttpClient client = new AzureHttpClient(azureToken, subscription, resourceGroup); string body = "{\"PreviousCount\": 1, \"Delay\": 9}"; var response = await client.ExecuteGenericRequestNoHeaderAsync(HttpMethod.Post, requestUri, body); return(new ActionResponse(ActionStatus.Success)); }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { var azureToken = request.DataStore.GetJson("AzureToken")["access_token"].ToString(); var subscription = request.DataStore.GetJson("SelectedSubscription")["SubscriptionId"].ToString(); var resourceGroup = request.DataStore.GetValue("SelectedResourceGroup"); var logicAppName = request.DataStore.GetValue("LogicAppNameHistorical"); AzureHttpClient client = new AzureHttpClient(azureToken, subscription, resourceGroup); var response = await client.ExecuteWithSubscriptionAndResourceGroupAsync(HttpMethod.Post, $"providers/Microsoft.Logic/workflows/{logicAppName}/triggers/manual/listCallbackUrl", "2016-06-01", string.Empty); if (!response.IsSuccessStatusCode) { return(new ActionResponse(ActionStatus.Failure)); } var postUrl = JsonUtility.GetJObjectFromJsonString(await response.Content.ReadAsStringAsync()); response = await client.ExecuteGenericRequestNoHeaderAsync(HttpMethod.Post, postUrl["value"].ToString(), string.Empty); return(new ActionResponse(ActionStatus.Success)); }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { string azureToken = request.DataStore.GetJson("AzureToken", "access_token"); string refreshToken = request.DataStore.GetJson("AzureToken", "refresh_token"); string subscription = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId"); string resourceGroup = request.DataStore.GetValue("SelectedResourceGroup"); string triggerUrl = request.DataStore.GetValue("NotifierTriggerUrl"); string connectionString = request.DataStore.GetValue("SqlConnectionString"); string deploymentIdsConnection = Constants.BpstDeploymentIdDatabase; string deploymentId = Guid.NewGuid().ToString(); string dataPullCompleteThreshold = "80"; var asDisabled = request.DataStore.GetValue("ssasDisabled"); Dictionary <string, string> configValues = new Dictionary <string, string>() { { "NotifierUrl", Constants.BpstNotifierUrl }, { "NotificationEmails", request.DataStore.GetValue("EmailAddress") }, { "DeploymentId", deploymentId }, { "TemplateName", request.Info.AppName }, { "DeploymentTimestamp", DateTime.UtcNow.ToString("o") }, { "ASDeployment", string.IsNullOrEmpty(asDisabled) ? "False" : (!Convert.ToBoolean(asDisabled)).ToString() }, { "DataPullCompleteThreshold", dataPullCompleteThreshold }, { "DataPullStatus", "-1" } }; for (int i = 0; i < configValues.Count; i++) { dynamic payload = new ExpandoObject(); payload.SqlGroup = "SolutionTemplate"; payload.SqlSubGroup = "Notifier"; payload.SqlEntryName = configValues.ElementAt(i).Key; payload.SqlEntryValue = configValues.ElementAt(i).Value; request.DataStore.AddToDataStore("NotifierValues" + i, "SqlGroup", "SolutionTemplate"); request.DataStore.AddToDataStore("NotifierValues" + i, "SqlSubGroup", "Notifier"); request.DataStore.AddToDataStore("NotifierValues" + i, "SqlEntryName", configValues.ElementAt(i).Key); request.DataStore.AddToDataStore("NotifierValues" + i, "SqlEntryValue", configValues.ElementAt(i).Value); } var configResponse = await RequestUtility.CallAction(request, "Microsoft-SetConfigValueInSql"); if (!configResponse.IsSuccess) { return(configResponse); } //OnPrem scenario if (request.Info.WebsiteRootUrl.Contains("https://msi")) { var post = PostDeploymentId(deploymentId, azureToken, refreshToken); if (!post) { request.Logger.LogEvent("ConfigureNotifier failed for on prem scenario - couldn't reach service.", new Dictionary <string, string>()); } } else { //Website scenario var cmd = $"INSERT INTO deploymentids VALUES('{deploymentId}','{DateTime.UtcNow.ToString("o")}')"; SqlUtility.InvokeSqlCommand(deploymentIdsConnection, cmd, new Dictionary <string, string>()); } AzureHttpClient azureClient = new AzureHttpClient(azureToken, subscription, resourceGroup); var response = await azureClient.ExecuteGenericRequestNoHeaderAsync(HttpMethod.Post, triggerUrl, string.Empty); return(new ActionResponse(ActionStatus.Success)); }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { string azureToken = request.DataStore.GetJson("AzureToken", "access_token"); string refreshToken = request.DataStore.GetJson("AzureToken", "refresh_token"); string subscription = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId"); string resourceGroup = request.DataStore.GetValue("SelectedResourceGroup"); string connectionString = request.DataStore.GetValue("SqlConnectionString"); string sendNotification = request.DataStore.GetValue("SendCompletionNotification"); Dictionary <string, string> configValues = new Dictionary <string, string>(); if (!bool.Parse(sendNotification)) { configValues = new Dictionary <string, string>() { { "SendCompletionNotification", "0" }, }; CreatePayload(request, configValues); var resp = await RequestUtility.CallAction(request, "Microsoft-SetConfigValueInSql"); if (resp.IsSuccess) { return(resp); } } string triggerUrl = request.DataStore.GetValue("NotifierTriggerUrl"); string deploymentIdsConnection = Constants.BpstDeploymentIdDatabase; string deploymentId = Guid.NewGuid().ToString(); string dataPullCompleteThreshold = "80"; var asDisabled = request.DataStore.GetValue("ssasDisabled"); configValues = new Dictionary <string, string>() { { "SendCompletionNotification", "1" }, { "NotifierUrl", Constants.BpstNotifierUrl }, { "NotificationEmails", request.DataStore.GetValue("EmailAddress") }, { "DeploymentId", deploymentId }, { "TemplateName", request.Info.AppName }, { "DeploymentTimestamp", DateTime.UtcNow.ToString("o") }, { "ASDeployment", string.IsNullOrEmpty(asDisabled) ? "False" : (!Convert.ToBoolean(asDisabled)).ToString() }, { "DataPullCompleteThreshold", dataPullCompleteThreshold }, { "DataPullStatus", "-1" } }; CreatePayload(request, configValues); var configResponse = await RequestUtility.CallAction(request, "Microsoft-SetConfigValueInSql"); if (!configResponse.IsSuccess) { return(configResponse); } //OnPrem scenario if (request.Info.WebsiteRootUrl.Contains("https://msi")) { var post = PostDeploymentId(deploymentId, azureToken, refreshToken); if (!post) { request.Logger.LogEvent("ConfigureNotifier failed for on prem scenario - couldn't reach service.", new Dictionary <string, string>()); } } else { //Website scenario SqlParameter[] parameters = SqlUtility.MapValuesToSqlParameters(deploymentId, DateTime.UtcNow); SqlUtility.ExecuteQueryWithParameters(deploymentIdsConnection, "INSERT INTO deploymentids VALUES(@p1, @p2)", parameters); } AzureHttpClient azureClient = new AzureHttpClient(azureToken, subscription, resourceGroup); var response = await azureClient.ExecuteGenericRequestNoHeaderAsync(HttpMethod.Post, triggerUrl, string.Empty); return(new ActionResponse(ActionStatus.Success)); }