static async void ImportFlatFile(string postURL) { try { const string importFileLocation = @"C:\Maximo Import\"; const string expectedFileColumnHeaders = "FROMSTORELOC,SITEID,USETYPE,STATUS,LINETYPE,QUANTITY,ITEMNUM,FROMBIN,IUL_USETYPE,IUL_FROMSTORELOC,ACTUALDATE,IUL_ORGID"; string[] directoryFiles = Directory.GetFiles(importFileLocation, "*.csv"); List <IntegrationData> importData = new List <IntegrationData>(); foreach (string file in directoryFiles) { string[] fileContents = File.ReadAllLines(file); if (fileContents[1].Equals(expectedFileColumnHeaders)) { for (int i = 2; i < fileContents.Length; i++) { string[] values = fileContents[i].Split(','); IntegrationData data = new IntegrationData(); data.FromStoreLoc = values[0]; data.SiteID = values[1]; data.UseType = values[2]; data.Status = values[3]; data.LineType = values[4]; data.Value = values[5]; data.ItemNum = values[6]; data.FromBin = values[7]; data.IUL_UseType = values[8]; data.IUL_FromStoreLoc = values[9]; data.dt = Convert.ToDateTime(values[10]); data.IUL_OrgID = values[11]; importData.Add(data); } Console.WriteLine($"Sucessfully read and prepared data from {file} for import..."); } else { Console.WriteLine($"Import header does not match expected import in {file}..."); } } ApiHelper apiHelper = new ApiHelper(); //If there is data items to send int he data object... if (importData.Count > 0) { //...convert the list of integration data objects to json for http post to consume... string json = JsonConvert.SerializeObject(importData); //...and make the post call and return a boolean identifying if our data was successfully posted. await apiHelper.MakeHttpPostRequestAsync(postURL, json); } } catch (Exception ex) { logger.LogError(ex, "ImportFlatFile"); } }
static async Task <List <IntegrationData> > BuildIntegrationData(List <IntegrationItem> integrationItems) { try { List <IntegrationData> integrationData = new List <IntegrationData>(); ApiHelper apiHelper = new ApiHelper(); //Iterate over each integration item that we pulled in from the API foreach (IntegrationItem item in integrationItems) { string itemURL = item.GetString; string currentDate = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 00:00:00"; string callResponse = ""; //Replace the GetString date with the current date that is being checked. itemURL = itemURL.Replace("DateToBePulled", currentDate); //Call for the current items sent data information callResponse = await apiHelper.MakeHTTPGetRequestAsync(itemURL); //If there is no response (no value that has been sent previous) or the last sent value is different then... if (callResponse != "" && item.MostRecentSentValue != callResponse) { //...build our data item... IntegrationData dataToSend = new IntegrationData(); dataToSend.dt = Convert.ToDateTime(currentDate); dataToSend.iID = item.iID; dataToSend.Value = callResponse; //...and add it to the integrationData object. integrationData.Add(dataToSend); } } return(integrationData); } catch (Exception ex) { logger.LogError(ex, "BuildIntegrationData"); return(null); } }