public ExportTask(XmlElement node) : base(node) { foreach (XmlElement propertyNode in node.ChildNodes) { switch (propertyNode.Name) { case "id": this._Id = ParseLong(propertyNode.InnerText); continue; case "alias": this._Alias = propertyNode.InnerText; continue; case "name": this._Name = propertyNode.InnerText; continue; case "dataType": this._DataType = (ExportDataType)StringEnum.Parse(typeof(ExportDataType), propertyNode.InnerText); continue; case "filter": this._Filter = propertyNode.InnerText; continue; case "exportType": this._ExportType = (ExportType)StringEnum.Parse(typeof(ExportType), propertyNode.InnerText); continue; case "frequency": this._Frequency = ParseLong(propertyNode.InnerText); continue; case "notificationUrl": this._NotificationUrl = propertyNode.InnerText; continue; case "vodTypes": this._VodTypes = new List <IntegerValue>(); foreach (XmlElement arrayNode in propertyNode.ChildNodes) { this._VodTypes.Add(ObjectFactory.Create <IntegerValue>(arrayNode)); } continue; case "isActive": this._IsActive = ParseBool(propertyNode.InnerText); continue; } } }
public async Task ExportDownload_SingleJsonFile() { _mockExportManager.Setup(p => p.ExportData(ExportDataType.Tags)) .Returns(Task.FromResult(new ExportResult { ExportFormat = ExportFormat.SingleJsonFile, Content = Array.Empty <byte>() })); var settingsController = CreateDataPortingController(); ExportDataType type = ExportDataType.Tags; var result = await settingsController.ExportDownload(type); Assert.IsInstanceOf <FileContentResult>(result); }
public void SaveToXML(XmlDocument doc, IDTSInfoEvents infoEvents) { var data = doc.CreateElement("VaiablesToXmlData"); data.SetAttribute("ExportBinaryData", ExportBinaryData.ToString()); data.SetAttribute("ExportDataType", ExportDataType.ToString()); data.SetAttribute("ExportDescription", ExportDescription.ToString()); data.SetAttribute("ExportValueDataType", ExportValueDataType.ToString()); data.SetAttribute("ExportVariablePath", ExportVariablePath.ToString()); data.SetAttribute("RootElementName", RootElementName); data.SetAttribute("VariableElementName", VariableElementName); data.SetAttribute("VariablesToExport", VariablesToExport); data.SetAttribute("XmlSaveOptions", XmlSaveOptions.ToString()); data.SetAttribute("XmlVariable", XmlVariable); doc.AppendChild(data); }
/// <summary> /// Creates the export data string. /// </summary> /// <param name="client">IRoadsService client object(WCF).</param> /// <param name="exportDataType">Type of the export data.</param> /// <returns>Specific output string.</returns> public string CreateExportData(IRoadsService client, ExportDataType exportDataType) { switch (exportDataType) { case ExportDataType.Dynamic: _dynamicTranslations = new List<DynamicTranslationExport>(); var dynamicTranslationsData = client.GetAllDynamicTranslationsData().ToList(); foreach (var data in dynamicTranslationsData) { _dynamicTranslations.Add(new DynamicTranslationExport() { DynamicKey = data.DynamicKey, Value = data.Value, DescriptionValue = data.DescriptionValue, LanguageName = data.Lenguage.Name, LanguageId = data.LanguageId }); } return _exportStringBuilder.GetExportString(_dynamicTranslations); case ExportDataType.Static: _staticTranslations = new List<StaticTranslationExport>(); var staticTranslationsData = client.GetAllStaticTranslations().ToList(); foreach (var data in staticTranslationsData) { _staticTranslations.Add(new StaticTranslationExport() { EnumKey = data.EnumKey, Value = data.Value, LanguageName = data.Language.Name, LanguageId = data.LanguageId }); } return _exportStringBuilder.GetExportString(_staticTranslations); case ExportDataType.MapObject: return MapObjectsExportData(client); default: return String.Empty; } }
public async Task ExportDownload_ZippedJsonFiles() { Mock <IExportManager> mockExpman = new(); mockExpman.Setup(p => p.ExportData(ExportDataType.Posts)) .Returns(Task.FromResult(new ExportResult { ExportFormat = ExportFormat.ZippedJsonFiles, FilePath = @"C:\996\icu.zip" })); var settingsController = CreateSettingsController(); settingsController.ControllerContext = new() { HttpContext = new DefaultHttpContext() }; ExportDataType type = ExportDataType.Posts; var result = await settingsController.ExportDownload(mockExpman.Object, type); Assert.IsInstanceOf <PhysicalFileResult>(result); } //[Test] //public void ClearDataCache_StateUnderTest_ExpectedBehavior() //{ // // Arrange // var settingsController = CreateSettingsController(); // string[] cachedObjectValues = null; // IBlogCache cache = null; // // Act // var result = settingsController.ClearDataCache( // cachedObjectValues, // cache); // // Assert // Assert.Fail(); // _mockRepository.VerifyAll(); //} }
public async Task ExportDownload_SingleCSVFile() { _mockExportManager.Setup(p => p.ExportData(ExportDataType.Categories)) .Returns(Task.FromResult(new ExportResult { ExportFormat = ExportFormat.SingleCSVFile, FilePath = @"C:\996\icu.csv" })); var settingsController = CreateDataPortingController(); settingsController.ControllerContext = new() { HttpContext = new DefaultHttpContext() }; ExportDataType type = ExportDataType.Categories; var result = await settingsController.ExportDownload(type); Assert.IsInstanceOf <PhysicalFileResult>(result); }
public async Task <IActionResult> ExportDownload(ExportDataType type) { var exportResult = await _expman.ExportData(type); switch (exportResult.ExportFormat) { case ExportFormat.SingleJsonFile: return(new FileContentResult(exportResult.Content, exportResult.ContentType) { FileDownloadName = $"moonglade-{type.ToString().ToLowerInvariant()}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.json" }); case ExportFormat.SingleCSVFile: Response.Headers.Add("Content-Disposition", $"attachment;filename={Path.GetFileName(exportResult.FilePath)}"); return(PhysicalFile(exportResult.FilePath, exportResult.ContentType, Path.GetFileName(exportResult.FilePath))); case ExportFormat.ZippedJsonFiles: return(PhysicalFile(exportResult.FilePath, exportResult.ContentType, Path.GetFileName(exportResult.FilePath))); default: return(BadRequest(ModelState.CombineErrorMessages())); } }
public async Task ExportDownload_ZippedJsonFiles() { _mockExportManager.Setup(p => p.ExportData(ExportDataType.Posts, CancellationToken.None)) .Returns(Task.FromResult(new ExportResult { ExportFormat = ExportFormat.ZippedJsonFiles, FilePath = @"C:\996\icu.zip" })); var settingsController = CreateDataPortingController(); settingsController.ControllerContext = new() { HttpContext = new DefaultHttpContext() }; ExportDataType type = ExportDataType.Posts; var result = await settingsController.ExportDownload(type, CancellationToken.None); Assert.IsInstanceOf <PhysicalFileResult>(result); } }
public async Task <ExportResult> ExportData(ExportDataType dataType) { switch (dataType) { case ExportDataType.Tags: var tagExp = new SingeJsonExporter <TagEntity>(_tagRepository); var tagExportData = await tagExp.ExportData(p => new { NormalizedTagName = p.NormalizedName, TagName = p.DisplayName }); return(tagExportData); case ExportDataType.Categories: var catExp = new SingeJsonExporter <CategoryEntity>(_catRepository); var catExportData = await catExp.ExportData(p => new { p.DisplayName, Route = p.RouteName, p.Note }); return(catExportData); case ExportDataType.FriendLinks: var fdExp = new SingeJsonExporter <FriendLinkEntity>(_friendlinkRepository); var fdExportData = await fdExp.ExportData(p => new { p.Title, p.LinkUrl }); return(fdExportData); case ExportDataType.Pingbacks: //var pbExp = new SingeJsonExporter<PingbackHistoryEntity>(_pingbackRepository); //var pbExportData = await pbExp.ExportData(p => new //{ // p.Domain, // p.PingTimeUtc, // p.SourceIp, // p.SourceTitle, // p.SourceUrl, // p.TargetPostTitle //}); //return pbExportData; throw new NotImplementedException("Pingback export is not supported for now."); case ExportDataType.Pages: var pgExp = new ZippedJsonExporter <CustomPageEntity>(_pageRepository, "moonglade-pages"); var pgExportData = await pgExp.ExportData(p => new { p.Title, p.CreateOnUtc, p.CssContent, p.HideSidebar, p.HtmlContent, RouteName = p.Slug, p.MetaDescription, p.UpdatedOnUtc }); return(pgExportData); case ExportDataType.Posts: var poExp = new ZippedJsonExporter <PostEntity>(_postRepository, "moonglade-posts"); var poExportData = await poExp.ExportData(p => new { p.Title, p.Slug, p.ContentAbstract, p.PostContent, p.CreateOnUtc, p.CommentEnabled, p.PostExtension.Hits, p.PostExtension.Likes, p.PubDateUtc, p.ContentLanguageCode, p.ExposedToSiteMap, p.IsDeleted, p.IsFeedIncluded, p.IsPublished, Categories = p.PostCategory.Select(pc => pc.Category.DisplayName), Tags = p.PostTag.Select(pt => pt.Tag.DisplayName) }); return(poExportData); default: throw new ArgumentOutOfRangeException(nameof(dataType), dataType, null); } }
public async Task <IActionResult> Export4Download([FromServices] IExportManager expman, ExportDataType type) { var exportResult = await expman.ExportData(type); switch (exportResult.ExportFormat) { case ExportFormat.SingleJsonFile: var bytes = Encoding.UTF8.GetBytes(exportResult.JsonContent); return(new FileContentResult(bytes, "application/octet-stream") { FileDownloadName = $"moonglade-{type.ToString().ToLowerInvariant()}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.json" }); case ExportFormat.ZippedJsonFiles: return(PhysicalFile(exportResult.ZipFilePath, "application/zip", Path.GetFileName(exportResult.ZipFilePath))); default: return(BadRequest()); } }
public async Task <ExportResult> ExportData(ExportDataType dataType, CancellationToken cancellationToken) { switch (dataType) { case ExportDataType.Tags: var tagExp = new CSVExporter <TagEntity>(_tagRepository, "moonglade-tags", _dataDir); var tagExportData = await tagExp.ExportData(p => new { p.Id, p.NormalizedName, p.DisplayName }, cancellationToken); return(tagExportData); case ExportDataType.Categories: var catExp = new CSVExporter <CategoryEntity>(_catRepository, "moonglade-categories", _dataDir); var catExportData = await catExp.ExportData(p => new { p.Id, p.DisplayName, p.RouteName, p.Note }, cancellationToken); return(catExportData); case ExportDataType.FriendLinks: var fdExp = new CSVExporter <FriendLinkEntity>(_friendlinkRepository, "moonglade-friendlinks", _dataDir); var fdExportData = await fdExp.ExportData(p => p, cancellationToken); return(fdExportData); case ExportDataType.Pages: var pgExp = new ZippedJsonExporter <PageEntity>(_pageRepository, "moonglade-pages", _dataDir); var pgExportData = await pgExp.ExportData(p => new { p.Id, p.Title, p.Slug, p.MetaDescription, p.HtmlContent, p.CssContent, p.HideSidebar, p.IsPublished, p.CreateTimeUtc, p.UpdateTimeUtc }, cancellationToken); return(pgExportData); case ExportDataType.Posts: var poExp = new ZippedJsonExporter <PostEntity>(_postRepository, "moonglade-posts", _dataDir); var poExportData = await poExp.ExportData(p => new { p.Title, p.Slug, p.ContentAbstract, p.PostContent, p.CreateTimeUtc, p.CommentEnabled, p.PostExtension.Hits, p.PostExtension.Likes, p.PubDateUtc, p.ContentLanguageCode, p.ExposedToSiteMap, p.IsDeleted, p.IsFeedIncluded, p.IsPublished, Categories = p.PostCategory.Select(pc => pc.Category.DisplayName), Tags = p.Tags.Select(pt => pt.DisplayName) }, cancellationToken); return(poExportData); default: throw new ArgumentOutOfRangeException(nameof(dataType), dataType, null); } }
public ActionResult Upload(HttpPostedFileBase file, ExportDataType dataType) { IImportFileProvider provider = ImportProviderResolver.ResolveImportProvider(file); provider.Update(client, file, dataType); return new JsonResult {Data = provider.Report}; }
public ActionResult ExportXml(ExportDataType dataType) { var fileName = String.Format(dataType + "Translations"); var exportProvider = new ExportDataProvider(new XmlStringBuilder()); var report = exportProvider.CreateExportData(client, dataType); return new XmlActionResult(report, fileName); }