123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- /**
- Licensed Materials - Property of IBM
- IBM Cognos Products: DOCS
- (C) Copyright IBM Corp. 2005, 2008
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
- IBM Corp.
- */
- // *
- // * CreateDrillThroughTarget.sln
- // *
- // * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
- // * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
- // *
- // * Description: Creates a target definition for drill through.
- using System;
- using System.IO;
- using System.Windows.Forms;
- using System.Web;
- using System.Xml;
- using SamplesCommon;
- using cognosdotnet_10_2;
- namespace CreateDrillThroughTarget
- {
- /// <summary>
- /// Summary description for Class1.
- /// </summary>
- class CreateDrillThroughTarget
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- ///
- public CreateDrillThroughTarget() { }
- [STAThread]
- static void Main(string[] args)
- {
- string cBIUrl = "";
- contentManagerService1 cBICMS = null;
- SamplesConnect connectDlg = new SamplesConnect();
- CreateDrillThroughTargetDlg createDrillThroughTargetDlgObject = new CreateDrillThroughTargetDlg();
- if (args.GetLength(0) == 0)
- {
- // GUI mode
- connectDlg.ShowDialog();
- if (connectDlg.IsConnectedToCBI() == true)
- {
- cBICMS = connectDlg.CBICMS;
- cBIUrl = connectDlg.CBIURL;
- createDrillThroughTargetDlgObject.setConnection(connectDlg, cBIUrl);
- createDrillThroughTargetDlgObject.setPackageList(BaseClassWrapper.getPackageNameList(cBICMS));
- createDrillThroughTargetDlgObject.ShowDialog();
- }
- }
- }
- public string createDrillThrough(SamplesConnect cBIConnection, BaseClassWrapper report, string packageName)
- {
- if (cBIConnection == null)
- {
- return null;
- }
- baseParameter[] reportPrompts = getPrompts(cBIConnection, report);
- drillPath drillThroughDef = new drillPath();
- //Get a name from the user and set it
- SamplesInput getDrillThroughName = new SamplesInput();
- string dtName = getDrillThroughName.getInput("Drill Through Name", "Enter a name for the Drill Through Definition", "IBM Cognos Software Development Kit Drill Through Sample");
- drillThroughDef = setDrillThroughName(dtName, drillThroughDef);
- // set a description
- drillThroughDef = setDrillThroughDescription(drillThroughDef);
- // set drill through contact to the current user
- account myAccount = SamplesConnect.getLogonAccount(cBIConnection);
- drillThroughDef = setDrillThroughContact(myAccount, drillThroughDef);
- // set the drill through action
- drillThroughDef = setDrillThroughAction(drillThroughDef);
- // set the drill through target
- drillThroughDef = setDrillThroughTarget(report, drillThroughDef);
- // set the drill through parameter values
- drillThroughDef = setDrillThroughParameters(cBIConnection, report, drillThroughDef);
- return addDrillThroughDefinition(cBIConnection, drillThroughDef, packageName);
- }
- public BaseClassWrapper[] getPromptedReports(SamplesConnect cBIConnection, String packageName)
- {
- baseClass[] reports = new baseClass[0];
- propEnum[] props =
- new propEnum[] { propEnum.searchPath, propEnum.defaultName, propEnum.objectClass, propEnum.parent };
- sort[] sortOptions = { new sort() };
- sortOptions[0].order = orderEnum.ascending;
- sortOptions[0].propName = propEnum.defaultName;
- searchPathMultipleObject reportsPath = new searchPathMultipleObject();
- reportsPath.Value = "/content/folder[@name='Samples']/folder[@name='Models']/package[@name='" + packageName + "']//report";
- reports =
- cBIConnection.CBICMS.query(
- reportsPath,
- props,
- sortOptions,
- new queryOptions());
- BaseClassWrapper[] reportList = new BaseClassWrapper[reports.GetLength(0)];
- int nbReports = 0;
- int count = 0;
- if ((reports != null) && (reports.GetLength(0) > 0))
- {
- nbReports = reports.GetLength(0);
- for (int i = 0; i < nbReports; i++)
- {
- BaseClassWrapper report = new BaseClassWrapper(reports[i]);
- if (hasPrompts(cBIConnection, report))
- {
- reportList[count++] = report;
- }
- }
- }
- BaseClassWrapper[] promptedReportList = new BaseClassWrapper[count];
- for (int i = 0; i < count; i++)
- promptedReportList[i] = reportList[i];
- return promptedReportList;
- }
- public bool hasPrompts(SamplesConnect cBIConnection, BaseClassWrapper report)
- {
- searchPathSingleObject reportPath = new searchPathSingleObject();
- reportPath.Value = report.searchPath.value;
- asynchReply getParamsReply = cBIConnection.CBIRS.getParameters(reportPath, new parameterValue[] { }, new option[] { });
- if (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
- {
- while (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
- {
- getParamsReply = cBIConnection.CBIRS.wait(
- getParamsReply.primaryRequest,
- new parameterValue[] { },
- new option[] { });
- }
- }
- for (int i = 0; i < getParamsReply.details.Length; i++)
- {
- if (getParamsReply.details[i] is asynchDetailParameters)
- {
- return (((asynchDetailParameters)getParamsReply.details[i]).parameters.Length > 0);
- }
- }
- return false;
- }
- public baseParameter[] getPrompts(SamplesConnect cBIConnection, BaseClassWrapper report)
- {
- searchPathSingleObject reportPath = new searchPathSingleObject();
- reportPath.Value = report.searchPath.value;
- asynchReply getParamsReply = cBIConnection.CBIRS.getParameters(reportPath, new parameterValue[] { }, new option[] { });
- if (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
- {
- while (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
- {
- getParamsReply = cBIConnection.CBIRS.wait(
- getParamsReply.primaryRequest,
- new parameterValue[] { },
- new option[] { });
- }
- }
- for (int i = 0; i < getParamsReply.details.Length; i++)
- {
- if (getParamsReply.details[i] is asynchDetailParameters)
- {
- return ((asynchDetailParameters)getParamsReply.details[i]).parameters;
- }
- }
- return null;
- }
- public BaseClassWrapper getPackage(SamplesConnect cBIConnection, string packageName)
- {
- searchPathMultipleObject packagesPath = new searchPathMultipleObject();
- packagesPath.Value = "/content//package[@name='" + packageName + "']";
- baseClass[] bc = cBIConnection.CBICMS.query(packagesPath, new propEnum[] {}, new sort[] {}, new queryOptions());
- string[] packageNames = new string[bc.GetLength(0)];
- if (bc.Length == 1)
- {
- return new BaseClassWrapper(bc[0]);
- }
- return null;
- }
- public bool hasSecondaryRequest(asynchReply response, string secondaryRequest)
- {
- asynchSecondaryRequest[] secondaryRequests =
- response.secondaryRequests;
- for (int i = 0; i < secondaryRequests.Length; i++)
- {
- if (secondaryRequests[i].name.CompareTo(secondaryRequest)
- == 0)
- {
- return true;
- }
- }
- return false;
- }
- // set a name
- public drillPath setDrillThroughName(string dtName, drillPath drillThroughDef)
- {
- tokenProp myDrillName = new tokenProp();
- myDrillName.value = dtName;
- drillThroughDef.defaultName = myDrillName;
- return drillThroughDef;
- }
- // set a description
- public drillPath setDrillThroughDescription(drillPath drillThroughDef)
- {
- stringProp myDrillDesc = new stringProp();
- myDrillDesc.value = "This is an example of how to create a Drill-through definition using the SDK.";
- drillThroughDef.defaultDescription = myDrillDesc;
- return drillThroughDef;
- }
- // set a contact
- public drillPath setDrillThroughContact(account myAccount, drillPath drillThroughDef)
- {
- baseClass[] contactData = new baseClass[] {myAccount};
- baseClassArrayProp contact = new baseClassArrayProp();
- contact.value = contactData;
- drillThroughDef.contact = contact;
- return drillThroughDef;
- }
- // set an action
- public drillPath setDrillThroughAction(drillPath drillThroughDef)
- {
- baseReportActionEnumProp drillAction = new baseReportActionEnumProp();
- drillAction.value = baseReportActionEnum.run;
- drillThroughDef.action = drillAction;
- return drillThroughDef;
- }
- // set a target
- public drillPath setDrillThroughTarget(BaseClassWrapper targetReport, drillPath drillThroughDef)
- {
- baseClassArrayProp targetProp = new baseClassArrayProp();
- baseClass[] targets = new baseClass[] {targetReport.baseclassobject};
- targetProp.value = targets;
- drillThroughDef.target = targetProp;
- return drillThroughDef;
- }
- // set parameters
- public drillPath setDrillThroughParameters(SamplesConnect cBIConnection, BaseClassWrapper report, drillPath drillThroughDef)
- {
- //get the parameters for the target report
- baseParameter[] parameters = getPrompts(cBIConnection, report);
- baseParameterAssignment[] paramAssignments = new baseParameterAssignment[parameters.Length];
- //loop through and set parameter info
- parameterAssignmentDataItem paramAssignmentItem;
- metadataModelItemName paramDataItemName;
- for (int i = 0; i < parameters.Length; i++)
- {
- paramAssignmentItem = new parameterAssignmentDataItem();
- string parameterName = ( (parameter) parameters[i]).name;
- paramAssignmentItem.parameterName = parameterName;
- paramDataItemName = new metadataModelItemName();
- string itemNameStr = ( (parameter) parameters[i]).modelFilterItem;
- paramDataItemName.Value = itemNameStr;
- paramAssignmentItem.dataItemName = paramDataItemName;
-
- paramAssignments[i] = paramAssignmentItem;
- }
- //add the parameter info to the drillThroughDef
- baseParameterAssignmentArrayProp parameterAssignmentsProp = new baseParameterAssignmentArrayProp();
- parameterAssignmentsProp.value = paramAssignments;
- drillThroughDef.parameterAssignments = parameterAssignmentsProp;
- return drillThroughDef;
- }
-
- public string addDrillThroughDefinition(SamplesConnect cBIConnection, drillPath drillThroughDef, string packageName)
- {
- string addResult;
- searchPathSingleObject parentPath = new searchPathSingleObject();
- baseClass[] bcDrill = new baseClass[1];
- bcDrill[0] = drillThroughDef;
- addOptions addOpts = new addOptions();
- addOpts.updateAction = updateActionEnum.replace;
- string packagePathStr = getPackage(cBIConnection, packageName).baseclassobject.searchPath.value;
- if (packagePathStr != null)
- {
- parentPath.Value = packagePathStr;
- }
- baseClass[] drillResult = cBIConnection.CBICMS.add(parentPath, bcDrill, addOpts);
- drillPath response = (drillPath) drillResult[0];
- addResult = "Added Drill Through Definition with search path: " + response.searchPath.value;
- return addResult;
- }
- }
- }
|