public static SIDocument Load(Stream stream, bool read = true) { var document = new SIDocument(); document.LoadInternal(stream, read); return(document); }
private async Task CopyMedia(SIDocument newDocument, Atom atom) { var link = atom.Text.ExtractLink(); var collection = Images; var newCollection = newDocument.Images; switch (atom.Type) { case AtomTypes.Audio: collection = Audio; newCollection = newDocument.Audio; break; case AtomTypes.Video: collection = Video; newCollection = newDocument.Video; break; } if (!newCollection.Contains(link)) { if (collection.Contains(link)) { using var stream = collection.GetFile(link).Stream; await newCollection.AddFile(link, stream); } } }
/// <summary> /// Загрузка пакета из папки /// </summary> /// <param name="folder">Папка с содержимым пакета</param> /// <returns>Загруженный пакет</returns> public static SIDocument Load(string folder) { var document = new SIDocument(); document.LoadInternal(folder, true); return(document); }
public async Task CopyCollections(SIDocument newDocument, Question question) { CopyAuthorsAndSources(newDocument, question); foreach (var atom in question.Scenario) { await CopyMedia(newDocument, atom); } }
/// <summary> /// Скопировать все необходимые коллекции в новый документ, взяв за основу объект /// </summary> /// <param name="newDocument"></param> /// <param name="theme"></param> public async Task CopyCollections(SIDocument newDocument, Theme theme) { CopyAuthorsAndSources(newDocument, theme); foreach (var question in theme.Questions) { await CopyCollections(newDocument, question); } }
public async Task CopyCollections(SIDocument newDocument, Round round) { CopyAuthorsAndSources(newDocument, round); foreach (var theme in round.Themes) { await CopyCollections(newDocument, theme); } }
public async Task CopyCollections(SIDocument newDocument) { CopyAuthorsAndSources(newDocument, Package); foreach (var round in Package.Rounds) { await CopyCollections(newDocument, round); } }
public static SIDocument Create(string name, string author, ISIPackage source) { var document = new SIDocument(); document.CreateInternal(source, name, author); Init(document); return(document); }
public static SIDocument Create(string name, string author, string folder) { var document = new SIDocument(); document.CreateInternal(folder, name, author); Init(document); return(document); }
public static SIDocument Create(string name, string author, Stream stream = null) { var document = new SIDocument(); var ms = stream ?? new MemoryStream(); document.CreateInternal(ms, name, author); Init(document); return(document); }
public static SIDocument Create( string name, string author, Stream stream, bool leaveStreamOpen = false) { var document = new SIDocument(); var ms = stream ?? new MemoryStream(); document.CreateInternal(ms, name, author, leaveStreamOpen); Init(document); return(document); }
public void CopyAuthorsAndSources(SIDocument newDocument, InfoOwner infoOwner) { var length = infoOwner.Info.Authors.Count; for (int i = 0; i < length; i++) { var authorID = infoOwner.Info.Authors[i].ExtractLink(); if (authorID.Length > 0) { if (newDocument.Authors.All(author => author.Id != authorID)) { var newAuthor = Authors.FirstOrDefault(author => author.Id == authorID); if (newAuthor != null) { newDocument.Authors.Add(newAuthor.Clone()); } } } } length = infoOwner.Info.Sources.Count; for (int i = 0; i < length; i++) { var sourceID = infoOwner.Info.Sources[i].ExtractLink(true); if (sourceID.Length > 0) { if (newDocument.Sources.All(source => source.Id != sourceID)) { var newSource = Sources.FirstOrDefault(source => source.Id == sourceID); if (newSource != null) { newDocument.Sources.Add(newSource.Clone()); } } } } }
public static async Task <SIDocument> LoadXml(Stream stream) { var document = new SIDocument(); var ms = new MemoryStream(); document.CreateInternal(ms, "", ""); using (var reader = XmlReader.Create(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "package") { document._package = new Package(); document._package.ReadXml(reader); break; } } } return(document); }
public SIDocument SaveAs(Stream stream, bool switchTo) { var newSource = _source.CopyTo(stream, switchTo, out bool isNew); if (isNew) { newSource.CreateStream(ContentFileName, "si/xml"); newSource.CreateStream(TextsStorageName, AuthorsFileName, "si/xml"); newSource.CreateStream(TextsStorageName, SourcesFileName, "si/xml"); } if (switchTo) { _source.Dispose(); _source = newSource; _images.UpdateSource(_source); _audio.UpdateSource(_source); _video.UpdateSource(_source); } SaveCore(newSource); if (switchTo) { return(this); } var doc = new SIDocument { _source = newSource }; doc.InitializeStorages(); return(doc); }
public static async Task <SIDocument> LoadXml(Stream stream, Func <string, Stream> mediaExtractor = null) { var document = new SIDocument(); var ms = new MemoryStream(); document.CreateInternal(ms, "", ""); using (var reader = XmlReader.Create(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "package") { document._package = new Package(); document._package.ReadXml(reader); break; } } } if (mediaExtractor != null) { // Загрузим файлы контента при наличии ссылок на них foreach (var round in document.Package.Rounds) { foreach (var theme in round.Themes) { foreach (var question in theme.Questions) { foreach (var atom in question.Scenario) { if (atom.IsLink) { var link = atom.Text.ExtractLink(false); var collection = document.Images; switch (atom.Type) { case AtomTypes.Audio: collection = document.Audio; break; case AtomTypes.Video: collection = document.Video; break; } if (collection.Contains(link)) { continue; } var mediaStream = mediaExtractor(link); if (mediaStream == null) { continue; } using (mediaStream) { await collection.AddFile(link, mediaStream); } } } } } } } return(document); }
public void CopyData(SIDocument doc) { doc._package = _package; doc._authors = _authors; doc._sources = _sources; }
private static void Init(SIDocument document) { document._package.ID = Guid.NewGuid().ToString(); document._package.Date = DateTime.UtcNow.ToString("dd.MM.yyyy"); }