CancelReport.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // *
  9. // * Cancel.sln
  10. // *
  11. // * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. // *
  14. // * Description: Cancels a running report.
  15. using System;
  16. using System.Windows.Forms;
  17. using System.Web.Services.Protocols;
  18. using SamplesCommon;
  19. using cognosdotnet_10_2;
  20. namespace CancelReport
  21. {
  22. class CancelReport
  23. {
  24. public CancelReport(){}
  25. static void Main(string[] args)
  26. {
  27. string cBIUrl = "";
  28. reportService1 cBIRS = null;
  29. contentManagerService1 cBICMS = null;
  30. SamplesConnect connectDlg = new SamplesConnect();
  31. CancelReportDlg cancelReportDlgObject = new CancelReportDlg();
  32. if (args.GetLength(0) == 0 )
  33. {
  34. // GUI mode
  35. connectDlg.ShowDialog();
  36. if (connectDlg.IsConnectedToCBI() == true)
  37. {
  38. cBIRS = connectDlg.CBIRS;
  39. cBICMS = connectDlg.CBICMS;
  40. cBIUrl = connectDlg.CBIURL;
  41. cancelReportDlgObject.setConnection(cBIRS, cBIUrl);
  42. cancelReportDlgObject.setReportList(BaseClassWrapper.buildReportQueryList(cBICMS));
  43. cancelReportDlgObject.setSelectedReportIndex(0);
  44. cancelReportDlgObject.ShowDialog();
  45. }
  46. }
  47. }
  48. public string doCancelReport(reportService1 cBIRS, string reportPath, ref string resultMessage)
  49. {
  50. if (cBIRS == null)
  51. {
  52. return "the Server connection provided is invalid.";
  53. }
  54. asynchReply runResponse = null;
  55. option[] arrReportRunOpts = new option[4];
  56. asynchOptionInt primaryWait = new asynchOptionInt(); // primary wait threshold
  57. asynchOptionBoolean includeReq = new asynchOptionBoolean();
  58. runOptionStringArray formatList = new runOptionStringArray();
  59. runOptionBoolean blnOutputRunOpts = new runOptionBoolean();
  60. runOptionBoolean continueConversation = new runOptionBoolean();
  61. parameterValue[] paramValueArray = new parameterValue[] {};
  62. // Specify to save the output
  63. // When Cancel is invoked, the output will not be saved.
  64. blnOutputRunOpts.name = runOptionEnum.saveOutput;
  65. blnOutputRunOpts.value = false;
  66. // execute the report in HTML format
  67. string[] format = new string[1];
  68. format[0] = "HTML";
  69. formatList.name = runOptionEnum.outputFormat;
  70. formatList.value = format;
  71. continueConversation.name = runOptionEnum.continueConversation;
  72. continueConversation.value = true;
  73. // set the primary wait threshold to 1 second, so we can call cancel
  74. primaryWait.name = asynchOptionEnum.primaryWaitThreshold;
  75. primaryWait.value = 1;
  76. // ensure the response always includes the primary request
  77. includeReq.name = asynchOptionEnum.alwaysIncludePrimaryRequest;
  78. includeReq.value = true;
  79. // fill the array with the run options
  80. arrReportRunOpts[0] = blnOutputRunOpts;
  81. arrReportRunOpts[1] = formatList;
  82. arrReportRunOpts[2] = primaryWait;
  83. arrReportRunOpts[3] = includeReq;
  84. searchPathSingleObject reportPathSO = new searchPathSingleObject();
  85. reportPathSO.Value = reportPath;
  86. // set the continue conversation as a run options
  87. // execute the report
  88. // sn_dg_sdk_method_reportService_cancel_start_0
  89. runResponse = cBIRS.run(reportPathSO, paramValueArray, arrReportRunOpts);
  90. // sn_dg_sdk_method_reportService_cancel_end_0
  91. //Check to see if we can cancel
  92. if (hasSecondaryRequest(runResponse, "cancel"))
  93. {
  94. //Use the cancel method to stop execution and saving of report.
  95. // sn_dg_sdk_method_reportService_cancel_start_1
  96. cBIRS.cancel(runResponse.primaryRequest);
  97. // sn_dg_sdk_method_reportService_cancel_end_1
  98. resultMessage += "The report has been successfully cancelled.";
  99. }
  100. else
  101. {
  102. resultMessage += "The report ran too quickly to be cancelled.";
  103. }
  104. return resultMessage;
  105. }
  106. public bool hasSecondaryRequest(asynchReply response, string secondaryRequest)
  107. {
  108. asynchSecondaryRequest[] secondaryRequests =
  109. response.secondaryRequests;
  110. for (int i = 0; i < secondaryRequests.Length; i++)
  111. {
  112. if (secondaryRequests[i].name.CompareTo(secondaryRequest)
  113. == 0)
  114. {
  115. return true;
  116. }
  117. }
  118. return false;
  119. }
  120. }
  121. }