Exemplo n.º 1
0
        private PatientMRCScore BuildMRCScore(Patient patient, IDictionary record)
        {
            var score = new PatientMRCScore();

            score.PatientId = patient.ID;
            var stringScore = (string)record[SCORE];

            if (stringScore == "NULL" || string.IsNullOrEmpty(stringScore))
            {
                return(null);
            }
            score.Score = stringScore;
            string stringDateTaken = (string)record[DATE_TAKEN];
            var    dateTaken       = ParseDate(stringDateTaken);

            if (dateTaken == null)
            {
                return(null);
            }
            score.DateTaken = dateTaken.Value;
            _context.Entry(patient).Collection(p => p.PatientMRCScores).Load();
            var dates           = patient.PatientMRCScores.Select(s => s.DateTaken.Date).ToList();
            var existingDbDates = dates.FindAll(d => d.Date == score.DateTaken.Date);

            if (existingDbDates.Count > 0)
            {
                return(null);
            }
            Imported.Add(score);
            return(score);
        }
Exemplo n.º 2
0
 private void ReadCellsForPatient(Patient patient, IRow row, int cellCount)
 {
     for (int cellCursor = 0; cellCursor < cellCount; cellCursor++)
     {
         if (patient.ID <= 0)
         {
             continue;
         }
         if (!patient.PatientNACDates.Any())
         {
             patient.PatientNACDates = new List <PatientNACDates>()
             {
                 new PatientNACDates()
             }
         }
         ;
         if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null)
         {
             ReadCell(patient, row, cellCursor);
         }
     }
     if (patient.ID > 0)
     {
         Imported.Add(patient);
     }
 }
 public void ReadDOCXFile()
 {
     ResetStream();
     ConvertToDocxIfDoc();
     InitializeRequiredProperties();
     using (_wordDocument = WordprocessingDocument.Open(_wordPackage))
     {
         var           diagnosisElement        = GetDiagnosisElement();
         var           rm2Number               = FindRM2InDocumentName();
         var           potentialDiagnoses      = FindDiagnosesFromWord();
         List <string> discoveredDiagnosesList = CopyToNewList(potentialDiagnoses);
         Patient       patient = _patientManager.FindPatientByRM2Number(rm2Number, true);
         if (patient == null)
         {
             return;
         }
         foreach (var potentialDiagnosis in potentialDiagnoses)
         {
             var diagnosis = GetPatientDiagnosesFromWord(patient, potentialDiagnosis);
             if (diagnosis != null)
             {
                 Imported.Add(diagnosis);
                 discoveredDiagnosesList.Remove(potentialDiagnosis);
             }
             GetPatientSurgeriesFromWord(patient, potentialDiagnosis);
         }
         BuildPatientGenericNotes(patient, discoveredDiagnosesList);
     }
     _stream.Close();
     _context.SaveChanges();
 }
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                List <PatientSTGQuestionnaire> sgrqs = _context.PatientSTGQuestionnaires.Where(d => d.PatientId.Equals(patient.ID)).ToList();
                var newSgrq = new PatientSTGQuestionnaire()
                {
                    PatientId = patient.ID
                };
                patient = ReadRowCellsIntoPatientObject(patient, row, cellCount, newSgrq);
                var  existingDates    = sgrqs.Select(pi => pi.DateTaken.Date).ToList();
                bool dateDoesNotExist = existingDates.FindAll(d => d.Date == newSgrq.DateTaken.Date).ToList().Count == 0;
                if (newSgrq.DateTaken.Year > 1 && dateDoesNotExist)
                {
                    if (patient.STGQuestionnaires == null)
                    {
                        patient.STGQuestionnaires = new List <PatientSTGQuestionnaire>();
                    }
                    patient.STGQuestionnaires.Add(newSgrq);
                }
                Imported.Add(patient);
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
        private void ReadCell(Patient patient, IRow row, int cellCursor)
        {
            string header          = _headers.ElementAt(cellCursor);
            string newObjectFields = (string)_dictonary[header];
            string propertyValue   = row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();

            if (string.IsNullOrEmpty(propertyValue))
            {
                return;
            }
            switch (header)
            {
            case "OtherDiagnosisAndNotes":
                SetPatientGenericNote(patient, propertyValue);
                break;

            case "HasLungSurgery":
                var            surgeryResolver = new ManARTSPatientSurgeryResolver(_context, propertyValue, row, _headers);
                PatientSurgery surgery         = surgeryResolver.Resolve();
                if (surgery != null)
                {
                    surgery.PatientId = patient.ID;
                    _context.PatientSurgeries.Add(surgery);
                    Imported.Add(surgery);
                    _context.SaveChanges();
                }
                break;
            }
        }
        private void CheckIfAlreadyImportedInDatabase(Patient patientFromExcel, Patient existingImportedPatient)
        {
            var dbPatient = FindPatientInDatabase(patientFromExcel);

            if (dbPatient != null && !string.IsNullOrEmpty(patientFromExcel.NhsNumber))
            {
                dbPatient.NhsNumber = patientFromExcel.NhsNumber;
            }

            if (dbPatient != null)
            {
                var excelPatientDrugLevelList = patientFromExcel.DrugLevels.Select(dl => dl.ResultValue).ToList();
                var dbPatientDrugLevelList    = dbPatient.DrugLevels.Select(dl => dl.ResultValue).ToList();
                var newDrugLevels             = excelPatientDrugLevelList.Except(dbPatientDrugLevelList);

                var toInsertDrugLevels = patientFromExcel.DrugLevels.Where(dl => newDrugLevels.Contains(dl.ResultValue));

                foreach (var drugLevel in toInsertDrugLevels)
                {
                    dbPatient.DrugLevels.Add(drugLevel);
                }
                Imported.Add(dbPatient);
            }
            else
            {
                if (patientFromExcel.IsValid() && existingImportedPatient == null)
                {
                    Imported.Add(patientFromExcel);
                }
            }
        }
        private void ReadCell(Patient patient, IRow row, int cellCursor)
        {
            string header          = _headers.ElementAt(cellCursor);
            string newObjectFields = (string)_dictonary[header];
            string propertyValue   = row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();

            if (string.IsNullOrEmpty(propertyValue))
            {
                return;
            }
            var capturedKeys = new List <string>();

            foreach (var key in HeadersDictionary().Keys)
            {
                capturedKeys.Add(key as String);
            }
            if (header == "Smoker")
            {
                var smokingStatusResolver = new SmokingStatusResolver(_context, propertyValue, row, _headers);
                var smokingStatus         = smokingStatusResolver.Resolve();
                if (smokingStatus != null)
                {
                    smokingStatus.PatientId = patient.ID;
                    patient.PatientSmokingDrinkingStatus = smokingStatus;
                    _context.PatientSmokingDrinkingStatus.Add(smokingStatus);
                    Imported.Add(smokingStatus);
                }
            }
        }
        private Patient ReadCellsForPatient(Patient patient, IRow row, int cellCount)
        {
            var allDates = _context.PatientNACDates
                           .Where(p => p.PatientId == patient.ID)
                           .FirstOrDefault();
            var dates = patient.PatientNACDates.FirstOrDefault();

            if (dates == null)
            {
                dates = new PatientNACDates();
            }
            dates.PatientId = patient.ID;
            for (int cellCursor = 0; cellCursor < cellCount; cellCursor++)
            {
                if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null)
                {
                    ReadCell(patient, row, dates, cellCursor);
                }
            }

            patient.PatientNACDates.Add(dates);
            if (dates.PatientId != 0 && dates.PatientId > 0)
            {
                Imported.Add(dates);
            }
            return(patient);
        }
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                patient = ReadRowCellsIntoPatientObject(patient, row, cellCount);
                var existingPatient = ExistingPatient(patient.RM2Number);
                Imported.Add(patient);
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
Exemplo n.º 10
0
        private void ParseAndSaveLines(List <string> matched)
        {
            _uom = _context.UnitOfMeasurements.Where(uom => uom.Name == "g/l").FirstOrDefault();

            var patient = _context.Patients.Where(p => p.RM2Number.Contains(_id))
                          .Include(p => p.PatientTestResults)
                          .ThenInclude(pt => pt.TestType)
                          .FirstOrDefault();

            var testType = _context.TestTypes
                           .Where(tt => tt.Name == "Albumin")
                           .FirstOrDefault();

            var existingDates = patient.PatientTestResults
                                .Where(ig => ig.TestTypeId == testType.ID)
                                .Select(pi => pi.DateTaken.Date)
                                .ToList();

            foreach (string line in matched)
            {
                var    dataArray  = line.Split(" ");
                string range      = "";
                string dateString = dataArray.Take(3).ToList().Join(" ");
                string testValue  = dataArray[5].Replace("*", String.Empty)
                                    .Replace("<", String.Empty)
                                    .Replace(">", String.Empty);
                string sampleId = dataArray[4];
                if (dataArray.Length > 6)
                {
                    range = dataArray[6] + dataArray[7] + dataArray[8];
                }
                else
                {
                    range = "(" + Regex.Match(_lines[12], @"\(([^)]*)\)").Groups[1].Value + ")";
                    Console.WriteLine(dataArray);
                }
                DateTime parsedDate;
                DateTime.TryParseExact(dateString, "dd MMM yyyy", null, System.Globalization.DateTimeStyles.None, out parsedDate);
                if (existingDates.FindAll(d => d.Date == parsedDate.Date).ToList().Count == 0)
                {
                    var crp = new PatientTestResult();
                    crp.TestTypeId        = testType.ID;
                    crp.SampleId          = sampleId;
                    crp.Range             = range;
                    crp.PatientId         = patient.ID;
                    crp.Value             = decimal.Parse(testValue);
                    crp.DateTaken         = parsedDate;
                    crp.UnitOfMeasurement = _uom;
                    _context.PatientTestResult.Add(crp);
                    Imported.Add(crp);
                }
            }
        }
Exemplo n.º 11
0
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                var modifiedPatient = ReadCellsForPatient(patient, row, cellCount);
                if (modifiedPatient.IsValid())
                {
                    Imported.Add(modifiedPatient);
                }
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
Exemplo n.º 12
0
        private void ParseAndSaveLines(List <string> matched)
        {
            var patient = _context.Patients.Where(p => p.RM2Number.Contains(_id))
                          .Include(p => p.PatientImmunoglobulines)
                          .ThenInclude(p => p.ImmunoglobulinType)
                          .FirstOrDefault();

            var igType = _context.ImmunoglobulinTypes
                         .Where(it => it.Name == "Total IgE")
                         .FirstOrDefault();

            var existingDates = patient.PatientImmunoglobulines
                                .Where(ig => ig.ImmunoglobulinTypeId == igType.ID)
                                .Select(pi => pi.DateTaken.Date)
                                .ToList();

            foreach (string line in matched)
            {
                var    dataArray  = line.Split(" ");
                string range      = "";
                string dateString = dataArray.Take(3).ToList().Join(" ");
                string igeValue   = dataArray[5].Replace("*", String.Empty)
                                    .Replace("<", String.Empty)
                                    .Replace(">", String.Empty);
                string sampleId = dataArray[4];
                if (dataArray.Length > 6)
                {
                    range = dataArray[6] + dataArray[7] + dataArray[8];
                }
                else
                {
                    range = "(" + Regex.Match(_lines[11], @"\(([^)]*)\)").Groups[1].Value + ")";
                    Console.WriteLine(dataArray);
                }
                DateTime parsedDate;
                DateTime.TryParseExact(dateString, "dd MMM yyyy", null, System.Globalization.DateTimeStyles.None, out parsedDate);
                if (existingDates.FindAll(d => d.Date == parsedDate.Date).ToList().Count == 0)
                {
                    var totalIgE = new PatientImmunoglobulin();
                    totalIgE.ImmunoglobulinType = igType;
                    totalIgE.SampleId           = sampleId;
                    totalIgE.Range     = range;
                    totalIgE.PatientId = patient.ID;
                    totalIgE.Value     = decimal.Parse(igeValue);
                    totalIgE.DateTaken = parsedDate;
                    _context.PatientImmunoglobulins.Add(totalIgE);
                    Imported.Add(totalIgE);
                }
            }
        }
        private object ReadCellsForPatient(Patient patient, IRow row, int cellCount)
        {
            var pft = new PatientPulmonaryFunctionTest();
            var hmt = new PatientHaematology();

            for (int cellCursor = 0; cellCursor < cellCount; cellCursor++)
            {
                if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null)
                {
                    ReadCell(patient, pft, hmt, row, cellCursor);
                }
            }
            Imported.Add(patient);
            return(patient);
        }
Exemplo n.º 14
0
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                _patientAliveStatus    = _context.PatientStatuses.Where(s => s.Name == "Active").FirstOrDefault().ID;
                _patientDeceasedStatus = _context.PatientStatuses.Where(s => s.Name == "Deceased").FirstOrDefault().ID;
                _cpaDiagnosis          = _context.DiagnosisTypes.Where(dt => dt.Name.Contains("Chronic pulmonary aspergillosis")).SingleOrDefault();
                _primaryDiagnosisCat   = _context.DiagnosisCategories.Where(dc => dc.CategoryName == "Primary").SingleOrDefault();

                var importedPatient = ReadCellsToPatient(patient, row, cellCount);
                AddPatientDiagnosis(patient);
                if (importedPatient.IsValid())
                {
                    Imported.Add(importedPatient);
                }
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
        private Patient ReadCellsForPatient(Patient patient, IRow row, int cellCount)
        {
            var admission = new PatientHospitalAdmission();

            admission.PatientId = patient.ID;
            for (int cellCursor = 0; cellCursor < cellCount; cellCursor++)
            {
                if (row.GetCell(cellCursor, MissingCellPolicy.CREATE_NULL_AS_BLANK) != null)
                {
                    ReadCell(patient, row, admission, cellCursor);
                }
            }

            patient.PatientHospitalAdmissions.Add(admission);
            if (admission.PatientId != 0 && admission.PatientId > 0)
            {
                Imported.Add(admission);
            }
            return(patient);
        }
Exemplo n.º 16
0
        private PatientSTGQuestionnaire BuildPatientSTGQuestionnaire(Patient patient, IDictionary record)
        {
            var sgrquestionare = new PatientSTGQuestionnaire();

            sgrquestionare.PatientId     = patient.ID;
            sgrquestionare.SymptomScore  = decimal.Parse((string)record[SYMPTOM_SCORE]);
            sgrquestionare.ImpactScore   = decimal.Parse((string)record[IMPACT_SCORE]);
            sgrquestionare.ActivityScore = decimal.Parse((string)record[ACTIVITY_SCORE]);
            sgrquestionare.TotalScore    = decimal.Parse((string)record[TOTAL_SCORE]);
            string dateTaken = (string)record[DATE_TAKEN];

            try
            {
                sgrquestionare.DateTaken = DateTime.ParseExact(dateTaken, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            } catch (FormatException)
            {
                try
                {
                    sgrquestionare.DateTaken = Convert.ToDateTime(dateTaken);
                } catch (FormatException)
                {
                    Console.WriteLine(dateTaken);
                }
            }
            _context.Entry(patient).Collection(p => p.STGQuestionnaires).Load();
            var dates           = patient.STGQuestionnaires.Select(sgrq => sgrq.DateTaken.Date).ToList();
            var existingDbDates = dates.FindAll(d => d.Date == sgrquestionare.DateTaken.Date);

            if (existingDbDates.Count > 0)
            {
                return(sgrquestionare);
            }
            if (sgrquestionare.IsValid())
            {
                Imported.Add(sgrquestionare);
            }
            return(sgrquestionare);
        }
Exemplo n.º 17
0
        protected override void ProcessSheet(ISheet currentSheet)
        {
            Action <Patient, IRow, int> sheetProcessingAction = (patient, row, cellCount) =>
            {
                string identifierValue = row.Cells[1].StringCellValue;
                var    dbPatient       = FindByDOBAndNames(row, identifierValue);
                if (dbPatient == null)
                {
                    return;
                }
                else
                {
                    patient = dbPatient;
                }
                var modifiedPatient = ReadCellsForPatient(patient, row, cellCount);
                if (modifiedPatient.IsValid() && dbPatient != null)
                {
                    Imported.Add(modifiedPatient);
                }
            };

            InitializeSheetProcessingForRows(HeadersDictionary(), currentSheet, sheetProcessingAction);
        }
Exemplo n.º 18
0
        private void ParseAndSaveLines(List <string> matched)
        {
            var patient = _context.Patients.Where(p => p.RM2Number.Contains(_id))
                          .Include(p => p.PatientImmunoglobulines)
                          .ThenInclude(p => p.ImmunoglobulinType)
                          .FirstOrDefault();

            var igType = _context.ImmunoglobulinTypes
                         .Where(it => it.Name == "Aspergillus F IgG")
                         .FirstOrDefault();

            var existingDates = patient.PatientImmunoglobulines
                                .Where(pi => pi.ImmunoglobulinTypeId == igType.ID)
                                .Select(pi => pi.DateTaken.Date)
                                .ToList();

            foreach (string line in matched)
            {
                var    dataArray  = line.Split(" ");
                string dateString = dataArray.Take(3).ToList().Join(" ");
                string igGValue   = dataArray[5].Replace("*", String.Empty)
                                    .Replace("<", String.Empty)
                                    .Replace(">", String.Empty);
                DateTime parsedDate;
                DateTime.TryParseExact(dateString, "dd MMM yyyy", null, System.Globalization.DateTimeStyles.None, out parsedDate);
                if (existingDates.FindAll(d => d.Date == parsedDate.Date).ToList().Count == 0)
                {
                    var patientIGg = new PatientImmunoglobulin();
                    patientIGg.ImmunoglobulinType = igType;
                    patientIGg.PatientId          = patient.ID;
                    patientIGg.Value     = decimal.Parse(igGValue);
                    patientIGg.DateTaken = parsedDate;
                    _context.PatientImmunoglobulins.Add(patientIGg);
                    Imported.Add(patientIGg);
                }
            }
        }
        private void ReadCell(Patient patient, IRow row, int cellCursor)
        {
            string header          = _headers.ElementAt(cellCursor);
            string newObjectFields = (string)_dictonary[header];

            if (string.IsNullOrEmpty(newObjectFields))
            {
                return;
            }
            string headerWithoutNumbers = Regex.Replace(header, @"[\d-]", string.Empty);

            if (header.Equals("DrugAssayDate1"))
            {
                for (int cursor = 1; cursor < 33; cursor++)
                {
                    var namesWithCursor  = HeaderNames().Select(h => h + cursor.ToString());
                    var patientDrugLevel = new PatientDrugLevel();
                    patientDrugLevel.UnitOfMeasurementId = 1;
                    foreach (var name in namesWithCursor)
                    {
                        int    headerIndex         = _headers.IndexOf(name);
                        string klassAndProperty    = (string)HeadersDictionary()[name];
                        var    klassAndPropertyAry = klassAndProperty.Split(".");
                        ICell  cell = row.GetCell(headerIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK);
                        if (name.Contains("DrugAssayDate"))
                        {
                            String stringDate = cell.StringCellValue;
                            if (stringDate == "")
                            {
                                continue;
                            }
                            var date = DateTime.Parse(stringDate);
                            var existingDrugLevel = _context.PatientDrugLevels
                                                    .Where(dl => dl.PatientId == patient.ID &&
                                                           dl.DateTaken.Day == date.Day &&
                                                           dl.DateTaken.Month == date.Month &&
                                                           dl.DateTaken.Year == date.Year)
                                                    .FirstOrDefault();
                            if (existingDrugLevel != null)
                            {
                                patientDrugLevel = existingDrugLevel;
                            }
                            patientDrugLevel.DateReceived = date;
                            patientDrugLevel.DateTaken    = date;
                        }
                        else if (name.Contains("DrugAssayDrug"))
                        {
                            var drug = _context.Drugs.FirstOrDefault(d => d.Name.Equals(cell.StringCellValue.Trim()));
                            if (drug == null)
                            {
                                continue;
                            }
                            patientDrugLevel.DrugId = drug.ID;
                        }
                        else if (name.Contains("DrugAssayResult"))
                        {
                            string result = cell.StringCellValue.Replace("<", String.Empty).Replace(">", String.Empty);
                            if (string.IsNullOrEmpty(result))
                            {
                                continue;
                            }
                            patientDrugLevel.ResultValue = Decimal.Parse(result);
                        }
                    }
                    if (patientDrugLevel.DateReceived == null)
                    {
                        continue;
                    }
                    if (patientDrugLevel.DrugId == 0)
                    {
                        continue;
                    }
                    patientDrugLevel.Patient = patient;
                    if (patient.DrugLevels == null)
                    {
                        patient.DrugLevels = new List <PatientDrugLevel>();
                    }
                    if (patientDrugLevel.ID.Equals(0))
                    {
                        patient.DrugLevels.Add(patientDrugLevel);
                        _context.PatientDrugLevels.Add(patientDrugLevel);
                    }
                    else
                    {
                        _context.PatientDrugLevels.Update(patientDrugLevel);
                    }
                    Imported.Add(patientDrugLevel);
                }
            }
        }
Exemplo n.º 20
0
        private void GetObjects(string document, string file, TranslateRule globalTranslate, TranslateRule playerTranslate, bool isRoot)
        {
            // If this file was already loaded, don't load it again.
            if (Imported.Contains(file))
            {
                return;
            }
            Imported.Add(file);
            Diagnostics.AddFile(file);

            // Get the ruleset.
            RulesetNode ruleset = GetRuleset(file, document);

            Rulesets.Add(file, ruleset);

            if (ruleset != null && !Diagnostics.ContainsErrors())
            {
                if (isRoot)
                {
                    VarCollection = new VarCollection(ruleset.UseGlobalVar, ruleset.UsePlayerVar, ruleset.UseBuilderVar);
                    Root          = new ScopeGroup(VarCollection);
                }

                // Get the defined types
                foreach (var definedType in ruleset.DefinedTypes)
                {
                    try
                    {
                        if (DefinedTypes.Any(type => type.Name == definedType.Name))
                        {
                            throw SyntaxErrorException.NameAlreadyDefined(definedType.Location);
                        }
                        DefinedTypes.Add(DefinedType.GetDefinedType(definedType));
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                // Get the user methods.
                for (int i = 0; i < ruleset.UserMethods.Length; i++)
                {
                    try
                    {
                        UserMethods.Add(new UserMethod(Root, ruleset.UserMethods[i]));
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                // Get the rules
                RuleNodes.AddRange(ruleset.Rules);

                List <string> importedFiles = new List <string>();

                foreach (ImportObjectNode importObject in ruleset.ObjectImports)
                {
                    try
                    {
                        Importer importer = new Importer(Diagnostics, importedFiles, importObject.File, file, importObject.Location);
                        if (!importer.AlreadyImported)
                        {
                            importedFiles.Add(importer.ResultingPath);
                            string content = importer.GetFile();
                            switch (importer.FileType)
                            {
                            case ".obj":
                                Model newModel = Model.ImportObj(content);
                                new ModelVar(importObject.Name, Root, importObject, newModel);
                                break;
                            }
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                // Check the imported files.
                foreach (ImportNode importNode in ruleset.Imports)
                {
                    try
                    {
                        Importer importer = new Importer(Diagnostics, importedFiles, importNode.File, file, importNode.Location);
                        if (!importer.AlreadyImported)
                        {
                            string content = File.ReadAllText(importer.ResultingPath);
                            GetObjects(content, importer.ResultingPath, globalTranslate, playerTranslate, false);
                            importedFiles.Add(importer.ResultingPath);
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                // Get the variables
                foreach (var definedVar in ruleset.DefinedVars)
                {
                    try
                    {
                        IndexedVar var;
                        if (definedVar.UseVar == null)
                        {
                            var = VarCollection.AssignVar(Root, definedVar.VariableName, definedVar.IsGlobal, definedVar);
                        }
                        else
                        {
                            var = VarCollection.AssignVar(
                                Root,
                                definedVar.VariableName,
                                definedVar.IsGlobal,
                                definedVar.UseVar.Variable,
                                definedVar.UseVar.Index,
                                definedVar
                                );
                        }
                        if (definedVar.Type != null)
                        {
                            var.Type = GetDefinedType(definedVar.Type, definedVar.Location);
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void GetRulesets(string document, string file, bool isRoot, ImportedFile cache)
        {
            string absolute = new Uri(file).AbsolutePath;

            // If this file was already loaded, don't load it again.
            if (Imported.Contains(absolute))
            {
                return;
            }
            Imported.Add(absolute);
            Diagnostics.AddFile(file);

            // Get the ruleset.
            RulesetNode ruleset;

            if (cache == null)
            {
                ruleset = GetRuleset(file, document);
            }
            else if (cache.Update() || cache.Cache == null)
            {
                ruleset     = GetRuleset(file, cache.Content);
                cache.Cache = ruleset;
            }
            else
            {
                ruleset = (RulesetNode)cache.Cache;
            }

            Rulesets.Add(file, ruleset);

            // Get the imported files.
            if (ruleset != null && !Diagnostics.ContainsErrors())
            {
                ReservedGlobalIDs.AddRange(ruleset.ReservedGlobalIDs);
                ReservedPlayerIDs.AddRange(ruleset.ReservedPlayerIDs);
                if (ruleset.ReservedGlobal != null)
                {
                    ReservedGlobalIDs.AddRange(ruleset.ReservedGlobal.ReservedIDs);
                    ReservedGlobalNames.AddRange(ruleset.ReservedGlobal.ReservedNames);
                }
                if (ruleset.ReservedPlayer != null)
                {
                    ReservedPlayerIDs.AddRange(ruleset.ReservedPlayer.ReservedIDs);
                    ReservedPlayerNames.AddRange(ruleset.ReservedPlayer.ReservedNames);
                }

                List <string> importedFiles = new List <string>();
                foreach (ImportNode importNode in ruleset.Imports)
                {
                    try
                    {
                        Importer importer = new Importer(Diagnostics, importedFiles, importNode.File, file, importNode.Location);
                        if (!importer.AlreadyImported)
                        {
                            GetRulesets(null, importer.ResultingPath, false, importer.FileData);
                            importedFiles.Add(importer.ResultingPath);
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }
            }
        }