/// <summary> /// Helper method to download XSD files from DST. /// </summary> /// <param name="surveyId">Id of survey, i.e. 1153000</param> /// <param name="periodBegin">Survey begin time, i.e. DateTime(2019, 08, 01)</param> /// <param name="periodEnd">Survey end time, i.e. DateTime(2019, 08, 31)</param> private static async Task DownloadXsdFile(string surveyId, DateTime periodBegin, DateTime periodEnd) { // Create new WCF client var client = new ReportingServiceClient(); // Path for XSD file, look in the XSD folder of the binary compiled file var xsdPath = Path.Combine(Directory.GetCurrentDirectory(), "XSD", $"{surveyId}-{periodBegin.ToShortDateString()}-{periodEnd.ToShortDateString()}.xsd"); // Folder path of XSD file var xsdFolderPath = Path.GetDirectoryName(xsdPath); // Verify folder exists, before attempting to create file if (!Directory.Exists(xsdFolderPath)) { Directory.CreateDirectory(xsdFolderPath); } // Create new file or re-use existing using var writer = File.CreateText(xsdPath); // Download XSD from DST var xsdMarkup = await client.GetSurveyDefinitionAsync(new GetSurveyDefinitionRequest(surveyId, periodBegin, periodEnd)); // Print it in console (just for help) Console.WriteLine(xsdMarkup.GetSurveyDefinitionResult); // Write the actual content to the XSD file writer.Write(xsdMarkup.GetSurveyDefinitionResult); }
public void Dispose() { if (cs != null) { try { cs.Close(); cs = null; } catch { } } }
public GetAllLicenseActivationsResult GetAllServiceLicenseActivations(string url, string token, EncryptionInfo encryptionInfo, KeyPair serviceKeys) { ReportingServiceClient client = ReportingClientCreator(url); string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo); string encryptedResult = client.GetAllLicenseActivations(encryptedToken); string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys); GetAllLicenseActivationsResult result = _objectSerializationProvider.Deserialize <GetAllLicenseActivationsResult>(decryptedResult); return(result); }
public async Task <IActionResult> GeneratePdf() { var client = new ReportingServiceClient(); var fileDef = System.IO.File.ReadAllBytes(_environment.ContentRootPath + "\\Reports\\SampleReport.rdl"); var objects = new[] { new { Id = 1, FullName = "Ahmed 1" }, new { Id = 2, FullName = "Ahmed 2" } }; var ds = new DataSet(); ds.Tables.Add(objects.ToDataTable("DataSet1")); var reportContent = await client.ExportWithDataTablesAsync(fileDef, ds); await client.CloseAsync(); return(File(reportContent.ExportWithDataTablesResult.Content, reportContent.ExportWithDataTablesResult.MimeType, "NewFile.pdf")); }
private ReportingServiceClient Check() { if (cs == null) { cs = new ReportingServiceClient("BasicHttpBinding_IReportingService"); } else if (cs.State != CommunicationState.Opened && cs.State != CommunicationState.Opening) { try { cs.Open(); } catch (Exception ex) { Log(new LogEventArgs(ServiceType.Reporting, "Check", ex.Message, null, ex, null, LogLevel.Warn)); } } return(cs); }
public NDatasource LookupDataSource(string itemPath, ReportingServiceClient srsProxy) { NDatasource nDataSource = null; DataSourceDefinition dataSourceDefinition = srsProxy.GetDataSourceContents(itemPath); if (dataSourceDefinition != null) { string dataSourceName = itemPath.Substring(itemPath.LastIndexOf(@"/", StringComparison.OrdinalIgnoreCase) + 1); // Consume the data source in SQL client to validate that it is the right format // and to get the Server and database... instead of writing custom parse code. SqlConnection sqlConnection = new SqlConnection(dataSourceDefinition.ConnectString); string server = sqlConnection.DataSource; string database = sqlConnection.Database; string providerExtension = dataSourceDefinition.Extension; string userName = string.Empty; string password = string.Empty; bool getCredentialsFromSRSDef = true; try { BOConfiguredDataSource configuredDataSourceDefinition = this.ConfiguredDataSourceCollection[itemPath]; if (configuredDataSourceDefinition != null) { string credentials = Utility.DecryptValue(configuredDataSourceDefinition.Credentials); if ((credentials.IndexOf("uid=", StringComparison.OrdinalIgnoreCase) == 0) && (credentials.IndexOf(";pwd=", StringComparison.OrdinalIgnoreCase) > 0)) { string[] credentialPieces = credentials.Split(new char[] { ';' }); userName = credentialPieces[0].Split(new char[] { '=' })[1]; password = credentialPieces[1].Split(new char[] { '=' })[1]; getCredentialsFromSRSDef = false; } } } catch { // Getting credentails from our application's configured credentials failed, use SRS's information } if (getCredentialsFromSRSDef) { if (dataSourceDefinition.ImpersonateUserSpecified) { userName = dataSourceDefinition.UserName; password = dataSourceDefinition.Password; } } nDataSource = new NDatasource(dataSourceName, itemPath, providerExtension, server, database, userName, password); } return nDataSource; }
/// <summary> /// Build the CatalogItemCollection structure from SRS /// </summary> public NCatalogItemCollection LookupCatalogItems(string itemPath, bool recursive, bool useHttpClient, ReportingServiceClient srsClient) { NCatalogItemCollection catalogItemCollection = new NCatalogItemCollection(); // If no ItemPath is specified, use the Root if (itemPath == null) { itemPath = "/"; } // Retrieve the full list of catalog items from SRS CatalogItem[] unsecureCatalogItems = null; if (srsClient != null) { unsecureCatalogItems = srsClient.ListChildren(itemPath, recursive); } else { if (useHttpClient) { unsecureCatalogItems = this.ReportingServiceClient.ListChildren(itemPath, recursive); } else { unsecureCatalogItems = this.ReportingServiceNonHttpClient.ListChildren(itemPath, recursive); } } // Secure the list List<CatalogItem> secureCatalogList = buildSecureCatalogList(unsecureCatalogItems); foreach (CatalogItem item in secureCatalogList) { NCatalogItem nItem = NCatalogItem.CreateNRCatalogItem(item); // TODO: Still not decided if it's wise to get all the parameters upon login // Supply the parameters /* if (nItem.ItemType.Equals(Constants.CatalogItemTypes.Report)) { try { nItem.ReportParameters = GetReportParameters(nItem.Path, null); } catch { //TODO: Prepare an error display for this //Error retrieving the parameters. nItem.ReportParameters = null; } } */ catalogItemCollection.Add(nItem); } /* // Create a map between SRS folders and Nodes collections in the tree Hashtable folderMapTable = new Hashtable(); if (itemPath == "/") { folderMapTable.Add("", catalogItemCollection); } else { folderMapTable.Add(itemPath, catalogItemCollection); } foreach (CatalogItem item in secureCatalogList) { // Get the path to the current item's folder string folderPath = item.Path.Substring(0, item.Path.LastIndexOf("/", StringComparison.OrdinalIgnoreCase)); // Get the node collection associated with that folder path NCatalogItemCollection nodes = folderMapTable[folderPath] as NCatalogItemCollection; if (nodes != null) { NCatalogItem nci = NCatalogItem.CreateNRCatalogItem(item); nodes.Add(nci); if (nci.ItemType == Constants.CatalogItemTypes.Folder) { if (folderMapTable.ContainsKey(nci.Path)) { throw new InvalidCatalogStructureException("Folder already exists"); } NFolder nf = nci as NFolder; folderMapTable.Add(nf.Path, nf.ChildCatalogItems); } } } */ return catalogItemCollection; }
//TODO: Add the parameter values used in subscriptions public NReportParameterCollection GetReportParameters(string itemPath, ParameterValue[] parameterValueArray, ReportingServiceClient srsClient) { NReportParameterCollection parameters = new NReportParameterCollection(); ReportParameter[] reportParameterArray; if (srsClient != null) { reportParameterArray = srsClient.GetReportParameters(itemPath, null, true, parameterValueArray, null); } else { reportParameterArray = ReportingServiceClient.GetReportParameters(itemPath, null, true, parameterValueArray, null); } foreach (ReportParameter parameter in reportParameterArray) { parameters.Add(new NReportParameter(parameter)); } return parameters; }
/// <summary> /// Gets the Datasource from the SRS. /// </summary> public void GetDataSourceItem(AuthenticatedUserManager user, ReportingServiceClient srsProxy) { string address = Path.Substring(Path.IndexOf('/')); NDatasource datasource = user.CatalogInteractionManager.LookupDataSource(address, srsProxy); if (datasource != null) { DataSourceItem.itemProperties.Clear(); DataSourceItem.ConnectionString = datasource.ConnectionString; DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.Datasource, CatalogConstants.DataSourceLabels.DatasourceLabel, datasource.Name)); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.Database, CatalogConstants.DataSourceLabels.DatabaseLabel, datasource.DatabaseName)); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.Server, CatalogConstants.DataSourceLabels.ServerLabel, datasource.ServerName)); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.Provider, CatalogConstants.DataSourceLabels.ProviderLabel, datasource.Provider)); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.User, CatalogConstants.DataSourceLabels.UserNameLabel, datasource.UserName)); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.Password, CatalogConstants.DataSourceLabels.Password, "")); DataSourceItem.itemProperties.Add(new DataSourceProperty(CatalogConstants.DataSourceProperties.ConfirmPassword, CatalogConstants.DataSourceLabels.ConfirmPassLabel, "")); } else { //Throw an error Error = new Exception(string.Format("No datasource property found in this path {0}.", address)); } }
public ReportingHelper(EventHandler <LogEventArgs> handler = null, EventHandler <ProgressChangeEventArgs> progressChangedHandler = null) : base(handler) { cs = new ReportingServiceClient("BasicHttpBinding_IReportingService"); this._progressChangedHandler = progressChangedHandler; }
/// <summary> /// Gets the catalog items from the SRS. /// </summary> public static CatalogModel GetCatalogItems(AuthenticatedUserManager user, ReportingServiceClient srsProxy) { CatalogModel final = new CatalogModel(); NCatalogItemCollection catalogs = user.CatalogInteractionManager.LookupCatalogItems(null, true, true, srsProxy); List<CatalogModel> models = new List<CatalogModel>(); foreach (NCatalogItem item in catalogs) { models.Add(ToModel(item)); } final.AllItems = models; //Process Child List<CatalogModel> finalCatalog = new List<CatalogModel>(); foreach (var parent in models) { parent.AllItems.Add(parent); if (parent.ItemType.Equals("Folder", StringComparison.OrdinalIgnoreCase)) { foreach (var child in models) { //check parents if (child.Parent.Equals(parent.Path, StringComparison.OrdinalIgnoreCase)) { parent.Children.Add(child); } } if(parent.Parent.Equals("root", StringComparison.OrdinalIgnoreCase)) { finalCatalog.Add(parent); } } } final.Catalogs = finalCatalog; final.SRSProxy = srsProxy; return final; }
private static System.ServiceModel.Channels.Binding GetDefaultBinding() { return(ReportingServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpsBinding_IReportingService)); }
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() { return(ReportingServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpsBinding_IReportingService)); }
public ReportingServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : base(ReportingServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) { this.Endpoint.Name = endpointConfiguration.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
public ReportingServiceClient(EndpointConfiguration endpointConfiguration) : base(ReportingServiceClient.GetBindingForEndpoint(endpointConfiguration), ReportingServiceClient.GetEndpointAddress(endpointConfiguration)) { this.Endpoint.Name = endpointConfiguration.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
public ReportingServiceClient() : base(ReportingServiceClient.GetDefaultBinding(), ReportingServiceClient.GetDefaultEndpointAddress()) { this.Endpoint.Name = EndpointConfiguration.BasicHttpsBinding_IReportingService.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_reportingServiceClient != null) { _reportingServiceClient.Dispose(); _reportingServiceClient = null; } if (_reportingServiceNonHttpClient != null) { _reportingServiceNonHttpClient.Dispose(); _reportingServiceNonHttpClient = null; } if (_executionServiceClient != null) { _executionServiceClient.Dispose(); _executionServiceClient = null; } if (_reportingTargetServiceClient != null) { _reportingTargetServiceClient.Dispose(); _reportingTargetServiceClient = null; } if (_reportingTargetServiceNonHttpClient != null) { _reportingTargetServiceNonHttpClient.Dispose(); _reportingTargetServiceNonHttpClient = null; } if (_reportingSourceServiceClient != null) { _reportingSourceServiceClient.Dispose(); _reportingSourceServiceClient = null; } if (_reportingSourceServiceNonHttpClient != null) { _reportingSourceServiceNonHttpClient.Dispose(); _reportingSourceServiceNonHttpClient = null; } } }
private static SettingsModel InitializeCatalog(AuthenticatedUserManager user, ReportingServiceClient proxy) { SettingsModel model = new SettingsModel(); model.Catalog = new CatalogModel(); model.Catalog = CatalogModel.GetCatalogItems(user, proxy); return model; }
private void checkClientCacheExpired() { if ((_reportingServiceClient != null) && (_reportingServiceClient.AuthCookie != null)) { // Check to see if the cached client connection has expired if (_reportingServiceClient.AuthCookie.Expired) { _reportingServiceClient.Dispose(); _reportingServiceClient = null; _configurationCollection.Clear(); _configurationCollection = null; } } }
/// <summary> /// Gets all of the Report Parameters from the SRS. /// </summary> public void GetReportParameters(AuthenticatedUserManager user, ReportingServiceClient srsClient) { string address = Path.Substring(Path.IndexOf('/')); ReportParameters = user.CatalogInteractionManager.GetReportParameters(address, null, srsClient); }