//button to click on PDP page -> to sync add enteries public async Task <JsonResult> SyncAll(JiraProxyRequest jiraRequest) { try { if (jiraRequest == null) { return(Json(new ProxyResponse { Result = "ko", Data = "Jira request is null" }, JsonRequestBehavior.AllowGet)); } ExecuteJira jiraToDbSyncAll = new ExecuteJira(UnitOfWork); await jiraToDbSyncAll.Execute(jiraRequest.ProjectUid, jiraRequest.SystemId, jiraRequest.ProjectId, jiraRequest.EpicKey); return(Json(new ProxyResponse { Result = "ok", Data = jiraRequest.ProjectUid.ToString() }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(HandleException(exception)); } }
public async Task <string> GetJiraResponse(JiraProxyRequest jiraProxyRequest) { logger.Info("GetJiraResponse " + jiraApiUrl + "/" + jiraProxyRequest.ApiUrl.Trim('/')); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(jiraApiUrl + "/" + jiraProxyRequest.ApiUrl.Trim('/')); httpWebRequest.Method = jiraProxyRequest.RequestType; httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("Authorization", "Basic " + EncodeTo64(jiraUserName, jiraPassword)); if ((jiraProxyRequest.RequestType == "POST" || jiraProxyRequest.RequestType == "PUT") && !String.IsNullOrEmpty(jiraProxyRequest.PostData)) { byte[] byteArray = Encoding.UTF8.GetBytes(jiraProxyRequest.PostData); httpWebRequest.ContentLength = byteArray.Length; Stream dataStream = httpWebRequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); } HttpWebResponse httpWebResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync(); Stream responseStream = httpWebResponse.GetResponseStream(); if (responseStream != null) { StreamReader streamReader = new StreamReader(responseStream); string response = await streamReader.ReadToEndAsync(); return(response); } return(null); }
public async Task <JsonResult> ExecuteRequest([FromBody] JiraProxyRequest jiraRequest) { if (jiraRequest.SystemId == null) { return(Json(new ProxyResponse { Result = "ko", Data = "System Id is null" }, JsonRequestBehavior.AllowGet)); } try { string response = null; SyncSystemDTO syncSystem = await SyncSystemBusinessService.GetSyncSystemAsync(jiraRequest.SystemId.Value); if (syncSystem != null) { JiraAccessService jiraAccessService = new JiraAccessService(syncSystem); response = await jiraAccessService.GetJiraResponse(jiraRequest); } if (String.IsNullOrEmpty(response)) { return(Json(new ProxyResponse { Result = "ko", Data = "Jira Response is empty" }, JsonRequestBehavior.AllowGet)); } JsonResult jsonResult = Json(new ProxyResponse { Result = "ok", Data = response }, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = Int32.MaxValue; return(jsonResult); } catch (Exception exception) { return(HandleException(exception)); } }
public async Task <JsonResult> Execute(JiraProxyRequest jiraRequest) { logger.Info("TFS SyncAll STARTED"); ExecuteTfs executer = new ExecuteTfs(UnitOfWork); int issueId = 0; if (jiraRequest.EpicKey != null) { issueId = int.Parse(jiraRequest.EpicKey); } string projectId = ""; if (jiraRequest.ProjectId != null) { projectId = jiraRequest.ProjectId; } var executeResult = await executer.Execute((int)jiraRequest.SystemId, issueId, projectId); return(Json(executeResult, JsonRequestBehavior.AllowGet)); }