private ValidationProfile GetStoredValidationProfile(IObjectRepository tdb, int implementationGuideFileId)
        {
            ValidationProfile           foundProfile     = loadedProfiles.SingleOrDefault(y => y.Id == implementationGuideFileId);
            ImplementationGuideFileData latestSchematron = (from igf in tdb.ImplementationGuideFiles
                                                            join igfd in tdb.ImplementationGuideFileDatas on igf.Id equals igfd.ImplementationGuideFileId
                                                            where igf.Id == implementationGuideFileId
                                                            select igfd).OrderByDescending(y => y.UpdatedDate).FirstOrDefault();
            ImplementationGuideFile igFile = tdb.ImplementationGuideFiles.Single(y => y.Id == implementationGuideFileId);
            int implementationGuideId      = igFile.ImplementationGuideId;

            if (foundProfile != null && latestSchematron != null && foundProfile.LastUpdated != latestSchematron.UpdatedDate)
            {
                lock (loadedProfilesLock)
                {
                    loadedProfiles.Remove(foundProfile);
                }

                foundProfile = null;
            }

            // The profile is not already loaded
            if (foundProfile == null)
            {
                lock (loadedProfilesLock)
                {
                    string type           = igFile.ImplementationGuide.ImplementationGuideType.Name;
                    string schemaLocation = Path.Combine(
                        Trifolia.Shared.Helper.GetSchemasDirectory(igFile.ImplementationGuide.ImplementationGuideType.Name),
                        igFile.ImplementationGuide.ImplementationGuideType.SchemaLocation);

                    foundProfile = new ValidationProfile()
                    {
                        Id = implementationGuideFileId
                    };

                    List <ImplementationGuideFile> schHelperFiles = (from pigf in tdb.ImplementationGuideFiles
                                                                     join igf in tdb.ImplementationGuideFiles on pigf.ImplementationGuideId equals igf.ImplementationGuideId
                                                                     where pigf.ImplementationGuideId == implementationGuideId && igf.ContentType == ImplementationGuideFile.ContentTypeSchematronHelper
                                                                     select igf).ToList();

                    IValidator schValidator = SchematronValidationFactory.NewValidator(ASCIIEncoding.UTF8.GetString(latestSchematron.Data));

                    List <ImplementationGuideFile> additionalFiles = (from pigf in tdb.ImplementationGuideFiles
                                                                      join igf in tdb.ImplementationGuideFiles on pigf.ImplementationGuideId equals igf.ImplementationGuideId
                                                                      where pigf.Id == implementationGuideFileId && igf.ContentType == ImplementationGuideFile.ContentTypeVocabulary
                                                                      select igf).ToList();

                    foreach (ImplementationGuideFile cAdditionalFile in additionalFiles)
                    {
                        ImplementationGuideFileData latestVersion = cAdditionalFile.Versions
                                                                    .OrderByDescending(y => y.UpdatedDate)
                                                                    .FirstOrDefault();

                        schValidator.AddInclude(cAdditionalFile.FileName, latestVersion.Data);
                    }

                    foundProfile.SchematronValidator = schValidator;
                    foundProfile.LastUpdated         = latestSchematron.UpdatedDate;
                    foundProfile.Type           = type;
                    foundProfile.SchemaPrefix   = igFile.ImplementationGuide.ImplementationGuideType.SchemaPrefix;
                    foundProfile.SchemaUri      = igFile.ImplementationGuide.ImplementationGuideType.SchemaURI;
                    foundProfile.SchemaLocation = schemaLocation;

                    loadedProfiles.Add(foundProfile);
                }
            }

            return(foundProfile);
        }