/// <summary>
 /// Handles the Click event of the startChannelToolStripMenuItem control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void startChannelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         ChannelStatusView channel = lvwChannelStatus.SelectedObject as ChannelStatusView;
         if (channel != null)
         {
             EventAction action = new EventAction(StringEnum.GetStringValue(EventNotificationType.StartGateway));
             action.Values.Add(EventParameter.GatewayId, channel.Name);
             EventResponse response = RemotingHelper.NotifyEvent(ServiceEventListenerUrl, action);
             channel.Status = StringEnum.GetStringValue(GatewayStatus.Starting);
             lvwChannelStatus.RefreshObject(channel);
             //lvwChannelStatus.RefreshSelectedObjects();
             //FormHelper.ShowInfo(Resources.MsgGatewayStarting);
         }
         else
         {
             FormHelper.ShowInfo(Resources.MsgNoChannelSelected);
         }
     }
     catch (Exception ex)
     {
         FormHelper.ShowError(ex.Message);
     }
 }
        /// <summary>
        /// Checks the channels.
        /// </summary>
        private void CheckChannels()
        {
            try
            {
                List <ChannelStatusView> channels = new List <ChannelStatusView>();
                while (true)
                {
                    channels.Clear();
                    foreach (GatewayConfig gwConfig in GatewayConfig.All().OrderBy(gw => gw.Id))
                    {
                        try
                        {
                            EventAction action = new EventAction(StringEnum.GetStringValue(EventNotificationType.QueryGatewayStatus));
                            action.ActionType = EventAction.Synchronous;
                            action.Values.Add(EventParameter.GatewayId, gwConfig.Id);
                            EventResponse response = RemotingHelper.NotifyEvent(ServiceEventListenerUrl, action);

                            ChannelStatusView channel = new ChannelStatusView();
                            channel.Name = gwConfig.Id;
                            channel.Port = gwConfig.ComPort;

                            if (StringEnum.GetStringValue(EventNotificationResponse.Failed).Equals(response.Status))
                            {
                                channel.Status = StringEnum.GetStringValue(GatewayStatus.Stopped);
                            }
                            else
                            {
                                channel.Status         = response.Results[EventParameter.GatewayStatus];
                                channel.Operator       = response.Results[EventParameter.GatewayOperator];
                                channel.SignalStrength = response.Results[EventParameter.GatewaySignalStrength];
                            }

                            channels.Add(channel);
                        }
                        catch (Exception ex)
                        {
                            log.Error(string.Format("Error checking channel - [{0}]", gwConfig.Id));
                            log.Error(ex.Message, ex);
                        }
                    }
                    RefreshView(channels);
                    Thread.Sleep(ChannelPollingInterval);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }
        }
        /// <summary>
        /// Refreshes the view.
        /// </summary>
        private void RefreshView(List <ChannelStatusView> channels)
        {
            if (this.lvwChannelStatus.InvokeRequired)
            {
                SetListCallback callback = new SetListCallback(RefreshView);
                this.Invoke(callback, channels);
            }
            else
            {
                ChannelStatusView selectedChannel = lvwChannelStatus.SelectedObject as ChannelStatusView;

                lvwChannelStatus.BeginUpdate();
                lvwChannelStatus.ClearObjects();
                lvwChannelStatus.SetObjects(channels);

                lvwChannelStatus.EndUpdate();
                lvwChannelStatus.Refresh();

                if (selectedChannel != null)
                {
                    lvwChannelStatus.SelectObject(selectedChannel, true);
                }
            }
        }