ViewReports.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. //
  11. // Description: This code sample demonstrates how to get information about
  12. // report objects using the query method.
  13. //
  14. // Use this method to request objects from Content Manager.
  15. using System;
  16. using System.Text;
  17. using System.Web.Services.Protocols;
  18. using System.Threading;
  19. using System.Windows.Forms;
  20. using SamplesCommon;
  21. using cognosdotnet_10_2;
  22. namespace ViewReports
  23. {
  24. /// <summary>
  25. /// Demonstrate the query() method.
  26. /// </summary>
  27. class ViewReports
  28. {
  29. public ViewReports(){}
  30. static void Main(string[] args)
  31. {
  32. string cBIUrl = "";
  33. contentManagerService1 cBIServer = null;
  34. SamplesConnect connectDlg = new SamplesConnect();
  35. ViewReportsDlg ViewReportsDlgObject = new ViewReportsDlg();
  36. if (args.GetLength(0) == 0 )
  37. {
  38. // GUI mode
  39. connectDlg.ShowDialog();
  40. if (connectDlg.IsConnectedToCBI() == true)
  41. {
  42. cBIServer = connectDlg.CBICMS;
  43. cBIUrl = connectDlg.CBIURL;
  44. ViewReportsDlgObject.setConnection(cBIServer, cBIUrl);
  45. ViewReportsDlgObject.ShowDialog();
  46. }
  47. }
  48. }
  49. public bool doViewReportsAndQueries( contentManagerService1 cBICMS, ref string resultMessage )
  50. {
  51. if (cBICMS == null)
  52. {
  53. resultMessage = "the Server connection provided is invalid.";
  54. return false;
  55. }
  56. propEnum[] props = new propEnum[] { propEnum.searchPath, propEnum.defaultName };
  57. sort[] s = new sort[]{ new sort() };
  58. s[0].order = orderEnum.ascending;
  59. s[0].propName = propEnum.defaultName;
  60. queryOptions qo = new queryOptions();
  61. StringBuilder output = new StringBuilder();
  62. // Look for all of the reports.
  63. output.AppendFormat( "\nReports:\n" );
  64. searchPathMultipleObject reportsPath = new searchPathMultipleObject();
  65. reportsPath.Value = "/content//report";
  66. baseClass[] bc = cBICMS.query( reportsPath, props, s, qo );
  67. if( bc.Length > 0 )
  68. {
  69. foreach( baseClass report_item in bc )
  70. {
  71. output.AppendFormat( " {0}\n", report_item.defaultName.value );
  72. output.AppendFormat( " {0}\n", report_item.searchPath.value );
  73. }
  74. }
  75. else
  76. {
  77. output.Append( " No reports currently exist.\n" );
  78. }
  79. // Find all of the queries.
  80. output.AppendFormat( "\nQueries:\n" );
  81. searchPathMultipleObject queriesPath = new searchPathMultipleObject();
  82. queriesPath.Value = "/content//query";
  83. baseClass[] bcQueries = cBICMS.query( queriesPath, props, s, qo );
  84. if( bcQueries.Length > 0 )
  85. {
  86. foreach( baseClass query_item in bcQueries )
  87. {
  88. output.AppendFormat( " {0}\n", query_item.defaultName.value );
  89. output.AppendFormat( " {0}\n", query_item.searchPath.value );
  90. }
  91. }
  92. else
  93. {
  94. output.Append( " No queries in this package.\n" );
  95. }
  96. resultMessage = output.ToString();
  97. return true;
  98. }
  99. }
  100. }