public async Task <HttpResponseMessage> PostDeploymentId() { try { var resp = new HttpResponseMessage(); var body = this.Request.Content.ReadAsStringAsync().Result; if (string.IsNullOrEmpty(body)) { resp = new HttpResponseMessage(HttpStatusCode.Forbidden); resp.ReasonPhrase = "Content is null"; return(resp); } var content = JsonUtility.GetJsonObjectFromJsonString(body); string refreshToken = content["tokens"]?["refresh"].ToString(); string accessToken = content["tokens"]?["access"].ToString(); string deploymentId = content["deploymentId"].ToString(); if (string.IsNullOrEmpty(refreshToken) || string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(deploymentId)) { resp = new HttpResponseMessage(HttpStatusCode.Forbidden); resp.ReasonPhrase = "Refresh token, access token or deployment id is null."; return(resp); } string tokenUrl = string.Format(Constants.AzureTokenUri, "common"); var refreshResponse = await GetToken(refreshToken, tokenUrl, Constants.MicrosoftClientId); if (!refreshResponse.IsSuccessStatusCode) { resp = new HttpResponseMessage(HttpStatusCode.Forbidden); resp.ReasonPhrase = "Access token could not be refreshed."; return(resp); } string deploymentIdsConnection = Constants.BpstDeploymentIdDatabase; string statement = "INSERT INTO dbo.deploymentids VALUES(@p1, @p2)"; SqlParameter[] parameters = SqlUtility.MapValuesToSqlParameters(deploymentId, DateTime.UtcNow); SqlUtility.ExecuteQueryWithParameters(deploymentIdsConnection, statement, parameters); resp = new HttpResponseMessage(HttpStatusCode.OK); return(resp); } catch { var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError); resp.ReasonPhrase = "An internal error has occurred "; return(resp); } }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { string searchQuery = request.DataStore.GetValue("SearchQuery") ?? string.Empty; string sqlConnectionString = request.DataStore.GetValueAtIndex("SqlConnectionString", "SqlServerIndex"); searchQuery = searchQuery.Replace("'", "''"); searchQuery = searchQuery.Replace("“", "\""); searchQuery = searchQuery.Replace("”", "\""); bool isAdvanced = IsAdvancedTwitterQuery(searchQuery); SqlParameter[] parameters = SqlUtility.MapValuesToSqlParameters(1, isAdvanced, searchQuery); SqlUtility.ExecuteQueryWithParameters(sqlConnectionString, INSERT_INTO_TWITTER_QUERY, parameters); if (!isAdvanced) { List <string> conditions = SplitQueryByOr(searchQuery); int detailId = 1; for (int i = 0; i < conditions.Count; i++) { ReadableQueryPart readableQueryPart = GetReadableQueryPart(conditions[i]); parameters = SqlUtility.MapValuesToSqlParameters(i + 1, 1, readableQueryPart.Query, conditions[i]); SqlUtility.ExecuteQueryWithParameters(sqlConnectionString, INSERT_INTO_TWITTER_QUERY_READABLE, parameters); for (int j = 0; j < readableQueryPart.Details.Count; j++) { string detail = readableQueryPart.Details[j]; if (detail[0] == 'C') { parameters = SqlUtility.MapValuesToSqlParameters(detailId, i + 1, TWITTER_OPERATOR_CONTAINS, detail.Substring(TWITTER_OPERATOR_CONTAINS.Length + 2).TrimEnd('"')); SqlUtility.ExecuteQueryWithParameters(sqlConnectionString, INSERT_INTO_TWITTER_QUERY_DETAILS, parameters); } else { parameters = SqlUtility.MapValuesToSqlParameters(detailId, i + 1, TWITTER_OPERATOR_DOES_NOT_CONTAIN, detail.Substring(TWITTER_OPERATOR_DOES_NOT_CONTAIN.Length + 2).TrimEnd('"')); SqlUtility.ExecuteQueryWithParameters(sqlConnectionString, INSERT_INTO_TWITTER_QUERY_DETAILS, parameters); } detailId++; } } } return(new ActionResponse(ActionStatus.Success)); }
public async override Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { string connectionString = request.DataStore.GetValue("SqlConnectionString"); string counts = request.DataStore.GetValue("InitialCounts"); string schema = request.DataStore.GetValue("SqlSchema"); Dictionary <string, int> countsObj = JsonConvert.DeserializeObject <Dictionary <string, int> >(counts); schema = SqlUtility.SanitizeSchemaName(schema); string statement = string.Format(commandTemplate, schema); DateTime timeStamp = DateTime.UtcNow; foreach (var entry in countsObj) { SqlParameter[] parameters = SqlUtility.MapValuesToSqlParameters(entry.Key, entry.Value, 0, timeStamp); SqlUtility.ExecuteQueryWithParameters(connectionString, statement, parameters); } 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)); }