Schedule.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2007
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // *
  9. // * Schedule.sln
  10. // *
  11. // * Copyright (C) 2007 Cognos ULC, an IBM Company. All rights reserved.
  12. // * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. // *
  14. // * Description: Schedule running a report.
  15. using System;
  16. using System.Web.Services.Protocols;
  17. using SamplesCommon;
  18. using System.Globalization;
  19. using cognosdotnet_10_2;
  20. namespace Schedule
  21. {
  22. /// <summary>
  23. /// Summary description for Class1.
  24. /// </summary>
  25. class Schedule
  26. {
  27. public Schedule(){}
  28. static void Main(string[] args)
  29. {
  30. string cBIUrl = "";
  31. contentManagerService1 cBICMS = null;
  32. SamplesConnect connectDlg = new SamplesConnect();
  33. ScheduleDlg schedDlgObject = new ScheduleDlg();
  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. schedDlgObject.setConnection(connectDlg, cBIUrl);
  43. schedDlgObject.setReportList(BaseClassWrapper.buildReportQueryList(cBICMS));
  44. schedDlgObject.setSelectedReportIndex(0);
  45. schedDlgObject.ShowDialog();
  46. }
  47. }
  48. }
  49. //Create a simple schedule
  50. public bool createSchedule(
  51. SamplesConnect connection,
  52. BaseClassWrapper reportToSchedule,
  53. ref string resultMessage)
  54. {
  55. schedule newSched = new schedule();
  56. //
  57. //Set the schedule properties
  58. //
  59. // sn_dg_prm_smpl_schedulereport_P1_start_0
  60. //get the credential for the schedule
  61. credential schedCred = connection.getCredential();
  62. baseClassArrayProp credentials = new baseClassArrayProp();
  63. credentials.value = new baseClass[] {schedCred};
  64. newSched.credential = credentials;
  65. // sn_dg_prm_smpl_schedulereport_P1_end_0
  66. // sn_dg_prm_smpl_schedulereport_P5_start_0
  67. //mark the schedule as active
  68. booleanProp isActive = new booleanProp();
  69. isActive.value = true;
  70. newSched.active = isActive;
  71. //Set the type of schedule
  72. cognosdotnet_10_2.nmtokenProp scheduleType = new nmtokenProp();
  73. scheduleType.value = "daily";
  74. newSched.type = scheduleType;
  75. //make the schedule for every x minutes
  76. nmtokenProp period = new nmtokenProp();
  77. period.value = "minute";
  78. newSched.dailyPeriod = period;
  79. //set that every x minutes to be every 1 minute
  80. positiveIntegerProp runFreqProp = new positiveIntegerProp();
  81. runFreqProp.value = "1";
  82. newSched.everyNPeriods = runFreqProp;
  83. // sn_dg_prm_smpl_schedulereport_P5_end_0
  84. // sn_dg_prm_smpl_schedulereport_P3_start_0
  85. //set the owner
  86. baseClassArrayProp ownersProp = new baseClassArrayProp();
  87. baseClass[] owners = new baseClass[] { SamplesConnect.getLogonAccount(connection) };
  88. ownersProp.value = owners;
  89. newSched.owner = ownersProp;
  90. // sn_dg_prm_smpl_schedulereport_P3_end_0
  91. // sn_dg_prm_smpl_schedulereport_P2_start_0
  92. // set schedule time to now + 2 minutes
  93. System.DateTime startTime = new DateTime();
  94. startTime = DateTime.Now;
  95. startTime = startTime.AddMinutes(2);
  96. dateTimeProp schedStartTime = new dateTimeProp();
  97. schedStartTime.value = startTime;
  98. newSched.startDate = schedStartTime;
  99. // set schedule end time to now + 5 minutes
  100. System.DateTime endTime = new DateTime();
  101. endTime = DateTime.Now;
  102. endTime = endTime.AddMinutes(5);
  103. dateTimeProp schedEndTime = new dateTimeProp();
  104. schedEndTime.value = endTime;
  105. newSched.endDate = schedEndTime;
  106. // set the schedule end type
  107. nmtokenProp endType = new nmtokenProp();
  108. endType.value = "onDate";
  109. newSched.endType = endType;
  110. // sn_dg_prm_smpl_schedulereport_P2_end_0
  111. //
  112. //Build the run options for the schedule
  113. //
  114. // sn_dg_prm_smpl_schedulereport_P4_start_0
  115. //Set the name of the reportView
  116. multilingualToken[] reportViewName = new multilingualToken[1];
  117. reportViewName[0] = new multilingualToken();
  118. reportViewName[0].locale = "en-us";
  119. reportViewName[0].value = "View of Report " + reportToSchedule.baseclassobject.defaultName.value;
  120. //Save the output as report view with name saveasName
  121. runOptionSaveAs saveAs = new runOptionSaveAs();
  122. saveAs.name = runOptionEnum.saveAs;
  123. saveAs.objectClass = reportSaveAsEnum.reportView;
  124. saveAs.objectName = reportViewName;
  125. saveAs.parentSearchPath = reportToSchedule.parentPath.value;
  126. //Turn off prompting
  127. runOptionBoolean prompt = new runOptionBoolean();
  128. prompt.name = runOptionEnum.prompt;
  129. prompt.value = false;
  130. //set the output format
  131. runOptionStringArray format = new runOptionStringArray();
  132. format.name = runOptionEnum.outputFormat;
  133. format.value = new string[] { "HTML" };
  134. //put the run options where they need to go
  135. runOption[] schedRunOptArr = new runOption[3];
  136. schedRunOptArr[0] = saveAs;
  137. schedRunOptArr[1] = prompt;
  138. schedRunOptArr[2] = format;
  139. optionArrayProp schedRunOptions = new optionArrayProp();
  140. schedRunOptions.value = schedRunOptArr;
  141. newSched.options = schedRunOptions;
  142. // sn_dg_prm_smpl_schedulereport_P4_end_0
  143. // sn_dg_prm_smpl_schedulereport_P5_start_1
  144. searchPathSingleObject reportSearchPath = new searchPathSingleObject();
  145. reportSearchPath.Value = ((baseClass) reportToSchedule.baseclassobject).searchPath.value;
  146. // add the schedule to the report
  147. addOptions ao = new addOptions();
  148. ao.updateAction = updateActionEnum.replace;
  149. baseClass newBc = connection.CBICMS.add(
  150. reportSearchPath,
  151. new baseClass[] { newSched },
  152. ao)[0];
  153. // sn_dg_prm_smpl_schedulereport_P5_end_1
  154. if (newBc != null)
  155. {
  156. resultMessage = "Schedule Created";
  157. return true;
  158. }
  159. resultMessage = "Schedule Creation Failed.";
  160. return false;
  161. }
  162. }
  163. }