Beispiel #1
0
        private Task <HomeworkWeek> _processFile(string id, string fileName)
        {
            return(Task.Run(() => {
                var fi = new FileInfo(fileName);

                var sb = new StringBuilder();
                using (var doc = WordprocessingDocument.Open(fileName, false)) {
                    var week = new HomeworkWeek(id);
                    week.WeekCommencing = DateTimeExtensions.GetNextWeekday(DateTime.Now, DayOfWeek.Monday);
                    var notes = new StringBuilder();

                    var paragraphs = doc.MainDocumentPart.Document.Body.Elements().OfType <Paragraph>();
                    foreach (var paragraph in paragraphs)
                    {
                        try {
                            //check if we got the date
                            var date = _parseOrdinalDateTime(paragraph.InnerText);
                            week.WeekCommencing = date;
                            continue;
                        } catch (Exception /*ex*/) {
                            // _logger.LogError(ex.Message);
                        }
                        notes.Append(paragraph.InnerText);
                        notes.Append(Environment.NewLine);
                        notes.Append(Environment.NewLine);
                    }

                    week.Notes = notes.ToString();
                    var table = doc.MainDocumentPart.Document.Body.Elements().OfType <Table>().FirstOrDefault();
                    if (table == null)
                    {
                        return null;
                    }

                    _processTable(table, ref week);
                    return week;
                }
            }));
        }
Beispiel #2
0
        private void _processTable(Table node, ref HomeworkWeek week)
        {
            //parse the subjects
            week.Subjects = node.Descendants <TableRow>()
                            .First()
                            .Skip(2)
                            .Select(r => r.InnerText)
                            .ToList();
            short dayIndex = 0;

            foreach (var dow in Enum.GetValues(typeof(DayOfWeek))
                     .OfType <DayOfWeek>()
                     .ToList()
                     .Skip(1).Take(4))
            {
                var entries = node.Descendants <TableRow>()
                              .Skip(dayIndex + 1)
                              .First()
                              .Skip(2)
                              .Select(r => r.InnerText)
                              .ToArray();
                var   days       = new Dictionary <string, string>();
                short entryIndex = 0;
                foreach (var entry in entries)
                {
                    try {
                        var subject = week.Subjects[entryIndex++];
                        days.Add(subject, entry);
                    } catch (Exception ex) {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                week.Days.Add(dow, days);
                dayIndex++;
            }
        }
Beispiel #3
0
 public async Task Remove(HomeworkWeek homeworkIn)
 {
     await _homeworkWeeks.DeleteOneAsync(homework => homework.Id == homeworkIn.Id);
 }
Beispiel #4
0
 public async Task Update(string id, HomeworkWeek homeworkIn)
 {
     await _homeworkWeeks.ReplaceOneAsync(homework => homework.Id == id, homeworkIn);
 }
Beispiel #5
0
        public async Task <HomeworkWeek> Create(HomeworkWeek homework)
        {
            await _homeworkWeeks.InsertOneAsync(homework);

            return(homework);
        }