/// <summary> /// Adds a new report to the report server database. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the folder.</param> /// <param name="param[3]">The full path name of the RDL.</param> /// <param name="param[4]">The name of the new report.</param> /// <param name="param[5]">The value of a property for a report.</param> /// <returns>True for successful; False for otherwise</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string folderPath = (string)param[2]; string rdlPath = (string)param[3]; string reportName = (string)param[4]; string reportDescription = (string)param[5]; Byte[] definition; // Read the RDL file and convert to byte array using (FileStream stream = File.OpenRead(rdlPath)) { definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); } //stream.Close(); ReportingService rs = host.Proxy(server, virtualRoot); // Create properties. Property[] props = null; Property descriptionProp = new Property(); descriptionProp.Name = "Description"; descriptionProp.Value = reportDescription; const string InternalReport = @"SubReport_"; // Hide the internal sub-report. if (reportName.Length >= InternalReport.Length && string.Compare(reportName.Substring(0, InternalReport.Length), InternalReport, true) == 0) { // Hide internal view report. Property hideProp = new Property(); hideProp.Name = "Hidden"; hideProp.Value = "true"; props = new Property[2]; props[0] = descriptionProp; props[1] = hideProp; } else { props = new Property[1]; props[0] = descriptionProp; } // Upload the report rs.CreateReport(reportName, folderPath, true, definition, props); return(true); }
/// <summary> /// Gets a list of children of a specified folder. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the parent folder. </param> /// <param name="param[3]">Whether the search is recursive</param> /// <returns>An array of CatalogItem[] objects. If no children exist, this /// method returns an empty CatalogItem object.</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string parentPath = (string)param[2]; bool recur = (bool)param[3]; ReportingService rs = host.Proxy(server, virtualRoot); CatalogItem[] items = rs.ListChildren(parentPath, recur); return(items); }
/// <summary> /// Determines if a folder already exists. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the folder.</param> /// <returns>True if folder exists; False for otherwise</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string folderPath = (string)param[2]; bool folderExists = false; ReportingService rs = host.Proxy(server, virtualRoot); ItemTypeEnum itemType = rs.GetItemType(folderPath); if (itemType == ItemTypeEnum.Folder) { folderExists = true; } return(folderExists); }
/// <summary> /// Creates a new data source in the report server database. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the parent folder that contains /// the data source.</param> /// <param name="param[3]">The name of the data source.</param> /// <param name="param[4]">The value of a property in a data source.</param> /// <param name="param[5]">The database has the Reporting Services.</param> /// <param name="param[6]">The name of the server that has the database.</param> /// <param name="param[7]">The user name that the report server uses /// to connect to a data source.</param> /// <param name="param[8]">The password that the report server uses to connect to /// a data source.</param> /// <param name="param[9]">A Boolean expression that indicates whether an existing /// data source with the same name in the location specified should be overwritten.</param> /// <returns>True for successful; False for otherwise</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string parentPath = (string)param[2]; string dataSourceName = (string)param[3]; string dsDescription = (string)param[4]; string reportDB = (string)param[5]; string reportHost = (string)param[6]; string reportUser = (string)param[7]; string reportPassword = (string)param[8]; bool overwrite = (bool)param[9]; ReportingService rs = host.Proxy(server, virtualRoot); Property setProp = new Property(); setProp.Name = "Description"; setProp.Value = dsDescription; Property[] props = new Property[1]; props[0] = setProp; // Define the data source definition. DataSourceDefinition definition = new DataSourceDefinition(); definition.CredentialRetrieval = CredentialRetrievalEnum.Store; definition.ConnectString = "data source=" + reportHost + ";initial catalog=" + reportDB; definition.Enabled = true; definition.EnabledSpecified = true; definition.Extension = "SQL"; definition.UserName = reportUser; definition.Password = reportPassword; definition.Prompt = null; definition.WindowsCredentials = true; rs.CreateDataSource(dataSourceName, parentPath, overwrite, definition, props); return(true); }
/// <summary> /// Adds a folder to the report server database. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the parent folder to which to add /// the new folder. </param> /// <param name="param[3]">The name of the new folder. </param> /// <param name="param[4]">The value of a property for a folder.</param> /// <returns>True for successful; False for otherwise</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string parentPath = (string)param[2]; string folderName = (string)param[3]; string folderDescription = (string)param[4]; ReportingService rs = host.Proxy(server, virtualRoot); Property setProp = new Property(); setProp.Name = "Description"; setProp.Value = folderDescription; Property[] props = new Property[1]; props[0] = setProp; rs.CreateFolder(folderName, parentPath, props); return(true); }
/// <summary> /// Gets a list of children of a specified folder. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the parent folder. </param> /// <returns>True if data source exists; false if doesn't.</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string parentPath = (string)param[2]; ReportingService rs = host.Proxy(server, virtualRoot); CatalogItem[] items = rs.ListChildren(parentPath, false); bool exists = false; foreach (CatalogItem ci in items) { if (ci.Type == ItemTypeEnum.DataSource) { exists = true; } } return(exists); }
/// <summary> /// Determines whether the user has the requested permissions. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The item in the ReportServer database that the user /// permissions are associated with.</param> /// <param name="param[3]">The required permissions in question.</param> /// <returns>True is has requested permissions; False if doesn't</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string reportItem = (string)param[2]; string[] requiredPermissions = (string[])param[3]; String[] grantedPermissions; ReportingService proxy = host.Proxy(server, virtualRoot); // GetPermissions returns a string array containing a list of user // permissions that are associated with a particular item in the // Reporting Server database. The required input parameter is a // string representing the name of the item. grantedPermissions = proxy.GetPermissions(reportItem); int i = 0; bool hasPermissions = false; foreach (string requiredPerm in requiredPermissions) { foreach (string grantedPerm in grantedPermissions) { if (grantedPerm.ToLower() == requiredPerm.ToLower()) { i++; break; } } if (i == requiredPermissions.Length) { hasPermissions = true; break; } } return(hasPermissions); }
/// <summary> /// Adds a new report to the report server database. /// </summary> /// <param name="host">The IProxyFactory that the algorithm or 'visitor' is executed on.</param> /// <param name="param[0]">The name of the server that has Reporting Service.</param> /// <param name="param[1]">The virtual directory in the server.</param> /// <param name="param[2]">The full path name of the folder.</param> /// <param name="param[3]">The full path name of the RDL.</param> /// <param name="param[4]">The name of the new report.</param> /// <param name="param[5]">The value of a property for a report.</param> /// <returns>True for successful; False for otherwise</returns> public object Execute(IProxyFactory host, params object[] param) { string server = (string)param[0]; string virtualRoot = (string)param[1]; string folderPath = (string)param[2]; string rdlPath = (string)param[3]; string reportName = (string)param[4]; string reportDescription = (string)param[5]; Byte[] definition; // Read the RDL file and convert to byte array using (FileStream stream = File.OpenRead(rdlPath)) { definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); } //stream.Close(); ReportingService rs = host.Proxy(server, virtualRoot); Property setProp = new Property(); setProp.Name = "Description"; setProp.Value = reportDescription; Property[] props = new Property[1]; props[0] = setProp; // Upload the report rs.CreateReport(reportName, folderPath, true, definition, props); return(true); }