0

Do you have any idea how to achieve the follow? I would like to do a comparison between what is currently stored in the TFS and the live version of SSRS reports, SSIS packages, SQL stored procedures/table definitions....

It could look like that for SSRS reports: 1. Extract definition of the report 2. Add this to TFS 3. Run a comparison between the previous and the current version of the report. 4. Send/store the report with differences

How can I achieve that automatically, I was thinking about using TFS API, but not sure where to start.

Thank you for your help, Rafal

dobrzak
  • 19
  • 3

1 Answers1

0

There is a way through ReportExecutionService Class to generate reports using the TFS API and SSRS.

Provided that a web service reference was added to the project already, this will generate a file with the given parameters. Here the start and end dates are provided as parameters and the report is generated using the Render() method. Source Link

private void GenerateReport()
  {
    ReportExecutionService rs = new ReportExecutionService();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rs.Url = "http://<TFS server name>/reportserver/ReportExecution2005.asmx";

   // Render arguments
   byte[] result = null;
   tring reportPath = @"<SSRS report path>";
   string format = "PDF";
   string historyID = null;
   string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

   // Prepare report parameter.
    ParameterValue[] parameters = new ParameterValue[2];
    parameters[0] = new ParameterValue();
    parameters[0].Name = "StartDateParam";
    parameters[0].Value = "2016-05-01 00:00:00";
    parameters[1] = new ParameterValue();
    parameters[1].Name = "EndDateParam";
    parameters[1].Value = "2016-05-30 00:00:00";
    parameters[2] = new ParameterValue();
    parameters[2].Name = "AreaParam";
    parameters[2].Value = "[Work Item].[Area Hierarchy].[All]";
    parameters[3] = new ParameterValue();
    parameters[3].Name = "WorkItemTypeParam";
    parameters[3].Value = "[Work Item].[System_WorkItemType].&[Task]";
    parameters[4] = new ParameterValue();
    parameters[4].Name = "StateParam";
    parameters[4].Value = "[Work Item].[System_State].&[Active]";
    parameters[5] = new ParameterValue();
    parameters[5].Name = "TrendLineParam";
    parameters[5].Value = "both";

   DataSourceCredentials[] credentials = null;
    string showHideToggle = null;
    string encoding;
    string mimeType;
    string extension;
    Warning[] warnings = null;
    ParameterValue[] reportHistoryParameters = null;
    string[] streamIDs = null;

   ExecutionInfo execInfo = new ExecutionInfo();
    ExecutionHeader execHeader = new ExecutionHeader();

   rs.ExecutionHeaderValue = execHeader;

   execInfo = rs.LoadReport(reportPath, historyID);

   var parameters_ = rs.GetExecutionInfo().Parameters;

  rs.SetExecutionParameters(parameters, "en-us"); 
    String SessionId = rs.ExecutionHeaderValue.ExecutionID;

   Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);

   try
    {
        result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

  execInfo = rs.GetExecutionInfo();

   Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);

   }
    catch (SoapException e)
   {
        Console.WriteLine(e.Detail.OuterXml);
   }
   // Write the contents of the report to an MHTML file.
   try
   {
       FileStream stream = File.Create("report.pdf", result.Length);
        Console.WriteLine("File created.");
        stream.Write(result, 0, result.Length);
        Console.WriteLine("Result written to the file.");
        stream.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }

}

After the report generated, you just need to check them into TFS server. Then you just need to use Difference.DiffFiles method which compares two files using the internal diff engine, and return the linked list of DiffSegments. More details, please refer this MSDN blog.

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thank you Patrick for your answer, but it is not for I was asking for. I want to compare automatically the source of the report (.rdl file) stored on the SSRS server with what is currently checked in in the TFS. – dobrzak Jun 01 '16 at 12:47
  • Why you just want to compare two files? For your situation, there is a diff window in VS to clearly see the difference between two files or two versions of the same file. https://www.visualstudio.com/en-us/docs/tfvc/compare-files About how to diff files using TFS API, please refer this blog: https://blogs.msdn.microsoft.com/mohamedg/2009/03/08/how-to-diff-files-using-tfs-apis/ – PatrickLu-MSFT Jun 03 '16 at 11:08
  • Because I would like to schedule that on weekly/monthly basis to check if what is in SSRS/SSIS/SQL is the same as in TFS and if not investigate that. There are few people working on different things and they not always follow the process correctly. – dobrzak Jun 03 '16 at 15:33