public void UploadEventByTime(sqlEventByTimeRec _eventByTimeRec) { //upload the event by time record to the AWS / mySQL database while (isSendingEventByTime) { //keep looping until the file is sent Application.DoEvents(); } ; isSendingEventByTime = true; RunAsyncCreateEventByTime(_eventByTimeRec).GetAwaiter(); while (isSendingEventByTime) { //keep looping until the file is sent Application.DoEvents(); } ; }
//for the event by time static async Task RunAsyncCreateEventByTime(sqlEventByTimeRec _eventByTimeRec) { //client had to be setup prior to entering here try { HttpResponseMessage response = await client2.PostAsJsonAsync <sqlEventByTimeRec>( "api/eventbytime", _eventByTimeRec); response.EnsureSuccessStatusCode(); var isCreateSuccessful = response.IsSuccessStatusCode; isSendingEventByTime = false; } catch (Exception e) { Console.WriteLine("---an error occurred"); Console.WriteLine(e.Message); } }
public void UploadAllEventsByTime() { // Update port # in the following line. client2.BaseAddress = new Uri("https://devnetlogger.herokuapp.com/"); client2.DefaultRequestHeaders.Accept.Clear(); client2.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); //refresh the log file list if (LogFiles.Disp_LogEvents_table.Count() > 0) { for (int i = 0; i < LogFiles.Disp_LogEvents_table.Count(); i++) { sqlEventByTimeRec eventByTimeRec = new sqlEventByTimeRec(); eventByTimeRec.startTimeStr = LogFiles.Disp_LogEvents_table[i].timeStartStr; eventByTimeRec.endTimeStr = LogFiles.Disp_LogEvents_table[i].timeStopStr; eventByTimeRec.eventDuration = LogFiles.Disp_LogEvents_table[i].timeDiffStr; string tempTimeString = eventByTimeRec.startTimeStr; string tempString = tempTimeString.Substring(0, 4); eventByTimeRec.ontim_utc_yr = int.Parse(tempString); tempString = tempTimeString.Substring(5, 2); eventByTimeRec.ontim_utc_mon = int.Parse(tempString); tempString = tempTimeString.Substring(8, 2); eventByTimeRec.ontim_utc_day = int.Parse(tempString); tempString = tempTimeString.Substring(11, 2); eventByTimeRec.ontim_utc_hr = int.Parse(tempString); tempString = tempTimeString.Substring(14, 2); eventByTimeRec.ontim_utc_min = int.Parse(tempString); tempString = tempTimeString.Substring(17, 2); eventByTimeRec.ontim_utc_sec = int.Parse(tempString); //stop time tempTimeString = eventByTimeRec.endTimeStr; tempString = tempTimeString.Substring(0, 4); eventByTimeRec.offtim_utc_yr = int.Parse(tempString); tempString = tempTimeString.Substring(5, 2); eventByTimeRec.offtim_utc_mon = int.Parse(tempString); tempString = tempTimeString.Substring(8, 2); eventByTimeRec.offtim_utc_day = int.Parse(tempString); tempString = tempTimeString.Substring(11, 2); eventByTimeRec.offtim_utc_hr = int.Parse(tempString); tempString = tempTimeString.Substring(14, 2); eventByTimeRec.offtim_utc_min = int.Parse(tempString); tempString = tempTimeString.Substring(17, 2); eventByTimeRec.offtim_utc_sec = int.Parse(tempString); //duration time tempTimeString = eventByTimeRec.eventDuration; eventByTimeRec.durtim_utc_yr = int.Parse("0"); eventByTimeRec.durtim_utc_mon = int.Parse("0"); eventByTimeRec.durtim_utc_day = int.Parse("0"); tempString = tempTimeString.Substring(0, 2); eventByTimeRec.durtim_utc_hr = int.Parse(tempString); tempString = tempTimeString.Substring(3, 2); eventByTimeRec.durtim_utc_min = int.Parse(tempString); tempString = tempTimeString.Substring(6, 2); eventByTimeRec.durtim_utc_sec = int.Parse(tempString); eventByTimeRec.m1 = LogFiles.Disp_LogEvents_table[i].mach_01; eventByTimeRec.m2 = LogFiles.Disp_LogEvents_table[i].mach_02; eventByTimeRec.m3 = LogFiles.Disp_LogEvents_table[i].mach_03; eventByTimeRec.m4 = LogFiles.Disp_LogEvents_table[i].mach_04; eventByTimeRec.m5 = LogFiles.Disp_LogEvents_table[i].mach_05; eventByTimeRec.m6 = LogFiles.Disp_LogEvents_table[i].mach_06; eventByTimeRec.m7 = LogFiles.Disp_LogEvents_table[i].mach_07; eventByTimeRec.m8 = LogFiles.Disp_LogEvents_table[i].mach_08; eventByTimeRec.m9 = LogFiles.Disp_LogEvents_table[i].mach_09; Console.WriteLine($"Sending # {i} : {LogFiles.Disp_LogEvents_table[i].timeStartStr}"); UploadEventByTime(eventByTimeRec); } ; } ; }