ExecuteReport.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2007
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // *
  9. // * ExecuteReport.sln
  10. // *
  11. // * Copyright (C) 2007 Cognos ULC, an IBM Company. All rights reserved.
  12. // * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. // *
  14. // * Description: Executes a report.
  15. using System;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. using System.Web.Services.Protocols;
  19. using SamplesCommon;
  20. using cognosdotnet_10_2;
  21. namespace ExecuteReport
  22. {
  23. /// <summary>
  24. /// Summary description for Class1.
  25. /// </summary>
  26. class ExecuteReport
  27. {
  28. /// <summary>
  29. /// The main entry point for the application.
  30. /// </summary>
  31. ///
  32. public ExecuteReport(){}
  33. [STAThread]
  34. static void Main(string[] args)
  35. {
  36. string cBIUrl = "";
  37. contentManagerService1 cBICMS = null;
  38. SamplesConnect connectDlg = new SamplesConnect();
  39. ExecuteReportDlg executeReportDlgObject = new ExecuteReportDlg();
  40. if (args.GetLength(0) == 0 )
  41. {
  42. // GUI mode
  43. connectDlg.ShowDialog();
  44. if (connectDlg.IsConnectedToCBI() == true)
  45. {
  46. cBICMS = connectDlg.CBICMS;
  47. cBIUrl = connectDlg.CBIURL;
  48. executeReportDlgObject.setConnection(connectDlg, cBIUrl);
  49. executeReportDlgObject.setReportList(BaseClassWrapper.buildReportQueryList(cBICMS));
  50. executeReportDlgObject.setSelectedReportIndex(0);
  51. executeReportDlgObject.ShowDialog();
  52. }
  53. }
  54. }
  55. public string doExecuteReport(SamplesConnect cBIConnection, string reportPath)
  56. {
  57. if (cBIConnection == null)
  58. {
  59. return null;
  60. }
  61. string html = "";
  62. string ERR_MESG = "run() failed to return a valid report in this format";
  63. cognosdotnet_10_2.asynchReply executeReportResponse = null;
  64. option[] arrRunOpts = new option[4];
  65. // sn_dg_prm_smpl_runreport_P1_start_0
  66. parameterValue[] arrParm = new parameterValue[] {};
  67. // sn_dg_prm_smpl_runreport_P1_end_0
  68. // sn_dg_prm_smpl_runreport_P3_start_0
  69. runOptionBoolean blnPromptOption = new runOptionBoolean();
  70. runOptionStringArray outputFormat = new runOptionStringArray();
  71. asynchOptionInt primaryWait = new asynchOptionInt(); // primary wait threshold
  72. string[] strarrFmt = new string[1];
  73. runOptionBoolean blnSaveOption = new runOptionBoolean();
  74. // Specify do not save the output
  75. blnSaveOption.name = runOptionEnum.saveOutput;
  76. blnSaveOption.value = false;
  77. // execute the report in HTML format
  78. strarrFmt[0] = "HTML";
  79. outputFormat.name = runOptionEnum.outputFormat;
  80. outputFormat.value = strarrFmt;
  81. // Specify do not prompt for parameters (being passed)
  82. blnPromptOption.name = runOptionEnum.prompt;
  83. blnPromptOption.value = false;
  84. // set the primary wait threshold to 0 seconds - wait indefinitely
  85. primaryWait.name = asynchOptionEnum.primaryWaitThreshold;
  86. primaryWait.value = 0;
  87. // fill the array with the run options
  88. arrRunOpts[0] = blnPromptOption;
  89. arrRunOpts[1] = outputFormat;
  90. arrRunOpts[2] = primaryWait;
  91. arrRunOpts[3] = blnSaveOption;
  92. // sn_dg_prm_smpl_runreport_P3_end_0
  93. searchPathSingleObject cmReportPath = new searchPathSingleObject();
  94. cmReportPath.Value = reportPath;
  95. // execute the report
  96. // sn_dg_sdk_method_reportService_getOutput_start_0
  97. // sn_dg_sdk_method_reportService_run_start_0
  98. // sn_dg_prm_smpl_runreport_P4_start_0
  99. executeReportResponse = cBIConnection.CBIRS.run(cmReportPath, arrParm, arrRunOpts);
  100. // sn_dg_sdk_method_reportService_run_end_0
  101. // If response is not immediately complete, call wait until complete
  102. if (!executeReportResponse.status.Equals(asynchReplyStatusEnum.complete))
  103. {
  104. // sn_dg_sdk_method_reportService_getOutput_end_0
  105. while (!executeReportResponse.status.Equals(asynchReplyStatusEnum.complete))
  106. {
  107. //before calling wait, double check that it is okay
  108. if (!hasSecondaryRequest(executeReportResponse, "wait"))
  109. {
  110. return ERR_MESG;
  111. }
  112. executeReportResponse =
  113. cBIConnection.CBIRS.wait(
  114. executeReportResponse.primaryRequest,
  115. new parameterValue[] {},
  116. new option[] {});
  117. }
  118. //After calling wait() it is necessary to check to make sure
  119. //the output is ready before retrieving it
  120. // sn_dg_sdk_method_reportService_getOutput_start_1
  121. if (outputIsReady(executeReportResponse))
  122. {
  123. executeReportResponse =
  124. cBIConnection.CBIRS.getOutput(
  125. executeReportResponse.primaryRequest,
  126. new parameterValue[] {},
  127. new option[] {});
  128. }
  129. // sn_dg_sdk_method_reportService_getOutput_end_1
  130. // sn_dg_prm_smpl_runreport_P4_end_0
  131. else
  132. {
  133. return ERR_MESG;
  134. }
  135. }
  136. html = getOutputPage(executeReportResponse);
  137. baseClass[] bcOutput;
  138. searchPathMultipleObject outputPath = new searchPathMultipleObject();
  139. outputPath.Value = "~~/output";
  140. bcOutput = cBIConnection.CBICMS.query(outputPath, new propEnum[] { propEnum.searchPath }, new sort[] {}, new queryOptions());
  141. if ((bcOutput != null) && (bcOutput.GetLength(0)> 0) )
  142. {
  143. CommonFunctions cf = new CommonFunctions();
  144. html = cf.setupGraphics(cBIConnection.CBICMS, html);
  145. }
  146. return html;
  147. }
  148. public bool hasSecondaryRequest(asynchReply response, string secondaryRequest)
  149. {
  150. asynchSecondaryRequest[] secondaryRequests =
  151. response.secondaryRequests;
  152. for (int i = 0; i < secondaryRequests.Length; i++)
  153. {
  154. if (secondaryRequests[i].name.CompareTo(secondaryRequest)
  155. == 0)
  156. {
  157. return true;
  158. }
  159. }
  160. return false;
  161. }
  162. public bool outputIsReady(asynchReply response)
  163. {
  164. for (int i = 0; i < response.details.Length; i++)
  165. {
  166. if ((response.details[i] is asynchDetailReportStatus)
  167. && (((asynchDetailReportStatus)response.details[i]).status == asynchDetailReportStatusEnum.responseReady)
  168. && (hasSecondaryRequest(response, "getOutput")))
  169. {
  170. return true;
  171. }
  172. }
  173. return false;
  174. }
  175. public string getOutputPage(asynchReply executeReportResponse)
  176. {
  177. // sn_dg_sdk_method_reportService_getOutput_start_2
  178. asynchDetailReportOutput reportOutput = null;
  179. for (int i = 0; i < executeReportResponse.details.Length; i++)
  180. {
  181. if (executeReportResponse.details[i] is asynchDetailReportOutput)
  182. {
  183. reportOutput =
  184. (asynchDetailReportOutput)executeReportResponse.details[i];
  185. break;
  186. }
  187. }
  188. // sn_dg_sdk_method_reportService_getOutput_end_2
  189. //text based output is split into pages -- return the current page
  190. return reportOutput.outputPages[0].ToString();
  191. }
  192. }
  193. }