/**
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.
*/
/**
* AddReport.sln
*
* Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
* Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
*
* Description: This code sample demonstrates how to add reports using the
* following methods:
* - validate(search, object, options)
* Use this method to validate reports in the content store.
* - add(search, object, options)
* Use this method to add reports to the content store.
*
*/
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Web.Services.Protocols;
using SamplesCommon;
using cognosdotnet_10_2;
using System.Xml;
namespace AddReport
{
///
/// Summary description for AddReport.
///
public class AddReport
{
public AddReport(){}
[STAThread]
static void Main(string[] args)
{
string cBIUrl = "";
string accountPath = "";
reportService1 cBIServer = null;
AddReportDlg ardlgObject = new AddReportDlg();
SamplesConnect connectDlg = new SamplesConnect();
if (args.GetLength(0) == 0 )
{
// GUI mode
connectDlg.ShowDialog();
if (connectDlg.IsConnectedToCBI() == true)
{
cBIServer = connectDlg.CBIRS;
cBIUrl = connectDlg.CBIURL;
accountPath = connectDlg.GetAccountPath();
ardlgObject.setConnection(cBIServer, cBIUrl, accountPath);
ardlgObject.CBISS = connectDlg.CBISS;
ardlgObject.ShowDialog();
}
}
}
public bool validateReportSpec(reportService1 cBIRS, reportServiceReportSpecification reportSpec, ref string resultMessage)
{
asynchReply validationResults = null;
if (cBIRS == null)
{
resultMessage = "...the Server connection is invalid.\n";
return false;
}
option[] validateOptions = new option[2];
asynchOptionInt primaryWaitThreshold = new asynchOptionInt();
primaryWaitThreshold.name = asynchOptionEnum.primaryWaitThreshold;
primaryWaitThreshold.value = 0;
validateOptions[0] = primaryWaitThreshold;
asynchOptionInt secondaryWaitThreshold = new asynchOptionInt();
secondaryWaitThreshold.name = asynchOptionEnum.secondaryWaitThreshold;
secondaryWaitThreshold.value = 0;
validateOptions[1] = secondaryWaitThreshold;
// sn_dg_sdk_method_reportService_validateSpecification_start_0
validationResults = cBIRS.validateSpecification(reportSpec, new parameterValue[]{}, validateOptions);
// sn_dg_sdk_method_reportService_validateSpecification_end_0
if (validationResults == null)
{
resultMessage = "...unknown error validating the report.";
return false;
}
bool status = true;
string errresult = "";
string defects = "";
// sn_dg_sdk_method_reportService_validateSpecification_start_1
for (int i = 0; i < validationResults.details.Length; i++)
{
if (validationResults.details[i] is asynchDetailReportValidation)
{
if ( ( (asynchDetailReportValidation) validationResults.details[i]).defects.Value.Length > 0 )
{
defects = ( (asynchDetailReportValidation) validationResults.details[i]).defects.Value;
}
}
}
//Parse the defects xml string to see what type of errors, if any
// sn_dg_sdk_method_reportService_validateSpecification_end_1
XmlDocument vrDocument = new XmlDocument();
vrDocument.LoadXml(defects);
XmlElement root = vrDocument.DocumentElement;
XmlNodeList queryProblems = root.SelectNodes("//queryProblems");
XmlNodeList layoutProblems = root.SelectNodes("//layoutProblems");
for (int i=0; i 0)
{
searchPath = accountPath + "/folder[@name='My Folders']";
}
else
{
searchPath = "CAMID(\"::Anonymous\")/folder[@name='My Folders']";
}
if (cBIRS == null)
{
resultMessage = "...the Server connection is invalid.\n...the specification was not added.";
return false;
}
if (!validateReportSpec(cBIRS, reportSpec, ref resultMessage))
{
resultMessage += "\n...the specification was not added.";
return false;
}
report newReport = new report();
anyTypeProp reportSpecProperty = new anyTypeProp();
reportSpecProperty.value = reportSpec.value.Value.ToString();
multilingualToken[] reportNames = new multilingualToken[1];
reportNames[0] = new multilingualToken();
if (0 != inputReportName.CompareTo(""))
{
newReportName = inputReportName;
}
reportNames[0].value = newReportName;
newReport.name = new multilingualTokenProp();
newReport.name.value = reportNames;
configurationData data = null;
locale[] locales = null;
configurationDataEnum[] config = new configurationDataEnum[1];
config[0] = configurationDataEnum.serverLocale;
// sn_dg_sdk_method_systemService_getConfiguration_start_0
data = cBISS.getConfiguration(config);
locales = data.serverLocale;
if (locales == null)
{
locales[0] = new locale();
locales[0].locale1 = "en";
}
// sn_dg_sdk_method_systemService_getConfiguration_end_0
reportNames[0].locale = locales[0].locale1;
newReport.specification = reportSpecProperty;
addOptions addReportOptions = new addOptions();
addReportOptions.updateAction = updateActionEnum.replace;
searchPathSingleObject searchPathSO = new searchPathSingleObject();
searchPathSO.Value = searchPath;
// sn_dg_sdk_method_reportService_add_start_0
cBIRS.add(searchPathSO, newReport, addReportOptions);
// sn_dg_sdk_method_reportService_add_end_0
resultMessage = "\n...the report \"" + newReport + "\" has been added successfully to \"" + searchPath + "\".";
return true;
}
}
}