123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723 |
- /**
- Licensed Materials - Property of IBM
- IBM Cognos Products: DOCS
- (C) Copyright IBM Corp. 2005
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
- IBM Corp.
- */
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Web.Services.Protocols;
- using SamplesCommon;
- using cognosdotnet_10_2;
- namespace SamplesCommon
- {
- /// <summary>
- /// Summary description for SamplesConnect.
- /// </summary>
- public class SamplesConnect : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox serverUrlTB;
- private System.Windows.Forms.Button buttonOK;
- private System.Windows.Forms.Button buttonCancel;
- private System.Windows.Forms.Label connectLBL;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- // sn_dg_prm_smpl_connect_start_0
- private agentService cBIAS = null;
- // sn_dg_prm_smpl_connect_end_0
- private batchReportService1 cBIBRS = null;
- private contentManagerService1 cBICMS = null;
- private dataIntegrationService1 cBIDIS = null;
- private deliveryService1 cBIDS = null;
- private eventManagementService1 cBIEMS = null;
- private jobService1 cBIJS = null;
- private monitorService1 cBIMS = null;
- private reportService1 cBIRS = null;
- private systemService1 cBISS = null;
- private string cBIUrl = "";
- private string errorText = null;
- private bool connectedToServer = false;
- private static string savedUserName = "";
- private static string savedUserPassword = "";
- private static string savedNamespace = "";
- private static string savedAccountSearchPath = "";
- public SamplesConnect()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SamplesConnect));
- this.label1 = new System.Windows.Forms.Label();
- this.serverUrlTB = new System.Windows.Forms.TextBox();
- this.buttonOK = new System.Windows.Forms.Button();
- this.buttonCancel = new System.Windows.Forms.Button();
- this.connectLBL = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(10, 23);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(69, 16);
- this.label1.TabIndex = 0;
- this.label1.Text = "Server URL";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // serverUrlTB
- //
- this.serverUrlTB.Location = new System.Drawing.Point(87, 23);
- this.serverUrlTB.Name = "serverUrlTB";
- this.serverUrlTB.Size = new System.Drawing.Size(312, 20);
- this.serverUrlTB.TabIndex = 1;
- this.serverUrlTB.Text = "http://localhost:9300/p2pd/servlet/dispatch";
- this.serverUrlTB.KeyDown += new System.Windows.Forms.KeyEventHandler(this.serverUrlTB_OnKeyPress);
- //
- // buttonOK
- //
- this.buttonOK.Location = new System.Drawing.Point(239, 55);
- this.buttonOK.Name = "buttonOK";
- this.buttonOK.Size = new System.Drawing.Size(75, 23);
- this.buttonOK.TabIndex = 2;
- this.buttonOK.Text = "OK";
- this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
- this.buttonOK.KeyDown += new System.Windows.Forms.KeyEventHandler(this.buttonOK_OnKeyPress);
- //
- // buttonCancel
- //
- this.buttonCancel.Location = new System.Drawing.Point(327, 55);
- this.buttonCancel.Name = "buttonCancel";
- this.buttonCancel.Size = new System.Drawing.Size(75, 23);
- this.buttonCancel.TabIndex = 3;
- this.buttonCancel.Text = "Cancel";
- this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
- this.buttonCancel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.buttonCancel_OnKeyPress);
- //
- // connectLBL
- //
- this.connectLBL.Location = new System.Drawing.Point(24, 55);
- this.connectLBL.Name = "connectLBL";
- this.connectLBL.Size = new System.Drawing.Size(152, 23);
- this.connectLBL.TabIndex = 4;
- //
- // SamplesConnect
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(414, 86);
- this.Controls.Add(this.connectLBL);
- this.Controls.Add(this.buttonCancel);
- this.Controls.Add(this.buttonOK);
- this.Controls.Add(this.serverUrlTB);
- this.Controls.Add(this.label1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "SamplesConnect";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Connect to server";
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private void buttonOK_Click(object sender, System.EventArgs e)
- {
- connectLBL.Visible = true;
- connectLBL.Text = "Connecting...";
- cBICMS = new contentManagerService1();
- if (cBICMS != null)
- {
- //Test for Anonymous Authentication
- Boolean bTestAnonymous = false;
- try
- {
- cBIUrl = serverUrlTB.Text;
- cBICMS.Url = cBIUrl;
- searchPathMultipleObject homeDirSearchPath = new searchPathMultipleObject();
- homeDirSearchPath.Value = "~";
- baseClass[] bc = CBICMS.query ( homeDirSearchPath, new propEnum[]{} , new sort[]{}, new queryOptions () );
- if (bc != null)
- {
- bTestAnonymous = true;
- }
- }
- catch(Exception ex)
- {
- if (ex == null) { }
- //if security is enabled, we will end up here
- }
- if (bTestAnonymous == true)
- {
- connectedToServer = true;
- connectLBL.Visible = true;
- connectLBL.Text = "Connected.";
- savedAccountSearchPath = "CAMID(\"::Anonymous\")";
- }
- else
- {
- // Attempt to log on.
- SamplesLogon logon = new SamplesLogon( this );
- logon.setUserName(savedUserName);
- logon.setUserPassword(savedUserPassword);
- logon.setNamespace(savedNamespace);
- logon.ShowDialog( );
- if( !logon.loggedOn )
- {
- errorText = ( "Connection to server: Unable to log on." );
- connectedToServer = false;
- connectLBL.Visible = false;
- return;
- }
- else
- {
- connectedToServer = true;
- savedUserName = logon.getUserName();
- savedUserPassword = logon.getUserPassword();
- savedNamespace = logon.getNamespace();
- connectLBL.Visible = true;
- connectLBL.Text = "Connected.";
- savedAccountSearchPath = getLogonAccount(this).searchPath.value;;
- }
- }
- }
- this.Close();
- }
- private void buttonCancel_Click(object sender, System.EventArgs e)
- {
- connectedToServer = false;
- this.Close();
- }
- public bool IsConnectedToCBI()
- {
- return connectedToServer;
- }
- public string GetAccountPath()
- {
- return savedAccountSearchPath;
- }
- public string GetErrorText()
- {
- return errorText;
- }
- public string getUserName()
- {
- return savedUserName;
- }
- public string getUserPassword()
- {
- return savedUserPassword;
- }
-
- public string getNamespace()
- {
- return savedNamespace;
- }
- private void serverUrlTB_OnKeyPress(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- buttonOK_Click(sender, e);
- }
- else if (e.KeyCode == Keys.Escape)
- {
- this.Close();
- }
- }
- private void buttonOK_OnKeyPress(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- this.Close();
- }
- }
- private void buttonCancel_OnKeyPress(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- this.Close();
- }
- }
- public bool makeCLConnection(ref string cBIUrl,
- ref string userName,
- ref string userPassword,
- ref string userNamespace,
- ref bool isAnonymous)
- {
- Console.WriteLine("Connecting...");
- cBICMS = new contentManagerService1();
- if (cBICMS == null)
- {
- Console.WriteLine("Unable to get a contentManagerService1 instance.");
- return false;
- }
- //Test for Anonymous Authentication
- try
- {
- // sn_dg_prm_smpl_connect_start_1
- cBIUrl = "http://localhost:9300/p2pd/servlet/dispatch";
- cBICMS.Url = cBIUrl;
- // sn_dg_prm_smpl_connect_end_1
- searchPathMultipleObject homeDirSearchPath = new searchPathMultipleObject();
- homeDirSearchPath.Value = "~";
-
- baseClass[] bc = cBICMS.query ( homeDirSearchPath, new propEnum[]{} , new sort[]{}, new queryOptions () );
- if (bc != null)
- {
- isAnonymous = true;
- }
- }
- catch(Exception ex)
- {
- // Anonymous if OFF
- isAnonymous = false;
- if (0 != ex.Message.CompareTo("The client did something wrong"))
- {
- SamplesException.ShowExceptionMessage("\n" + ex.Message, false, "Error connecting to server");
- return false;
- }
- }
- if (isAnonymous == true)
- {
- // Anonymous if ON
- connectedToServer = true;
- Console.WriteLine("Connected.");
- return true;
- }
- else
- {
- // Attempt to log on.
- if ( (userName == null) || (0 == userName.CompareTo("")) )
- {
- Console.Write("userName: ");
- userName = Console.ReadLine();
- }
- if ( (userPassword == null) || (0 == userPassword.CompareTo("")) )
- {
- Console.Write("userPassword: ");
- userPassword = Console.ReadLine();
- }
- if ( (userNamespace == null) || (0 == userNamespace.CompareTo("")) )
- {
- Console.Write("userNamespace: ");
- userNamespace = Console.ReadLine();
- }
- SamplesLogon logon = new SamplesLogon(this);
- logon.specificUserLogon(false, userName, userPassword, userNamespace);
- if( !logon.loggedOn )
- {
- Console.WriteLine("Unable to connect to server." );
- connectedToServer = false;
- return false;
- }
- else
- {
- connectedToServer = true;
- savedUserName = logon.getUserName();
- savedUserPassword = logon.getUserPassword();
- savedNamespace = logon.getNamespace();
- Console.WriteLine("Connected.");
- return true;
- }
- }
- }
- public static account getLogonAccount(SamplesConnect connectedAs)
- {
- propEnum[] props =
- new propEnum[] { propEnum.searchPath, propEnum.defaultName, propEnum.policies };
- account myAccount = null;
- if (connectedAs.CBICMS == null)
- {
- Console.WriteLine("Invalid parameter passed to function logon.");
- return myAccount;
- }
- try
- {
- searchPathMultipleObject dummy = new searchPathMultipleObject();
- dummy.Value = "~";
- baseClass[] bc =
- connectedAs.CBICMS.query(dummy, props, new sort[] {}, new queryOptions());
- if ((bc != null) && (bc.Length == 1))
- {
- myAccount = (account)bc[0];
- }
- }
- catch (Exception ex)
- {
- //An exception here likely indicates the client is not currently
- //logged in, so the query fails.
- Console.WriteLine("Caught Exception:\n" + ex.Message);
- }
- return myAccount;
- }
- public credential getCredential()
- {
- baseClass[] results;
- searchPathMultipleObject credSearchPath = new searchPathMultipleObject();
- credSearchPath.Value = "~/credential[@name='Credential']";
- results = CBICMS.query(credSearchPath, new propEnum[] {}, new sort[] {}, new queryOptions());
- for (int i = 0; i < results.Length; i++)
- {
- if (results[i] is credential)
- {
- return (credential) results[i];
- }
- }
- return addCredential();
- }
- public credential addCredential()
- {
- credential mCredential = new credential();
- anyTypeProp mCredentials = new anyTypeProp();
- mCredentials.value = credentialString;
- baseClass[] addedObjects;
-
- //Prepare the name property for the new credential object
- multilingualToken[] names = new multilingualToken[1];
- names[0] = new multilingualToken();
- locale[] locales = getLocale();
- names[0].locale = locales[0].locale1;
- names[0].value = "Credential";
- multilingualTokenProp credNameTokenProp = new multilingualTokenProp();
- credNameTokenProp.value = names;
-
- //Add the searchPath, name and defaultname to the new credential object
- mCredential.name = credNameTokenProp;
- mCredential.credentials = mCredentials;
- baseClass[] addArray = new baseClass[1];
- addArray[0] = mCredential;
- //Add the credential object to the content store
- searchPathSingleObject parentPath = new searchPathSingleObject();
- parentPath.Value = getLogonAccount(this).searchPath.value;
- addOptions ao = new addOptions();
- ao.updateAction = updateActionEnum.replace;
- try
- {
- addedObjects = CBICMS.add(parentPath, addArray, ao);
- for (int i = 0; i < addedObjects.Length; i++)
- {
- if (addedObjects[i] is credential)
- {
- return (credential) addedObjects[i];
- }
- }
-
- }
- catch (Exception ex)
- {
- Console.WriteLine("Caught Exception:\n" + ex.Message);
- }
- return null;
- }
- public locale[] getLocale()
- {
- configurationData data = null;
- locale[] locales = null;
- configurationDataEnum[] config = new configurationDataEnum[1];
- config[0] = configurationDataEnum.serverLocale;
- try
- {
- /**
- * Use this method to retrieve global configuration data.
- *
- * Input Parameters
- *
- * config
- * Specifies the set of properties to be returned.
- *
- * Return Value
- * This method returns the server locale.
- */
- data = CBISS.getConfiguration(config);
- locales = data.serverLocale;
- if (locales == null)
- {
- Console.WriteLine("No serverLocale configured!");
- }
- }
- catch(Exception ex)
- {
- Console.WriteLine("Caught Exception:\n" + ex.Message);
- }
- return locales;
- }
- //property definition for the server URL
- public string CBIURL
- {
- get
- {
- return cBIUrl;
- }
- }
- public string credentialString
- {
- get
- {
- string credentialXML = "<credential>";
- //Namespace
- if (savedNamespace != "")
- {
- credentialXML += "<namespace>";
- credentialXML += savedNamespace;
- credentialXML += "</namespace>";
- }
-
- //Username
- credentialXML += "<username>";
- if (savedUserName == "")
- {
- credentialXML += "Anonymous";
- }
- else
- {
- credentialXML += savedUserName;
- }
- credentialXML += "</username>";
- //Password
- if (savedUserPassword != "")
- {
- credentialXML += "<password>";
- credentialXML += savedUserPassword;
- credentialXML += "</password>";
- }
- credentialXML += "</credential>";
- return credentialXML;
- }
- }
- //property definitions to give read access the various service objects
- //
- //header and url information is retrieved from the contentManagerService1 object
- //as this it the service used to connect and logon.
- public agentService CBIAS
- {
- get
- {
- // sn_dg_prm_smpl_connect_start_2
- if (cBIAS == null)
- {
- cBIAS = new agentService();
- cBIAS.Url = cBICMS.Url;
- }
- if (cBIAS.biBusHeaderValue == null)
- {
- cBIAS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- // sn_dg_prm_smpl_connect_end_2
- return cBIAS;
- }
- }
-
- public batchReportService1 CBIBRS
- {
- get
- {
- if (cBIBRS == null)
- {
- cBIBRS = new batchReportService1();
- cBIBRS.Url = cBICMS.Url;
- }
- if (cBIBRS.biBusHeaderValue == null)
- {
- cBIBRS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIBRS;
- }
- }
- public contentManagerService1 CBICMS
- {
- //This service is the initial connect and logon point.
- //It _must_ be initialized before calling this accessor.
- get
- {
- return cBICMS;
- }
- }
- public dataIntegrationService1 CBIDIS
- {
- get
- {
- if (cBIDIS == null)
- {
- cBIDIS = new dataIntegrationService1();
- cBIDIS.Url = cBICMS.Url;
- }
- if (cBIDIS.biBusHeaderValue == null)
- {
- cBIDIS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIDIS;
- }
- }
- public deliveryService1 CBIDS
- {
- get
- {
- if (cBIDS == null)
- {
- cBIDS = new deliveryService1();
- cBIDS.Url = cBICMS.Url;
- }
- if (cBIDS.biBusHeaderValue == null)
- {
- cBIDS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIDS;
- }
- }
- public eventManagementService1 CBIEMS
- {
- get
- {
- if (cBIEMS == null)
- {
- cBIEMS = new eventManagementService1();
- cBIEMS.Url = cBICMS.Url;
- }
- if (cBIEMS.biBusHeaderValue == null)
- {
- cBIEMS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIEMS;
- }
- }
- public jobService1 CBIJS
- {
- get
- {
- if (cBIJS == null)
- {
- cBIJS = new jobService1();
- cBIJS.Url = cBICMS.Url;
- }
- if (cBIJS.biBusHeaderValue == null)
- {
- cBIJS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIJS;
- }
- }
- public monitorService1 CBIMS
- {
- get
- {
- if (cBIMS == null)
- {
- cBIMS = new monitorService1();
- cBIMS.Url = cBICMS.Url;
- }
- if (cBIMS.biBusHeaderValue == null)
- {
- cBIMS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIMS;
- }
- }
- public reportService1 CBIRS
- {
- get
- {
- if (cBIRS == null)
- {
- cBIRS = new reportService1();
- cBIRS.Url = cBICMS.Url;
- }
- if (cBIRS.biBusHeaderValue == null)
- {
- cBIRS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBIRS;
- }
- }
- public systemService1 CBISS
- {
- get
- {
- if (cBISS == null)
- {
- cBISS = new systemService1();
- cBISS.Url = cBICMS.Url;
- }
- if (cBISS.biBusHeaderValue == null)
- {
- cBISS.biBusHeaderValue = cBICMS.biBusHeaderValue;
- }
- return cBISS;
- }
- }
- }
- }
|