private void GetMonths() { if (File.Exists(FullPath)) { string[] lines; lock (_fileLock) { lines = File.ReadAllLines(FullPath); } List <string> monthLines = new List <string>(); foreach (string line in lines) { monthLines.Add(line); if (line == "</TimeLog>") { try { Months.Add(MonthData.FromLines(monthLines)); } catch (Exception ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Error, Message = ex.Message }); } monthLines.Clear(); } } int monthcount = Months.Count; } }
public static MonthData FromLines(List <string> lines) { // expected: // opener // date line // hours line // warning line // x timestamps lines // closer if (5 > lines.Count) { throw new ArgumentException("Error parsing Month data: At least 5 lines are expected for Month data."); } MonthData data = new MonthData(); data.Year = int.Parse(lines[0].Substring(15, 4)); data.Month = int.Parse(lines[0].Substring(28, 2)); for (int i = 4; i < lines.Count - 1; i++) { string[] fields = lines[i].Split(_csvDelimiter); if (DateTime.DaysInMonth(data.Year, data.Month) != fields.Length) { throw new ArgumentException(string.Format("Error parsing Month data: {0}.{1} should have {2} days. Only {3} fields in line {4} found.", data.Month, data.Year, DateTime.DaysInMonth(data.Year, data.Month), fields.Length, i + 1)); } for (int day = 0; day < fields.Length; day++) { if (string.Empty != fields[day]) { string field = fields[day]; data.AddStamp(new DateTime( data.Year, data.Month, day + 1, int.Parse(fields[day].Substring(0, 2)), int.Parse(fields[day].Substring(3, 2)), int.Parse(fields[day].Substring(6, 2)))); } } } // verify data string[] hours = lines[2].Split(_csvDelimiter); for (int day = 0; day < hours.Length; day++) { if (0.01 < Math.Abs(double.Parse(hours[day]) - data.TotalHours(day))) { throw new ArgumentException(string.Format("Error parsing Month data: {0}.{1}.{2} should have {3} hours from stamps, but has {4} hours from totalhours.", data.Month, data.Year, day + 1, data.TotalHours(day), double.Parse(hours[day]))); } } return(data); }
public MonthDataView(MonthData monthData) { MonthData = monthData; DayDataViewSource.FontFamily = this.FontFamily; foreach (DayData d in MonthData.DayData) { d.Stamps.CollectionChanged += (o, e) => UpdateTable(); } UpdateTable(); InitializeComponent(); MonthDataViewer.Initialized += AutoScroll; }