Beispiel #1
0
        private ImplementationGuideFileData CreateFileData(FileModel model)
        {
            ImplementationGuideFileData data = new ImplementationGuideFileData()
            {
                Data        = model.Data,
                UpdatedBy   = CheckPoint.Instance.UserName,
                UpdatedDate = DateTime.Now,
                Note        = model.Note
            };

            return(data);
        }
Beispiel #2
0
        private void UpdateFile(FileModel model)
        {
            ImplementationGuideFile foundFile = this.tdb.ImplementationGuideFiles.Single(y => y.Id == model.FileId);

            foundFile.Description = model.Description;
            foundFile.Url         = model.Url;

            if (model.Data != null && model.Data.Length > 0)
            {
                ImplementationGuideFileData version = CreateFileData(model);
                foundFile.Versions.Add(version);
            }
        }
Beispiel #3
0
        public FileResult Download(int versionId)
        {
            ImplementationGuideFileData file = this.tdb.ImplementationGuideFileDatas.Single(y => y.Id == versionId);

            if (!CheckPoint.Instance.GrantViewImplementationGuide(file.ImplementationGuideFile.ImplementationGuideId))
            {
                throw new AuthorizationException("You do not have access to view this implementation guide's files.");
            }

            string fileName = file.ImplementationGuideFile.FileName;

            if (fileName.LastIndexOf(".") >= 0)
            {
                fileName = fileName.Insert(fileName.LastIndexOf("."), "_" + file.UpdatedDate.ToString("yyyyMMddHHmmss"));
            }

            return(File(file.Data, file.ImplementationGuideFile.MimeType, fileName));
        }
Beispiel #4
0
        private void UpdateFiles(ImplementationGuide implementationGuide, ImportImplementationGuide importImplementationGuide)
        {
            var    currentUser     = CheckPoint.Instance.GetUser(this.tdb);
            string currentUserName = currentUser != null?
                                     string.Format("{0} {1} ({2})", currentUser.FirstName, currentUser.LastName, currentUser.Email) :
                                         "Unknown user";

            foreach (var importFile in importImplementationGuide.File)
            {
                if (string.IsNullOrEmpty(importFile.name))
                {
                    continue;
                }

                var foundFile = implementationGuide.Files.SingleOrDefault(y => y.FileName.ToLower() == importFile.name.ToLower());

                if (foundFile == null)
                {
                    foundFile                     = new ImplementationGuideFile();
                    foundFile.FileName            = importFile.name;
                    foundFile.ImplementationGuide = implementationGuide;
                    this.tdb.ImplementationGuideFiles.Add(foundFile);
                }

                var    latestData = foundFile.Versions.Count > 0 ? foundFile.GetLatestData() : null;
                byte[] content    = Convert.FromBase64String(importFile.Content);

                if (latestData == null || latestData.Data.Length != content.Length)
                {
                    latestData = new ImplementationGuideFileData();
                    latestData.ImplementationGuideFile = foundFile;
                    latestData.Data        = content;
                    latestData.UpdatedDate = DateTime.Now;
                    latestData.UpdatedBy   = currentUserName;
                    this.tdb.ImplementationGuideFileDatas.Add(latestData);
                }

                // Update properties of the file
                foundFile.MimeType    = importFile.mimeType;
                foundFile.ContentType = importFile.type.ToString();
                foundFile.Description = importFile.Description;
            }
        }
Beispiel #5
0
        private void AddFile(int implementationGuideId, FileModel model)
        {
            if (model.Data == null || model.Data.Length == 0)
            {
                throw new ArgumentNullException("Cannot add a file that does not have any data.");
            }

            ImplementationGuideFile newFile = new ImplementationGuideFile()
            {
                ImplementationGuideId = implementationGuideId,
                ContentType           = model.Type.ToString(),
                FileName    = model.Name,
                MimeType    = model.MimeType,
                Description = model.Description,
                Url         = model.Url
            };

            ImplementationGuideFileData version = CreateFileData(model);

            newFile.Versions.Add(version);

            this.tdb.ImplementationGuideFiles.AddObject(newFile);
        }
        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);
        }