public JsonResult ValidateFile(IFormFile uploadedFile) { if (uploadedFile != null) { var stream = uploadedFile.OpenReadStream(); var file = ParserExtension.FileToCollection(stream); _parser.CompletedNotify += CompletedHandler; _parser.StartParse(file.ToArray()); } return(Json(new { errors = _errors, warnings = _warnings })); }
public async override Task <DoctorDto> GetByIdAsync(int id) { string sql = "exec [dbo].[GetDoctor] @id"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; command.Parameters.AddWithValue("id", id); using (var reader = await command.ExecuteReaderAsync()) { reader.Read(); var doctor = await ParserExtension.DoctorParser(reader); return(doctor); } } }
public async override Task <IEnumerable <DoctorDto> > GetAllAsync() { var doctors = new List <DoctorDto>(); string sql = "exec [dbo].[GetAllDoctors]"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; using (var reader = await command.ExecuteReaderAsync()) { while (reader.Read()) { var doctor = await ParserExtension.DoctorParser(reader); doctors.Add(doctor); } } return(doctors); } }
public async override Task <IEnumerable <PatientDto> > GetAllAsync() { var patients = new List <PatientDto>(); string sql = "exec [dbo].[GetAllPatients]"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; using (var reader = await command.ExecuteReaderAsync()) { while (reader.Read()) { var patient = await ParserExtension.PatientParser(reader); patients.Add(patient); } } return(patients); } }
public async Task <IEnumerable <DoctorDto> > SearchAsync(string pattern) { var doctors = new List <DoctorDto>(); string sql = "exec [dbo].[SearchDoctors] @pattern"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; command.Parameters.AddWithValue("pattern", pattern); using (var reader = await command.ExecuteReaderAsync()) { while (reader.Read()) { var doctor = await ParserExtension.DoctorParser(reader); doctors.Add(doctor); } } return(doctors); } }
public async Task <IEnumerable <PatientDto> > GetDoctorPatientsAsync(int doctorId) { var patients = new List <PatientDto>(); string sql = "exec [dbo].[GetDoctorPatients] @doctorId"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; command.Parameters.AddWithValue("doctorId", doctorId); using (var reader = await command.ExecuteReaderAsync()) { while (reader.Read()) { var patient = await ParserExtension.PatientParser(reader); patients.Add(patient); } } return(patients); } }
public async Task <IEnumerable <DiseaseDto> > GetPatientDiseasesAsync(int patientId) { var diseases = new List <DiseaseDto>(); string sql = "exec [dbo].[GetPatientDiseasesHistory] @id"; using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = sql; command.Parameters.AddWithValue("id", patientId); using (var reader = await command.ExecuteReaderAsync()) { while (reader.Read()) { var disieas = await ParserExtension.DiseaseParser(reader); diseases.Add(disieas); } } return(diseases); } }
public void StartParse(string[] file) { _excelMapper = new Dictionary <string, string>(file.Length); _errors = new List <Error>(); _warnings = new List <Warning>(); _errorsList = new List <string>(); _warningsPairs = new List <string>(); _units = new HashSet <Unit>(); var unitNumber = _indexTemplate; var unitIndex = 0; BuildTree(0, ""); int BuildTree(int rowIndex, string parentNodeNumber) { var prevNodeNumber = string.Empty; while (rowIndex < file.Length) { if (file[rowIndex].StartsWith("Unit")) { var unit = ParserExtension.GetUnit(file[rowIndex], rowIndex + 1); if (unit == null) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Unit title is wrong format", Line = file[rowIndex] }); } else if (_units.Any(u => u.Name == unit.Name && u.Row != unit.Row) && !_errors.Any(u => u.Row == unit.Row)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Unit with the same name already exist", Line = file[rowIndex] + " ◎◎◎" + " Look at line - " + _units.First(u => u.Name == unit.Name && u.Row != unit.Row).Row + "." }); } else if (!_units.Any(u => u.Name == unit.Name)) { _units.Add(unit); } unitNumber = $"{_indexTemplate}.{++unitIndex}"; if (string.IsNullOrWhiteSpace(parentNodeNumber)) { _excelMapper.Add(unitNumber, file[rowIndex]); rowIndex = BuildTree(rowIndex + 1, unitNumber); } else { return(--rowIndex); } } else { var currentNodeNumber = ParserExtension.GetCriterionNumberOfString(file[rowIndex]); var currentNodeNumberFull = $"{unitNumber}.{currentNodeNumber}"; int nestingLevelCurrent = currentNodeNumberFull.Count(x => x == '.'); int nestingLevelPrev = prevNodeNumber.Count(x => x == '.'); if (string.IsNullOrWhiteSpace(currentNodeNumber)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "String doesn't start with number", Line = file[rowIndex] }); } else { if (prevNodeNumber != string.Empty && (nestingLevelCurrent > nestingLevelPrev)) { //current 1.1.1.3.1 prev 1.1.1.3 check 1.1.1.3==1.1.1.3 if (!NumberingChecks.CheckRoot(prevNodeNumber, currentNodeNumberFull)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Nesting does't match previous", Line = file[rowIndex] }); } rowIndex = BuildTree(rowIndex, prevNodeNumber); } else if (nestingLevelCurrent < nestingLevelPrev) { //current 1.1.1.4 prev 1.1.1.3.1 check 1.1.1 == 1.1.1 and 4>3 if (!NumberingChecks.CheckNumberingPrev(prevNodeNumber, currentNodeNumberFull)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Nesting does't match previous", Line = file[rowIndex] }); } return(--rowIndex); } else { if (!NumberingChecks.CheckNumberingCurrent(prevNodeNumber, currentNodeNumberFull)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Nesting does't match previous", Line = file[rowIndex] }); } if (!NumberingChecks.IsCorrectNumbering(prevNodeNumber, currentNodeNumberFull)) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Wrong numbering", Line = file[rowIndex] }); } try { bool needCheckWarning = false; bool haveError = false; switch (ParserExtension.DoesHaveChild(file[rowIndex], currentNodeNumber, rowIndex + 1 >= file.Length ? null : file[rowIndex + 1]))//check regexp { case ParserExtension.State.UnCorrect: _errors.Add(new Error { Row = rowIndex + 1, Message = "Line in the wrong format for children", Line = file[rowIndex] }); haveError = true; break; case ParserExtension.State.Correct: break; case ParserExtension.State.NeedCheckWarning: needCheckWarning = true; switch (ParserExtension.DoesNotHaveChild(file[rowIndex], currentNodeNumber, rowIndex + 1 >= file.Length ? null : file[rowIndex + 1])) //check regexp { case ParserExtension.State.UnCorrect: _errors.Add(new Error { Row = rowIndex + 1, Message = "Line is not formatted correctly for concatenation", Line = file[rowIndex] }); haveError = true; needCheckWarning = false; break; case ParserExtension.State.Correct: needCheckWarning = false; break; case ParserExtension.State.NeedCheckWarning: needCheckWarning = true; break; } break; } if (!haveError)//check regexp { if (ParserExtension.InCorrectString(file[rowIndex])) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Incorrect string", Line = file[rowIndex] }); haveError = true; } } if (!haveError && needCheckWarning) { if (!ParserExtension.CheckWarnings(file[rowIndex]))// check warning regexp { _warnings.Add(new Warning { Row = rowIndex + 1, Message = "Check this line", Line = file[rowIndex] }); } } if (ParserExtension.ContainsDirtyInfo(file[rowIndex])) { _warnings.Add(new Warning { Row = rowIndex + 1, Message = "Maybe there useless information exists", Line = file[rowIndex] }); } if (!currentNodeNumberFull.IsTemplateValid()) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Template is not valid!", Line = file[rowIndex] }); } } catch (Exception e) { if (!_errors.Where(error => error.Message.Contains("Nesting does't match previous") && error.Row == rowIndex + 1).Any()) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Not unique content or invalid string", Line = file[rowIndex] }); } } if (rowIndex != 0 && ParserExtension.CheckForDuplicated(file[rowIndex], file[rowIndex - 1])) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Duplicated criteria", Line = file[rowIndex] }); } prevNodeNumber = currentNodeNumberFull; if (!_excelMapper.ContainsKey(currentNodeNumberFull)) { _excelMapper.Add(currentNodeNumberFull, file[rowIndex]); } else { if (!_errors.Where(error => error.Message.Contains("Nesting does't match previous") && error.Row == rowIndex + 1).Any()) { _errors.Add(new Error { Row = rowIndex + 1, Message = "Not unique content or invalid string", Line = file[rowIndex] }); } } } } } rowIndex++; } return(rowIndex); } this.OnParsingCompleted(); }
public RCBlock CreateVerbTable(Type type, out bool module) { RCBlock result = RCBlock.Empty; // Is it an extension? object[] attributes = type.GetCustomAttributes(typeof(RCExtension), false); if (attributes.Length > 0) { RCExtension ext = (RCExtension)attributes[0]; ParserExtension extension = (ParserExtension)type.GetConstructor(_ctor).Invoke(_ctor); _extByToken[ext.StartToken] = extension; _extByCode[ext.TypeCode] = extension; } // Is it a standalone module (with no operators) module = false; attributes = type.GetCustomAttributes(typeof(RCModule), false); if (attributes.Length > 0) { module = true; } foreach (MethodInfo method in type.GetMethods()) { attributes = method.GetCustomAttributes(typeof(RCVerb), false); for (int i = 0; i < attributes.Length; ++i) { RCVerb verb = (RCVerb)attributes[i]; // Check to see if this verb has a custom implementation. // This is for operators that need to override methods on RCOperator // like Next for example. switch and each are good examples. // Having an entry in _operator is what distinguishes a built-in // operator from a RCUserOperator implemented in RCL. // note: a user operator may obscure a built-in operator if it has the same name Type optype; _operator.TryGetValue(verb.Name, out optype); if (optype == null || optype == typeof(RCOperator)) { if (type.IsSubclassOf(typeof(RCOperator))) { _operator[verb.Name] = type; } else { _operator[verb.Name] = typeof(RCOperator); } } ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == 3) { OverloadKey key = new OverloadKey(verb.Name, typeof(object), null, parameters[2].ParameterType); if (_dispatch.ContainsKey(key)) { throw new Exception("dispatch table already contains the key:" + key); } OverloadValue value = new OverloadValue(type, method); _dispatch.Add(key, value); result = new RCBlock(result, verb.Name, ":", verb.Name); module = true; } else if (parameters.Length == 4) { OverloadKey key = new OverloadKey(verb.Name, typeof(object), parameters[2].ParameterType, parameters[3].ParameterType); if (_dispatch.ContainsKey(key)) { throw new Exception("dispatch table already contains the key:" + key); } OverloadValue value = new OverloadValue(type, method); _dispatch.Add(key, value); result = new RCBlock(result, verb.Name, ":", verb.Name); module = true; } } } if (module) { _modules.Add(type); } return(result); }