AddReport.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. * AddReport.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: This code sample demonstrates how to add reports using the
  15. * following methods:
  16. * - validate(search, object, options)
  17. * Use this method to validate reports in the content store.
  18. * - add(search, object, options)
  19. * Use this method to add reports to the content store.
  20. *
  21. */
  22. using System;
  23. using System.IO;
  24. using System.Text;
  25. using System.Threading;
  26. using System.Windows.Forms;
  27. using System.Web.Services.Protocols;
  28. using SamplesCommon;
  29. using cognosdotnet_10_2;
  30. using System.Xml;
  31. namespace AddReport
  32. {
  33. /// <summary>
  34. /// Summary description for AddReport.
  35. /// </summary>
  36. public class AddReport
  37. {
  38. public AddReport(){}
  39. [STAThread]
  40. static void Main(string[] args)
  41. {
  42. string cBIUrl = "";
  43. string accountPath = "";
  44. reportService1 cBIServer = null;
  45. AddReportDlg ardlgObject = new AddReportDlg();
  46. SamplesConnect connectDlg = new SamplesConnect();
  47. if (args.GetLength(0) == 0 )
  48. {
  49. // GUI mode
  50. connectDlg.ShowDialog();
  51. if (connectDlg.IsConnectedToCBI() == true)
  52. {
  53. cBIServer = connectDlg.CBIRS;
  54. cBIUrl = connectDlg.CBIURL;
  55. accountPath = connectDlg.GetAccountPath();
  56. ardlgObject.setConnection(cBIServer, cBIUrl, accountPath);
  57. ardlgObject.CBISS = connectDlg.CBISS;
  58. ardlgObject.ShowDialog();
  59. }
  60. }
  61. }
  62. public bool validateReportSpec(reportService1 cBIRS, reportServiceReportSpecification reportSpec, ref string resultMessage)
  63. {
  64. asynchReply validationResults = null;
  65. if (cBIRS == null)
  66. {
  67. resultMessage = "...the Server connection is invalid.\n";
  68. return false;
  69. }
  70. option[] validateOptions = new option[2];
  71. asynchOptionInt primaryWaitThreshold = new asynchOptionInt();
  72. primaryWaitThreshold.name = asynchOptionEnum.primaryWaitThreshold;
  73. primaryWaitThreshold.value = 0;
  74. validateOptions[0] = primaryWaitThreshold;
  75. asynchOptionInt secondaryWaitThreshold = new asynchOptionInt();
  76. secondaryWaitThreshold.name = asynchOptionEnum.secondaryWaitThreshold;
  77. secondaryWaitThreshold.value = 0;
  78. validateOptions[1] = secondaryWaitThreshold;
  79. // sn_dg_sdk_method_reportService_validateSpecification_start_0
  80. validationResults = cBIRS.validateSpecification(reportSpec, new parameterValue[]{}, validateOptions);
  81. // sn_dg_sdk_method_reportService_validateSpecification_end_0
  82. if (validationResults == null)
  83. {
  84. resultMessage = "...unknown error validating the report.";
  85. return false;
  86. }
  87. bool status = true;
  88. string errresult = "";
  89. string defects = "";
  90. // sn_dg_sdk_method_reportService_validateSpecification_start_1
  91. for (int i = 0; i < validationResults.details.Length; i++)
  92. {
  93. if (validationResults.details[i] is asynchDetailReportValidation)
  94. {
  95. if ( ( (asynchDetailReportValidation) validationResults.details[i]).defects.Value.Length > 0 )
  96. {
  97. defects = ( (asynchDetailReportValidation) validationResults.details[i]).defects.Value;
  98. }
  99. }
  100. }
  101. //Parse the defects xml string to see what type of errors, if any
  102. // sn_dg_sdk_method_reportService_validateSpecification_end_1
  103. XmlDocument vrDocument = new XmlDocument();
  104. vrDocument.LoadXml(defects);
  105. XmlElement root = vrDocument.DocumentElement;
  106. XmlNodeList queryProblems = root.SelectNodes("//queryProblems");
  107. XmlNodeList layoutProblems = root.SelectNodes("//layoutProblems");
  108. for (int i=0; i<queryProblems.Count; i++)
  109. {
  110. XmlNode queryProblemsNode = queryProblems.Item(i);
  111. if (queryProblemsNode.HasChildNodes)
  112. {
  113. errresult += "\nThe following queryProblems were found:\n";
  114. XmlNodeList messageNodes = queryProblemsNode.SelectNodes("//message[@type='xmlStructure']/@title");
  115. for (int j=0; j<messageNodes.Count; j++)
  116. {
  117. XmlNode messageNode = messageNodes.Item(j);
  118. if (messageNode != null)
  119. {
  120. errresult += "\t" + messageNode.Value + "\n";
  121. status = false;
  122. }
  123. }
  124. }
  125. }
  126. for (int i=0; i<layoutProblems.Count; i++)
  127. {
  128. XmlNode layoutProblemsNode = layoutProblems.Item(i);
  129. if (layoutProblemsNode.HasChildNodes)
  130. {
  131. errresult += "\nThe following layoutProblems were found:\n";
  132. XmlNodeList messageNodes = layoutProblemsNode.SelectNodes("//message[@type='layout']/@title");
  133. for (int j=0; j<messageNodes.Count; j++)
  134. {
  135. XmlNode messageNode = messageNodes.Item(j);
  136. if (messageNode != null)
  137. {
  138. errresult += "\t" + messageNode.Value + "\n";
  139. status = false;
  140. }
  141. }
  142. }
  143. }
  144. if (!status)
  145. {
  146. resultMessage = errresult;
  147. return false;
  148. }
  149. resultMessage += "\n...validation succeeded.";
  150. return true;
  151. }
  152. public bool addReportSpec(systemService1 cBISS,
  153. reportService1 cBIRS,
  154. reportServiceReportSpecification reportSpec,
  155. string inputReportName,
  156. string accountPath,
  157. ref string resultMessage)
  158. {
  159. string newReportName = "My Sample Report";
  160. string searchPath = "";
  161. if (accountPath.Length > 0)
  162. {
  163. searchPath = accountPath + "/folder[@name='My Folders']";
  164. }
  165. else
  166. {
  167. searchPath = "CAMID(\"::Anonymous\")/folder[@name='My Folders']";
  168. }
  169. if (cBIRS == null)
  170. {
  171. resultMessage = "...the Server connection is invalid.\n...the specification was not added.";
  172. return false;
  173. }
  174. if (!validateReportSpec(cBIRS, reportSpec, ref resultMessage))
  175. {
  176. resultMessage += "\n...the specification was not added.";
  177. return false;
  178. }
  179. report newReport = new report();
  180. anyTypeProp reportSpecProperty = new anyTypeProp();
  181. reportSpecProperty.value = reportSpec.value.Value.ToString();
  182. multilingualToken[] reportNames = new multilingualToken[1];
  183. reportNames[0] = new multilingualToken();
  184. if (0 != inputReportName.CompareTo(""))
  185. {
  186. newReportName = inputReportName;
  187. }
  188. reportNames[0].value = newReportName;
  189. newReport.name = new multilingualTokenProp();
  190. newReport.name.value = reportNames;
  191. configurationData data = null;
  192. locale[] locales = null;
  193. configurationDataEnum[] config = new configurationDataEnum[1];
  194. config[0] = configurationDataEnum.serverLocale;
  195. // sn_dg_sdk_method_systemService_getConfiguration_start_0
  196. data = cBISS.getConfiguration(config);
  197. locales = data.serverLocale;
  198. if (locales == null)
  199. {
  200. locales[0] = new locale();
  201. locales[0].locale1 = "en";
  202. }
  203. // sn_dg_sdk_method_systemService_getConfiguration_end_0
  204. reportNames[0].locale = locales[0].locale1;
  205. newReport.specification = reportSpecProperty;
  206. addOptions addReportOptions = new addOptions();
  207. addReportOptions.updateAction = updateActionEnum.replace;
  208. searchPathSingleObject searchPathSO = new searchPathSingleObject();
  209. searchPathSO.Value = searchPath;
  210. // sn_dg_sdk_method_reportService_add_start_0
  211. cBIRS.add(searchPathSO, newReport, addReportOptions);
  212. // sn_dg_sdk_method_reportService_add_end_0
  213. resultMessage = "\n...the report \"" + newReport + "\" has been added successfully to \"" + searchPath + "\".";
  214. return true;
  215. }
  216. }
  217. }