internal static void AddIdentificationReport(JsonFileReport id, IdentificationReport a) { id.Data.Add(a); }
public static void ParseCSVLumen(string fileLocation) { JsonFileReport JsonFile = new JsonFileReport(); IdentificationReport IDReport = new IdentificationReport(); DateTime today = DateTime.Today; using (CsvReader csv = new CsvReader(new System.IO.StreamReader(fileLocation), true)) { csv.MissingFieldAction = MissingFieldAction.ReplaceByNull; DailyReport currentDailyReport = new DailyReport(); int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { for (int i = 0; i < fieldCount; i++) { if (headers[i] == "blogId") { currentDailyReport.blogID = Int32.Parse(csv[headers[i]]); } else if (headers[i] == "clicks") { currentDailyReport.Clicks = Int32.Parse(csv[headers[i]]); } else if (headers[i] == "views") { currentDailyReport.Views = Int32.Parse(csv[headers[i]]); } currentDailyReport.Date = today.ToString("yyyy-MM-dd"); } using (StreamReader readFile = File.OpenText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\", "output.json"))) { string json = readFile.ReadToEnd(); if (json == "") { JsonFile = new JsonFileReport(); } else { JsonFile = JsonConvert.DeserializeObject <JsonFileReport>(json); } readFile.Close(); } var FindOldIdentificationReport = new IdentificationReport(); if (JsonFile.Data.Count > 0) { if ((FindOldIdentificationReport = JsonFile.Data.Find(x => x.blogID == currentDailyReport.blogID)) != null) { currentDailyReport.DailyViews = currentDailyReport.Views - FindOldIdentificationReport.IdentificationData[FindOldIdentificationReport.IdentificationData.Count - 1].Views; currentDailyReport.DailyClicks = currentDailyReport.Clicks - FindOldIdentificationReport.IdentificationData[FindOldIdentificationReport.IdentificationData.Count - 1].Clicks; IdentificationReport.AddDailyReport(FindOldIdentificationReport, currentDailyReport); } else { currentDailyReport.DailyViews = currentDailyReport.Views; currentDailyReport.DailyClicks = currentDailyReport.Clicks; IdentificationReport NewIDReport = new IdentificationReport(); NewIDReport.blogID = currentDailyReport.blogID; IdentificationReport.AddDailyReport(NewIDReport, currentDailyReport); AddIdentificationReport(JsonFile, NewIDReport); } } else { currentDailyReport.DailyViews = currentDailyReport.Views; currentDailyReport.DailyClicks = currentDailyReport.Clicks; IDReport.blogID = currentDailyReport.blogID; IdentificationReport.AddDailyReport(IDReport, currentDailyReport); AddIdentificationReport(JsonFile, IDReport); } StreamWriter file = File.CreateText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\", "output.json")); JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, JsonFile); file.Close(); Console.Write(JsonConvert.SerializeObject(currentDailyReport)); } } }
private static void OnTimedEvent(Object source, ElapsedEventArgs e) { Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime); JsonFileReport.ParseCSVLumen(@"..\..\test.csv"); }