Save.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. // * Save.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: Saves a 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 Save
  21. {
  22. /// <summary>
  23. /// Summary description for Class1.
  24. /// </summary>
  25. class Save
  26. {
  27. public Save(){}
  28. static void Main(string[] args)
  29. {
  30. string cBIUrl = "";
  31. contentManagerService1 cBICMS = null;
  32. SamplesConnect connectDlg = new SamplesConnect();
  33. SaveDlg SaveDlgObject = new SaveDlg();
  34. if (args.GetLength(0) == 0 )
  35. {
  36. // GUI mode
  37. connectDlg.ShowDialog();
  38. if (connectDlg.IsConnectedToCBI() == true)
  39. {
  40. cBICMS = connectDlg.CBICMS;
  41. cBIUrl = connectDlg.CBIURL;
  42. SaveDlgObject.setConnection(connectDlg, cBIUrl);
  43. SaveDlgObject.setReportList(BaseClassWrapper.buildReportQueryList(cBICMS));
  44. SaveDlgObject.setSelectedReportIndex(0);
  45. SaveDlgObject.ShowDialog();
  46. }
  47. }
  48. }
  49. /**
  50. * runOption will execute a query/report and save either the report
  51. * or the report output back in the content store, as specified by the
  52. * saveAs parameter.
  53. *
  54. * This method executes a report and saves the output
  55. * or the report spec, as indicated by the saveAs flag
  56. */
  57. public bool runOption(SamplesConnect connection,
  58. string reportPath,
  59. bool saveAs,
  60. string newReportName,
  61. ref string resultMessage)
  62. {
  63. if (connection == null)
  64. {
  65. resultMessage = "The connection provided is invalid.";
  66. return false;
  67. }
  68. runOption[] executerunOptions = new runOption[4];
  69. runOption[] saveAsrunOptions = new runOption[2];
  70. runOptionBoolean roSaveOutput = new runOptionBoolean();
  71. runOptionStringArray roOutputFormat = new runOptionStringArray();
  72. runOptionBoolean roPrompt = new runOptionBoolean();
  73. runOptionBoolean roContinueConv = new runOptionBoolean();
  74. asynchReply rsr = null;
  75. string[] reportFormat = null;
  76. // We may want to save this output, but not by using
  77. // runOptions. That would be for another sample.
  78. roSaveOutput.name = runOptionEnum.saveOutput;
  79. roSaveOutput.value = false;
  80. //What format do we want the report in? HTML.
  81. reportFormat = new string[] { "HTML" };
  82. roOutputFormat.name = runOptionEnum.outputFormat;
  83. roOutputFormat.value = reportFormat;
  84. //Set the report not to prompt as we pass the parameter if any
  85. roPrompt.name = runOptionEnum.prompt;
  86. roPrompt.value = false;
  87. //Remember to set continueConversation to true, so we can invoke
  88. //secondary requests
  89. roContinueConv.name = runOptionEnum.continueConversation;
  90. roContinueConv.value = true;
  91. // Fill the array with the run options.
  92. executerunOptions[0] = roSaveOutput;
  93. executerunOptions[1] = roOutputFormat;
  94. executerunOptions[2] = roPrompt;
  95. executerunOptions[3] = roContinueConv;
  96. parameterValue[] reportParameters = new parameterValue[0];
  97. searchPathSingleObject cmReportPath = new searchPathSingleObject();
  98. cmReportPath.Value = reportPath;
  99. rsr = connection.CBIRS.run(cmReportPath, reportParameters, executerunOptions);
  100. if (rsr == null)
  101. {
  102. resultMessage = "...executing the report failed.";
  103. return false;
  104. }
  105. if (saveAs)
  106. {
  107. int position = reportPath.IndexOf("/report");
  108. string packagePath = reportPath.Substring(0, position);
  109. multilingualToken[] nameTokens = new multilingualToken[2];
  110. nameTokens[0] = new multilingualToken();
  111. nameTokens[0].locale = "en-us";
  112. nameTokens[0].value = newReportName;
  113. runOptionSaveAs roSaveAs = new runOptionSaveAs();
  114. roSaveAs.name = runOptionEnum.saveAs;
  115. roSaveAs.objectClass = reportSaveAsEnum.reportView;
  116. roSaveAs.objectName = nameTokens;
  117. roSaveAs.parentSearchPath = packagePath;
  118. saveAsrunOptions[0] = roSaveAs;
  119. runOptionBoolean roContinueConv2 = new runOptionBoolean();
  120. roContinueConv2.name = runOptionEnum.continueConversation;
  121. roContinueConv2.value = true;
  122. saveAsrunOptions[1] = roContinueConv2;
  123. rsr = connection.CBIRS.deliver(rsr.primaryRequest,new parameterValue[] {}, saveAsrunOptions);
  124. // If it has not yet completed, keep waiting until it is done.
  125. if (rsr.status != asynchReplyStatusEnum.complete)
  126. {
  127. while (rsr.status != asynchReplyStatusEnum.complete)
  128. {
  129. rsr = connection.CBIRS.wait(rsr.primaryRequest, new parameterValue[] {},new option[] {});
  130. }
  131. rsr = connection.CBIRS.getOutput(rsr.primaryRequest,new parameterValue[] {}, new option[] {});
  132. }
  133. resultMessage = "...the 'save as' request completed successfuly.";
  134. }
  135. else
  136. {
  137. option[] saverunOptions = new option[2];
  138. runOptionBoolean bSaveOutput = new runOptionBoolean();
  139. bSaveOutput.name = runOptionEnum.saveOutput;
  140. bSaveOutput.value = true;
  141. saverunOptions[0] = bSaveOutput;
  142. runOptionBoolean roContinueConv2 = new runOptionBoolean();
  143. roContinueConv2.name = runOptionEnum.continueConversation;
  144. roContinueConv2.value = true;
  145. saverunOptions[1] = roContinueConv2;
  146. rsr = connection.CBIRS.deliver(rsr.primaryRequest, new parameterValue[] {}, saverunOptions);
  147. // If it has not yet completed, keep waiting until it is done.
  148. if (rsr.status != asynchReplyStatusEnum.complete)
  149. {
  150. while (rsr.status != asynchReplyStatusEnum.complete)
  151. {
  152. rsr = connection.CBIRS.wait(rsr.primaryRequest,new parameterValue[] {}, new option[] {});
  153. }
  154. rsr = connection.CBIRS.getOutput(rsr.primaryRequest, new parameterValue[] {}, new option[] {});
  155. }
  156. resultMessage = "...the 'save' request completed successfuly.";
  157. }
  158. return true;
  159. }
  160. }
  161. }