static void Main(string[] args) { string folderPath = args[0]; Creds creds = new Creds { host = "84dc23c9-0d9c-4e8b-a186-079196664732-bluemix.cloudant.com", password = "******", username = "******" }; CloudantBulkUploader uploader = new CloudantBulkUploader(creds); IEnumerable <string> files = Directory.GetFiles(folderPath, "*.csv").OrderBy(s => s); Console.WriteLine("Starting file processing..."); foreach (string file in files) { Dictionary <DateTime, List <ForexEntry> > monthlyEntries = new Dictionary <DateTime, List <ForexEntry> >(); Console.WriteLine($"Processing file {file}..."); using (StreamReader reader = new StreamReader(file)) { string line; while ((line = reader.ReadLine()) != null) { string[] parts = line.Split(','); DateTime timestamp = DateTime.ParseExact(parts[0], "yyyyMMdd HHmmssfff", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); ForexEntry entry = new ForexEntry(timestamp.Ticks, float.Parse(parts[1]), float.Parse(parts[2])); DateTime timestampDate = timestamp.Date; if (monthlyEntries.ContainsKey(timestampDate)) { monthlyEntries[timestampDate].Add(entry); } else { monthlyEntries.Add(timestampDate, new List <ForexEntry> { entry }); } } List <ForexEntry> monthlyAverages = new List <ForexEntry>(); foreach (DateTime date in monthlyEntries.Keys.OrderBy(k => k)) { var dayEntries = monthlyEntries[date]; monthlyAverages.Add(new ForexEntry ( date.Ticks, dayEntries.Average(e => e.Low), dayEntries.Average(e => e.High) )); } uploader.Upload(monthlyAverages); } Console.WriteLine("Finished proceessing..."); Console.WriteLine("Uploading results to Cloudant..."); } }
/// <summary> /// Initializes a new instance of the <see cref="CloudantBulkUploader"/> class. /// </summary> /// <param name="cloudantCreds">The cloudant creds.</param> public CloudantBulkUploader(Creds cloudantCreds) { this.cloudantCreds = cloudantCreds; }