public List<Transaction> ConvertRecords(Stream s) { List<Transaction> xacts = new List<Transaction>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { if (fields[0] == "TRANSACTION DATE") continue; Transaction xact = new Transaction(); try { xact.Date = DateTime.ParseExact(fields[0], "mm/dd/yy", null); xact.PostedDate = DateTime.ParseExact(fields[1], "mm/dd/yy", null); xact.Payee = fields[2].Trim(); xact.Code = fields[3].Trim(); xact.Amount = Convert.ToDecimal(fields[4].Trim()); if (xact.Code.Length == 0) xact.Code = null; xacts.Add(xact); } catch (System.FormatException) {} } } return xacts; }
public List<Posting> ConvertRecords(Stream s) { List<Posting> posts = new List<Posting>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { if (fields[0] == "POSTING DATE") continue; Posting post = new Posting(); post.Date = DateTime.ParseEpost(fields[0], "mm/dd/yy", null); post.PostedDate = DateTime.ParseEpost(fields[1], "mm/dd/yy", null); post.Payee = fields[2].Trim(); post.Code = fields[3].Trim(); post.Amount = Convert.ToDecimal(fields[4].Trim()); if (post.Code.Length == 0) post.Code = null; posts.Add(post); } } return posts; }
public async Task <List <FruitPriceInformation> > GetPrice(List <int> fruitIDs) { // create result list List <FruitPriceInformation> result = new List <FruitPriceInformation>(); try { // read CSV entries CSVReader.CSVReader reader = new CSVReader.CSVReader(); List <CSVEntry> csvEntries = await reader.ReadFile("Fruit Price.CSV"); foreach (CSVEntry csvEntry in csvEntries) { // parse ID int id = int.Parse(csvEntry.Entry[0]); // check if ID was requested if (fruitIDs.Contains(id)) { // add price result.Add(new FruitPriceInformation(id, decimal.Parse(csvEntry.Entry[1]))); } } } catch (Exception ex) { Console.WriteLine("Error getting fruit prices"); } return(result); }
public List <Posting> ConvertRecords(Stream s) { List <Posting> posts = new List <Posting>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { if (fields[0] == "POSTING DATE") { continue; } Posting post = new Posting(); post.Date = DateTime.ParseEpost(fields[0], "mm/dd/yy", null); post.PostedDate = DateTime.ParseEpost(fields[1], "mm/dd/yy", null); post.Payee = fields[2].Trim(); post.Code = fields[3].Trim(); post.Amount = Convert.ToDecimal(fields[4].Trim()); if (post.Code.Length == 0) { post.Code = null; } posts.Add(post); } } return(posts); }
public async Task <List <FruitSearchResult> > SearchFruits(string name) { // create result list List <FruitSearchResult> result = new List <FruitSearchResult>(); // convert name to lowercase string nameLower = name.ToLower(); try { // read CSV entries CSVReader.CSVReader reader = new CSVReader.CSVReader(); List <CSVEntry> csvEntries = await reader.ReadFile("Fruits.CSV"); foreach (CSVEntry csvEntry in csvEntries) { // get name string entryName = csvEntry.Entry[1]; // check if name matches search if (entryName.ToLower().Contains(nameLower)) { // add result result.Add(new FruitSearchResult(int.Parse(csvEntry.Entry[0]), entryName)); } } } catch (Exception ex) { Console.WriteLine("Error searching for fruits"); } return(result); }
public List <Transaction> ConvertRecords(Stream s) { List <Transaction> xacts = new List <Transaction>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { Transaction xact = new Transaction(); xact.Date = DateTime.ParseExact(fields[0], "m/dd/yyyy", null); xact.Payee = fields[2].Trim(); xact.Code = fields[3].Trim(); xact.Amount = -Convert.ToDecimal(fields[4].Trim()); if (xact.Code.Length == 0) { xact.Code = null; } xacts.Add(xact); } } return(xacts); }
public List <Transaction> ConvertRecords(Stream s) { List <Transaction> xacts = new List <Transaction>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { if (fields[0] == "TRANSACTION DATE") { continue; } Transaction xact = new Transaction(); try { xact.Date = DateTime.ParseExact(fields[0], "mm/dd/yy", null); xact.PostedDate = DateTime.ParseExact(fields[1], "mm/dd/yy", null); xact.Payee = fields[2].Trim(); xact.Code = fields[3].Trim(); xact.Amount = Convert.ToDecimal(fields[4].Trim()); if (xact.Code.Length == 0) { xact.Code = null; } xacts.Add(xact); } catch (System.FormatException) {} } } return(xacts); }
public List<Transaction> ConvertRecords(Stream s) { List<Transaction> xacts = new List<Transaction>(); using (CSVReader.CSVReader csv = new CSVReader.CSVReader(s)) { string[] fields; while ((fields = csv.GetCSVLine()) != null) { Transaction xact = new Transaction(); xact.Date = DateTime.ParseExact(fields[0], "m/dd/yyyy", null); xact.Payee = fields[2].Trim(); xact.Code = fields[3].Trim(); xact.Amount = - Convert.ToDecimal(fields[4].Trim()); if (xact.Code.Length == 0) xact.Code = null; xacts.Add(xact); } } return xacts; }
internal CsvEventSource(CSVReader reader) { m_reader = reader; m_sb = new StringBuilder(); MaxEventTimeRelativeMsec = double.PositiveInfinity; }
public CSVStackSource(CSVReader reader, string eventName, double startRelativeMSec, double endRelativeMSec) { lock (reader) { reader.m_stackEventType = eventName; reader.T0 = (long)(startRelativeMSec * 1000); reader.T1 = long.MaxValue - 1000000; double endusec = endRelativeMSec * 1000; if (endusec < reader.T1) { reader.T1 = (long)endusec; } reader.m_trace.Parameters.T0 = reader.T0; reader.m_trace.Parameters.T1 = reader.T1; var result = reader.m_trace.StackStream(delegate(ETLTrace.Frame frame, ETLTrace.TreeComputer treeComputer, long timeUsec, ulong weight) { m_fullModulePaths = treeComputer.fullModuleNames; StackSourceSample sample = new StackSourceSample(this); sample.TimeRelativeMSec = timeUsec / 1000.0; sample.Metric = weight; if (reader.m_stackEventType == "CSwitch") { sample.Metric = sample.Metric / 1000.0F; } if (sample.Metric == 0) { sample.Metric = 1; } // Get rid of quotes. treeComputer.fullModuleNames["\"Unknown\""] = "UNKNOWN"; // We are traversing frames from the root (threadStart), to leaf (caller before callee). StackSourceCallStackIndex stackIndex = StackSourceCallStackIndex.Invalid; bool callerFrameIsThread = false; while (frame != null) { var fullFrameName = treeComputer.atomsNodeNames.MakeString(frame.id); string moduleName = ""; // Parse it into module and function name var frameName = fullFrameName; var index = fullFrameName.IndexOf('!'); if (index >= 0) { frameName = fullFrameName.Substring(index + 1); frameName = frameName.Replace(';', ','); // They use ';' for template separators for some reason, fix it. moduleName = fullFrameName.Substring(0, index); string fullModuleName; if (treeComputer.fullModuleNames.TryGetValue(moduleName, out fullModuleName)) { moduleName = fullModuleName; } if (moduleName.Length > 4 && moduleName[moduleName.Length - 4] == '.') { #if false // TODO decide if we want to ignore the .NI.DLL and if so do it uniformly. if (moduleName.Length > 7 && moduleName[moduleName.Length - 7] == '.' && moduleName[moduleName.Length - 6] == 'n' && moduleName[moduleName.Length - 5] == 'i') { moduleName = moduleName.Substring(0, moduleName.Length - 7); } else #endif moduleName = moduleName.Substring(0, moduleName.Length - 4); } // If the thread does not call into ntdll, we consider it broken if (callerFrameIsThread && !moduleName.EndsWith("ntdll", StringComparison.Ordinal)) { var brokenFrame = Interner.FrameIntern("BROKEN", Interner.ModuleIntern("")); stackIndex = Interner.CallStackIntern(brokenFrame, stackIndex); } } else { Match m = Regex.Match(frameName, @"^tid *\( *(\d+)\)"); if (m.Success) { frameName = "Thread (" + m.Groups[1].Value + ")"; } else { m = Regex.Match(frameName, @"^(.*?)(\.exe)? *\( *(\d+)\) *$"); if (m.Success) { frameName = "Process " + m.Groups[1].Value + " (" + m.Groups[3].Value + ")"; } } } var myModuleIndex = Interner.ModuleIntern(moduleName); var myFrameIndex = Interner.FrameIntern(frameName, myModuleIndex); stackIndex = Interner.CallStackIntern(myFrameIndex, stackIndex); callerFrameIsThread = frameName.StartsWith("tid "); frame = frame.next; } sample.StackIndex = stackIndex; AddSample(sample); }); Interner.DoneInterning(); } }