public void ExportDataSources() { reader.GetDataSources("/SSRSMigrate_AW_Tests", GetDataSources_Reporter); foreach (DataSourceItem actualDataSourceItem in actualDataSourceItems) { string saveFilePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(actualDataSourceItem.Path, "json"); ExportStatus actualStatus = dataSourceExporter.SaveItem( actualDataSourceItem, saveFilePath, true); // Export was successful Assert.True(actualStatus.Success, string.Format("Success; {0}", actualDataSourceItem.Path)); // Was exported to the expected location Assert.AreEqual(saveFilePath, actualStatus.ToPath, string.Format("ToPath; {0}", actualDataSourceItem.Path)); // Was exported from the expected location Assert.AreEqual(actualDataSourceItem.Path, actualStatus.FromPath, string.Format("ToPath; {0}", actualDataSourceItem.Path)); // The exported DataSourceItem exists on disk Assert.True(File.Exists(actualStatus.ToPath)); } }
public void ExportReports() { reader.GetReports("/SSRSMigrate_AW_Tests", GetReports_Reporter); foreach (ReportItem actualReportItem in actualReportItems) { string saveFilePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(actualReportItem.Path, "rdl"); ExportStatus actualStatus = reportExporter.SaveItem( actualReportItem, saveFilePath, true); // Export was successful Assert.True(actualStatus.Success, string.Format("Success; {0}", actualReportItem.Path)); // Exported to the expected location Assert.AreEqual(saveFilePath, actualStatus.ToPath, string.Format("ToPath; {0}", actualReportItem.Path)); // Was exported from the expected location Assert.AreEqual(actualReportItem.Path, actualStatus.FromPath, string.Format("ToPath; {0}", actualReportItem.Path)); // The exported ReportItem exists on disk Assert.True(File.Exists(actualStatus.ToPath)); } // The exported reports file matches the expected file Assert.True(TesterUtility.CompareTextFiles(testReportFiles[0], outputPath + "\\SSRSMigrate_AW_Tests\\Reports\\Company Sales.rdl")); Assert.True(TesterUtility.CompareTextFiles(testReportFiles[1], outputPath + "\\SSRSMigrate_AW_Tests\\Reports\\Sales Order Detail.rdl")); Assert.True(TesterUtility.CompareTextFiles(testReportFiles[2], outputPath + "\\SSRSMigrate_AW_Tests\\Reports\\Store Contacts.rdl")); }
public void GetServerPathToPhysicalPath_Folder_PathEndsWithSlash() { string ssrsPath = "/SSRSMigrate/Reports/Sub Folder/"; string expected = "\\SSRSMigrate\\Reports\\Sub Folder"; string actual = SSRSUtil.GetServerPathToPhysicalPath(ssrsPath); Assert.AreEqual(expected, actual); }
public void GetServerPathToPhysicalPath_Folder_NullExtension() { string ssrsPath = "/SSRSMigrate/Reports/Sub Folder"; string expected = "\\SSRSMigrate\\Reports\\Sub Folder"; string actual = SSRSUtil.GetServerPathToPhysicalPath(ssrsPath, null); Assert.AreEqual(expected, actual); }
public void GetServerPathToPhysicalPath_Report_PathEndsWithSlash() { string ssrsPath = "/SSRSMigrate/Reports/Inquiry/"; string extension = "rdl"; string expected = "\\SSRSMigrate\\Reports\\Inquiry.rdl"; string actual = SSRSUtil.GetServerPathToPhysicalPath(ssrsPath, extension); Assert.AreEqual(expected, actual); }
public void ExportFolderItem() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(folderItems[0].Path); ExportStatus actualStatus = exporter.SaveItem(folderItems[0], filePath); Assert.True(actualStatus.Success); Assert.AreEqual(filePath, actualStatus.ToPath); Assert.Null(actualStatus.Errors); Assert.True(Directory.Exists(actualStatus.ToPath)); }
public void ExportReportItem_NullItem() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(reportItem_CompanySales.Path, "rdl"); ArgumentNullException ex = Assert.Throws <ArgumentNullException>( delegate { exporter.SaveItem(null, filePath); }); Assert.That(ex.Message, Is.EqualTo("Value cannot be null.\r\nParameter name: item")); }
public void ExportReportItem() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(reportItem_CompanySales.Path, "rdl"); ExportStatus actualStatus = exporter.SaveItem(reportItem_CompanySales, filePath); Assert.True(actualStatus.Success); Assert.AreEqual(filePath, actualStatus.ToPath); Assert.True(File.Exists(actualStatus.ToPath)); Assert.Null(actualStatus.Errors); Assert.True(TesterUtility.CompareTextFiles(Path.Combine(TestContext.CurrentContext.TestDirectory, testReportFiles[0]), actualStatus.ToPath)); }
public void ExportDataSourceItem() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(dataSourceItem.Path, "json"); ExportStatus actualStatus = exporter.SaveItem(dataSourceItem, filePath); Assert.True(actualStatus.Success); Assert.AreEqual(filePath, actualStatus.ToPath); Assert.Null(actualStatus.Errors); Assert.True(File.Exists(filePath)); Assert.AreEqual(expectedDataSourceJson, File.ReadAllText(filePath)); }
public void GetServerPathToPhysicalPath_EmptyPath() { string extension = "rdl"; ArgumentException ex = Assert.Throws <ArgumentException>( delegate { string actual = SSRSUtil.GetServerPathToPhysicalPath("", extension); }); Assert.That(ex.Message, Is.EqualTo("serverPath")); }
public void ExportFolderItem_FileDontOverwrite() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(folderItems[0].Path); // Create dummy directory Directory.CreateDirectory(filePath); ExportStatus actualStatus = exporter.SaveItem(folderItems[0], filePath, false); Assert.False(actualStatus.Success); Assert.AreEqual(filePath, actualStatus.ToPath); Assert.NotNull(actualStatus.Errors); Assert.True(actualStatus.Errors.Any(e => e.Contains(string.Format("Directory '{0}' already exists.", filePath)))); }
public void ExportReportItem_FileDontOverwrite() { string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(reportItem_CompanySales.Path, "rdl"); // Create dummy file, so the output file already exists, causing the SaveItem to fail Directory.CreateDirectory(Path.GetDirectoryName(filePath)); File.WriteAllText(filePath, "DUMMY FILE"); ExportStatus actualStatus = exporter.SaveItem(reportItem_CompanySales, filePath, false); Assert.False(actualStatus.Success); Assert.AreEqual(filePath, actualStatus.ToPath); Assert.NotNull(actualStatus.Errors); Assert.True(actualStatus.Errors.Any(e => e.Contains(string.Format("File '{0}' already exists.", filePath)))); }
public void ExportReportItems() { for (int i = 0; i < reportItems.Count(); i++) { ReportItem reportItem = reportItems[i]; string filePath = outputPath + SSRSUtil.GetServerPathToPhysicalPath(reportItem.Path, "rdl"); ExportStatus actualStatus = exporter.SaveItem(reportItem, filePath); Assert.True(actualStatus.Success, "Success"); Assert.AreEqual(filePath, actualStatus.ToPath, "ToPath"); Assert.True(File.Exists(actualStatus.ToPath), " ToPath.Exists"); Assert.Null(actualStatus.Errors); Assert.True(TesterUtility.CompareTextFiles(Path.Combine(TestContext.CurrentContext.TestDirectory, testReportFiles[i]), actualStatus.ToPath), "CompareTextFiles"); } }
private void ExportItemsWorker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string exportPath = (string)e.Argument; // Stopwatch to track how long the export takes Stopwatch watch = new Stopwatch(); // Start stopwatch to get how long it takes to get the total number of checked items watch.Start(); IEnumerable <ListViewItem> lvItems = GetListViewItems(this.lstSrcReports).Cast <ListViewItem>(); // Get total count of items in ListView that are checked int totalItems = lvItems.Where(lv => lv.Checked == true).Count(); int progressCounter = 0; int reportsExportedCounter = 0; int reportsTotalCount = 0; int foldersExportedCounter = 0; int foldersTotalCount = 0; int dataSourcesExportedCounter = 0; int dataSourcesTotalCount = 0; // Stop stopwatch after getting the total number of checked items, and log how long it took watch.Stop(); this.mLogger.Debug("ExportItemsWorker - Took {0} seconds to get checked ListView items", watch.Elapsed.TotalSeconds); // Start stopwatch to get how long it takes to export everything watch.Start(); // Export folders // Get path of ListView items in the folder group that are checked. var folderPaths = from lv in lvItems where lv.Group.Name == "foldersGroup" && lv.Checked == true select(string) lv.Tag; foldersTotalCount = folderPaths.Count(); this.mLogger.Debug("ExportItemsWorker - {0} folders in Listview", foldersTotalCount); foreach (string folderPath in folderPaths) { ExportStatus status = null; if (!string.IsNullOrEmpty(folderPath)) { FolderItem folderItem = this.mReportServerReader.GetFolder(folderPath); if (folderItem != null) { // Path to where to export folder on disk string saveFilePath = exportPath + SSRSUtil.GetServerPathToPhysicalPath(folderPath); this.mLogger.Debug("ExportItemsWorker - Got save file path of '{0}' for folder item path '{1}'", saveFilePath, folderPath); status = this.mFolderExporter.SaveItem(folderItem, saveFilePath, true); this.mLogger.Debug("ExportItemsWorker - FolderItem.Success = {0}; FromPath = {1}; ToPath = {2}", status.Success, status.FromPath, status.ToPath); // If the save to the temporary path was successful, add folder to the ZipBundler if (status.Success) { this.mZipBundler.AddItem( "Folders", status.ToPath, status.FromPath, true); ++foldersExportedCounter; } } else { this.mLogger.Warn("ExportItemsWorker - FolderItem for path '{0}' returned NULL.", folderPath); } } // Always report progress, even if a ListViewItem has an empty path and even if the item isn't retrieved by ReportServerReader. // This will keep the progress bar value from suddenly jumping up several values. if (worker != null) { worker.ReportProgress(((++progressCounter * 100) / totalItems), status); } else { this.mLogger.Warn("ExportItemsWorker - worker is NULL."); } } // Export data sources var dataSourcePaths = from lv in lvItems where lv.Group.Name == "dataSourcesGroup" && lv.Checked == true select(string) lv.Tag; dataSourcesTotalCount = dataSourcePaths.Count(); this.mLogger.Debug("ExportItemsWorker - {0} data sources in Listview", dataSourcesTotalCount); foreach (string dataSourcePath in dataSourcePaths) { ExportStatus status = null; if (!string.IsNullOrEmpty(dataSourcePath)) { DataSourceItem dataSourceItem = this.mReportServerReader.GetDataSource(dataSourcePath); if (dataSourceItem != null) { // Path to where to export data source on disk string saveFilePath = exportPath + SSRSUtil.GetServerPathToPhysicalPath(dataSourcePath, "json"); this.mLogger.Debug("ExportItemsWorker - Got save file path of '{0}' for data source item path '{1}'", saveFilePath, dataSourcePath); status = this.mDataSourceExporter.SaveItem(dataSourceItem, saveFilePath, true); this.mLogger.Debug("ExportItemsWorker - DataSourceItem.Success = {0}; FromPath = {1}; ToPath = {2}", status.Success, status.FromPath, status.ToPath); // If the save to the temporary path was successful, add file to the ZipBundler if (status.Success) { this.mZipBundler.AddItem( "DataSources", status.ToPath, status.FromPath, false); ++dataSourcesExportedCounter; } } else { this.mLogger.Warn("ExportItemsWorker - DataSourceItem for path '{0}' returned NULL.", dataSourcePath); } } // Always report progress, even if a ListViewItem has an empty path and even if the item isn't retrieved by ReportServerReader. // This will keep the progress bar value from suddenly jumping up several values. if (worker != null) { worker.ReportProgress(((++progressCounter * 100) / totalItems), status); } else { this.mLogger.Warn("ExportItemsWorker - worker is NULL."); } } // Export reports var reportPaths = from lv in lvItems where lv.Group.Name == "reportsGroup" && lv.Checked == true select(string) lv.Tag; reportsTotalCount = reportPaths.Count(); this.mLogger.Debug("ExportItemsWorker - {0} reports in Listview", reportsTotalCount); foreach (string reportPath in reportPaths) { ExportStatus status = null; if (!string.IsNullOrEmpty(reportPath)) { ReportItem reportItem = this.mReportServerReader.GetReport(reportPath); if (reportItem != null) { // Path to where to export report on disk string saveFilePath = exportPath + SSRSUtil.GetServerPathToPhysicalPath(reportPath, "rdl"); this.mLogger.Debug("ExportItemsWorker - Got save file path of '{0}' for report item path '{1}'", saveFilePath, reportPath); status = this.mReportExporter.SaveItem(reportItem, saveFilePath, true); this.mLogger.Debug("ExportItemsWorker - ReportItem.Success = {0}; FromPath = {1}; ToPath = {2}", status.Success, status.FromPath, status.ToPath); // If the save to the temporary path was successful, add file to the ZipBundler if (status.Success) { this.mZipBundler.AddItem( "Reports", status.ToPath, status.FromPath, false); ++reportsExportedCounter; } } else { this.mLogger.Warn("ExportItemsWorker - ReportItem for path '{0}' returned NULL.", reportPath); } } // Always report progress, even if a ListViewItem has an empty path and even if the item isn't retrieved by ReportServerReader. // This will keep the progress bar value from suddenly jumping up several values. if (worker != null) { worker.ReportProgress(((++progressCounter * 100) / totalItems), status); } else { this.mLogger.Warn("ExportItemsWorker - worker is NULL."); } } // Stop stopwatch and get how long it took for the export to complete successfully watch.Stop(); double averageItem = watch.Elapsed.TotalSeconds / progressCounter; string result = string.Format("{0}/{1} folders, {2}/{3} data sources, {4}/{5} reports exported in {6}h {7}m {8}s (@ {9:0.00} items/s)", foldersExportedCounter, foldersTotalCount, dataSourcesExportedCounter, dataSourcesTotalCount, reportsExportedCounter, reportsTotalCount, watch.Elapsed.Hours, watch.Elapsed.Minutes, watch.Elapsed.Seconds, averageItem); this.mLogger.Info("ExportItemsWorker - {0}", result); e.Result = result; }