123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- using System;
- using System.IO;
- using System.Text;
- using System.Web.Services.Protocols;
- using SamplesCommon;
- using cognosdotnet_10_2;
- namespace reportrunner
- {
-
-
-
-
-
-
-
-
- class ReportRunner
- {
-
-
-
- [STAThread]
- static void Main( string[] args )
- {
-
-
- string serverHost = "localhost";
- string serverPort = "9300";
-
- searchPathSingleObject reportPath = new searchPathSingleObject();
- reportPath.Value = "/content/folder[@name='Samples']/folder[@name='Models']/package[@name='GO Data Warehouse (query)']/folder[@name='SDK Report Samples']/report[@name='Product Description List']";
-
- string outputPath = "reportrunner.html";
-
- string userName = "";
- string userPassword = "";
- string userNamespace = "";
-
- bool exit = false;
- for( int idx = 0; idx < args.Length; idx++ ) {
- if( args[idx].CompareTo( "-host" ) == 0 ) {
- idx++;
- serverHost = args[idx];
- } else if( args[idx].CompareTo( "-port" ) == 0 ) {
- idx++;
- serverPort = args[idx];
- } else if( args[idx].CompareTo( "-report" ) == 0 ) {
- idx++;
- reportPath.Value = args[idx];
- } else if( args[idx].CompareTo( "-output" ) == 0 ) {
- idx++;
- outputPath = args[idx];
- } else if( args[idx].CompareTo( "-user" ) == 0 ) {
- idx++;
- userName = args[idx];
- } else if( args[idx].CompareTo( "-password" ) == 0 ) {
- idx++;
- userPassword = args[idx];
- } else if( args[idx].CompareTo( "-namespace" ) == 0 ) {
- idx++;
- userNamespace = args[idx];
- } else {
- Console.WriteLine( "Unknown argument: {0}\n", args[idx] );
- showUsage();
- exit = true;
- }
- }
- if( !exit ) {
-
-
-
-
-
-
- string Server_URL = "http://" + serverHost + ":" + serverPort + "/p2pd/servlet/dispatch";
- Console.WriteLine( "Creating connection to {0}:{1}...", serverHost, serverPort );
- Console.WriteLine( "Server URL: {0}", Server_URL );
- reportService1 cBIRS = new reportService1();
- cBIRS.Url = Server_URL;
- Console.WriteLine( "... done." );
-
- if( userName.Length > 0 && userPassword.Length > 0 && userNamespace.Length > 0 ) {
- Console.WriteLine( "Logging on as {0} in the {1} namespace.", userName, userNamespace );
- setUpHeader( cBIRS, userName, userPassword, userNamespace );
- }
-
- parameterValue[] parameters = new parameterValue[]{};
- option[] runOptions = new option[5];
-
- runOptionBoolean saveOutput = new runOptionBoolean();
- saveOutput.name = runOptionEnum.saveOutput;
- saveOutput.value = false;
- runOptions[0] = saveOutput;
-
- runOptionStringArray outputFormat = new runOptionStringArray();
- outputFormat.name = runOptionEnum.outputFormat;
- outputFormat.value = new string[]{ "HTML" };
- runOptions[1] = outputFormat;
- runOptionOutputEncapsulation outputEncapsulation = new runOptionOutputEncapsulation();
- outputEncapsulation.name = runOptionEnum.outputEncapsulation;
- outputEncapsulation.value = outputEncapsulationEnum.none;
- runOptions[2] = outputEncapsulation;
- asynchOptionInt primaryWait = new asynchOptionInt();
- primaryWait.name = asynchOptionEnum.primaryWaitThreshold;
- primaryWait.value = 0;
- runOptions[3] = primaryWait;
- asynchOptionInt secondaryWait = new asynchOptionInt();
- secondaryWait.name = asynchOptionEnum.secondaryWaitThreshold;
- secondaryWait.value = 0;
- runOptions[4] = secondaryWait;
-
- try {
- Console.WriteLine( "Running the report..." );
- Console.WriteLine( "Report search path is:" );
- Console.WriteLine( reportPath.Value );
- asynchReply res = cBIRS.run( reportPath, parameters, runOptions );
- Console.WriteLine( "... done." );
-
-
- string data = null;
- if( res.status == asynchReplyStatusEnum.complete )
- {
- for (int i = 0; i < res.details.Length; i++)
- {
- if (res.details[i] is asynchDetailReportOutput)
- {
- data = ( (asynchDetailReportOutput)res.details[i]).outputPages[0];
- }
- }
- Console.WriteLine( "Writing report output to {0}...", outputPath );
- FileStream fs = new FileStream( outputPath, FileMode.Create );
-
-
- string uriFix = "http://" + serverHost + ":" + serverPort + "/crn/";
-
- string fixed_hunk = data.Replace( "../", uriFix );
- byte[] hunk_data = UTF8Encoding.UTF8.GetBytes( fixed_hunk );
- fs.Write( hunk_data, 0, hunk_data.Length );
-
- fs.Close();
- Console.WriteLine( "... done." );
- }
- } catch( SoapException ex ) {
- string ex_str = Exceptions.CognosException.ConvertToString( ex );
- Console.WriteLine( "SOAP exception!\n" );
- Console.WriteLine( ex_str );
- } catch( Exception ex ) {
- Console.WriteLine( "Unhandled exception!" );
- Console.WriteLine( "Message: {0}", ex.Message );
- Console.WriteLine( "Stack trace:\n{0}", ex.StackTrace );
- }
- }
- }
-
-
-
-
-
-
-
-
-
- static void setUpHeader( reportService1 cBIRS, string user, string pass, string name ) {
-
- if( cBIRS.biBusHeaderValue != null ) {
- if( cBIRS.biBusHeaderValue.tracking != null ) {
- if( cBIRS.biBusHeaderValue.tracking.conversationContext != null ) {
- cBIRS.biBusHeaderValue.tracking.conversationContext = null;
- }
- }
- return;
- }
-
- cBIRS.biBusHeaderValue = new biBusHeader();
- cBIRS.biBusHeaderValue.CAM = new CAM();
- cBIRS.biBusHeaderValue.CAM.action = "logonAs";
- cBIRS.biBusHeaderValue.hdrSession = new hdrSession();
- formFieldVar[] ffs = new formFieldVar[3];
- ffs[0] = new formFieldVar();
- ffs[0].name = "CAMUsername";
- ffs[0].value = user;
- ffs[0].format = formatEnum.not_encrypted;
- ffs[1] = new formFieldVar();
- ffs[1].name = "CAMPassword";
- ffs[1].value = pass;
- ffs[1].format = formatEnum.not_encrypted;
- ffs[2] = new formFieldVar();
- ffs[2].name = "CAMNamespace";
- ffs[2].value = name;
- ffs[2].format = formatEnum.not_encrypted;
- cBIRS.biBusHeaderValue.hdrSession.formFieldVars = ffs;
- }
- static void showUsage() {
- Console.WriteLine( "Run a report and save the output as HTML.\n" );
- Console.WriteLine( "usage:\n" );
- Console.WriteLine( "-host hostName Host name of the server. " );
- Console.WriteLine( " Default: localhost" );
- Console.WriteLine( "-port portNumber Port number of the server 'host'." );
- Console.WriteLine( " Default: 80" );
- Console.WriteLine( "-report searchPath Search path to a report." );
- Console.WriteLine( " Default: /content/package[@name='GO Sales and Retailers']/folder[@name='Documentation Report Samples']/report[@name='Show Detailed Rows and Summaries']" );
- Console.WriteLine( "-output outputPath File name for the output HTML document." );
- Console.WriteLine( " Default: reportrunner.html" );
- Console.WriteLine( "-user userName User to log on as. Must exist in 'userNamespace'." );
- Console.WriteLine( " Default: none" );
- Console.WriteLine( "-password userPassword Password for 'userName' in 'userNamespace'." );
- Console.WriteLine( " Default: none" );
- Console.WriteLine( "-namespace userNamespace Security namespace to log on to." );
- Console.WriteLine( " Default: none" );
- }
- }
- }
|