public string WriteDataSource(DataSourceItem dataSourceItem) { if (dataSourceItem == null) { throw new ArgumentNullException("dataSourceItem"); } if (!this.mReportRepository.ValidatePath(dataSourceItem.Path)) { throw new InvalidPathException(dataSourceItem.Path); } string name = dataSourceItem.Name; string parentPath = SSRSUtil.GetParentPath(dataSourceItem); if (!this.mOverwrite) { if (this.mReportRepository.ItemExists(dataSourceItem.Path, "DataSource")) { throw new ItemAlreadyExistsException(dataSourceItem.Path); } } return(this.mReportRepository.WriteDataSource(parentPath, dataSourceItem, this.mOverwrite)); }
public string[] WriteReport(ReportItem reportItem) { if (reportItem == null) { throw new ArgumentNullException("reportItem"); } // Verify that the report's path is valid if (!this.mReportRepository.ValidateItemPath(reportItem.Path)) { throw new InvalidPathException(reportItem.Path); } // Get the report's name and path to its parent folder string name = reportItem.Name; string parentPath = SSRSUtil.GetParentPath(reportItem); // Check if a report already exists at the specified path if (!this.mOverwrite) { if (this.mReportRepository.ItemExists(reportItem.Path, "Report")) { throw new ItemAlreadyExistsException(reportItem.Path); } } // Create the report at parentPath and return any warnings return(this.mReportRepository.WriteReport(parentPath, reportItem, this.mOverwrite)); }
public void GetParentPath_NullItem() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>( delegate { SSRSUtil.GetParentPath(null); }); Assert.That(ex.Message, Is.EqualTo("Value cannot be null.\r\nParameter name: item")); }
public void GetParentPath_PathMissingFirstSlash() { ReportServerItem item = new ReportServerItem() { Name = "Sub Folder", Path = "SSRSMigrate/Reports/Sub Folder" }; string expected = "/SSRSMigrate/Reports"; string actual = SSRSUtil.GetParentPath(item); Assert.AreEqual(expected, actual); }
public void GetParentPath_PathIsSlash() { ReportServerItem item = new ReportServerItem() { Name = "Sub Folder", Path = "/" }; string expected = "/"; string actual = SSRSUtil.GetParentPath(item); Assert.AreEqual(expected, actual); }
public void GetParentPath_ParentContainsName() { ReportServerItem item = new ReportServerItem() { Name = "Reports", Path = "/SSRSMigrate/Reports/Reports" }; string expected = "/SSRSMigrate/Reports"; string actual = SSRSUtil.GetParentPath(item); Assert.AreEqual(expected, actual); }
public void GetParentPath_EmptyPath() { ReportServerItem item = new ReportServerItem() { Name = "Sub Folder", Path = "" }; ArgumentException ex = Assert.Throws <ArgumentException>( delegate { SSRSUtil.GetParentPath(item); }); Assert.That(ex.Message, Is.EqualTo("item.Path")); }
public void GetParentPath_NullName() { ReportServerItem item = new ReportServerItem() { Name = null, Path = "/SSRSMigrate/Reports/Sub Folder" }; ArgumentException ex = Assert.Throws <ArgumentException>( delegate { SSRSUtil.GetParentPath(item); }); Assert.That(ex.Message, Is.EqualTo("item.Name")); }
public string[] WriteFolders(FolderItem[] folderItems) { if (folderItems == null) { throw new ArgumentNullException("folderItems"); } List <string> warnings = new List <string>(); for (int i = 0; i < folderItems.Count(); i++) { // Verify that the folder's path is valid if (!this.mReportRepository.ValidatePath(folderItems[i].Path)) { throw new InvalidPathException(folderItems[i].Path); } // Get the folder's name and path to its parent folder string name = folderItems[i].Name; string parentPath = SSRSUtil.GetParentPath(folderItems[i]); // Check if a folder already exists at the specified path if (this.mReportRepository.ItemExists(folderItems[i].Path, "Folder")) { // If allow overwrite is False, throw ItemAlreadyExistsException, otherwise delete the folder if (!this.mOverwrite) { throw new ItemAlreadyExistsException(folderItems[i].Path); } else { //TODO Add tests for ReportServerWriter.WriteFolders where the folder exists and overwrite is True this.mReportRepository.DeleteItem(folderItems[i].Path); } } string warning = this.mReportRepository.CreateFolder(name, parentPath); if (!string.IsNullOrEmpty(warning)) { warnings.Add(warning); } } return(warnings.ToArray()); }
public string[] WriteReports(ReportItem[] reportItems) { if (reportItems == null) { throw new ArgumentNullException("reportItems"); } List <string> warnings = new List <string>(); for (int i = 0; i < reportItems.Count(); i++) { // Verify that the report's path is valid if (!this.mReportRepository.ValidateItemPath(reportItems[i].Path)) { throw new InvalidPathException(reportItems[i].Path); } // Get the report's name and path to its parent folder string name = reportItems[i].Name; string parentPath = SSRSUtil.GetParentPath(reportItems[i]); // Check if a report already exists at the specified path if (!this.mOverwrite) { if (this.mReportRepository.ItemExists(reportItems[i].Path, "Report")) { throw new ItemAlreadyExistsException(reportItems[i].Path); } } string[] reportWarnings = this.mReportRepository.WriteReport(parentPath, reportItems[i], this.mOverwrite); if (reportWarnings != null) { warnings.AddRange(reportWarnings); } } return(warnings.ToArray()); }
public string WriteFolder(FolderItem folderItem) { if (folderItem == null) { throw new ArgumentNullException("folderItem"); } // Verify that the folder's path is valid if (!this.mReportRepository.ValidatePath(folderItem.Path)) { throw new InvalidPathException(folderItem.Path); } //TODO Check folderItem.HasValidProperties and throw exception //if (!folderItem.HasValidProperties) // throw new InvalidItemException(string.Format("The item with ID '{0}' has a null or empty name or path value.", folderItem.ID)); // Get the folder's name and path to its parent folder string name = folderItem.Name; string parentPath = SSRSUtil.GetParentPath(folderItem); // Check if a folder already exists at the specified path if (this.mReportRepository.ItemExists(folderItem.Path, "Folder")) { // If allow overwrite is False, throw ItemAlreadyExistsException, otherwise delete the folder if (!this.mOverwrite) { throw new ItemAlreadyExistsException(folderItem.Path); } else { //TODO Add tests for ReportServerWriter.WriteFolder where the folder exists and overwrite is True this.mReportRepository.DeleteItem(folderItem.Path); } } return(this.mReportRepository.CreateFolder(name, parentPath)); }
public string[] WriteDataSources(DataSourceItem[] dataSourceItems) { if (dataSourceItems == null) { throw new ArgumentNullException("dataSourceItems"); } List <string> warnings = new List <string>(); for (int i = 0; i < dataSourceItems.Count(); i++) { if (!this.mReportRepository.ValidatePath(dataSourceItems[i].Path)) { throw new InvalidPathException(dataSourceItems[i].Path); } string name = dataSourceItems[i].Name; string parentPath = SSRSUtil.GetParentPath(dataSourceItems[i]); if (!this.mOverwrite) { if (this.mReportRepository.ItemExists(dataSourceItems[i].Path, "DataSource")) { throw new ItemAlreadyExistsException(dataSourceItems[i].Path); } } string warning = this.mReportRepository.WriteDataSource(parentPath, dataSourceItems[i], this.mOverwrite); if (!string.IsNullOrEmpty(warning)) { warnings.Add(warning); } } return(warnings.ToArray()); }