public void getPropertiesTest() { //Arrange CSVOutput newCSV = new CSVOutput("C:/Users/Jamie/Desktop/testCSV.csv"); //Assert Assert.AreEqual("C:/Users/Jamie/Desktop/testCSV.csv", newCSV.path); }
public void appendEntryTest() { //Arrange CSVOutput CSV = new CSVOutput("C:/Users/Jamie/Desktop/testCSV.csv"); //Act CSV.appendNewEntry("URL", "Title", "Status Code"); //Assert Assert.AreEqual("Title,\"URL\",Status Code\r\n", CSV.content.ToString()); }
public void TestMakeOneLine() { CSVOutput outer = new CSVOutput(); IList <string> list1 = new List <string>(); list1.Add("ABC"); list1.Add("DEF"); list1.Add("GHI"); string expVal1 = "ABC,DEF,GHI"; Assert.AreEqual(expVal1, outer.MakeOneLine(list1)); IList <string> list2 = new List <string>(); list2.Add("1\"ABC\""); list2.Add("2DEF"); list2.Add("3\"GHI\""); string expVal2 = "\"1\"\"ABC\"\"\",2DEF,\"3\"\"GHI\"\"\""; Assert.AreEqual(expVal2, outer.MakeOneLine(list2)); IList <string> list3 = new List <string>(); list3.Add("ABC"); list3.Add(",DEF"); list3.Add("G,H,I"); string expVal3 = "ABC,\",DEF\",\"G,H,I\""; Assert.AreEqual(expVal3, outer.MakeOneLine(list3)); IList <string> list4 = new List <string>(); list4.Add("ABC"); list4.Add("\nDEF"); list4.Add("G\nH\nI"); string expVal4 = "ABC,\"\nDEF\",\"G\nH\nI\""; Assert.AreEqual(expVal4, outer.MakeOneLine(list4)); outer.Delimitor = "\t"; IList <string> list5 = new List <string>(); list5.Add("ABC,"); list5.Add("\tDEF"); list5.Add("G\tH\tI"); string expVal5 = "ABC,\t\"\tDEF\"\t\"G\tH\tI\""; Assert.AreEqual(expVal5, outer.MakeOneLine(list5)); }
public void TestOpen() { // 例外をテストしてみる (既存ディレクトリと同名のファイルは作れない) using (CSVOutput outer3 = new CSVOutput()) { try { outer3.Open(Path.GetTempPath()); } catch (Exception ex) { Console.Write(@"----この例外はテスト用にわざと出してるので注意" + "\n"); Console.Write(ex.ToString() + "\n"); Console.Write(@"----ここまで" + "\n"); Assert.IsTrue(true); return; } } Assert.Fail(); }
public void TestMakeColumn() { CSVOutput outer = new CSVOutput(); string actVal1 = @"1-ABCD"; string expVal1 = @"1-ABCD"; Assert.AreEqual(expVal1, outer.MakeColumn(actVal1)); string actVal2 = "2-\"ABCD\""; string expVal2 = "\"2-\"\"ABCD\"\"\""; Assert.AreEqual(expVal2, outer.MakeColumn(actVal2)); string actVal3 = "3-AB\r\nCD"; string expVal3 = "\"3-AB\nCD\""; Assert.AreEqual(expVal3, outer.MakeColumn(actVal3)); string actVal4 = "4-AB\rCD"; string expVal4 = "\"4-AB\nCD\""; Assert.AreEqual(expVal4, outer.MakeColumn(actVal4)); string actVal5 = "5-AB\nCD"; string expVal5 = "\"5-AB\nCD\""; Assert.AreEqual(expVal5, outer.MakeColumn(actVal5)); string actVal6 = "6-AB\nC\"D"; string expVal6 = "\"6-AB\nC\"\"D\""; Assert.AreEqual(expVal6, outer.MakeColumn(actVal6)); string actVal7 = "7-AB,C,D"; string expVal7 = "\"7-AB,C,D\""; Assert.AreEqual(expVal7, outer.MakeColumn(actVal7)); string actVal8 = "8-A\nB,C\"D"; string expVal8 = "\"8-A\nB,C\"\"D\""; Assert.AreEqual(expVal8, outer.MakeColumn(actVal8)); }
public void TestWriteCsv() { string file = Path.GetTempFileName(); try { File.Delete(file); using (CSVOutput outer1 = new CSVOutput(file)) { IList <string>[] lists = { new List <string>(), new List <string>() }; lists[0].Add("あいう"); lists[0].Add("えおか"); lists[0].Add("きくけ"); lists[1].Add("こさし"); lists[1].Add("すせそ"); lists[1].Add("たちつ"); // とりあえず2行書く‘ outer1.WriteCsv(lists[0]); outer1.WriteCsv(lists[1]); } using (CSVOutput outer2 = new CSVOutput(file, true)) { string[] list = { "てとな", "にぬね", "のはひ" }; // 1行追記 outer2.WriteCsv(list); } Stream stream = File.Open(file, FileMode.Open); using (BinaryReader reader = new BinaryReader(stream)) { byte[] buff = reader.ReadBytes((int)stream.Length); Encoding enc = Encoding.GetEncoding("csWindows31J"); string act = enc.GetString(buff); string exp = "あいう,えおか,きくけ\r\n" + "こさし,すせそ,たちつ\r\n" + "てとな,にぬね,のはひ\r\n"; Assert.AreEqual(exp, act); } } finally { File.Delete(file); } }
static void Main(string[] args) { try { // Instantiate the LogQuery object LogQuery oLogQuery = new LogQuery(); // Instantiate the Event Log Input Format object EventLogInput eventInputFormat = new EventLogInput(); // When set to "FW", events are retrieved from the oldest to the // newest. When set to "BW", events are retrieved from the newest // to the oldest. eventInputFormat.direction = "FW"; // Event text messages often span multiple lines. When this parameter // is set to "ON", the EVT input format preserves readability of the // messages by removing carriage-return, line-feed, and multiple space // characters from the message text. // When this parameter is set to "OFF", the EVT input format returns // the original message text with no intervening post-processing. eventInputFormat.formatMessage = true; eventInputFormat.binaryFormat = "ASC"; eventInputFormat.stringsSep = ","; CSVOutput csvOutputFormat = new CSVOutput(); // ON: always write the header; // OFF: never write the header; // AUTO: write the header only when not appending to an existing file. csvOutputFormat.headers = "ON"; // Setting this parameter to "ON" causes the CSV output format to write // a tab character after each comma field separator, in order to // improve readability of the CSV output. Note that using tabs between // field values might generate output that is not compatible with // certain spreadsheet applications. csvOutputFormat.tabs = false; // ON: always enclose field values within double-quote characters; // OFF: never enclose field values within double-quote characters; // AUTO: enclose within double-quote characters only those field // values that contain comma (,) characters. csvOutputFormat.oDQuotes = "AUTO"; // This parameter specifies the date and/or time format to use when // formatting values of the TIMESTAMP data type. csvOutputFormat.oTsFormat = "yyyy-MM-dd"; // 0 is the system codepage, -1 is UNICODE. csvOutputFormat.oCodepage = -1; // 0: existing files are appended with the output; // 1: existing files are overwritten with the output; // 2: existing files are left intact, discarding the output. csvOutputFormat.fileMode = 1; /* * EventLog STRING Name of the Event Log or Event Log backup file * RecordNumber INTEGER Index of this event * TimeGenerated TIMESTAMP Event generated date/time (local time) * TimeWritten TIMESTAMP Event logged date/time (local time) * EventID INTEGER The ID of the event * EventType INTEGER The numeric type of the event * EventTypeName STRING The descriptive type of the event * EventCategory INTEGER The numeric category of the event * EventCategoryName STRING The descriptive category of the event * SourceName STRING The source that generated the event * Strings STRING The textual data * ComputerName STRING The name of the computer * SID STRING The Security Identifier associated with the event * Message STRING The full event message * Data STRING The binary data associated with the event */ string query = @"SELECT TOP 10 EventLog, RecordNumber, Message INTO " // Enclose path in single ticks to handle spaces. query += "'" + FullPathToCsv + "' FROM "; // Name of application Log, System, Security, Application, CustomLogName query += "System"; oLogQuery.ExecuteBatch(query, eventInputFormat, csvOutputFormat); } catch (System.Runtime.InteropServices.COMException ex) { Console.WriteLine("Unexpected error: " + ex.Message); } }
private void UploadCSV(string csvFilePath) { IList<CSVOutput> csvOutputs = new List<CSVOutput>(); string[] csvLines = File.ReadAllLines(csvFilePath); foreach (string csvLine in csvLines) { string[] values = csvLine.Split('}'); CSVOutput csvOutput = new CSVOutput() { SBMID = values[0], CollectorName = values[1], CollectorID = values[2], ConsumerNo = values[3], DateofPayment = DateTime.Parse(values[4]), TimeofPayment = values[5], AmountCollected = double.Parse(values[6]), ReceiptNo = values[7], ChequeNo = values[8], ChequeDate = DateTime.Parse(values[9]), BankNameCode = values[10], ManualBookNo = values[11], ManualReceiptNo = values[12], PaymentType = values[13], InstallmentFlag = int.Parse(values[14]), }; csvOutputs.Add(csvOutput); string csvString = string.Empty; csvOutputs.ToList().ForEach(csv => csvString += string.Join("}", csv.ReceiptNo, csv.ManualBookNo, csv.ManualReceiptNo, csv.AmountCollected, csv.BankNameCode, csv.ChequeDate.ToString("yyyyMMdd"), csv.ChequeNo, "000000", "000000", "000000", csv.DateofPayment.ToString("yyyyMMdd"), csv.PaymentType, DateTime.Now.ToString("yyyyMMdd HH.mm.ss"), //Created Time "ADMIN" //CreatedBy ) + Environment.NewLine ); File.WriteAllText(Server.MapPath("") + "\\csv" + ".csv", csvString); } }
public static IList<CSVOutput> UploadCSV(string csvPath, string tempFolderPath) { if (Path.GetExtension(csvPath).ToLower() == ".dbf") { csvPath = ConvertDBFToCSV(csvPath, tempFolderPath); } IList<CSVOutput> csvOutputs = new List<CSVOutput>(); string[] csvLines = File.ReadAllLines(csvPath); foreach (string csvLine in csvLines) { string[] values = csvLine.Split('}'); CSVOutput csvOutput = new CSVOutput() { SBMID = values[0], CollectorName = values[1], CollectorID = values[2], ConsumerNo = values[3], DateofPayment = DateTime.Parse(values[4]), TimeofPayment = values[5], AmountCollected = double.Parse(values[6]), ReceiptNo = values[7], ChequeNo = values[8], ChequeDate = DateTime.Parse(values[9]), BankNameCode = values[10], ManualBookNo = values[11], ManualReceiptNo = values[12], PaymentType = values[13], InstallmentFlag = int.Parse(values[14]), }; csvOutputs.Add(csvOutput); } string csvString = string.Empty; csvOutputs.ToList().ForEach(csv => csvString += string.Join("}", csv.ConsumerNo, //ConnectionID (string.IsNullOrEmpty(csv.ReceiptNo) ? csv.ManualReceiptNo : csv.ReceiptNo), //Recipt No. csv.ManualBookNo, //Manual Book No csv.ManualReceiptNo, //Manual Recipt No. csv.AmountCollected, // AMount csv.BankNameCode, //Bank Name csv.ChequeDate.ToString("yyyyMMdd"), //Cheque date csv.ChequeNo, //Cheque No. "000000", //Sec Code "000000", //Sub Div Code "000000", //div Code csv.DateofPayment.ToString("yyyyMMdd"), // payment date csv.PaymentType, //payment Type DateTime.Now.ToString("yyyyMMdd HH.mm.ss"), //Created Time "ADMIN" //CreatedBy ) + Environment.NewLine ); File.WriteAllText(string.Format("{0}//csv.csv", tempFolderPath), csvString); ImportTODB(tempFolderPath, "csv"); return csvOutputs; }