예제 #1
0
        private void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // When proxy connection instances are added at during start-up, items are deserialized first then assigned
            // an editing control afterwards so we must handle attaching to events when the property has changed. During
            // post-load normal run-time a new connection will be associated with its editing control during creation
            // before the collection has even attached to this event (since item won't be in list yet) and the InsertItem
            // event attachment will be executed.
            if (e.PropertyName == "ProxyConnectionEditor")
            {
                ProxyConnection item = sender as ProxyConnection;

                if ((object)item != null)
                {
                    ProxyConnectionEditor editorControl = item.ProxyConnectionEditor;

                    if ((object)editorControl != null)
                    {
                        editorControl.GotFocus             += editorControl_GotFocus;
                        editorControl.ConfigurationChanged += editorControl_ConfigurationChanged;
                        editorControl.ApplyChanges         += editorControl_ApplyChanges;
                        editorControl.EnabledStateChanged  += editorControl_EnabledStateChanged;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Removes the item at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the item to remove.</param>
        /// <exception cref="System.NotSupportedException">You are removing a newly added item and <see cref="System.ComponentModel.IBindingList.AllowRemove"/> is set to false.</exception>
        protected override void RemoveItem(int index)
        {
            ProxyConnection connection = this[index];

            // Raise event notifying consumers about the item about to be removed - this affords
            // an opportunity to cancel this activity if the deletion was accidental
            if (OnRemovingItem(connection))
            {
                // Detach from editor control events
                ProxyConnectionEditor editorControl = connection.ProxyConnectionEditor;

                if ((object)editorControl != null)
                {
                    editorControl.GotFocus             -= editorControl_GotFocus;
                    editorControl.ConfigurationChanged -= editorControl_ConfigurationChanged;
                    editorControl.ApplyChanges         -= editorControl_ApplyChanges;
                    editorControl.EnabledStateChanged  -= editorControl_EnabledStateChanged;
                }

                // Detach from proxy connection events
                connection.PropertyChanged -= item_PropertyChanged;

                // Remove item from list
                base.RemoveItem(index);
            }
        }
예제 #3
0
        private void editorControl_EnabledStateChanged(object sender, EventArgs <bool> e)
        {
            ProxyConnectionEditor editorControl = sender as ProxyConnectionEditor;

            if ((object)editorControl != null)
            {
                OnEnabledStateChanged(editorControl.ProxyConnection, e.Argument);
            }
        }
예제 #4
0
        private void editorControl_ApplyChanges(object sender, EventArgs e)
        {
            ProxyConnectionEditor editorControl = sender as ProxyConnectionEditor;

            if ((object)editorControl != null)
            {
                OnApplyChanges(editorControl.ProxyConnection);
            }
        }
예제 #5
0
        private void editorControl_ConfigurationChanged(object sender, EventArgs e)
        {
            ProxyConnectionEditor editorControl = sender as ProxyConnectionEditor;

            if ((object)editorControl != null)
            {
                OnConfigurationChanged(editorControl.ProxyConnection);
            }
        }
예제 #6
0
        // Bubble up proxy editor control events
        private void editorControl_GotFocus(object sender, EventArgs e)
        {
            ProxyConnectionEditor editorControl = sender as ProxyConnectionEditor;

            if ((object)editorControl != null)
            {
                OnGotFocus(editorControl.ProxyConnection);
            }
        }
        // Select specified control
        private void SelectProxyConnectionEditorControl(ProxyConnectionEditor editorControl)
        {
            if ((object)editorControl == null || editorControl.Selected)
            {
                return;
            }

            // Unselect all existing controls
            UnselectProxyConnectionEditorControls();

            editorControl.Selected = true;
            flowLayoutPanelProxyConnections.ScrollControlIntoView(editorControl);

            flowLayoutPanelProxyConnections.Refresh();
        }
        private void RemoveProxyConnectionEditorControl(ProxyConnection connection)
        {
            if ((object)connection != null)
            {
                ProxyConnectionEditor editorControl = connection.ProxyConnectionEditor;

                if ((object)editorControl != null)
                {
                    flowLayoutPanelProxyConnections.Controls.Remove(editorControl);
                    editorControl.Dispose();
                }
            }

            ConfigurationSaved = false;
            Application.DoEvents();
        }
        private void AddProxyConnectionEditorControl(ProxyConnection connection)
        {
            toolTipNewHelp.Hide(this);

            // Create a new editing control for the proxy connection
            ProxyConnectionEditor editorControl = new ProxyConnectionEditor
            {
                ProxyConnection = connection
            };

            flowLayoutPanelProxyConnections.Controls.Add(editorControl);
            editorControl.buttonApply.Enabled = m_lastConnectedState;
            bindingSource.MoveLast();

            ConfigurationSaved = false;
            Application.DoEvents();
        }
예제 #10
0
        /// <summary>
        /// Inserts the specified item in the list at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index where the item is to be inserted.</param>
        /// <param name="connection">The item to insert in the list.</param>
        protected override void InsertItem(int index, ProxyConnection connection)
        {
            ProxyConnectionEditor editorControl = connection.ProxyConnectionEditor;

            // Attach to proxy connection events
            connection.PropertyChanged += item_PropertyChanged;

            // Attach to editor control events
            if ((object)editorControl != null)
            {
                editorControl.GotFocus             += editorControl_GotFocus;
                editorControl.ConfigurationChanged += editorControl_ConfigurationChanged;
                editorControl.ApplyChanges         += editorControl_ApplyChanges;
                editorControl.EnabledStateChanged  += editorControl_EnabledStateChanged;
            }

            base.InsertItem(index, connection);
        }
예제 #11
0
 private void ApplyStreamProxyStatusUpdate(ProxyConnectionEditor editorControl, StreamProxyStatus proxyStatus)
 {
     editorControl.ConnectionState  = proxyStatus.ConnectionState;
     editorControl.ConnectionStatus = proxyStatus.RecentStatusMessages;
 }
예제 #12
0
        private void m_serviceConnection_ConnectionState(object sender, EventArgs <bool> e)
        {
            bool connected = e.Argument;

            // Only refresh controls if state has actually changed
            if (connected != m_lastConnectedState)
            {
                m_lastConnectedState = connected;

                BeginInvoke((Action)(() => toolStripStatusLabelState.Text = connected ? "Connected to Service" : "Disconnected from Service"));
                BeginInvoke((Action)(() => toolStripStatusLabelState.Image = imageList.Images[connected ? 0 : 1]));

                if ((object)m_refreshProxyStatusTimer != null)
                {
                    m_refreshProxyStatusTimer.Enabled = connected;
                }

                BeginInvoke((Action)(() => toolStripButtonDownloadConfig.Enabled = connected));
                BeginInvoke((Action)(() => toolStripButtonUploadConfig.Enabled = connected));
                BeginInvoke((Action)(() => toolStripButtonRestartService.Enabled = connected));

                // Apply changes to proxy connection editors based on service connectivity state
                if ((object)m_proxyConnections != null)
                {
                    lock (m_proxyConnections)
                    {
                        foreach (ProxyConnection proxyConnection in m_proxyConnections)
                        {
                            ProxyConnectionEditor editorControl = proxyConnection.ProxyConnectionEditor;

                            if ((object)editorControl != null)
                            {
                                // Reset all connection indication bubbles to gray when disconnected
                                if (!connected)
                                {
                                    BeginInvoke((Action)(() => editorControl.ConnectionState = ConnectionState.Disabled));
                                }

                                // The apply button should only be enabled when service is connected
                                BeginInvoke((Action)(() => editorControl.buttonApply.Enabled = connected));
                            }
                        }
                    }
                }

                // If we are now connected and no configuration is loaded - we download config from the server
                if (connected)
                {
                    if (!m_configRequested && ((object)m_proxyConnections == null || m_proxyConnections.Count == 0))
                    {
                        m_configRequested = true;

                        // Kick-off request for configuration download from another thread to let event
                        // handler the state change on the service connection complete gracefully
                        ThreadPool.QueueUserWorkItem(state =>
                        {
                            if ((object)m_serviceConnection != null)
                            {
                                if (MessageBox.Show("Connected to service. Would you like to download the current running configuration?", Tag.ToNonNullString(Text), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    m_serviceConnection.SendCommand("DownloadConfig");
                                }
                            }
                        });
                    }
                }
                else
                {
                    m_configRequested = false;
                }

                BeginInvoke((Action)Refresh);
            }
        }