public static void ReadSV(TextReader reader, params string[] separators) { using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(reader)) { MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; MyReader.SetDelimiters(","); MyReader.HasFieldsEnclosedInQuotes = true; string[] currentRow = null; while (!MyReader.EndOfData) { try { currentRow = MyReader.ReadFields(); string currentField = null; foreach (string currentField_loopVariable in currentRow) { currentField = currentField_loopVariable; } } catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex) { } } } }
private void LoadTable(DataTable table, Stream stream) { var timespanExpression = new Regex("([0-9]+):([0-9]+):([0-9]+)"); var parseDictionary = new Dictionary<Type, Delegate>(); //parseDictionary.Add(typeof(Boolean), new Func<String, Boolean>(fieldValue => Convert.ToBoolean(Int32.Parse(fieldValue)))); parseDictionary.Add(typeof(DateTime), new Func<String, Object>(fieldValue => { if(fieldValue.Length.Equals(8)) return new DateTime(Int32.Parse(fieldValue.Substring(0, 4)), Int32.Parse(fieldValue.Substring(4, 2)), Int32.Parse(fieldValue.Substring(6, 2))); else return DBNull.Value; })); //parseDictionary.Add(typeof(Decimal), new Func<String, Decimal>(fieldValue => Decimal.Parse(fieldValue))); parseDictionary.Add(typeof(Int32), new Func<String, Object>(fieldValue => { Int32 test; if (Int32.TryParse(fieldValue, out test)) return test; else return DBNull.Value; })); //parseDictionary.Add(typeof(TimeSpan), new Func<String, Object>(fieldValue => { try { var timeSpanPart = fieldValue.Split(':'); return new TimeSpan(Int32.Parse(timeSpanPart[0]), Int32.Parse(timeSpanPart[1]), Int32.Parse(timeSpanPart[2])); } catch { return DBNull.Value; } })); var textFieldParser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream); textFieldParser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; textFieldParser.SetDelimiters(","); textFieldParser.HasFieldsEnclosedInQuotes = false; var fieldReferences = textFieldParser.ReadFields().Where(item=>!String.IsNullOrEmpty(item)).ToArray(); while (!textFieldParser.EndOfData) { var fields = textFieldParser.ReadFields(); var newRow = table.NewRow(); for (var index = 0; index < fieldReferences.Length; index++) { var fieldReference = fieldReferences[index]; var fieldValue = fields[index]; if (table.Columns.Contains(fieldReference)) { if (parseDictionary.ContainsKey(table.Columns[fieldReference].DataType)) newRow[fieldReference] = parseDictionary[table.Columns[fieldReference].DataType].DynamicInvoke(fieldValue); else newRow[fieldReference] = fieldValue; } } table.Rows.Add(newRow); //Console.WriteLine(String.Format("{0} {1}",table.TableName, table.Rows.Count)); } }
public async Task<IEnumerable<DistributorSalesmanImport>> Import(string path) { return await Task.Factory.StartNew(() => { var imports = new List<DistributorSalesmanImport>(); var tempFolder = Path.Combine(FileUtility.GetApplicationTempFolder(), Path.GetFileName(path)); if (File.Exists(tempFolder)) File.Delete(tempFolder); File.Copy(path, tempFolder); using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(tempFolder)) { parser.SetDelimiters("\t"); string[] currentRow = null; while (!parser.EndOfData) { currentRow = parser.ReadFields(); if (currentRow != null && currentRow.Length > 0) { imports.Add(MapSalesmanImport(currentRow)); } } } File.Delete(tempFolder); return imports; }); }
static void Main(string[] args) { string filename = @"C:\Users\Evan\Downloads\Dataset\Dataset\EasyClinic_tc_cc\oracle.csv"; string outfile = @"C:\Users\Evan\Downloads\Dataset\Dataset\EasyClinic_tc_cc\oracle.txt"; TextReader reader = new StreamReader(filename); int numSources = reader.ReadLine().Split(new char[] { ',' }, StringSplitOptions.None).Count(); reader.Close(); Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(filename); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); List<List<string>> data = new List<List<string>>(); for (int i = 0; i < numSources; i++) data.Add(new List<string>()); int curID = 0; while (!parser.EndOfData) { string[] currentRow = parser.ReadFields(); foreach (string currentField in currentRow) { data[curID].Add(currentField); curID++; } curID = 0; } TextWriter of = new StreamWriter(outfile); foreach (List<string> row in data) { of.WriteLine(String.Join(" ", row)); } of.Flush(); of.Close(); }
public IEnumerable<ProductDiscountGroupImport> Import(string path) { try { var productImports = new List<ProductDiscountGroupImport>(); var tempFolder = Path.Combine(FileUtility.GetApplicationTempFolder(), Path.GetFileName(path)); if (File.Exists(tempFolder)) File.Delete(tempFolder); File.Copy(path, tempFolder); using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(tempFolder)) { parser.SetDelimiters(","); string[] currentRow = null; while (!parser.EndOfData) { currentRow = parser.ReadFields(); if (currentRow != null && currentRow.Length > 0) { productImports.Add(MapImport(currentRow)); } } } File.Delete(tempFolder); return productImports; } catch (FileNotFoundException ex) { throw ex; } catch (FieldAccessException ex) { throw ex; } catch (Exception ex) { MessageBox.Show(ex.Message, "Importer Error", MessageBoxButton.OK, MessageBoxImage.Error); return null; } }
public static DataTable LoadCSV(string filePath) { var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(filePath); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); Regex regex = new Regex("\"(.*?)\""); DataTable table = new DataTable(); bool isFirstRow = true; while (!parser.EndOfData) { string[] row = parser.ReadFields(); if (row.Length == 0 || row[0].Length == 0) continue; string line = row[0]; string sub = regex.Match(line).Value; if (!string.IsNullOrEmpty(sub)) { line = line.Replace(sub, sub.Replace(", ", ",").Replace(",", "@")); } if(isFirstRow) { foreach (var c in line.Split(',')) { table.Columns.Add(c, typeof(string)); } isFirstRow = false; } else { table.Rows.Add(line.Split(',')); } } return table; }
public void LoadData() { int ttype = 0; lgroups.Clear(); ltags.Clear(); lfav.Clear(); lbGroup.Items.Clear(); lvTags.Items.Clear(); try { using (StreamReader sr = new StreamReader(new DirectoryInfo(srcFile).Parent.FullName + @"\" + favFile, System.Text.Encoding.Default)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); lfav.Add(line.Trim()); } } } catch (System.Exception ex) { #if DEBUG MessageBox.Show(ex.Message); #endif } try { Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(srcFile, System.Text.Encoding.Default); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); while (!parser.EndOfData) { string[] row = parser.ReadFields(); if (row[0].StartsWith(":IODisc")) { //18-1 ttype = 1; continue; } else if (row[0].StartsWith(":IOReal")) { //47-1 13-1 ttype = 2; continue; } else if (row[0].StartsWith(":IOInt")) { //46-1 ttype = 3; continue; } else if (row[0].StartsWith(":MemoryDisc")) { //13-1 ttype = 4; continue; } else if (row[0].StartsWith(":")) { ttype = 0; } if (ttype == 0) { continue; } string s = row[17 * Convert.ToInt32(ttype == 1) + 46 * Convert.ToInt32(ttype == 2 || ttype == 3) + 12 * Convert.ToInt32(ttype == 4)]; if (s.Length == 0) { continue; } ltags.Add(new InTouchTag { name = row[0], comment = s, group = (Groupring && s.IndexOf(":") > 0) ? s.Substring(0, s.IndexOf(":") + 1) : "", EU = (ttype == 2) || (ttype == 3) ? row[10] : "", maxEU = (ttype == 1) || (ttype == 4) ? 2 : Convert.ToSingle(row[13]), minEU = (ttype == 1) || (ttype == 4) ? -1 : Convert.ToSingle(row[12]), favorite = lfav.Contains(row[0]) }); if ((Groupring && s.IndexOf(":") > 0) && !lgroups.Exists(delegate(String text) { return(text == ltags[ltags.Count - 1].group); })) { lgroups.Add(ltags[ltags.Count - 1].group); } } } catch (System.Exception ex) { #if DEBUG MessageBox.Show(ex.Message); #endif } lbGroup.BeginUpdate(); lbGroup.Items.Add(ALL_TAGS); lbGroup.Items.Add(FAV_TAGS); try { foreach (string s in lgroups.OrderBy(item => item)) { lbGroup.Items.Add(s.Substring(0, s.Length - 1)); } } finally { lbGroup.EndUpdate(); } lbGroup.SelectedIndex = lbGroup.Items.IndexOf(FAV_TAGS); }
/// <summary> /// Displays the first portion of the CSV file. /// </summary> private void DisplayCSVProbe() { int maxRows = 20; //string[] fields=null; try { using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(TextboxSelectedRolesFile.Text)) { SuspendLayout(); ListviewCSV.BeginUpdate(); ListviewCSV.SuspendLayout(); ListviewCSV.Items.Clear(); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); bool firstRow = true; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); if (firstRow) { for (int k = 0; k < fields.Length; k++) { ListviewCSV.Columns.Add((k + 1).ToString()); } firstRow = false; } } using (StreamReader file = new StreamReader(TextboxSelectedRolesFile.Text)) { string templine; while ((templine = file.ReadLine()) != null) { string[] templinearray = templine.Split(','); RolesFileData.Add(new B { AttributeServiceCaller1 = templinearray[0], CalleroftheIFSAttributeService1 = templinearray[1], INFORBCionservice1 = templinearray[2] } ); UserRolesFile.Add(new C { AttributeServiceCaller2 = templinearray[0], CalleroftheIFSAttributeService2 = templinearray[1], INFORBCionservice2 = templinearray[2] } ); } } for (int i = 0; i < UserRolesFile.Count; i++) { for (int j = 0; j < UserFileData.Count; j++) { if (UserRolesFile[i].INFORBCionservice2.ToLower().Trim() == UserFileData[j].WindowsAccountName.ToLower().Trim()) { UserRolesFile[i].EmailAddress2 = UserFileData[j].EmailAddress; UserRolesFile[i].Identity12 = UserFileData[j].Identity; UserRolesFile[i].Identity22 = UserFileData[j].Identity2; UserRolesFile[i].UserPrincipalName2 = UserFileData[j].UserPrincipalName; UserRolesFile[i].ClientPrincipalName2 = UserFileData[j].ClientPrincipalName; UserRolesFile[i].CommonName2 = UserFileData[j].CommonName; UserRolesFile[i].Status2 = UserFileData[j].Status; } } } Netfile = new StringBuilder(); Netfile.Append("Name"); Netfile.Append(","); Netfile.Append("SecurityRole"); Netfile.Append(","); Netfile.Append("RoleDescription"); Netfile.Append(","); Netfile.Append("EmailID"); Netfile.Append(","); Netfile.Append("Identity1"); Netfile.Append(","); Netfile.Append("UserGUID"); Netfile.Append(","); Netfile.Append("User Name"); Netfile.Append(","); Netfile.Append("Client Principal Name"); Netfile.Append(","); Netfile.Append("Common Name"); Netfile.Append(","); Netfile.Append("Status"); Netfile.Append(Environment.NewLine); for (int p = 0; p < UserRolesFile.Count; p++) { if (UserRolesFile[p].INFORBCionservice2.Trim() != null) { Netfile.Append(UserRolesFile[p].INFORBCionservice2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].AttributeServiceCaller2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].CalleroftheIFSAttributeService2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].EmailAddress2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].Identity12); Netfile.Append(","); Netfile.Append(UserRolesFile[p].Identity22); Netfile.Append(","); Netfile.Append(UserRolesFile[p].UserPrincipalName2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].ClientPrincipalName2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].CommonName2); Netfile.Append(","); Netfile.Append(UserRolesFile[p].Status2); Netfile.Append(Environment.NewLine); } } } for (int l = 0; l <= UserRolesFile.Count; l++) { ListViewItem item = new ListViewItem(UserRolesFile[l].INFORBCionservice2); item.SubItems.Add(UserRolesFile[l].AttributeServiceCaller2); item.SubItems.Add(UserRolesFile[l].CalleroftheIFSAttributeService2); item.SubItems.Add(UserRolesFile[l].EmailAddress2); item.SubItems.Add(UserRolesFile[l].Identity12); item.SubItems.Add(UserRolesFile[l].Identity22); item.SubItems.Add(UserRolesFile[l].UserPrincipalName2); item.SubItems.Add(UserRolesFile[l].ClientPrincipalName2); item.SubItems.Add(UserRolesFile[l].CommonName2); item.SubItems.Add(UserRolesFile[l].Status2); ListviewCSV.Items.Add(item); if (maxRows-- < 0) { break; } } for (int i = 0; i < ListviewCSV.Columns.Count; i++) { ListviewCSV.Columns[i].Width = -2; } ListviewCSV.ResumeLayout(); ListviewCSV.EndUpdate(); ResumeLayout(); } catch { ListviewCSV.ResumeLayout(); } }
public async Task <ActionResult> getQuestions(string quiz, string state) { _logger.Error("Pulling in a saved state: " + state); oauthHelper oauth = Newtonsoft.Json.JsonConvert.DeserializeObject <oauthHelper>(sqlHelper.getStateJson(Guid.Parse(state))); oauth.accessToken = sqlHelper.getUserAccessToken(long.Parse(oauth.custom_canvas_user_id)); _logger.Error("State loaded: " + state); if (oauth.accessToken != null) { _logger.Error("Checking token validity for state: " + state); //now validate the token to make sure it's still good //if the token is no good try to refresh it if (oauth.accessToken.tokenRefreshRequired) { if (await userCalls.requestUserToken(oauth, oauth.accessToken.responseUrl, "refresh_token", null, oauth.accessToken.refreshToken) == false) { /***********************************************************/ // If we're here it the user may have deleted the access token in their profile. // In this case we will request a brand new token, forcing the user to "Authorize" again. // To test this, delete the token in your Canvas user profile. /***********************************************************/ _logger.Error("Token bad, renewal failed! state: " + state); return(Json(new { Result = "AUTHFAIL" })); } _logger.Error("token renewed! state: " + state); } } _logger.Error("Calling for quiz report"); JObject rvalQuizReportMake = await userCalls.createQuizReport(oauth.accessToken.accessToken, "https://" + oauth.host, oauth.custom_canvas_course_id, quiz); bool gotET = false; bool mayFailed = true; string reportLink = ""; int count = 0; while (!gotET) { System.Threading.Thread.Sleep(1000); count++; if (count > 12) { gotET = true; mayFailed = true; } rvalQuizReportMake = await userCalls.createQuizReport(oauth.accessToken.accessToken, "https://" + oauth.host, oauth.custom_canvas_course_id, quiz); try { reportLink = rvalQuizReportMake.Last.Previous.First.Value <string>("url"); gotET = true; } catch { } } if (mayFailed && reportLink == "") { _logger.Error("Call for quiz report failed in " + count + ": " + reportLink); return(Json(new { Result = "FAILED" })); } string localFileName = "C:\\qqg_temp_data\\" + quiz + "_report.csv"; WebClient webClient = new WebClient(); webClient.DownloadFile(reportLink, localFileName); _logger.Error("Call for quiz report returned in " + count + ": " + reportLink); var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(localFileName); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { "," }); List <string[]> dataToParse = new List <string[]>(); while (!parser.EndOfData) { string[] row = parser.ReadFields(); /* do something */ _logger.Error("Here's a row: " + row.ToString()); dataToParse.Add(row); } _logger.Error("Let's do a parse! Quiz: " + quiz); if (dataToParse[0][0] != "name" && dataToParse[0][1] != "id") { _logger.Error("Call for quiz report failed because: 00=" + dataToParse[0][0] + " 01=" + dataToParse[0][1] + " 10=" + dataToParse[1][0]); return(Json(new { Result = "FAILED" })); } JObject rval4 = await userCalls.getQuizSubmissions(oauth.accessToken.accessToken, "https://" + oauth.host, oauth.custom_canvas_course_id, quiz); //Adding question names to a list JArray rvalQuestions = await userCalls.getListQuestionsInQuiz(oauth.accessToken.accessToken, "https://" + oauth.host, oauth.custom_canvas_course_id, quiz); List <string> questionName = new List <string>(); JToken questionsToken = rvalQuestions.First; List <JToken> questionTokens = new List <JToken>(); while (questionsToken != null) { questionTokens.Add(questionsToken); questionsToken = questionsToken.Next; } for (int i = 0; i < questionTokens.Count; i++) { if (questionTokens[i].Value <string>("question_name").ToLower() != "question") { questionName.Add(questionTokens[i].Value <string>("question_name")); } else { questionName.Add(""); } } //Parse CSV into SQL database //SQL flow pseudocode: /* drop table of quizid_courseid * create table of quizid_courseid * columns are: * questionid * possible score * repeat following for all students: * studentid:respone * studentid:score * studentid:comment * * fill table per column * * functions needed for SQL: * recreate table quizid_courseid * create columns * update studentid submission for questionid * get studentid submission for questionid */ if (dataToParse.Count > 1) { // Generate a list of student IDs List <string> studentIDList = new List <string>(); for (int x = 1; x < dataToParse.Count; x++) { studentIDList.Add(dataToParse[x][1]); } // Convert to array because something? string[] students = studentIDList.ToArray(); // Create that table! bool didcreate = sqlHelper.createQuizTable(quiz, oauth.custom_canvas_course_id, students); // Okay, table made, let's parse! string toReturn = "{ \"questionArray\": ["; int z = 0; // Let's go by questions, across the columns for (int x = 7; x < dataToParse[0].Length - 3; x = x + 2) { // Grab the question data string question = dataToParse[0][x]; string score = dataToParse[0][x + 1]; // Remove everything after : including : string questionText = question.Substring(question.IndexOf(":") + 1); question = question.Substring(0, question.IndexOf(":")); if (z > 0) { toReturn = toReturn + ", "; } toReturn = toReturn + " {\"name\": \"" + questionName[z] + "\", \"id\": \"" + question + "\"}"; z++; // Store our list of students sqlHelper.updateListStudentSQL(quiz, oauth.custom_canvas_course_id, question, students); // Now grab and upload each student reponse for (int y = 1; y < dataToParse.Count; y++) { // Get student respone string studentResponse = dataToParse[y][x]; string studentScore = dataToParse[y][x + 1]; // Get submission ID JToken maybechilds = rval4.First.First[y - 1]; string id = maybechilds.Value <string>("id"); string userid = maybechilds.Value <string>("user_id"); // Update submission and submissionID bool doThatUpdate = sqlHelper.updateStudentSubmissionSQL(quiz, oauth.custom_canvas_course_id, question, questionText, score, students[y - 1], studentScore, studentResponse, ""); sqlHelper.updateStudentSubmissionID(quiz, oauth.custom_canvas_course_id, question, userid, id); } } toReturn = toReturn + "] }"; // Okay, data is parsed, so lets..pass off a list of questions! // Make sure to include id's... _logger.Error("We goo! Quiz: " + quiz); // Return a list of questions in order w/ names and ids return(Json(new { Result = "SUCCESS", Questions = toReturn })); //return Content(toReturn, "application/json"); } else { //TODO: No submissions, need to handle this somehow _logger.Error("We goo! Quiz: " + quiz); return(Json(new { Result = "SUCCESS", Questions = new { } })); } }
/// <summary> /// Открывает файл и добавляет элементы в источник данных /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { using (var openDialog = new OpenFileDialog { Filter = Resources.StartForm_OpenToolStripMenuItem_Click_CSV_____csv }) { if (openDialog.ShowDialog() != DialogResult.OK) { return; } FileOpenedOrCreated(openDialog.FileName); using (var fieldParser = new Microsoft.VisualBasic.FileIO.TextFieldParser(openDialog.FileName)) { if (fieldParser.TextFieldType == Microsoft.VisualBasic.FileIO.FieldType.Delimited) { fieldParser.SetDelimiters(";"); } else { currentFile = null; MessageBox.Show(Resources.StartForm_OpenToolStripMenuItem_Click_Invalid_File, Resources.StartForm_OpenToolStripMenuItem_Click_Error_Reading_File, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (fieldParser.EndOfData) { currentFile = null; MessageBox.Show(Resources.StartForm_OpenToolStripMenuItem_Click_Empty_File, Resources.StartForm_OpenToolStripMenuItem_Click_Error_Reading_File, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // Пропустить строку названий столбцов fieldParser.ReadFields(); while (!fieldParser.EndOfData) { try { clinicSource.Add(new Clinic(fieldParser.ReadFields())); } catch (Microsoft.VisualBasic.FileIO.MalformedLineException) { FileClosed(); if (MessageBox.Show(Resources.StartForm_OpenToolStripMenuItem_Click_Invalid_File__Open_Another, Resources.StartForm_OpenToolStripMenuItem_Click_Error_Reading_File, MessageBoxButtons.YesNo, MessageBoxIcon.Error) != DialogResult.Yes) { return; } OpenToolStripMenuItem_Click(this, EventArgs.Empty); return; } catch (Exception ex) { FileClosed(); MessageBox.Show(ex.Message, Resources.StartForm_OpenToolStripMenuItem_Click_Error_Reading_File, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } } }
static int Main(string[] args) { // Test if input arguments were supplied: if (args.Length != 1) { System.Console.WriteLine("Please give filename and path to the lectionary CSV file."); System.Console.WriteLine("Usage: {0} <filename>", Environment.CommandLine); return(1); } // Try to spec the file. This will throw // an exception if the file does not exist. // if(!(File.Exists(args[0]))) // { // System.Console.WriteLine("Bible csv file not found."); // System.Console.WriteLine("Usage: {0} <filename>", Environment.CommandLine); // return 1; // } string fileName = args[0]; //string path = @".\Bible"; //string fileName = "Sun_Lectionary_Raw.csv"; IDictionary <int, LectionaryEntry> lectionary = new Dictionary <int, LectionaryEntry>(); LectionaryEntry l; try { using (var sr = new StreamReader(fileName)) { string line; //long pos = GetActualPosition(sr); while ((line = sr.ReadLine()) != null) { //Console.WriteLine("-> {0} ", pos); using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new System.IO.StringReader(line))) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { //Processing row string[] fields = parser.ReadFields(); string readingType = fields[0]; string readings = fields[1]; int lectionary_number = int.Parse(fields[4]); string years = fields[5]; try { l = lectionary[lectionary_number]; } catch (Exception e) { lectionary[lectionary_number] = new LectionaryEntry(); l = lectionary[lectionary_number]; } if (years.Contains("A")) { switch (readingType) { case "OT": l.A.OT += (readings + ";"); break; case "NT": l.A.NT += (readings + ";"); break; case "PS": l.A.PS += (readings + ";"); break; case "G": l.A.G += (readings + ";"); break; } } if (years.Contains("B")) { switch (readingType) { case "OT": l.B.OT += (readings + ";"); break; case "NT": l.B.NT += (readings + ";"); break; case "PS": l.B.PS += (readings + ";"); break; case "G": l.B.G += (readings + ";"); break; } } if (years.Contains("C")) { switch (readingType) { case "OT": l.C.OT += (readings + ";"); break; case "NT": l.C.NT += (readings + ";"); break; case "PS": l.C.PS += (readings + ";"); break; case "G": l.C.G += (readings + ";"); break; } } if (years.Contains("1")) { switch (readingType) { case "OT": l.Y1.OT += (readings + ";"); break; case "NT": l.Y1.NT += (readings + ";"); break; case "PS": l.Y1.PS += (readings + ";"); break; case "G": l.Y1.G += (readings + ";"); break; } } if (years.Contains("2")) { switch (readingType) { case "OT": l.Y2.OT += (readings + ";"); break; case "NT": l.Y2.NT += (readings + ";"); break; case "PS": l.Y2.PS += (readings + ";"); break; case "G": l.Y2.G += (readings + ";"); break; } } l.LectionaryNumber = lectionary_number; /* * string dir = path + "\\" + book + "\\" + chapter; * * if (!(Directory.Exists(dir))) * { * DirectoryInfo di = Directory.CreateDirectory(dir); * } * * string verseIndexFile = dir + "\\" + verse; * * System.IO.File.WriteAllText(verseIndexFile, pos.ToString()); // pos is an index into the bible csv file, of that verse's * // csv record (id, bookname, booknumber, chapter, verse, text) * * //TODO: Process field * //Console.WriteLine(field); * * printLineAtPos(pos, fileName); */ } } //pos = GetActualPosition(sr); } } } catch (Exception e) { //Directory.Delete(path, true); Console.WriteLine("Failed to process file: {0}", e.Message); return(1); } //string outFileName = "Lectionary.csv"; //using (StreamWriter swOutputFile = new StreamWriter(new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Read))) //{} int i = 0; int index = 1; while (i < lectionary.Count) { try { l = lectionary[index]; Console.WriteLine("Lectionary #" + l.LectionaryNumber); if (l.A.OT != null || l.A.NT != null || l.A.PS != null || l.A.G != null) { WriteLectionaryEntry(l.LectionaryNumber, l.A.OT, LectionaryEntryType.OT, LectionaryEntryYear.YEAR_A); WriteLectionaryEntry(l.LectionaryNumber, l.A.NT, LectionaryEntryType.NT, LectionaryEntryYear.YEAR_A); WriteLectionaryEntry(l.LectionaryNumber, l.A.PS, LectionaryEntryType.PS, LectionaryEntryYear.YEAR_A); WriteLectionaryEntry(l.LectionaryNumber, l.A.G, LectionaryEntryType.G, LectionaryEntryYear.YEAR_A); Console.Write("\tA.OT\t" + l.A.OT); Console.Write("\tA.NT\t" + l.A.NT); Console.Write("\tA.PS\t" + l.A.PS); Console.Write("\tA.G \t" + l.A.G); Console.WriteLine(); } if (l.B.OT != null || l.B.NT != null || l.B.PS != null || l.B.G != null) { WriteLectionaryEntry(l.LectionaryNumber, l.B.OT, LectionaryEntryType.OT, LectionaryEntryYear.YEAR_B); WriteLectionaryEntry(l.LectionaryNumber, l.B.NT, LectionaryEntryType.NT, LectionaryEntryYear.YEAR_B); WriteLectionaryEntry(l.LectionaryNumber, l.B.PS, LectionaryEntryType.PS, LectionaryEntryYear.YEAR_B); WriteLectionaryEntry(l.LectionaryNumber, l.B.G, LectionaryEntryType.G, LectionaryEntryYear.YEAR_B); Console.Write("\tB.OT\t" + l.B.OT); Console.Write("\tB.NT\t" + l.B.NT); Console.Write("\tB.PS\t" + l.B.PS); Console.Write("\tB.G \t" + l.B.G); Console.WriteLine(); } if (l.C.OT != null || l.C.NT != null || l.C.PS != null || l.C.G != null) { WriteLectionaryEntry(l.LectionaryNumber, l.C.OT, LectionaryEntryType.OT, LectionaryEntryYear.YEAR_C); WriteLectionaryEntry(l.LectionaryNumber, l.C.NT, LectionaryEntryType.NT, LectionaryEntryYear.YEAR_C); WriteLectionaryEntry(l.LectionaryNumber, l.C.PS, LectionaryEntryType.PS, LectionaryEntryYear.YEAR_C); WriteLectionaryEntry(l.LectionaryNumber, l.C.G, LectionaryEntryType.G, LectionaryEntryYear.YEAR_C); Console.Write("\tC.OT\t" + l.C.OT); Console.Write("\tC.NT\t" + l.C.NT); Console.Write("\tC.PS\t" + l.C.PS); Console.Write("\tC.G \t" + l.C.G); Console.WriteLine(); } if (l.Y1.OT != null || l.Y1.NT != null || l.Y1.PS != null || l.Y1.G != null) { WriteLectionaryEntry(l.LectionaryNumber, l.Y1.OT, LectionaryEntryType.OT, LectionaryEntryYear.YEAR_1); WriteLectionaryEntry(l.LectionaryNumber, l.Y1.NT, LectionaryEntryType.NT, LectionaryEntryYear.YEAR_1); WriteLectionaryEntry(l.LectionaryNumber, l.Y1.PS, LectionaryEntryType.PS, LectionaryEntryYear.YEAR_1); WriteLectionaryEntry(l.LectionaryNumber, l.Y1.G, LectionaryEntryType.G, LectionaryEntryYear.YEAR_1); Console.Write("\tY1.OT\t" + l.Y1.OT); Console.Write("\tY1.NT\t" + l.Y1.NT); Console.Write("\tY1.PS\t" + l.Y1.PS); Console.Write("\tY1.G \t" + l.Y1.G); Console.WriteLine(); } if (l.Y2.OT != null || l.Y2.NT != null || l.Y2.PS != null || l.Y2.G != null) { WriteLectionaryEntry(l.LectionaryNumber, l.Y2.OT, LectionaryEntryType.OT, LectionaryEntryYear.YEAR_2); WriteLectionaryEntry(l.LectionaryNumber, l.Y2.NT, LectionaryEntryType.NT, LectionaryEntryYear.YEAR_2); WriteLectionaryEntry(l.LectionaryNumber, l.Y2.PS, LectionaryEntryType.PS, LectionaryEntryYear.YEAR_2); WriteLectionaryEntry(l.LectionaryNumber, l.Y2.G, LectionaryEntryType.G, LectionaryEntryYear.YEAR_2); Console.Write("\tY2.OT\t" + l.Y2.OT); Console.Write("\tY2.NT\t" + l.Y2.NT); Console.Write("\tY2.PS\t" + l.Y2.PS); Console.Write("\tY2.G \t" + l.Y2.G); Console.WriteLine(); } Console.WriteLine("--------------------------------------------------------------------------------"); index++; i++; } catch (Exception e) { index++; } } Console.ReadKey(); return(0); }
IEnumerable <CodeImport> ParseCSV(string file) { IList <CodeImport> listDTO = new List <CodeImport>(); using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file))) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); parser.TrimWhiteSpace = true; //get the headers string[] headers = parser.ReadFields(); //read the code import values while (parser.EndOfData == false) { CodeImport code = new CodeImport(); string[] line = parser.ReadFields(); int lineNumber = 1; for (int i = 0; i < line.Length; i++) { if (string.IsNullOrWhiteSpace(headers[i])) { continue; } switch (headers[i].ToUpperInvariant()) { case "CRITERIAINDEX": try { code.CriteriaIndex = Convert.ToInt32(line[i]); }catch { throw new FormatException($"Unable to convert Criteria Index to integer on line { lineNumber }. Value: \"{ line[i] }\""); } break; case "CODETYPE": code.CodeType = line[i]; break; case "CODE": code.Code = line[i]; break; case "EXACTMATCH": code.SearchMethodType = string.Equals("1", line[i], StringComparison.OrdinalIgnoreCase) ? TextSearchMethodType.ExactMatch : TextSearchMethodType.StartsWith; break; } } if (code.IsEmpty() == false) { listDTO.Add(code); } lineNumber++; } } return(listDTO.OrderBy(c => c.CriteriaIndex).ThenBy(c => c.CodeType).ThenBy(c => c.SearchMethodType)); }
/// <summary> /// For the specified response processes any associated tracking table documents, converting from csv to json array. /// The json array is set on the ResponseData property of the response, save is _not_ called. /// </summary> /// <param name="response"></param> /// <returns></returns> public async Task Process(Response response) { Guid[] trackingTableDocuments = await _db.Documents.AsNoTracking().Where(d => d.ItemID == response.ID && d.Kind == TrackingTableDocumentKind).Select(d => d.ID).ToArrayAsync(); if (trackingTableDocuments.Length == 0) { return; } StringBuilder buffer = new StringBuilder(); string[] tableHeader; string[] currentLine; using (var writer = new Newtonsoft.Json.JsonTextWriter(new StringWriter(buffer))) { writer.QuoteName = true; writer.WriteStartArray(); foreach (Guid trackingTableDocumentID in trackingTableDocuments) { //read the tracking table csv into a dictionary, each dictionary represents a row in the csv document using (var dsDataContext = new DataContext()) using (var reader = new StreamReader(new Data.Documents.DocumentStream(dsDataContext, trackingTableDocumentID))) using (var csv = new Microsoft.VisualBasic.FileIO.TextFieldParser(reader)) { csv.SetDelimiters(","); csv.TrimWhiteSpace = true; tableHeader = csv.ReadFields(); while (csv.EndOfData == false) { currentLine = csv.ReadFields(); if (currentLine.Length == 0) { continue; } writer.WriteStartObject(); for (int i = 0; i < currentLine.Length; i++) { writer.WritePropertyName(tableHeader[i]); writer.WriteValue(currentLine[i]); } writer.WriteEndObject(); } reader.Close(); } } writer.WriteEndArray(); writer.Flush(); response.ResponseData = buffer.ToString(); } }
/// <summary> /// List of invoice items. /// This is used for free-form invoices. /// </summary> /// <returns>The list of invoices.</returns> public IList <InvoiceItem> ListLineItems() { if (_listLineItems == null) { _listLineItems = new List <InvoiceItem>(); // Null check if (string.IsNullOrEmpty(CsvLineItems)) { return(_listLineItems); } // Get memory stream of data System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems)); // Use the inbuilt .NET CSV parser var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream) { TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited }; parser.SetDelimiters(","); List <string> headers = new List <string>(); int lineindex = 0; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); int fieldindex = 0; InvoiceItem invocieitem = null; foreach (string field in fields) { // Header, or content? if (lineindex == 0) { headers.Add(field); } else { if (invocieitem == null) { invocieitem = new InvoiceItem(); } // Parse by header name switch (headers[fieldindex]) { case "kind": invocieitem.Kind = field; break; case "description": invocieitem.Description = field; break; case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "taxed": invocieitem.Taxed = bool.Parse(field); break; case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break; case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break; } } fieldindex++; } lineindex++; if (invocieitem != null) { _listLineItems.Add(invocieitem); } } parser.Close(); } return(_listLineItems); }
public ActionResult UploadCsvProducts(HttpPostedFileBase file) { Session["ProductCsvImport"] = null; if (file != null && file.ContentLength > 0) { List <Product> products = new List <Product>(); using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(file.InputStream)) { parser.HasFieldsEnclosedInQuotes = true; parser.SetDelimiters(","); string[] fields; bool headersOkay = false; int i = 0; while (!parser.EndOfData) { i++; fields = parser.ReadFields(); if (fields.Length != 3) { return(RedirectToAction("Import", new { error = $"{fields.Length} fields found in row {i} instead of 3" })); } if (!headersOkay) { if (fields[0] != "StockCode" || fields[1] != "Description" || fields[2] != "UnitPrice") { return(RedirectToAction("Import", new { error = "Incorrect column headers" })); } headersOkay = true; continue; } Product product = new Product { StockCode = fields[0].ToUpper(), Description = fields[1] }; if (string.IsNullOrWhiteSpace(product.StockCode) || !Regex.IsMatch(product.StockCode, @"^[A-Z\d]+$") || product.StockCode.Length > 20) { return(RedirectToAction("Import", new { error = $"Invalid product code in line {i}" })); } if (string.IsNullOrWhiteSpace(product.Description) || product.Description.Length > 100) { return(RedirectToAction("Import", new { error = $"Invalid description in line {i}" })); } decimal unitPrice = 0; if (!decimal.TryParse(fields[2], out unitPrice)) { return(RedirectToAction("Import", new { error = $"Invalid unit price in line {i}" })); } product.UnitPrice = unitPrice; products.Add(product); } } Session["ProductCsvImport"] = products; return(RedirectToAction("Import")); } else { return(RedirectToAction("Import", new { error = "Error uploading csv file" })); } }
public async Task<IActionResult> LoadHistory(System.Web.HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var reader = new Microsoft.VisualBasic.FileIO.TextFieldParser(file.InputStream); reader.SetDelimiters(","); while (!reader.EndOfData) { var line = reader.ReadFields(); var stock = new Stock(line[0]); var model = new StockTransaction(DateTime.Parse(line[1]), Decimal.Parse(line[2]), int.Parse(line[3])); stockHistory.addTransaction(_applicationDbContext, await GetCurrentUserAsync(), stock, model); } } return Redirect("/Stocks/History"); }
public List<ImportItemModel> Import(string directoryPath) { string tempFolder = string.Empty; var dataModels = new List<ImportItemModel>(); try { tempFolder = Path.Combine(FileUtility.GetApplicationTempFolder(), Path.GetFileName(directoryPath)); if (File.Exists(tempFolder)) File.Delete(tempFolder); File.Copy(directoryPath, tempFolder); using (var parser =new Microsoft.VisualBasic.FileIO.TextFieldParser(tempFolder)) { parser.SetDelimiters(","); while (!parser.EndOfData) { string[] currentRow = parser.ReadFields(); if (currentRow != null && currentRow.Length > 1) { dataModels.Add( new ImportItemModel { ProductCode = currentRow.ElementAtOrDefault(0), Quantity = currentRow.ElementAtOrDefault(1), SalesmanCode = (currentRow.ElementAtOrDefault(2) != null && !string.IsNullOrEmpty(currentRow[2])) ? currentRow.ElementAtOrDefault(2) : "default", DocumentRef = currentRow.ElementAtOrDefault(3) }); } } } return dataModels; } catch (IOException ex) { MessageBox.Show("File Load Error\n" + ex.Message); return null; } catch (Exception ex) { MessageBox.Show("Error\n" + ex.Message); return null; } finally { if (File.Exists(tempFolder)) File.Delete(tempFolder); } }
private void openECitationCSVToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "CSV Files|*.txt;*.csv"; try { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string[] data = System.IO.File.ReadAllLines(openFileDialog1.FileName); char splitChar = '\t'; char[] splitChars = { ' ', '\t', ';', ',' }; foreach (char c in splitChars) { if (data[0].Split(c)[0] == "TITLE") splitChar = c; } var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { splitChar.ToString() }); int i = 0; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); if (i>0) dataGridView1.Rows.Add(fields); i++; } } } catch (Exception ex) { MessageBox.Show(string.Format("Error reading file: {0}", ex.Message)); } }
public static System.Data.DataSet GetInputDataset(Activity dnActivity, IEnumerable <LinkedService> linkedServices, IEnumerable <Dataset> datasets) { //SQL or Azure Blob CSV only var inLS = LinkedServiceHelper.GetInputLinkedService(dnActivity, linkedServices, datasets); System.Data.DataSet dsRtn = GetInputDatasetShell(dnActivity, linkedServices, datasets); //Figure out which Type switch (inLS.Properties.Type) { case "AzureStorage": CloudStorageAccount inputStorageAccount = CloudStorageAccount.Parse(((AzureStorageLinkedService)inLS.Properties.TypeProperties).ConnectionString); CloudBlobClient inputClient = inputStorageAccount.CreateCloudBlobClient(); foreach (var ds in dnActivity.Inputs) { var curTbl = dsRtn.Tables[ds.Name]; AzureBlobDataset abdInput = datasets.First(d => d.Name == ds.Name).Properties.TypeProperties as AzureBlobDataset; CloudBlockBlob cbbInputFile = new CloudBlockBlob(new Uri(inputStorageAccount.BlobEndpoint.AbsoluteUri + abdInput.FolderPath + "/" + abdInput.FileName)); System.IO.MemoryStream ms = new System.IO.MemoryStream(); cbbInputFile.DownloadToStream(ms); ms.Position = 0; using (Microsoft.VisualBasic.FileIO.TextFieldParser tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(ms)) { tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; tfp.SetDelimiters(","); while (!tfp.EndOfData) { string[] fields = tfp.ReadFields(); curTbl.LoadDataRow(fields, true); } } } break; case "AzureSqlDatabase": System.Data.SqlClient.SqlConnection scInput = new System.Data.SqlClient.SqlConnection(((AzureSqlDatabaseLinkedService)inLS.Properties.TypeProperties).ConnectionString); foreach (var ds in datasets) { var curTbl = dsRtn.Tables[ds.Name]; AzureSqlTableDataset astInput = ds.Properties.TypeProperties as AzureSqlTableDataset; System.Data.SqlClient.SqlCommand commInput = new System.Data.SqlClient.SqlCommand(); commInput.Connection = scInput; commInput.CommandType = System.Data.CommandType.Text; commInput.CommandText = string.Format("SELECT * FROM [{0}]", astInput.TableName); System.Data.SqlClient.SqlDataAdapter sdaInput = new System.Data.SqlClient.SqlDataAdapter(commInput); sdaInput.Fill(curTbl); } break; default: throw new NotImplementedException(); } return(dsRtn); }
/// <summary> /// Executes this instance. /// </summary> public virtual void Execute() { var dlg = new Microsoft.Win32.OpenFileDialog { DefaultExt = FileExtension, Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*" }; if (!dlg.ShowDialog().GetValueOrDefault()) { return; } if (PromptUserForContinue() == MessageBoxResult.No) { return; } if (!ValidateImportFileName(dlg.FileName)) { var message = string.Format("The file \"{0}\" could not be import due to the file name containing special characters (*,&,!,@,#, etc.) and/or dashes ( - ). Please replace any special characters and/or dashes to spaces and/or underscores ( _ ) and try again.", Path.GetFileName(dlg.FileName)); MessageBox.Show(message, "MONAHRQ Import File Open Error", MessageBoxButton.OK); return; } try { using (ApplicationCursor.SetCursor(Cursors.Wait)) { BeginImport(); //var lines = File.ReadAllLines(dlg.FileName); //Import3(lines); using (var csvRdr = new Microsoft.VisualBasic.FileIO.TextFieldParser(dlg.FileName)) { csvRdr.SetDelimiters(new[] { "," }); csvRdr.TrimWhiteSpace = true; csvRdr.HasFieldsEnclosedInQuotes = true; Import2(csvRdr); } //using (var fs = File.OpenRead(dlg.FileName)) //{ // Import(fs); //} } } catch (IOException exc) { Logger.Write(exc, "Error importing file \"{0}\"", dlg.FileName); var message = string.Format("Please close file\"{0}\" before trying to import.", dlg.FileName.SubStrAfterLast(@"\")); MessageBox.Show(message, "MONAHRQ Import File Open Error", MessageBoxButton.OK); } finally { EndImport(); } }
static List <InvoiceClass> ReadInvoiceFile(string invoiceFile) { string prevInvoiceNumber = "0"; List <InvoiceClass> invoiceList = new List <InvoiceClass>(); List <ItemsClass> itemsList = new List <ItemsClass>(); var format = new NumberFormatInfo(); format.NegativeSign = "-"; /* * i is used to iterate through invoiceList. If an invoice number is the same * as the previous invoice number (prevInvoiceNumber), it does not increment. This creates in object * that includes all items with the same invoice number. * - invoice #12345 might include multiple items */ int i = -1; try { /* * using TextFieldParser from Visual Basic to parse the CSV file * I originally had a problem parsing company names that contained commas. * This is the simplest method I found to ignore anything between double quotes. */ using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(invoiceFile)) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { string[] words = parser.ReadFields(); InvoiceClass invoice = new InvoiceClass(0, "", itemsList, 0); // Only continue if the first item in the words list does not contain any letters. // This is to skip anything that doesn't start with an invoice number. // Usually the first two lines and the last line of the file should be skipped. if (!words[0].Any(Char.IsLetter)) { if (words[0] != prevInvoiceNumber) { List <ItemsClass> items = new List <ItemsClass>(); // words[2] is the item name words[3] is the item price. items.Add(new ItemsClass(words[2], decimal.Parse(words[3], format))); // words[0] is the item number. words[1] is the invoice name invoiceList.Add(new InvoiceClass(int.Parse(words[0]), words[1], items, 0)); i++; prevInvoiceNumber = words[0]; } else { // words[2] is the item name. words[3] is the item price. invoiceList[i].InvoiceItemArray.Add(new ItemsClass(words[2], decimal.Parse(words[3], format))); prevInvoiceNumber = words[0]; } } } parser.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(invoiceList); }
/** <summary> * This method goes through the FLC_Extract in CSV form, filters out rows and columns we don't care about, and returns * a DataTable we can then consolidate and update to the Database. * Still under discussion whether we should update it to consolidate in-method... * </summary> * <value name="path">The path to the FLC_Extract file.</value> * <value name="dictionary">A Support object containing standardized product names and configs we need to report on.</value> * <returns name="sustainingData">A DataTable containing the relevant excerpt of FLC_Extract data.</returns> **/ public DataTable flcExtract(string path, Support dictionary) { var FS = ";"; string[] selectedHeaders = { @"Region", "Country", "CCN", "LOB", "Platform", "Configuration Type", "Config Name", "SKU", "SKU Description", "Commodity", "Total Measure Name", "Measure Detail", "MOD" }; Regex expression = new Regex(@"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec).*Mth 1$"); Dictionary <string, int> importantFields = new Dictionary <string, int>(); DataTable sustainData = new DataTable("flcExtract"); string fecha = ""; //## Start reading CSV ## Console.WriteLine("Trying to read CSV File..."); using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path)) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(FS); parser.TrimWhiteSpace = true; int row = 1; while (!parser.EndOfData) { string[] line = parser.ReadFields(); //Assuming the first row contains the headers if (row == 1) { //Find indexes for columns we're interested in foreach (string importantColumn in selectedHeaders) { int fieldNo = Array.IndexOf(line, importantColumn); if (fieldNo != -1) { importantFields.Add(importantColumn, Array.IndexOf(line, importantColumn)); } else { throw new IndexOutOfRangeException(importantColumn + " not found in row " + row + "."); } } //Now get the cost information. Subsequent months are assumed to be next to current month data. foreach (string column in line) { if (expression.IsMatch(column)) { fecha = expression.Match(column).ToString(); Console.WriteLine("Processing file for {0}", fecha); importantFields.Add("thisMonth", Array.IndexOf(line, column)); importantFields.Add("nextMonth", Array.IndexOf(line, column) + 1); importantFields.Add("monthPlus2", Array.IndexOf(line, column) + 2); importantFields.Add("monthPlus3", Array.IndexOf(line, column) + 3); } } //Finally, create the DataTable columns, handling the special case for cost. foreach (string column in importantFields.Keys.ToList()) { if (column == "thisMonth" || column == "nextMonth" || column == "monthPlus2" || column == "monthPlus3") { sustainData.Columns.Add(column); } else { sustainData.Columns.Add(line[importantFields[column]]); } } } else { //Variables for readability string region = line[importantFields["CCN"]]; string lob = line[importantFields["LOB"]]; string configName = line[importantFields["Config Name"]]; /** Now, filter out records we don't care about before adding importantFields to the DataTable. * Two IF statements allow us to check for available fields before we spend time parsing costs to float, * and ensuring they have data. **/ try { if (region == "DAO" && lob == "Dell Latitude" && dictionary.confValid(configName)) { float currCost = 0; float costPlus1 = 0; float costPlus2 = 0; float costPlus3 = 0; if (float.TryParse(line[importantFields["thisMonth"]], out currCost) && float.TryParse(line[importantFields["nextMonth"]], out costPlus1) && float.TryParse(line[importantFields["monthPlus2"]], out costPlus2) && float.TryParse(line[importantFields["monthPlus3"]], out costPlus3) && currCost != 0 && costPlus1 != 0 && costPlus2 != 0 && costPlus3 != 0) { DataRow rowData = sustainData.NewRow(); foreach (string column in importantFields.Keys.ToList()) { rowData[column] = line[importantFields[column]]; } sustainData.Rows.Add(rowData); } } } catch (KeyNotFoundException) { Console.WriteLine("R{0}: Error while looking up key in importantFields. Details below:", row); Console.WriteLine("[importantFields]"); foreach (var key in importantFields.Keys.ToList()) { Console.WriteLine("Key: {0}\t\tValue: {1}", key, importantFields[key]); } Console.WriteLine("\n[Record]"); foreach (string field in line) { Console.Write(field + ";"); } } } row++; } Console.WriteLine("Done. Processed {0} rows.\n", row); } return(sustainData); }
/// <summary> /// List of invoice items. /// This is used for free-form invoices. /// </summary> /// <returns>The list of invoices.</returns> public IList<InvoiceItem> ListLineItems() { if (_listLineItems == null) { _listLineItems = new List<InvoiceItem>(); // Null check if (string.IsNullOrEmpty(CsvLineItems)) return _listLineItems; // Get memory stream of data System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems)); // Use the inbuildt .NET CSV parser Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); List<string> headers = new List<string>(); int lineindex = 0; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); int fieldindex = 0; InvoiceItem invocieitem = null; foreach (string field in fields) { // Header, or content? if (lineindex == 0) { headers.Add(field); } else { if (invocieitem == null) invocieitem = new InvoiceItem(); // Parse by header name switch (headers[fieldindex]) { case "kind": invocieitem.Kind = field; break; case "description": invocieitem.Description = field; break; case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "taxed": invocieitem.Taxed = bool.Parse(field); break; case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break; case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break; } } fieldindex++; } lineindex++; if (invocieitem != null) _listLineItems.Add(invocieitem); } parser.Close(); } return _listLineItems; }
////////////////////////////////////////////////////////////////////////// static void Main(string[] args) { ////////////////////////////////////////////////////////////////////////// // parse board csv file into memory string path = @"M:\monopoly\board.csv"; var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); parser.ReadFields(); // skip first (header) row of CSV while (!parser.EndOfData) { string[] row = parser.ReadFields()[0].Split('|'); board.Add(new Property(row)); } ////////////////////////////////////////////////////////////////////////// // parse card csv file into memory path = @"M:\monopoly\cards.csv"; parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); parser.ReadFields(); // skip first (header) row of CSV while (!parser.EndOfData) { string[] row = parser.ReadFields()[0].Split('|'); if (row[2].Equals("Chance")) { chance.Add(new Card(row)); } else if (row[2].Equals("Community Chest")) { chest.Add(new Card(row)); } } shuffle_cards(ref chance); shuffle_cards(ref chest); ////////////////////////////////////////////////////////////////////////// // parse board art into memory path = @"M:\monopoly\board_art.txt"; board_art = File.ReadAllLines(path); ////////////////////////////////////////////////////////////////////////// // parse board art player placement index csv file into memory path = @"M:\monopoly\spaces_player.csv"; parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); parser.ReadFields(); // skip first (header) row of CSV while (!parser.EndOfData) { string[] row = parser.ReadFields()[0].Split('|'); int[] int_row = Array.ConvertAll(row, int.Parse); spaces_player.Add(int_row); } ///////////////////////////////////////////////////////////////////////// // parse board art house placement index csv file into memory path = @"M:\monopoly\spaces_houses.csv"; parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { ";" }); parser.ReadFields(); // skip first (header) row of CSV while (!parser.EndOfData) { string[] row = parser.ReadFields()[0].Split('|'); int[] int_row = Array.ConvertAll(row, int.Parse); spaces_houses.Add(int_row); } ////////////////////////////////////////////////////////////////////////// // configure game settings Console.WriteLine("Welcome to Monopoly!"); start_money = input_int("\nPlease enter the desired starting amount of money for each player.", 100, Int32.MaxValue); Console.WriteLine("Each player will start with ${0}.", start_money); go_value = input_int("\nPlease enter the desired amount of money earned upon passing go.", 0, Int32.MaxValue); Console.WriteLine("Each player will earn ${0} upon passing go.", go_value); go_bonus = input_int("\nPlease enter the desired amount of bonus money earned for landing on go.", 0, Int32.MaxValue); Console.WriteLine("Each player will earn a bonus of ${0} for landing on go.", go_bonus); free_parking_default = input_int("\nPlease enter the desired initial value of free parking.", 0, Int32.MaxValue); reset_free_parking(); Console.WriteLine("The free parking pot will be initialized to ${0} and reset to ${0} after each collection.", free_parking_default); num_players = input_int("\nPlease enter the number of players (at least 2, and at most 8) who will be participating.", 2, 8); Console.WriteLine("{0} players will be participating.", num_players); ////////////////////////////////////////////////////////////////////////// // configure players for (int i = 0; i < num_players; i++) { string name = input_string(string.Format("\nPlease enter player {0}'s name.", i + 1), 1, 25); Console.WriteLine("{0}, please select a character from the following list.", name); int index = 0; foreach (string s in available_characters) { Console.WriteLine("{0}: {1}", index, s); index++; } int choice = input_int("Enter the number corresponding to the desired character.", 0, available_characters.Count - 1); string character = available_characters[choice]; available_characters.RemoveAt(choice); players.Add(new Player(name, character, start_money, go_value, go_bonus)); Console.WriteLine("Welcome, {0} the {1}!", name, character); } ////////////////////////////////////////////////////////////////////////// // determine who begins game Console.WriteLine("\nLet's get started!"); foreach (Player p in players) { Console.WriteLine("\n{0}, please roll the dice to determine your starting position. Press enter to continue.", p.get_nickname()); Console.ReadLine(); int roll = roll_dice(dice); p.set_start_roll(roll); Console.WriteLine("{0}, you rolled a {1}.", p.get_name(), roll); } players.Sort((x, y) => y.get_start_roll().CompareTo(x.get_start_roll())); // sort in descending order of start roll Console.WriteLine("\nThe starting order is as follows:"); foreach (Player p in players) { Console.WriteLine(p.get_name()); } ////////////////////////////////////////////////////////////////////////// // run game while (players.Count > 1) { List <Player> eliminated_players = new List <Player>(); foreach (Player p in players) { p.refresh_properties(); Console.WriteLine("\n{0}\n\nIt is {1} the {2}'s turn.", stars, p.get_name(), p.get_char()); p.reset_double_count(); int dice_roll = 0; //for use in determining utility payments bool turn_is_over = false; //indicates whether player may roll or not bool turn_ended = false; //indicates whether player has elected to end turn (after purchases, etc.) bool has_rolled = false; //indicates whether player has rolled at least once and is thus eligible to buy bool rent_paid = false; //indicates whether player has paid rent (where applicable - see take_action()) while (!turn_ended) { //check before every action that player is still valid if (p.get_money() <= 0) { Console.WriteLine("\nYou've gone bankrupt! You're eliminated!"); eliminated_players.Add(p); p.kill(); turn_ended = true; break; } //run turn if (board[p.get_position()].get_name().Equals("Jail")) { if (p.jailed() == 0) { Console.WriteLine("\n***\n\nYou are currently at {0} (just visiting) [index {1}] and have ${2}.", board[p.get_position()].get_name(), p.get_position(), p.get_money()); } else { Console.WriteLine("\n***\n\nYou are currently in {0} [index {1}] and have ${2}.", board[p.get_position()].get_name(), p.get_position(), p.get_money()); } } else { Console.WriteLine("\n***\n\nYou are currently on {0} [index {1}] and have ${2}.", board[p.get_position()].get_name(), p.get_position(), p.get_money()); } List <string> options = generate_options(p, turn_is_over, has_rolled, rent_paid); Console.WriteLine("You may:\n"); for (int i = 0; i < options.Count; i++) { Console.WriteLine("{0}: {1}", i, options[i]); } int choice = input_int("\nEnter the number corresponding to the desired action.", 0, options.Count - 1); take_action(p, options, choice, ref turn_is_over, ref has_rolled, ref turn_ended, ref rent_paid, ref dice_roll); } if (players.Count - eliminated_players.Count <= 1) { //don't continue to the next player; only one remains break; } } foreach (Player p in eliminated_players) { players.Remove(p); } } Console.WriteLine("\n\n{0}\nGAME OVER!\n{1} the {2} wins!", stars, players[0].get_name(), players[0].get_char()); Console.ReadLine(); }
public static CsvImport TransactionsFromCsv(string filePath, DateTime?currentDate, int dateCol, int amountCol, int payeeCol, DirectionBehavior db) { CsvImport ci = new CsvImport(); ci.it = new List <TransactionModel>(); ci.status = CsvImport.successStatus; // open csv file var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(filePath); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(new string[] { "," }); // for each row int line = 0; while (!parser.EndOfData) { line++; string[] row = parser.ReadFields(); // skip if not enough columns in this row if (row.Length - 1 < Math.Max(Math.Max(dateCol, amountCol), payeeCol)) { ci.it = null; ci.status = $"Not enough columns ({row.Length}) for import on line {line}"; return(ci); } // set date TransactionModel t = new TransactionModel(); t.Payee = ""; t.Category = ""; t.Custom_notes = ""; if (currentDate != null) { t.Date = (DateTime)currentDate; } else { try { t.Date = Convert.ToDateTime(row[dateCol]); } catch { ci.it = null; ci.status = $"Invalid date ({row[dateCol]}) on line {line}"; return(ci); } } // set payee t.Payee = row[payeeCol]; // set amount based off of direction format try { switch (db) { case DirectionBehavior.Inflow: t.Amount = Math.Abs(Convert.ToDecimal(row[amountCol].Replace("$", ""))); break; case DirectionBehavior.Outflow: t.Amount = -Math.Abs(Convert.ToDecimal(row[amountCol].Replace("$", ""))); break; case DirectionBehavior.Both: t.Amount = Convert.ToDecimal(row[amountCol].Replace("$", "")); break; } if (t.Amount == 0) { continue; } } catch { ci.it = null; ci.status = $"Invalid amount ({row[amountCol]}) on line {line}"; return(ci); } ci.it.Add(t); } return(ci); }
// ******************************************************************************************************* // FUNCTION TO PERFORM THE ACTUAL IMPORT // ******************************************************************************************************* public static void runImport(string CSVpath, string authtoken, string IDpath, Windows.Forms.RichTextBox miniConsole) { // // Check CSV file // if (CSVpath == "") { updateConsole(miniConsole, true, "Need to supply a file!"); return; } if (!CSVpath.EndsWith(".csv")) { updateConsole(miniConsole, true, "Supplied file needs to be in .CSV format!"); return; } else if (!IO.File.Exists(CSVpath)) { updateConsole(miniConsole, true, "CSV file '" + CSVpath + "' does not exist."); return; } updateConsole(miniConsole, true, "File '" + CSVpath + "' exists!"); // // Check Authtoken // if (authtoken == "") { string msg = "No AUTHTOKEN supplied."; updateConsole(miniConsole, true, "\n" + msg); return; } else if (authtoken.Length != 32) { updateConsole(miniConsole, true, "AUTHTOKEN should have 32 characters. You supplied a " + authtoken.Length + "-character string."); return; } updateConsole(miniConsole, true, "\nUsing AUTHTOKEN " + authtoken); // // Read & use CSV file // Text.Encoding enc = Text.Encoding.UTF7; Microsoft.VisualBasic.FileIO.TextFieldParser CSVparser = new Microsoft.VisualBasic.FileIO.TextFieldParser(@CSVpath, enc); CSVparser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; CSVparser.SetDelimiters(","); string[] headings = CSVparser.ReadFields(); int[] zohofields = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int colsfound = 0; // match columns by heading (more versatile than assuming consistent column order) updateConsole(miniConsole, true, "\nChecking and matching column headings:"); for(int i = 0 ; i < headings.Length ; i++){ string heading = headings[i]; updateConsole(miniConsole, false, (" " + (i+1) + ":").PadRight(5) + heading.PadRight(35)); if (heading == "Account (SSO)") { updateConsole(miniConsole, true, "--> Matched to Account Name"); colsfound++; zohofields[0] = i+1; } else if (heading == "Product (VGPM)") { updateConsole(miniConsole, true, "--> Matched to Product Name"); colsfound++; zohofields[1] = i+1; } else if (heading == "Offering Type") { updateConsole(miniConsole, true, "--> Matched to Subject"); colsfound++; zohofields[2] = i+1; } else if (heading == "Quantity") { updateConsole(miniConsole, true, "--> Matched to Quantity"); colsfound++; zohofields[3] = i+1; } else if (heading == "Total Sales Value(TSV) (USD)") { updateConsole(miniConsole, true, "--> Matched to Grand Total"); colsfound++; zohofields[4] = i+1; } else if (heading == "Contract Start Date (SSO)") { updateConsole(miniConsole, true, "--> Matched to Contract Start Date"); colsfound++; zohofields[5] = i+1; } else if (heading == "Contract End Date (SSO)") { updateConsole(miniConsole, true, "--> Matched to Contract End Date"); colsfound++; zohofields[6] = i+1; } else if (heading == "Owner (SSO)") { updateConsole(miniConsole, true, "--> Matched to Salesperson"); colsfound++; zohofields[7] = i+1; } else if (heading == "Offering Description") { updateConsole(miniConsole, true, "--> Matched to Description" + i); colsfound++; zohofields[8] = i+1; } else { updateConsole(miniConsole, true, " Column ignored."); } } if (colsfound == 9) { updateConsole(miniConsole, true, "\nMatched all 9 required Zoho fields!"); } else if (colsfound == 0) { string msg = "Could not read .csv file"; updateConsole(miniConsole, true, "\n" + msg); return; } else { string msg = "WARNING: Failed to match all 9 required Zoho fields."; updateConsole(miniConsole, true, "\n" + msg); ErrorMessages.Add(msg); } // // Check Product ID list: // Dictionary<string, string> ids = new Dictionary<string, string>(); if (IDpath == "") { // use default ID list ids = ID_default.getIDs(); } // check if user-submitted ID list exists else if (!IO.File.Exists(IDpath)) { updateConsole(miniConsole, true, "Product ID list '" + IDpath + "' does not exist."); return; } // // Use Product ID list // else { // read product IDs Microsoft.VisualBasic.FileIO.TextFieldParser IDparser = new Microsoft.VisualBasic.FileIO.TextFieldParser(@IDpath); IDparser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; IDparser.SetDelimiters(","); updateConsole(miniConsole, true, "\nProcessing product IDs..."); while (!IDparser.EndOfData) { string[] IDfields = IDparser.ReadFields(); string prodID = IDfields[0]; string prodName = IDfields[1].Replace(";", ""); try { ids.Add(prodName, prodID); } catch (ArgumentException) { ErrorMessages.Add("Product ID duplicate entry found: " + prodID + ", " + prodName + ". Entry ignored. All sales will be imported under the first product."); } } } // // Start sending data // (This starts off sending batches of 5 records. If a batch returns an error, // it tries them again 1 by 1 to isolate the problem record(s) while uploading // the others which well-behaved). // updateConsole(miniConsole, true, "\nProcessing records from CSV file..."); int failCount = 0; int rowNumber = 1; int fullSize = 5; int batchSize = fullSize; // // Read CSV file // ReadBatch: string URLtosend = "https://crm.zoho.com/crm/private/xml/SalesOrders/insertRecords?authtoken="+authtoken+"&scope=crmapi&xmlData=<SalesOrders>"; int batchCount = 0; while (!CSVparser.EndOfData && batchCount < batchSize) { try { // put a blank value at the beginning for non-matched fields string[] CSVfieldsORIG = CSVparser.ReadFields(); string[] CSVfields = new string[CSVfieldsORIG.Length + 1]; string[] CSVblank = { "" }; CSVblank.CopyTo(CSVfields, 0); CSVfieldsORIG.CopyTo(CSVfields, 1); // collect all field values into strings string zoho_accname = CSVfields[zohofields[0]]; if (zoho_accname == "") { goto SkipRecord; } string zoho_prodname = zohoCodeFormat(CSVfields[zohofields[1]]); if (zoho_prodname == "") { goto SkipRecord; } string zoho_prodID = ""; try { zoho_prodID = ids[zoho_prodname]; } catch (Exception e) { ErrorMessages.Add("Error getting ID for " + zoho_prodname + ", so product name for this record set to 'unrecognized':" + e.Message); zoho_prodID = "1312357000000156015"; } string zoho_subject = CSVfields[zohofields[2]]; if (zoho_subject == "") { zoho_subject = getSubject(zoho_prodname); } string zoho_prodquan = CSVfields[zohofields[3]]; string zoho_total = CSVfields[zohofields[4]].Replace(",", ""); string zoho_start = USdate(CSVfields[zohofields[5]]); string zoho_end = USdate(CSVfields[zohofields[6]]); string zoho_salper = CSVfields[zohofields[7]]; string zoho_descrip = CSVfields[zohofields[8]]; // make this record into an XML string string thisXMLstring = XMLstring(zoho_accname, zoho_prodname, zoho_prodID, zoho_subject, zoho_prodquan, zoho_total, zoho_start, zoho_end, zoho_salper, zoho_descrip, rowNumber); URLtosend += thisXMLstring; updateConsole(miniConsole, true, " #"+(rowNumber.ToString()+":").PadRight(4)+zoho_prodname.PadRight(25)+zoho_accname); } catch (Exception e) { failCount += 1; ErrorMessages.Add("Error message:" + e.Message); updateConsole(miniConsole, true, e.Message); } SkipRecord: rowNumber++; batchCount++; if (batchSize == 1 && batchCount == fullSize) { batchSize = fullSize; } } // // Finish building XML string-based URL & send data to Zoho // URLtosend += "</SalesOrders>"; updateConsole(miniConsole, true, "Sending to Zoho..."); System.Net.WebClient webc = new System.Net.WebClient(); String ZohoFeedback = ""; try { ZohoFeedback = webc.DownloadString(URLtosend); // THIS LINE ACTUALLY SENDS THE DATA URLtosend = ""; } catch (Net.WebException we) { if (batchSize == 1) { updateConsole(miniConsole, true, "Got WebException for this record, so skipped it: " + we.Message); ErrorMessages.Add(we.Message); } else { updateConsole(miniConsole, true, "Got WebException for this batch: " + we.Message); updateConsole(miniConsole, true, "Retrying last " + batchSize + " records one by one..."); rowNumber -= batchSize; batchSize = 1; goto ReadBatch; } } // // Extract message from Zoho server // Regex r = new Regex(Regex.Escape("<message>") + "(.*?)" + Regex.Escape("</message>")); MatchCollection matches = taggedString("message", ZohoFeedback); // print message to mini console if(ZohoFeedback != ""){ updateConsole(miniConsole, false, "Message from Zoho server: "); } foreach (Match match in matches){ string msg = match.Groups[1].Value; updateConsole(miniConsole, true, msg+"\n"); if (msg != "Record(s) added successfully" && batchSize > 1) { rowNumber -= batchSize; batchSize = 1; goto ReadBatch; } else if (msg != "Record(s) added successfully" && batchSize == 1) { failCount += 1; updateConsole(miniConsole, true, msg); ErrorMessages.Add("Zoho server: "+msg); batchSize = fullSize; } } // // Loop back and keep sending batches until all records have been sent // if (!CSVparser.EndOfData) { goto ReadBatch; } // // Finish up and report any errors // updateConsole(miniConsole, true, "----------------------------------------------------------------------------------------"); updateConsole(miniConsole, true, "IMPORT COMPLETED"); updateConsole(miniConsole, true, (rowNumber - 1).ToString() + " records processed."); updateConsole(miniConsole, false, (rowNumber - 1 - failCount).ToString() + " successful, " + failCount.ToString() + " unsuccessful.\n"); if(ErrorMessages.Count > 0){ updateConsole(miniConsole, true, "Error messages:"); foreach(string errmsg in ErrorMessages){ updateConsole(miniConsole, true, errmsg); } } updateConsole(miniConsole, true, "----------------------------------------------------------------------------------------"); }