public static ResultGeneric BatchTrackingEvent(string logJobName, string batchNumber) { ResultGeneric result = new ResultGeneric(); result.ReturnCode = 0; result.Message = ""; result.RecordsCount = 0; try { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; BatchTracking batchTracking = new BatchTracking(); HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(15); string URL = ""; string bodyString = ""; string returnMessage = ""; string batchTrackingJS = ""; batchTracking.BatchNumber = batchNumber; batchTracking.InitialStatus = "Ready to Scan"; batchTracking.FinalStatus = "Ready to Scan"; batchTracking.Event = "Batch Registered"; batchTracking.OperatorName = "Auto Import Service"; batchTracking.StationName = Dns.GetHostName(); batchTrackingJS = JsonConvert.SerializeObject(batchTracking, Newtonsoft.Json.Formatting.Indented); batchTrackingJS = batchTrackingJS.Replace(@"\", "\\\\"); URL = AutoImportService.BaseURL + "Batches/NewBatchEvent"; bodyString = "'" + batchTrackingJS + "'"; HttpContent body_for_new = new StringContent(bodyString); body_for_new.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response_for_new = client.PostAsync(URL, body_for_new).Result; if (!response_for_new.IsSuccessStatusCode) { nlogger.Error("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage); Console.WriteLine("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage); result.Message = "Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage; result.ReturnCode = -1; } else { using (HttpContent content = response_for_new.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; result = JsonConvert.DeserializeObject <ResultGeneric>(returnMessage); } } } } catch (Exception ex) { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; nlogger.Fatal(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.White; result.Message = General.ErrorMessage(ex); result.ReturnCode = -2; } } return(result); }
public static ResultGeneric BatchRegistration(string logJobName, string batchNumber, string batchAlias, JobExtended job) { ResultGeneric result = new ResultGeneric(); result.ReturnCode = 0; result.Message = ""; result.RecordsCount = 0; try { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; Batch batch = new Batch(); HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(15); string URL = ""; string bodyString = ""; string returnMessage = ""; string batchJS = ""; batch.BatchNumber = batchNumber; batch.StatusFlag = "Ready to Scan"; batch.SubmittedBy = "Auto Import Service"; batch.SubmittedDate = DateTime.Now; batch.Customer = job.CustomerName; batch.ProjectName = job.ProjectName; batch.JobType = job.JobName; batch.DepName = job.DepartmentName; batch.BatchAlias = batchAlias; batchJS = JsonConvert.SerializeObject(batch, Newtonsoft.Json.Formatting.Indented); batchJS = batchJS.Replace(@"\", "\\\\"); URL = AutoImportService.BaseURL + "Batches/BatchRegistration"; bodyString = "'" + batchJS + "'"; HttpContent body_for_new = new StringContent(bodyString); body_for_new.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response_for_new = client.PostAsync(URL, body_for_new).Result; if (!response_for_new.IsSuccessStatusCode) { nlogger.Error("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage); Console.WriteLine("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage); result.Message = "Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage; result.ReturnCode = -1; } else { using (HttpContent content = response_for_new.Content) { Task <string> resultTemp = content.ReadAsStringAsync(); returnMessage = resultTemp.Result; result = JsonConvert.DeserializeObject <ResultGeneric>(returnMessage); } } } } catch (Exception ex) { lock (lockObj) { LogManager.Configuration.Variables["JobName"] = logJobName; nlogger.Fatal(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(General.ErrorMessage(ex)); Console.ForegroundColor = ConsoleColor.White; result.Message = General.ErrorMessage(ex); result.ReturnCode = -2; } } return(result); }