private static string EndTime(string[] splittedDocument, int i, CalendarEntry calendarEntry) { if (!IsTime(splittedDocument, i + 3)) return splittedDocument[i + 2]; //No split //Found split (4 "times" in one shift) calendarEntry.Pause = "Pause fra " + splittedDocument[i + 2] + " til " + splittedDocument[i + 3]; return splittedDocument[i + 4]; }
private void ProduceCalendarEntries(string fromDocument) { var splittedDocument = fromDocument.Split(new[] { "\r\n", "\n", " " }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < splittedDocument.Length; i++) { //Setting info to be used in file and path name for ical if (IsKardexNumber(splittedDocument, i)) SetKardexNumber(splittedDocument, i); if (IsPersonelNumber(splittedDocument, i)) SetPersonelNumber(splittedDocument, i); if (IsDate(splittedDocument, i)) //Its a date! { if (DateHasYearInfo(splittedDocument, i)) //This date had a year info. We update our year. { UpdateYear(splittedDocument, i); } if (IsTime(splittedDocument, i + 1)) //There is time for the date! ;) { //Can now with good conscience instantiate a new calendar entry. CalendarEntry calendarEntry = new CalendarEntry(null, null, null, null); //TODO should we use object initialiser? //Setting info to date. calendarEntry.Date = SetDate(splittedDocument, i); calendarEntry.StartTime = StartTime(splittedDocument, i); calendarEntry.EndTime = EndTime(splittedDocument, i, calendarEntry); //TODO Is there a better way? Pause(splittedDocument, i, calendarEntry); //Finally adding the entry to the list of entries. CalendarEntries.Add(calendarEntry); } } } }
private static void Pause(string[] splittedDocument, int i, CalendarEntry calendarEntry) { if (!string.IsNullOrEmpty(calendarEntry.Pause)) return; if (splittedDocument[i + 3] == "Pause") { //Returns predetermined pause time. calendarEntry.Pause = "Pause: " + splittedDocument[i + 4]; } }