예제 #1
0
        internal async Task Run(IClientProxy websocketToAll)
        {
            var reader             = new ExaminationReader.ExaminationReader();
            var examinationService = new ExaminationService(_password, _port);

            int TOTAL_COUNT = _filePaths.Length;
            int count       = 0;

            foreach (string path in _filePaths)
            {
                var result = new Progress
                {
                    FileName   = Path.GetFileName(path),
                    FileNumber = ++count,
                    TotalCount = TOTAL_COUNT,
                    Error      = null
                };

                string fileName = Path.GetFileName(path);
                await websocketToAll.SendAsync("ReadingFile", fileName);

                try
                {
                    Examination examination = reader.Read(path);
                    ValidateAndFixResults(examination.Results, fileName);
                    Domain.Examination dbExamination = Converter.PrepareEntity(examination);
                    examinationService.AddExamination(dbExamination);
                }
                catch (Exception e)
                {
                    _logger.FileError(fileName, e);
                    result.FileName += " UWAGA BŁĄD";
                    result.Error     = e.Message;
                }
                await websocketToAll.SendAsync("FileProcessed", result);
            }
        }