Exemple #1
0
        protected override void InnerStoreContentItem(H5PJsonDto h5pJson, string contentId, string content)
        {
            var fileDto = _fileDtos.FirstOrDefault(f => f.ContentId == contentId);

            fileDto.Title   = h5pJson.Title;
            fileDto.Content = content;
        }
        public void StoreContentItem(H5PJsonDto h5pJson, string contentId, string content)
        {
            InnerStoreContentItem(h5pJson, contentId, content);

            var touchedLibraries = new List <(string, int, int)>();

            if (h5pJson.PreloadedDependencies != null)
            {
                SaveContentDependencies(h5pJson.PreloadedDependencies, contentId, touchedLibraries, h5pJson.MainLibrary);
            }
        }
Exemple #3
0
        /// <summary>
        /// Store the content items's files and return the content json of the item.
        /// </summary>
        private string ImportContent(string contentId, ZipArchive zip, H5PJsonDto h5pJson)
        {
            var contentEntries = zip.Entries.Where(e => e.FullName.StartsWith("content"));

            foreach (var entry in contentEntries)
            {
                StoreContentFile(contentId, entry.FullName, zip);
            }

            var contentContentEntry = zip.Entries.FirstOrDefault(e => e.FullName == "content/content.json");

            if (contentContentEntry == null)
            {
                throw new Exception("Content item does not contain the content.json file!");
            }

            using var stream = contentContentEntry.Open();
            using var reader = new StreamReader(stream, Encoding.Default);
            return(reader.ReadToEnd());
        }
Exemple #4
0
        private H5PJsonDto.Library ImportDependencyLibrary(H5PJsonDto.Dependency dependency, ZipArchive zip, H5PJsonDto h5pJson)
        {
            var dirName = $"{dependency.MachineName}-{dependency.MajorVersion}.{dependency.MinorVersion}";

            // TODO: only proceed if patch version is higher than stored patch version

            var libraryEntry = zip.GetEntry(dirName + "/" + "library.json");

            using var libraryStream = libraryEntry.Open();
            using var reader        = new StreamReader(libraryStream, Encoding.Default);
            var libraryString = reader.ReadToEnd();
            var libraryJson   = JsonConvert.DeserializeObject <H5PJsonDto.Library>(libraryString);

            if (libraryJson.PreloadedDependencies != null)
            {
                foreach (var libraryDependency in libraryJson.PreloadedDependencies)
                {
                    var rootDependency = h5pJson.PreloadedDependencies.FirstOrDefault(d => d.MachineName == libraryDependency.MachineName && d.MajorVersion == libraryDependency.MajorVersion && d.MinorVersion == libraryDependency.MinorVersion);

                    // If the dependency exists in the root of the file, use it to fulfill this nested dependency
                    if (rootDependency?.Library != null)
                    {
                        libraryDependency.Library = rootDependency.Library;
                    }
                    else // import it on the spot
                    {
                        var library = ImportDependencyLibrary(libraryDependency, zip, h5pJson);
                        libraryDependency.Library = library;

                        // also save the library to the root dependency, if it exists in the root
                        if (rootDependency != null)
                        {
                            rootDependency.Library = library;
                        }
                    }
                }
            }

            var entries = zip.Entries.Where(e => e.FullName.StartsWith(dirName.TrimEnd('/') + "/"));

            foreach (var entry in entries)
            {
                StoreLibraryFile(entry.FullName, zip);
            }

            return(libraryJson);
        }