123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Xml;
- using System.IO;
- using System.Web.Services.Protocols;
- using System.Text;
- using cognosdotnet_10_2;
- namespace SamplesCommon
- {
-
-
-
- public class SamplesLogon : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.ComboBox namespaceBox;
- private System.Windows.Forms.TextBox userNameText;
- private System.Windows.Forms.TextBox passwordText;
- private System.Windows.Forms.Button logonButton;
- private System.Windows.Forms.Button cancelButton;
-
-
-
- private System.ComponentModel.Container components = null;
- public SamplesLogon( SamplesConnect connection )
- {
-
-
-
- InitializeComponent();
-
- cBICMS = connection.CBICMS;
- }
- public SamplesLogon(contentManagerService1 cmService)
- {
-
-
-
- InitializeComponent();
-
- cBICMS = cmService;
- }
-
-
-
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
-
-
-
-
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SamplesLogon));
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.namespaceBox = new System.Windows.Forms.ComboBox();
- this.userNameText = new System.Windows.Forms.TextBox();
- this.passwordText = new System.Windows.Forms.TextBox();
- this.logonButton = new System.Windows.Forms.Button();
- this.cancelButton = new System.Windows.Forms.Button();
- this.SuspendLayout();
-
-
-
- this.label1.Location = new System.Drawing.Point(16, 16);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(64, 24);
- this.label1.TabIndex = 0;
- this.label1.Text = "User Name:";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-
-
-
- this.label2.Location = new System.Drawing.Point(16, 48);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(64, 23);
- this.label2.TabIndex = 1;
- this.label2.Text = "Password:";
- this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-
-
-
- this.label3.Location = new System.Drawing.Point(16, 80);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(72, 24);
- this.label3.TabIndex = 2;
- this.label3.Text = "Namespace:";
- this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-
-
-
- this.namespaceBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.namespaceBox.BackColor = System.Drawing.SystemColors.Control;
- this.namespaceBox.Location = new System.Drawing.Point(88, 80);
- this.namespaceBox.Name = "namespaceBox";
- this.namespaceBox.Size = new System.Drawing.Size(184, 21);
- this.namespaceBox.TabIndex = 5;
-
-
-
- this.userNameText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.userNameText.Location = new System.Drawing.Point(88, 16);
- this.userNameText.Name = "userNameText";
- this.userNameText.Size = new System.Drawing.Size(184, 20);
- this.userNameText.TabIndex = 3;
- this.userNameText.Text = "";
-
-
-
- this.passwordText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.passwordText.Location = new System.Drawing.Point(88, 48);
- this.passwordText.Name = "passwordText";
- this.passwordText.PasswordChar = '*';
- this.passwordText.Size = new System.Drawing.Size(184, 20);
- this.passwordText.TabIndex = 4;
- this.passwordText.Text = "";
- this.passwordText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.passwordText_OnKeyPress);
-
-
-
- this.logonButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.logonButton.Location = new System.Drawing.Point(112, 128);
- this.logonButton.Name = "logonButton";
- this.logonButton.TabIndex = 6;
- this.logonButton.Text = "Logon";
- this.logonButton.Click += new System.EventHandler(this.logonButton_Click);
-
-
-
- this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.cancelButton.Location = new System.Drawing.Point(200, 128);
- this.cancelButton.Name = "cancelButton";
- this.cancelButton.TabIndex = 7;
- this.cancelButton.Text = "Cancel";
- this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
-
-
-
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(292, 166);
- this.Controls.Add(this.cancelButton);
- this.Controls.Add(this.logonButton);
- this.Controls.Add(this.passwordText);
- this.Controls.Add(this.userNameText);
- this.Controls.Add(this.namespaceBox);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "SamplesLogon";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Logon";
- this.Load += new System.EventHandler(this.SamplesLogon_Load);
- this.ResumeLayout(false);
- }
- #endregion
-
-
-
-
- private contentManagerService1 cBICMS = null;
-
-
-
-
- private bool isLoggedOn = false;
-
-
-
-
- private string defaultUserName = "";
- private string defaultPassword = "";
- private string defaultNamespace = "";
- private bool switchUserMode = false;
-
-
-
- public bool loggedOn
- {
- get {
- return isLoggedOn;
- }
- }
- private string[] getNamespaces()
- {
-
- String[] namespaces = new String[] {};
-
- try
- {
- searchPathMultipleObject rootSearchPath = new searchPathMultipleObject();
- rootSearchPath.Value = "~";
- cBICMS.query(rootSearchPath, null, new sort[] {},new queryOptions());
- }
- catch (System.Web.Services.Protocols.SoapException ex)
- {
- if (ex == null) { }
-
- }
- if (switchUserMode)
- {
-
- searchPathMultipleObject directorySearchPath = new searchPathMultipleObject();
- directorySearchPath.Value = "/directory/*";
- propEnum[] props =
- new propEnum[] { propEnum.searchPath, propEnum.defaultName };
- baseClass[] bcNamespaces = cBICMS.query(directorySearchPath, props, new sort[] {}, new queryOptions());
- if ( (bcNamespaces != null) && (bcNamespaces.GetLength(0) > 0) )
- {
- namespaces = new string[(bcNamespaces.GetLength(0)-1) * 2];
- for (int i=1; i < bcNamespaces.GetLength(0); i++)
- {
- namespaces[i-1] = bcNamespaces[i].defaultName.value;
- namespaces[i] = bcNamespaces[i].searchPath.value;
- }
- }
- }
- else
- {
-
-
- displayObject[] dob =
- cBICMS.biBusHeaderValue.CAM.exception.promptInfo.displayObjects;
- for (int i = 0; i < dob.Length; i++)
- {
- if (dob[i].name.Equals("CAMNamespace"))
- {
- promptOption[] pop = dob[i].promptOptions;
-
-
-
- if (pop != null)
- {
- namespaces = new string[pop.Length * 2];
- for (int j = 0, k = 0; k < pop.Length; j++, k++)
- {
- namespaces[j] = pop[k].value;
- namespaces[++j] = pop[k].id;
- }
- }
- else
- {
- namespaces = new string[2];
- namespaces[0] = dob[i].value;
- namespaces[1] = dob[i].value;
- }
- }
- }
- }
- return namespaces;
- }
-
-
-
-
-
-
- private void cancelButton_Click( object sender, System.EventArgs e )
- {
- isLoggedOn = false;
- this.Close();
- }
- private void passwordText_OnKeyPress(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- logonButton_Click(sender, e);
- }
- }
-
-
-
-
-
-
-
- private void logonButton_Click( object sender, System.EventArgs e )
- {
-
- if( namespaceBox.Text == null ) namespaceBox.Text = "";
- if( userNameText.Text == null ) userNameText.Text = "";
- if( passwordText.Text == null ) passwordText.Text = "";
- specificUserLogon(true, userNameText.Text, passwordText.Text, namespaceBox.Text);
- this.Close();
- }
- private void SamplesLogon_Load(object sender, System.EventArgs e)
- {
- string userName = getUserName();
- if ((userName != null) && (0 != userName.CompareTo("")) )
- {
- userNameText.Text = userName;
- }
-
-
-
- namespaceBox.Items.Clear();
- string[] namespaceInfo = getNamespaces();
- if ( (namespaceInfo == null) || (namespaceInfo.GetLength(0)<=0) )
- {
- System.Windows.Forms.MessageBox.Show(
- "Unable to connect to server",
- "Connect Failed");
- this.Close();
- return;
- }
-
- string[] namespaces = new string[namespaceInfo.Length / 2];
-
- for (int j = 0, k = 0; k < namespaceInfo.Length; j++, k++)
- {
- namespaces[j] = namespaceInfo[k++];
- namespaceBox.Items.Add(namespaceInfo[k]);
- }
- namespaceBox.SelectedIndex = 0;
- }
- public void specificUserLogon(bool guiMode, string userName, string userPassword, string userNamespace)
- {
- try
- {
-
- System.Text.StringBuilder credentialXML = new System.Text.StringBuilder("<credential>" );
- credentialXML.AppendFormat( "<namespace>{0}</namespace>", userNamespace );
- credentialXML.AppendFormat( "<username>{0}</username>", userName );
- credentialXML.AppendFormat( "<password>{0}</password>", userPassword );
- credentialXML.Append( "</credential>" );
-
- string encodedCredentials = credentialXML.ToString ();
- xmlEncodedXML xmlEncodedCredentials = new xmlEncodedXML();
- xmlEncodedCredentials.Value = encodedCredentials;
- searchPathSingleObject[] emptyRoleSearchPathList = new searchPathSingleObject[0];
- cBICMS.logon(xmlEncodedCredentials, null);
-
-
- setUserName(userName);
- setUserPassword(userPassword);
- setNamespace(userNamespace);
- isLoggedOn = true;
- }
- catch( SoapException ex )
- {
- isLoggedOn = false;
- SamplesException.ShowExceptionMessage( ex, guiMode, "Unable To Logon" );
- }
- catch (System.Exception ex)
- {
- isLoggedOn = false;
- SamplesException.ShowExceptionMessage( ex.Message, guiMode, "Unable To Logon" );
- }
- }
- public string getUserName()
- {
- if (defaultUserName == null)
- {
- return "";
- }
- return defaultUserName;
- }
-
- public void setUserName(string userName)
- {
- defaultUserName = userName;
- }
-
- public void setUserPassword(string password)
- {
- defaultPassword = password;
- }
-
- public string getUserPassword()
- {
- if (defaultPassword == null)
- {
- return "";
- }
- return defaultPassword;
- }
- public string getNamespace()
- {
- if (defaultNamespace == null)
- {
- return "";
- }
- return defaultNamespace;
- }
- public void setNamespace(string nmspace)
- {
- defaultNamespace = nmspace;
- }
- public void setSwitchUserMode(bool switchUser)
- {
- switchUserMode = true;
- }
- }
- }
|