protected override DTSExecResult ExecuteCore(ITaskExecuteContext context) { // Concatenate Querystring var reportPath = HttpUtility.UrlEncode(ReportPath.EnsureStartsWith("/")); var builder = new StringBuilder(reportPath); foreach (var arg in Arguments) { string strValue = arg.Value; //Get the actual value if (arg.ValueType == ReportArgumentValueType.Variable) { strValue = context.Variables.GetValue(arg.Value)?.ToString(); } if (strValue == null) { builder.AppendFormat("&{0}:isnull=true", HttpUtility.UrlEncode(arg.Name)); } else { builder.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(arg.Name), HttpUtility.UrlEncode(strValue)); } } ; builder.AppendFormat("&rs:Command=Render&rs:Format={0}", ReportFormat); //Get the connection var cm = context.Connections.GetConnection(ServerConnection); //Create a copy of the connection because we're going to change the URL var conn = new HttpClientConnection(cm.AcquireConnection(context.Transaction)).Clone(); if (conn == null) { throw new Exception("Unable to acquire connection."); } // Configure Full Report Url //Format: <serverUrl>?/<reportPath><parameters><options> var uri = new UriBuilder(conn.ServerURL) { Query = builder.ToString() }; conn.ServerURL = uri.Uri.ToString(); // Generate Report context.Events.LogInformation(b => b.Message("Generating report: {0}", conn.ServerURL)); try { var data = conn.DownloadData(); if (!String.IsNullOrWhiteSpace(Content)) { context.Variables.SetValue(Content, data); } context.Events.LogInformation(b => b.Message("Report generated with size {1}: {0}", conn.ServerURL, data?.Length)); } catch (Exception e) { //Handle some common exceptions throw HandleCommonExceptions(e); }; return(DTSExecResult.Success); }
/// <summary>Executes the task.</summary> /// <param name="context">The context.</param> /// <returns>The results.</returns> /// <remarks> /// The method is wrapped in an exception handler to prevent unhandled exceptions from boiling up to the runtime. /// </remarks> protected abstract DTSExecResult ExecuteCore(ITaskExecuteContext context);