CHAPTER 10 MANAGING REPORTS
- EventType: The type of event that triggers the subscription. The valid values are
TimedSubscription and SnapshotUpdated. - MatchData: The data that is associated with the specified EventType parameter.
This parameter is used by an event to match the subscription with an event that
has fired. - Parameters: An array of ParameterValue[] objects that contains a list of
parameters for the report.
In your report scheduler, you’ll create a new method, ScheduleReport, which is called whenever the
user chooses to have a report scheduled. This method sets these parameters to the appropriate values
and then calls the CreateSubscription method of the SSRS 2012 Report Server Web service. Most of the
values are just strings and are straightforward to set.
Check to see whether the user selected a subscription and, if so, whether it is based on a shared
schedule or a snapshot. You’ll use this to set the EventType accordingly. If the user selected Shared
Schedule, then set the variable matchData to the ScheduledlD. If not, set the variable to null to tell SSRS
2012 to trigger it based on a snapshot.
if (sharedSchedules.SelectedValue.ToString() == "SS")
{
eventType = "SnapshotUpdated";
matchData = null;
}
else
{
eventType = "TimedSubscription";
matchData = sharedSchedules.SelectedValue.ToStringQ;
}
To set up a subscription, you have to provide SSRS 2012 with some information about how to deliver
the subscription. To do this, set the delivery extensions through an ExtensionSettings object, which itself
contains ParameterValue objects. ParameterValue objects are essentially name-value pairs, making the
ExtensionSettings object essentially an array of name-value pairs.
To use the ExtensionSettings object, create ParameterValue objects (your name-value pairs) with
your delivery settings and then add them to the ExtensionSettings object. You’ll then call the
CreateSubscription method and pass in the ExtensionSettings object to give SSRS 2012 the subscription
specifics. (See Listing 10-7 for details.)
If the user decides on a subscription based on a shared schedule, and the report accepts parameters,
then you’ll need to collect them from your report viewer interface so that you can set them in the
subscription. These are the values that the report will run with whenever it’s run by the subscription. To
do this, you’ll add code to the PickSchedule form to call the GetParameters form. Because the
GetParameters class returns values in the form of Winforms.ReportParameters, you’ll have to convert
them into an array of ParameterValue objects required by the Report Server Web service. The only other
item you need is the report itself, which you already have as a class-level variable that was set in the
Forms constructor. The final method should look like Listing 10-7; add it to PickSchedule.cs.
Listing 10-7. Report Scheduler
private void ScheduleReport()
{
// See whether the user wants to schedule this versus run it now
if (sharedSchedules.SelectedValue.ToString() != "NS")