public void getInfoFromCsv() { dirs = Directory.GetFiles(folderClassBPath); List <UploadToGenericStoreRequest> genericImages = new List <UploadToGenericStoreRequest>(); using (CsvReader csv = new CsvReader(new StreamReader("D:\\Bella\\MediaStore\\ImageExport_Prod_Result_Sorted.csv"), true, ';')) { int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { for (int i = 0; i < fieldCount; i++) { string head = headers[i]; string value = csv[i]; switch (head) { case "FileName": GenericStoreRequest.Filename = value; GenericStoreRequest.FileContent = getClassBFilesFromFolder(value); break; case "ModellIdFound": GenericStoreRequest.InternalId = value; break; case "LabelHeading": GenericStoreRequest.Description = value; break; default: break; } //Send the file whene all info. is filled out, and only files that has content. if (i == fieldCount - 1 && GenericStoreRequest.FileContent != "") { SendGenericFile(GenericStoreRequest); GenericStoreRequest = new UploadToGenericStoreRequest(); } } } } //If notSendt has content one or more files has not been sendt. if (notSendt.Count > 0) { foreach (var item in notSendt) { LoggMessage(3, item.Filename + " was not sendt."); } } Console.WriteLine("Finished transfering Class B"); Console.ReadLine(); }
public void SendGenericFile(UploadToGenericStoreRequest imagesToUpload) { // Kategori B string jsonUserToPost; string url = "/uploadtogenericstore"; try { // GenericStoreRequest jsonUserToPost = JsonConvert.SerializeObject(imagesToUpload); var responseJson = PutJsonFromEndpoint(jsonUserToPost, urlBase + url, addAuth: true); Console.WriteLine(imagesToUpload.Filename + " sendt"); } catch (Exception e) { notSendt.Add(imagesToUpload); LoggMessage(3, "SendFileGenericId: File: " + imagesToUpload.Filename + " Error.s Exception: " + e.Message); } }