コード例 #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
        }//refreshConfigurationList()

        /// <summary>
        /// Refresh the DataSource for the configurations grid and drop down to use the most recent dictionary
        /// </summary>
        private void _refreshConfigurationOptions()
        {
            ConfigurationsGrid.AutoGenerateColumns = false;
            if (_configurationList.Count > 0)
            {//todo: ideally, a less computationally heavy method of refreshing should be found for updates after the first
                ConfigurationsGrid.DataSource = _configurationList.Values.ToList();
                ConfigurationsGrid.Columns["configName"].DataPropertyName = "Name";
                ConfigurationsGrid.Columns["Request"].DataPropertyName    = "RequestFormat";
                ConfigurationsGrid.Columns["Response"].DataPropertyName   = "ResponseFormat";
                ConfigurationsGrid.Columns["BaudRate"].DataPropertyName   = "BaudRate";
                ConfigurationsGrid.Columns["ParityBit"].DataPropertyName  = "ParityBit";
                ConfigurationsGrid.Columns["DataBits"].DataPropertyName   = "DataBits";
                ConfigurationsGrid.Columns["StopBits"].DataPropertyName   = "StopBits";
                ConfigurationsGrid.Columns["Handshake"].DataPropertyName  = "Handshake";
                ConfigurationsGrid.Refresh();

                Configuration.DataSource    = new BindingSource(_configurationList, null);
                Configuration.DisplayMember = "Key";
                Configuration.ValueType     = typeof(BalanceConfiguration);
                Configuration.ValueMember   = "Value";

                loadUserSettings();
            } //if _configurationList.Count > 0
        }     //_refreshConfigurationOptions()