Ejemplo n.º 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()
Ejemplo n.º 2
0
        }//performBalanceCheck()

        /// <summary>
        /// Announces Balance to NBT
        /// </summary>
        public void announceBalance( )
        {
            if (_isEnabled)
            {
                NbtAuth.SessionCompleteEvent SendBalanceToServer = delegate(NbtPublicClient Client)
                {
                    SerialBalance Response = Client.UpdateBalanceData(_balanceData);
                    string        Status   = "NonExistentSession";
                    if (null != Response)
                    {
                        _balanceData.NodeId = Response.NodeId;
                        Status = "Authenticated";
                    }
                    return(Status);
                };

                AuthenticationClient.PerformAction(SendBalanceToServer);
            }
        }//announceBalance()
Ejemplo n.º 3
0
        /// <summary>
        /// Attached to Save button on Configuration tab.
        /// Attempt to send current form values to NBT as a new balance config.
        /// On success: if the balance is new, append to the hardware grid
        /// On failure: switch to NBT tab and print error to output box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveTemplateButton_Click(object sender, EventArgs e)
        {
            NbtAuth.SessionCompleteEvent sendConfiguration = delegate(NbtPublicClient Client)
            {
                string StatusText = "";
                BalanceConfiguration ConfigurationToSend = new BalanceConfiguration();
                ConfigurationToSend.Name           = templateNameBox.Text;
                ConfigurationToSend.RequestFormat  = templateRequestBox.Text;
                ConfigurationToSend.ResponseFormat = templateExpressionBox.Text;
                templateBaudRateBox.Invoke((Action)(() => { ConfigurationToSend.BaudRate = (int)templateBaudRateBox.SelectedItem; }));
                templateDataBitsBox.Invoke((Action)(() => { ConfigurationToSend.DataBits = (int)templateDataBitsBox.SelectedItem; }));
                templateParityBitBox.Invoke((Action)(() => { ConfigurationToSend.ParityBit = templateParityBitBox.SelectedValue.ToString(); }));
                templateStopBitsBox.Invoke((Action)(() => { ConfigurationToSend.StopBits = templateStopBitsBox.SelectedValue.ToString(); }));
                templateHandshakeBox.Invoke((Action)(() => { ConfigurationToSend.Handshake = templateHandshakeBox.SelectedValue.ToString(); }));


                StatusText = Client.registerBalanceConfiguration(ConfigurationToSend).Authentication.AuthenticationStatus;
                if (StatusText == "Authenticated")
                {
                    saveUserSettings(this, new EventArgs());
                    refreshConfigurationList();
                }
                else if (StatusText != "NonExistentSession")
                {
                    tabControl1.BeginInvoke((Action)(() => { tabControl1.SelectedTab = NBTTab; }));
                }
                return(StatusText);
            };    //SessionCompleteEvent fetchConfigurations


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

            NbtTask.DoWork += _authenticationClient.PerformActionAsync;
            NbtTask.RunWorkerAsync(sendConfiguration);
        }//saveTemplateButton_Click()
Ejemplo n.º 4
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 )