123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using System;
- using System.Windows.Forms;
- using System.Web.Services.Protocols;
- using SamplesCommon;
- using cognosdotnet_10_2;
- namespace CMQuery
- {
-
-
-
-
- public class CMQuery
- {
- public CMQuery(){}
-
- static void Main(string[] args)
- {
- bool isGUImode = false;
- string BIServerURL = "";
- string userName = "";
- string userPassword = "";
- string userNamespace = "";
- string searchPath = "";
-
- CMQuery cmQueryObj = new CMQuery();
- CMQueryDlg cmQueryDlgObject = new CMQueryDlg();
-
- if (args.GetLength(0) == 0 )
- {
-
- isGUImode = true;
- SamplesConnect connectDlg = new SamplesConnect();
- connectDlg.ShowDialog();
- if (connectDlg.IsConnectedToCBI() == true)
- {
- cmQueryDlgObject.setConnection(connectDlg.CBICMS,
- connectDlg.CBIURL,
- userName,
- userPassword,
- userNamespace);
- cmQueryDlgObject.ShowDialog();
- }
- }
- else
- {
-
- isGUImode = false;
- if (!cmQueryObj.getCLInput(args, ref searchPath,
- ref userName,
- ref userPassword,
- ref userNamespace) )
- {
- return;
- }
- SamplesConnect connectCL = new SamplesConnect();
- bool isAnonymous = true;
- if (!connectCL.makeCLConnection(ref BIServerURL,
- ref userName,
- ref userPassword,
- ref userNamespace,
- ref isAnonymous) )
- {
- return;
- }
- if (isAnonymous && (0 != userName.CompareTo("")) )
- {
- userName = "";
- Console.WriteLine("\n***Note: This sample ignores user credentials for Anonymous connections\n");
- }
- string output = cmQueryObj.doQuery(connectCL.CBICMS,
- searchPath,
- userName,
- userPassword,
- userNamespace, isGUImode);
- Console.WriteLine(output);
- }
- }
- public bool getCLInput(string[] args,
- ref string searchPath,
- ref string userName,
- ref string userPassword,
- ref string userNamespace)
- {
- try
- {
-
- int argc = args.GetLength(0);
- for (int i=0; i<argc; i++)
- {
- if (0 == args[i].CompareTo("-sp"))
- {
- searchPath = args[++i];
- }
- else if (0 == args[i].CompareTo("-un"))
- {
- userName = args[++i];
- }
- else if (0 == args[i].CompareTo("-pwd"))
- {
- userPassword = args[++i];
- }
- else if (0 == args[i].CompareTo("-ns"))
- {
- userNamespace = args[++i];
- }
- else if (0 == args[i].CompareTo("-h"))
- {
-
- Console.WriteLine("cmquery.exe -sp <searchPath> [-un <userName> -pwd <userPassword> -ns <userNamepsace>].");
- return false;
- }
- else
- {
-
- Console.WriteLine("Invalid argument: {0}", args[0]);
- Console.WriteLine("cmquery.exe -sp <searchPath> [-un <userName> -pwd <userPassword> -ns <userNamepsace>].");
- return false;
- }
- }
- }
- catch(System.Exception ex)
- {
- if ( (searchPath == null) || (0 == searchPath.CompareTo("")) )
- {
- searchPath = "/*";
- Console.WriteLine("\n***Note: The searchPath argument is missing, '" + searchPath + "' will be used instead.\n");
- return true;
- }
- SamplesException.ShowExceptionMessage("getCLInput() failed with error: " + ex.Message, false,
- "Content Manager Query Sample - doQuery()" );
- Console.WriteLine("\nValid arguments:\ncmquery.exe -sp <search Path> [-un <userName> -pwd <userPassword> -ns <userNamepsace>].");
- return false;
- }
- return true;
- }
- public string doQuery(contentManagerService1 cBICMS,
- string searchPath,
- string userName,
- string userPassword,
- string userNamespace,
- bool isGUImode)
- {
- string output = "";
- try
- {
-
- propEnum[] properties =
- { propEnum.defaultName, propEnum.searchPath };
-
- sort[] sortBy = { new sort()};
- sortBy[0].order = orderEnum.ascending;
- sortBy[0].propName = propEnum.defaultName;
-
- queryOptions options = new queryOptions();
- searchPathMultipleObject qPath = new searchPathMultipleObject();
- qPath.Value = searchPath;
-
- baseClass[] results =
- cBICMS.query(qPath, properties, sortBy, options);
-
- output += "Results:\n\n";
- for (int i = 0; i < results.GetLength(0); i++)
- {
- tokenProp theDefaultName = results[i].defaultName;
- stringProp theSearchPath = results[i].searchPath;
- output += "\t" + theDefaultName.value + "\t\t" + theSearchPath.value + "\n";
- }
- }
- catch(SoapException ex)
- {
- SamplesException.ShowExceptionMessage("\n" + ex, isGUImode, "Content Manager Query Sample - doQuery()" );
- return "The error occurred in doQuery()";
- }
- catch(System.Exception ex)
- {
- if (0 != ex.Message.CompareTo("INPUT_CANCELLED_BY_USER"))
- {
- SamplesException.ShowExceptionMessage("\n" + ex.Message, isGUImode, "Content Manager Query Sample - doQuery()" );
- }
- return "The error occurred in doQuery()";
- }
- return output;
- }
- }
- }
|