public async Task <object> SaveXml(object userId, object articleId, IDocumentServiceModel document, string content) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } if (articleId == null) { throw new ArgumentNullException(nameof(articleId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } if (string.IsNullOrWhiteSpace(content)) { throw new ArgumentNullException(nameof(content)); } var xmlDocument = new XmlDocument { PreserveWhitespace = true }; xmlDocument.LoadXml(content); var result = await this.service.UpdateContent(userId, articleId, document, xmlDocument.OuterXml); return(result); }
public async Task <object> Create(object userId, object articleId, IDocumentServiceModel document, Stream inputStream) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } if (articleId == null) { throw new ArgumentNullException(nameof(articleId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } if (inputStream == null) { throw new ArgumentNullException(nameof(inputStream)); } string path = await this.xmlFileReaderWriter.GetNewFilePath(document.FileName, this.DataDirectory, ValidationConstants.MaximalLengthOfFullFileName); var entity = new Document { FileName = document.FileName, OriginalFileName = document.FileName, ContentLength = document.ContentLength, OriginalContentLength = document.ContentLength, ContentType = document.ContentType, OriginalContentType = document.ContentType, FileExtension = document.FileExtension, OriginalFileExtension = document.FileExtension, Comment = document.Comment, CreatedByUser = userId.ToString(), ModifiedByUser = userId.ToString() }; var repository = this.repositoryProvider.Create(); entity.FilePath = Path.GetFileNameWithoutExtension(path); entity.ContentLength = await this.xmlFileReaderWriter.Write(inputStream, entity.FilePath, this.DataDirectory); await repository.Add(entity); await repository.SaveChangesAsync(); repository.TryDispose(); return(entity.ContentLength); }
public async Task <object> SaveHtml(object userId, object articleId, IDocumentServiceModel document, string content) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } if (articleId == null) { throw new ArgumentNullException(nameof(articleId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } if (string.IsNullOrWhiteSpace(content)) { throw new ArgumentNullException(nameof(content)); } var xmlDocument = new XmlDocument { PreserveWhitespace = true }; xmlDocument.LoadXml(content .Replace(" ", " ") .Replace("<br>", @"<span elem-name=""break""></span>")); var xmlContent = await this.transformersFactory .GetFormatHtmlToXmlTransformer() .Transform(xmlDocument); xmlDocument.LoadXml(xmlContent); var result = await this.service.UpdateContent(userId, articleId, document, xmlDocument.OuterXml); return(result); }
public async Task <object> UpdateContent(object userId, object articleId, IDocumentServiceModel document, string content) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } if (articleId == null) { throw new ArgumentNullException(nameof(articleId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } var repository = this.repositoryProvider.Create(); var entity = await this.GetEntity(userId, articleId, document.Id, repository); using (var stream = new MemoryStream(Defaults.Encoding.GetBytes(content))) { entity.ContentLength = await this.xmlFileReaderWriter.Write(stream, entity.FilePath, this.DataDirectory); entity.ModifiedByUser = userId.ToString(); entity.DateModified = DateTime.UtcNow; entity.ContentType = document.ContentType; stream.Close(); } await repository.Update(entity : entity); await repository.SaveChangesAsync(); repository.TryDispose(); return(entity.ContentLength); }
public async Task <object> UpdateMeta(object userId, object articleId, IDocumentServiceModel document) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } if (articleId == null) { throw new ArgumentNullException(nameof(articleId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } var repository = this.repositoryProvider.Create(); var entity = await this.GetEntity(userId, articleId, document.Id, repository); entity.Comment = document.Comment; entity.ContentType = document.ContentType; entity.FileExtension = document.FileExtension; entity.FileName = document.FileName; entity.ModifiedByUser = userId.ToString(); entity.DateModified = DateTime.UtcNow; await repository.Update(entity : entity); await repository.SaveChangesAsync(); repository.TryDispose(); return(entity.ContentLength); }