public void AddManifestItem(ManifestItemKey?itemKey) { CurrentItemKey = itemKey; if (CurrentItemKey.HasValue && !ManifestItems.ContainsKey(CurrentItemKey.Value)) { ManifestItems.Add(CurrentItemKey.Value, new ManifestItem(LineNumber)); } }
private async Task <string> ConvertItems(IEnumerable <IItem> items, string tempPath, bool convertHtml, Func <string, IRetrievedFile> resourceHandler) { var baseTempPath = tempPath; tempPath = Path.Combine(baseTempPath, Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); var dir = new DirectoryInfo(tempPath); if (!dir.Exists) { dir.Create(); } var itemsList = items.ToList(); var htmlToQtiConverter = new HtmlToQtiConverter(tempPath, resourceHandler); var itemsDir = new DirectoryInfo(Path.Combine(tempPath, "items")); if (!itemsDir.Exists) { itemsDir.Create(); } var itemQti = string.Empty; foreach (var item in itemsList) { item.UniqueId = item.UniqueId.ReplaceIllegalFilenameChars(); switch (item) { case IMultipleChoiceItem choiceItem: itemQti = convertHtml ? await _choiceInterationCreator.CreateWithHtmlAsync(choiceItem, htmlToQtiConverter) : await _choiceInterationCreator.CreatePlainTextAsync(choiceItem); break; case ITextEntryItem textEntryItem: itemQti = convertHtml ? await _textEntryInteractionCreator.CreateWithHtmlAsync(textEntryItem, htmlToQtiConverter) : await _textEntryInteractionCreator.CreatePlainTextAsync(textEntryItem);; break; } var fileName = Path.Combine(itemsDir.ToString(), $"{item.UniqueId}.xml"); File.WriteAllText(fileName, itemQti); } var test = new QtiTest { Id = $"TST-{Guid.NewGuid()}", Items = itemsList, Title = _testname }; var testQti = await _testCreator.CreateAsync(test); var fileNameTest = Path.Combine(itemsDir.ToString(), $"{test.Id}.xml"); File.WriteAllText(fileNameTest, testQti); var css = htmlToQtiConverter.Css; var images = htmlToQtiConverter.Images; var imageList = images?.Select(i => $"img/{i.Key}").ToList() ?? new List <string>(); var cssList = !string.IsNullOrEmpty(css) ? new List <string> { "css/generated_styles.css" } : new List <string>(); var manifestItems = new ManifestItems { TestId = test.Id, Items = itemsList, Dependencies = htmlToQtiConverter.Dependencies, Media = imageList, Css = cssList }; var manifestQti = await _manifestCreator.CreateAsync(manifestItems); var fileNameManifest = Path.Combine(tempPath, "imsmanifest.xml"); File.WriteAllText(fileNameManifest, manifestQti); var cssDir = new DirectoryInfo(Path.Combine(tempPath, "css")); if (!cssDir.Exists) { cssDir.Create(); } var fileNameCss = Path.Combine(cssDir.ToString(), "generated_styles.css"); if (!string.IsNullOrEmpty(css)) { File.WriteAllText(fileNameCss, css); } var fileNameZip = Path.Combine(baseTempPath, $"qti-package-{DateTime.Now:yyyy-MM-dd_hh-mm-ss}.zip"); ZipFile.CreateFromDirectory(tempPath, fileNameZip, CompressionLevel.Optimal, false); return(fileNameZip); }
public Task <string> CreateAsync(ManifestItems items) { return(_engine.CompileRenderAsync($"Exports._{((int)_version).ToString()}.Manifest.cshtml", items)); }