ViewPackagesAndReports.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // packages and reports object using the query method.
  13. //
  14. // Use this method to request objects from Content Manager.
  15. using System;
  16. using System.Windows.Forms;
  17. using System.Text;
  18. using System.Web.Services.Protocols;
  19. using SamplesCommon;
  20. using cognosdotnet_10_2;
  21. namespace ViewAll
  22. {
  23. class ViewAll
  24. {
  25. public ViewAll(){}
  26. static void Main(string[] args)
  27. {
  28. string cBIUrl = "";
  29. contentManagerService1 cBICMS = null;
  30. SamplesConnect connectDlg = new SamplesConnect();
  31. ViewAllDlg viewAllDlgObject = new ViewAllDlg();
  32. if (args.GetLength(0) == 0 )
  33. {
  34. // GUI mode
  35. connectDlg.ShowDialog();
  36. if (connectDlg.IsConnectedToCBI() == true)
  37. {
  38. cBICMS = connectDlg.CBICMS;
  39. cBIUrl = connectDlg.CBIURL;
  40. viewAllDlgObject.setConnection(cBICMS, cBIUrl);
  41. viewAllDlgObject.ShowDialog();
  42. }
  43. }
  44. }
  45. public bool doViewAll(contentManagerService1 cBIServer, ref string resultMessage)
  46. {
  47. if (cBIServer == null)
  48. {
  49. resultMessage = "The connection provided is invalid.";
  50. return false;
  51. }
  52. propEnum[] props = new propEnum[] { propEnum.searchPath, propEnum.defaultName };
  53. sort[] s = new sort[]{ new sort() };
  54. s[0].order = orderEnum.ascending;
  55. s[0].propName = propEnum.defaultName;
  56. queryOptions qo = new queryOptions();
  57. StringBuilder output = new StringBuilder();
  58. // Look for all of the packages.
  59. searchPathMultipleObject packagePath = new searchPathMultipleObject();
  60. packagePath.Value = "/content//package";
  61. baseClass[] bc = cBIServer.query( packagePath, props, s, qo );
  62. if( bc.Length > 0 )
  63. {
  64. foreach( baseClass pack_item in bc )
  65. {
  66. output.AppendFormat( "\n {0}\n", pack_item.defaultName.value );
  67. output.AppendFormat( " {0}\n", pack_item.searchPath.value );
  68. // Find all of the reports in this package.
  69. output.AppendFormat( "\n Reports:\n" );
  70. string reportPath = pack_item.searchPath.value + "//report";
  71. searchPathMultipleObject reportsSearchPath = new searchPathMultipleObject();
  72. reportsSearchPath.Value = reportPath;
  73. baseClass[] bcReports = cBIServer.query( reportsSearchPath, props, s, qo );
  74. if( bcReports.Length > 0 )
  75. {
  76. foreach( baseClass report_item in bcReports )
  77. {
  78. output.AppendFormat( " {0}\n", report_item.defaultName.value );
  79. output.AppendFormat( " {0}\n", report_item.searchPath.value );
  80. }
  81. }
  82. else
  83. {
  84. output.Append( " No reports in this package.\n" );
  85. }
  86. // Find all of the queries in this package.
  87. output.AppendFormat( "\n Queries:\n" );
  88. string queryPath = pack_item.searchPath.value + "//query";
  89. searchPathMultipleObject queriesSearchPath = new searchPathMultipleObject();
  90. queriesSearchPath.Value = queryPath;
  91. baseClass[] bcQueries = cBIServer.query( queriesSearchPath, props, s, qo );
  92. if( bcQueries.Length > 0 )
  93. {
  94. foreach( baseClass query_item in bcQueries )
  95. {
  96. output.AppendFormat( " {0}\n", query_item.defaultName.value );
  97. output.AppendFormat( " {0}\n", query_item.searchPath.value );
  98. }
  99. }
  100. else
  101. {
  102. output.Append( " No queries in this package.\n" );
  103. }
  104. }
  105. }
  106. else
  107. {
  108. output.Append( "There are currently no published packages or reports.\n" );
  109. }
  110. resultMessage = output.ToString();
  111. return true;
  112. }
  113. }
  114. }