예제 #1
0
        /// <summary>Creates a new instance of the class, and logs into the server.</summary>
        /// <param name="serverUrl">The Server's URL</param>
        /// <param name="userName">The username to log in as.</param>
        /// <param name="userPassword">The password for the user to log in as.</param>
        /// <param name="appName">The application name.</param>
        /// <param name="hostName">The host name of the machine to pull tests for.</param>
        public SpiraConnect(string serverUrl, string userName, string userPassword, string appName, string hostName)
        {
            const string METHOD = ".ctor()";

            Logger.LogTrace(CLASS + METHOD + " Enter");

            this.ServerUrl    = serverUrl;
            this.UserName     = userName;
            this.UserPassword = userPassword;
            this.AppName      = AppName;
            this.HostName     = hostName;

            //Create the client.
            if (_client == null)
            {
                this._client = new SpiraImportExport.ImportExportClient();
                this._client.Endpoint.Address = new EndpointAddress(this.ServerUrl + IMPORT_WEB_SERVICES_URL);
                ConfigureBinding((BasicHttpBinding)this._client.Endpoint.Binding, this._client.Endpoint.Address.Uri);

                //Try logging in.
                if (!this._client.Connection_Authenticate2(this.UserName, this.UserPassword, this.AppName))
                {
                    Logger.LogTrace(CLASS + METHOD + " Couldn't log into SpiraTeam. Incorrect username / password.");
                    Logger.LogTrace(CLASS + METHOD + " Exit");
                    throw new Exception("Invalid username / password specified.");
                }
            }

            Logger.LogTrace(CLASS + METHOD + " Exit");
        }
        /// <summary>
        /// Creates the WCF endpoints
        /// </summary>
        /// <param name="fullUri">The URI</param>
        /// <returns>The client class</returns>
        /// <remarks>We need to do this in code because the app.config file is not available in VSTO</remarks>
        public static SpiraImportExport.ImportExportClient CreateClient(Uri fullUri)
        {
            //Configure the binding
            BasicHttpBinding httpBinding = new BasicHttpBinding();

            //Allow cookies and large messages
            httpBinding.AllowCookies           = true;
            httpBinding.MaxBufferSize          = 100000000;              //100MB
            httpBinding.MaxReceivedMessageSize = 100000000;              //100MB
            httpBinding.ReceiveTimeout         = new TimeSpan(0, 10, 0); //10 Minutes
            httpBinding.SendTimeout            = new TimeSpan(0, 10, 0); //10 Minutes
            httpBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
            httpBinding.ReaderQuotas.MaxDepth              = 2147483647;
            httpBinding.ReaderQuotas.MaxBytesPerRead       = 2147483647;
            httpBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
            httpBinding.ReaderQuotas.MaxArrayLength        = 2147483647;

            //Handle SSL if necessary
            if (fullUri.Scheme == "https")
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

                //Allow self-signed certificates
                PermissiveCertificatePolicy.Enact("");
            }
            else
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.None;
            }

            //Create the new client with endpoint and HTTP Binding
            EndpointAddress endpointAddress = new EndpointAddress(fullUri.AbsoluteUri);

            SpiraImportExport.ImportExportClient spiraImportExport = new SpiraImportExport.ImportExportClient(httpBinding, endpointAddress);

            //Modify the operation behaviors to allow unlimited objects in the graph
            foreach (var operation in spiraImportExport.Endpoint.Contract.Operations)
            {
                var behavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (behavior != null)
                {
                    behavior.MaxItemsInObjectGraph = 2147483647;
                }
            }

            return(spiraImportExport);
        }
예제 #3
0
        /// <summary>
        /// Logs into the specified project/domain combination
        /// </summary>
        /// <param name="sender">The sending object</param>
        /// <param name="e">The event arguments</param>
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            //Make sure that a login was entered
            if (this.txtLogin.Text.Trim() == "")
            {
                MessageBox.Show("You need to enter a SpiraTest login", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Make sure that a server was entered
            if (this.txtServer.Text.Trim() == "")
            {
                MessageBox.Show("You need to enter a SpiraTest web-server URL", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Store the info in settings for later
            Properties.Settings.Default.SpiraUrl      = this.txtServer.Text.Trim();
            Properties.Settings.Default.SpiraUserName = this.txtLogin.Text.Trim();
            if (chkPassword.Checked)
            {
                Properties.Settings.Default.SpiraPassword = this.txtPassword.Text;  //Don't trip in case it contains a space
            }
            else
            {
                Properties.Settings.Default.SpiraPassword = "";
            }
            Properties.Settings.Default.Save();

            //Default the Start Import and login button to disabled
            this.btnImport.Enabled  = false;
            this.btnLogin.Enabled   = false;
            this.progressBar1.Style = ProgressBarStyle.Marquee;

            try
            {
                //Instantiate the web-service proxy class and set the URL from the text box
                SpiraImportProxy = new SpiraImportExport.ImportExportClient();

                //Set the end-point and allow cookies
                SpiraImportProxy.Endpoint.Address = new EndpointAddress(Properties.Settings.Default.SpiraUrl + IMPORT_WEB_SERVICES_URL);
                BasicHttpBinding httpBinding = (BasicHttpBinding)SpiraImportProxy.Endpoint.Binding;
                ConfigureBinding(httpBinding, SpiraImportProxy.Endpoint.Address.Uri);

                //Authenticate asynchronously
                SpiraImportProxy.Connection_AuthenticateCompleted += new EventHandler <SpiraImportExport.Connection_AuthenticateCompletedEventArgs>(spiraImportExport_Connection_AuthenticateCompleted);
                SpiraImportProxy.Connection_AuthenticateAsync(Properties.Settings.Default.SpiraUserName, this.txtPassword.Text);
            }
            catch (TimeoutException exception)
            {
                // Handle the timeout exception.
                this.progressBar1.Style = ProgressBarStyle.Blocks;
                this.btnLogin.Enabled   = true;
                SpiraImportProxy.Abort();
                MessageBox.Show("A timeout error occurred! (" + exception.Message + ")", "Timeout Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CommunicationException exception)
            {
                // Handle the communication exception.
                this.progressBar1.Style = ProgressBarStyle.Blocks;
                this.btnLogin.Enabled   = true;

                SpiraImportProxy.Abort();
                MessageBox.Show("A communication error occurred! (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }