コード例 #1
0
        }//refreshHardwareList()

        /// <summary>
        /// Query NBT for a list of balance configurations already defined on the server
        /// </summary>
        public void refreshConfigurationList()
        {
            //define how to update UI when the authentication attempt resolves
            NbtAuth.SessionCompleteEvent fetchConfigurations = delegate(NbtPublicClient Client)
            {
                CswNbtBalanceReturn ReceivedConfigurations = Client.ListBalanceConfigurations();
                string StatusText = ReceivedConfigurations.Authentication.AuthenticationStatus;
                if ("Authenticated" == StatusText)
                {
                    Dictionary <string, BalanceConfiguration> NewConfigurationList = new Dictionary <string, BalanceConfiguration>();

                    foreach (BalanceConfiguration Item in ReceivedConfigurations.Data.ConfigurationList)
                    {
                        NewConfigurationList.Add(Item.Name, Item);
                    }

                    if (false == NewConfigurationList.SequenceEqual(_configurationList))
                    {//only refresh the grid and pick lists if the configuration choices have changed
                        _configurationList = NewConfigurationList;
                        ConfigurationsGrid.BeginInvoke((Action)(_refreshConfigurationOptions));
                    }
                } //if( "Authenticated" == StatusText )
                //really annoying edge case first time program is loaded
                else if ("Object reference not set to an instance of an object." == StatusText || "Invalid URI: The format of the URI could not be determined." == StatusText)
                {
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Please provide connection details for ChemSW Live.\r\n"; }));
                    tabControl1.BeginInvoke((Action)(() => { tabControl1.SelectedTab = NBTTab; }));
                }
                else if ("NonExistentSession" != StatusText)
                {
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Connection Error: " + StatusText + "\r\n"; }));
                    tabControl1.BeginInvoke((Action)(() => { tabControl1.SelectedTab = NBTTab; }));
                }

                return(StatusText);
            };//SessionCompleteEvent fetchConfigurations

            //Perform a test connection asynchronously, using the managed thread pool
            BackgroundWorker GetConfigurations = new BackgroundWorker();

            GetConfigurations.DoWork += _authenticationClient.PerformActionAsync;
            GetConfigurations.RunWorkerAsync(fetchConfigurations);
        }//refreshConfigurationList()
コード例 #2
0
        /// <summary>
        /// Attached to Test Connection button on the NBT tab.
        /// Try to connect to NBT with the values entered, and display result to output box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void testConnectionButton_Click(object sender, EventArgs e)
        {
            //define how to update UI when the authentication attempt resolves
            NbtAuth.SessionCompleteEvent PrintStatusMessage = delegate(NbtPublicClient Client)
            {
                string StatusText = "";
                try
                {
                    CswNbtWebServiceSessionCswNbtAuthReturn AuthenticationRequest = Client.SessionInit(new CswWebSvcSessionAuthenticateDataAuthenticationRequest
                    {
                        CustomerId  = _authenticationClient.AccessId,
                        UserName    = _authenticationClient.UserId,
                        Password    = _authenticationClient.Password,
                        IsMobile    = true,
                        SuppressLog = true
                    });

                    StatusText = AuthenticationRequest.Authentication.AuthenticationStatus;
                }
                catch (Exception E)
                {
                    StatusText += E.Message;
                }
                switch (StatusText)
                {
                case "Failed":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "You have supplied an incorrect username or password for this account.\r\n"; }));
                    break;

                case "NonExistentAccessId":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "The Customer Id you have supplied does not exist in the database.\r\n"; }));
                    break;

                case "Authenticated":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Connection successful.\r\n"; }));
                    if (false == _authenticationClient.announceBalanceTimer.Enabled)
                    {
                        _authenticationClient.announceBalanceTimer.Start();
                    }
                    break;

                case "Object reference not set to an instance of an object.":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Please enter the connection details you use to connect to NBT.\r\n"; }));
                    break;

                case "Invalid URI: The format of the URI could not be determined.":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Please check the host address for your connection.\r\n"; }));
                    break;

                case "ShowLicense":
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "An administrator must accept the license for Cispro Cloud before using the client.\r\n"; }));
                    break;

                default:
                    ConnectionResultsOutput.Invoke((Action)(() => { ConnectionResultsOutput.Text += "Connection Error: " + StatusText + "\r\n"; }));
                    break;
                } //switch ( StatusText )
                return(StatusText);
            };    //SessionCompleteEvent PrintStatusMessage


            //Perform a test connection asynchronously, using the managed thread pool
            ConnectionResultsOutput.Text += "Attempting to connect...\r\n";
            BackgroundWorker NbtTask = new BackgroundWorker();

            NbtTask.DoWork += _authenticationClient.PerformActionAsync;
            NbtTask.RunWorkerAsync(PrintStatusMessage);
        }//testConnectionButton_Click( object sender, EventArgs e )