Example #1
0
        public SledTargetsForm(List<ISledTarget> lstTargets, ISledTarget selectedTarget)
        {
            InitializeComponent();

            m_lstView.ListViewItemSorter = new TargetSorter();

            // Add each plugin as a category
            foreach (var plugin in m_networkPluginService.Get.NetworkPlugins)
            {
                var lstItem = new ListViewItem(plugin.Protocol) { Tag = plugin };
                m_lstView.Items.Add(lstItem);
            }

            // Store list reference
            m_lstTargets = lstTargets;

            // Add list contents to ListView
            foreach (var target in m_lstTargets)
            {
                var lstItem = CreateItemFromTarget(target);

                // Check mark selected item
                if (target == selectedTarget)
                    lstItem.Checked = true;

                m_lstView.Items.Add(lstItem);
            }

            if (m_lstView.Items.Count > 0)
                AdjustColumnHeaders();

            UpdateButtonStates();
        }
Example #2
0
 private static int ComparePluginToTarget(ISledNetworkPlugin plugin, ISledTarget target)
 {
     return
         (string.Compare(
              plugin.Protocol,
              target.Plugin.Protocol));
 }
Example #3
0
 private void SocketDisconnected(object sender, ISledTarget target)
 {
     if (DisconnectedEvent != null)
     {
         DisconnectedEvent(this, target);
     }
 }
Example #4
0
 private static int CompareTargetToTarget(ISledTarget target1, ISledTarget target2)
 {
     return
         (target1.Plugin == target2.Plugin
             ? string.Compare(target1.Name, target2.Name)
             : string.Compare(target1.Plugin.Protocol, target2.Plugin.Protocol));
 }
Example #5
0
        public void Connect(ISledTarget target)
        {
            var tcpTarget = target as SledTcpTarget;

            if (tcpTarget == null)
            {
                throw new InvalidOperationException("target is not a TcpTarget");
            }

            m_socket                     = new TargetTcpSocket(1000);
            m_socket.Connected          += SocketConnected;
            m_socket.Disconnected       += SocketDisconnected;
            m_socket.DataReady          += SocketDataReady;
            m_socket.UnHandledException += SocketUnHandledException;

            try
            {
                m_socket.Connect(tcpTarget);
            }
            catch (Exception ex)
            {
                if (UnHandledExceptionEvent != null)
                {
                    UnHandledExceptionEvent(this, ex);
                }
            }
        }
Example #6
0
        public bool TryGetSelectedTarget(out ISledTarget target)
        {
            target = null;

            foreach (ListViewItem lstItem in m_lstView.CheckedItems)
                target = lstItem.Tag as ISledTarget;

            return target != null;
        }
Example #7
0
        /// <summary>
        /// Connects using IPEndPoint</summary>
        /// <param name="target">Target</param>
        public void Connect(ISledTarget target)
        {
            lock (m_syncSocket)
            {
                if (m_connectionInProgress)
                {
                    return;
                }
            }

            if (IsConnected)
            {
                return;
            }

            lock (m_syncSocket)
            {
                if (m_theSocket != null)
                {
                    m_theSocket.Close();
                    m_theSocket = null;
                    m_curTarget = null;
                }
            }

            // try to connect;
            try
            {
                lock (m_syncSocket)
                {
                    var ipaddr = target.EndPoint.Address;
                    m_theSocket = new Socket(ipaddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                    {
                        Blocking    = true,
                        SendTimeout = 5000
                    };

                    //m_theSocket.ExclusiveAddressUse = true;
                    m_theSocket.BeginConnect(ipaddr, target.EndPoint.Port, m_connectClb, target);
                    m_connectionInProgress = true;
                }
            }
            catch (Exception ex)
            {
                lock (m_syncSocket)
                {
                    if (m_theSocket != null)
                    {
                        m_theSocket.Close();
                        m_theSocket = null;
                        m_curTarget = null;
                    }
                }
                OnUnHandledException(ex);
            }
        }
Example #8
0
        public SledTargetForm(ISledTarget target)
        {
            InitializeComponent();

            // Add protocols to combo box
            foreach (var netPlugin in m_networkPluginService.Get.NetworkPlugins)
            {
                if (netPlugin is ISledNetworkPluginTargetFormCustomizer)
                {
                    var customizer = (ISledNetworkPluginTargetFormCustomizer)netPlugin;
                    if (!customizer.AllowProtocolOption)
                    {
                        continue;
                    }
                }

                m_cmbProtocol.Items.Add(new PluginTextAssociation(netPlugin));

                //
                // Add settings control from each plugin
                //

                // Create plugin defined user control
                var userControl = netPlugin.CreateSettingsControl(target);

                // Move inside the group box a bit
                userControl.Location = new System.Drawing.Point(10, 15);

                // Set up references
                userControl.Tag = netPlugin;
                m_dictControls.Add(netPlugin, userControl);

                // Add control to group box
                m_grpProtocolSettings.Controls.Add(userControl);

                // Hide control for now
                userControl.Hide();
            }

            // Select a protocol
            if (target == null)
            {
                // Select TCP by default
                SelectProtocol("TCP");
            }
            else
            {
                m_targetDefault = target;

                // Set up from existing details
                m_txtName.Text = target.Name;
                m_txtHost.Text = target.EndPoint.Address.ToString();
                m_txtPort.Text = target.EndPoint.Port.ToString();
                SelectProtocol(target.Plugin);
            }
        }
Example #9
0
        private void NetPluginPluginsReadyEvent(ISledTarget target)
        {
            // Fake event

            // Fire event
            PluginsReady.Raise(this, new SledDebugServiceEventArgs(target));

            // Respond saying we're ready to go
            SendScmp(new Shared.Scmp.Ready(SledPluginId));
        }
Example #10
0
        public bool TryGetSelectedTarget(out ISledTarget target)
        {
            target = null;

            foreach (ListViewItem lstItem in m_lstView.CheckedItems)
            {
                target = lstItem.Tag as ISledTarget;
            }

            return(target != null);
        }
Example #11
0
        public SledTargetForm(ISledTarget target)
        {
            InitializeComponent();

            // Add protocols to combo box
            foreach (var netPlugin in m_networkPluginService.Get.NetworkPlugins)
            {
                if (netPlugin is ISledNetworkPluginTargetFormCustomizer)
                {
                    var customizer = (ISledNetworkPluginTargetFormCustomizer)netPlugin;
                    if (!customizer.AllowProtocolOption)
                        continue;
                }

                m_cmbProtocol.Items.Add(new PluginTextAssociation(netPlugin));
                
                //
                // Add settings control from each plugin
                //

                // Create plugin defined user control
                var userControl = netPlugin.CreateSettingsControl(target);

                // Move inside the group box a bit
                userControl.Location = new System.Drawing.Point(10, 15);
                
                // Set up references
                userControl.Tag = netPlugin;
                m_dictControls.Add(netPlugin, userControl);

                // Add control to group box
                m_grpProtocolSettings.Controls.Add(userControl);

                // Hide control for now
                userControl.Hide();
            }

            // Select a protocol
            if (target == null)
            {
                // Select TCP by default
                SelectProtocol("TCP");
            }
            else
            {
                m_targetDefault = target;

                // Set up from existing details
                m_txtName.Text = target.Name;
                m_txtHost.Text = target.EndPoint.Address.ToString();
                m_txtPort.Text = target.EndPoint.Port.ToString();
                SelectProtocol(target.Plugin);
            }
        }
Example #12
0
        private void NetPluginReadyEvent(ISledTarget target)
        {
            // Fake event

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetReady, target));

            // Fire event
            Ready.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #13
0
        private void AddNewTarget(ISledTarget target)
        {
            if (target == null)
                return;

            m_lstTargets.Add(target);

            var lstItem = CreateItemFromTarget(target);
            m_lstView.Items.Add(lstItem);

            AdjustColumnHeaders();
        }
Example #14
0
 /// <summary>
 /// Constructor with parameters
 /// </summary>
 /// <param name="gfx">GDI+ drawing surface</param>
 /// <param name="bounds">Bounding rectangle for drawing</param>
 /// <param name="font">Font</param>
 /// <param name="selected">Whether item selected</param>
 /// <param name="item">ISledTarget item being rendered</param>
 /// <param name="textColor">Text color</param>
 /// <param name="highlightTextColor">Highlight text color</param>
 /// <param name="highlightBackColor">Highlight background color</param>
 public SledNetworkTargetsFormRenderArgs(Graphics gfx, Rectangle bounds, Font font, bool selected, ISledTarget item, Color textColor, Color highlightTextColor, Color highlightBackColor)
 {
     Graphics           = gfx;
     Bounds             = bounds;
     Font               = font;
     Selected           = selected;
     Item               = item;
     DrawDefault        = false;
     TextColor          = textColor;
     HighlightTextColor = highlightTextColor;
     HighlightBackColor = highlightBackColor;
 }
Example #15
0
        private void NetPluginConnectingEvent(ISledTarget target)
        {
            // Fake event

            m_curTarget = target;

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetConnectionNegotiating, target));

            // Fire event
            Connecting.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #16
0
        private void OnConnect(ISledTarget trg)
        {
            var handler = Connected;

            m_curTarget = trg;

            if (handler != null)
            {
                m_cctx.Send(delegate
                {
                    handler(this, trg);
                }, null);
            }
        }
Example #17
0
        private void Connect(ISledTarget target)
        {
            CurrentlyHitBp = null;
            m_lastDebugCmd = DebugCommand.Default;

            try
            {
                Freeze();

                if (target == null)
                {
                    throw new NullReferenceException("Target is null!");
                }

                if (target.Plugin == null)
                {
                    throw new NullReferenceException("No network plugin found or specified!");
                }

                // Grab network plugin from target
                m_netPlugin = target.Plugin;

                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(Localization.SledTargetConnectingTo, target));

                SetEndianness(Endian.Unknown);
                IsConnecting = true;
                m_recvBuf.Reset();

                CreateScmpLoggingFile();

                // Subscribe to events
                m_netPlugin.ConnectedEvent          += NetPluginConnectedEvent;
                m_netPlugin.DisconnectedEvent       += NetPluginDisconnectedEvent;
                m_netPlugin.DataReadyEvent          += NetPluginDataReadyEvent;
                m_netPlugin.UnHandledExceptionEvent += NetPluginUnHandledExceptionEvent;

                // Fire event
                DebugConnect.Raise(this, new SledDebugServiceEventArgs(target));

                // Try and connect
                m_netPlugin.Connect(target);
            }
            catch (Exception ex)
            {
                NetPluginUnHandledExceptionEvent(m_netPlugin, ex);
            }
        }
Example #18
0
        private void AddNewTarget(ISledTarget target)
        {
            if (target == null)
            {
                return;
            }

            m_lstTargets.Add(target);

            var lstItem = CreateItemFromTarget(target);

            m_lstView.Items.Add(lstItem);

            AdjustColumnHeaders();
        }
Example #19
0
        public bool Load(out ISledTarget target, XmlElement elem)
        {
            target = null;

            if (elem == null)
            {
                return(false);
            }

            var bSuccessful = false;

            try
            {
                var name = elem.GetAttribute("name");
                if (string.IsNullOrEmpty(name))
                {
                    return(false);
                }

                var ipaddress = elem.GetAttribute("ipaddress");
                if (string.IsNullOrEmpty(ipaddress))
                {
                    return(false);
                }

                IPAddress ipAddr;
                if (!IPAddress.TryParse(ipaddress, out ipAddr))
                {
                    return(false);
                }

                int port;
                if (!int.TryParse(elem.GetAttribute("port"), out port))
                {
                    return(false);
                }

                target      = CreateAndSetup(name, new IPEndPoint(ipAddr, port), null);
                bSuccessful = target != null;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(SledMessageType.Error, "{0}: Exception loading settings: {1}", this, ex.Message);
                target = null;
            }

            return(bSuccessful);
        }
Example #20
0
        private static ListViewItem CreateItemFromTarget(ISledTarget target)
        {
            var lstItem =
                new ListViewItem(
                    new[]
            {
                target.Name,
                target.EndPoint.Address.ToString(),
                target.EndPoint.Port.ToString()
            })
            {
                Tag = target
            };

            return(lstItem);
        }
Example #21
0
        private void NetPluginDisconnectedEvent(object sender, ISledTarget target)
        {
            try
            {
                m_recvBuf.Reset();

                SetEndianness(Endian.Unknown);

                IsConnected              = false;
                IsDebugging              = false;
                IsConnecting             = false;
                m_bAuthenticated         = false;
                IsUpdateInProgress       = false;
                CurrentlyHitBp           = null;
                IsCurrentlyHitBpActualBp = false;

                Disconnected.Raise(this, new SledDebugServiceEventArgs(target));

                // Update status text
                m_connectStatus.Text = Localization.SledDisconnected;

                if (target != null)
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledTargetDisconnectedFrom, target));
                }

                m_curTarget = null;

                // Unsubscribe from events & release resources
                m_netPlugin.ConnectedEvent          -= NetPluginConnectedEvent;
                m_netPlugin.DisconnectedEvent       -= NetPluginDisconnectedEvent;
                m_netPlugin.DataReadyEvent          -= NetPluginDataReadyEvent;
                m_netPlugin.UnHandledExceptionEvent -= NetPluginUnHandledExceptionEvent;
                m_netPlugin.Dispose();
                m_netPlugin = null;
            }
            finally
            {
                Thaw();
            }
        }
Example #22
0
        public bool Save(ISledTarget target, XmlElement elem)
        {
            if (elem == null)
            {
                return(false);
            }

            var tcpTarget = target as SledTcpTarget;

            if (tcpTarget == null)
            {
                return(false);
            }

            elem.SetAttribute("name", tcpTarget.Name);
            elem.SetAttribute("ipaddress", tcpTarget.EndPoint.Address.ToString());
            elem.SetAttribute("port", tcpTarget.EndPoint.Port.ToString());

            return(true);
        }
Example #23
0
        public SledTargetsForm(List <ISledTarget> lstTargets, ISledTarget selectedTarget)
        {
            InitializeComponent();

            m_lstView.ListViewItemSorter = new TargetSorter();

            // Add each plugin as a category
            foreach (var plugin in m_networkPluginService.Get.NetworkPlugins)
            {
                var lstItem = new ListViewItem(plugin.Protocol)
                {
                    Tag = plugin
                };
                m_lstView.Items.Add(lstItem);
            }

            // Store list reference
            m_lstTargets = lstTargets;

            // Add list contents to ListView
            foreach (var target in m_lstTargets)
            {
                var lstItem = CreateItemFromTarget(target);

                // Check mark selected item
                if (target == selectedTarget)
                {
                    lstItem.Checked = true;
                }

                m_lstView.Items.Add(lstItem);
            }

            if (m_lstView.Items.Count > 0)
            {
                AdjustColumnHeaders();
            }

            UpdateButtonStates();
        }
Example #24
0
        public void Connect(ISledTarget target)
        {
            var tcpTarget = target as SledTcpTarget;
            if (tcpTarget == null)
                throw new InvalidOperationException("target is not a TcpTarget");

            m_socket = new TargetTcpSocket(1000);
            m_socket.Connected += SocketConnected;
            m_socket.Disconnected += SocketDisconnected;
            m_socket.DataReady += SocketDataReady;
            m_socket.UnHandledException += SocketUnHandledException;

            try
            {
                m_socket.Connect(tcpTarget);
            }
            catch (Exception ex)
            {
                if (UnHandledExceptionEvent != null)
                    UnHandledExceptionEvent(this, ex);
            }
        }        
Example #25
0
        private void NetPluginConnectedEvent(object sender, ISledTarget target)
        {
            if (!m_bAuthenticated)
            {
                NetPluginConnectingEvent(target);
            }
            else
            {
                IsConnecting = false;
                IsConnected  = true;
                IsDebugging  = true;

                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(Localization.SledTargetConnectionEstablishedTo, target));

                // Update status text
                m_connectStatus.Text = Localization.SledConnected + ": " + target;

                // Fire event
                Connected.Raise(this, new SledDebugServiceEventArgs(target));
            }
        }
Example #26
0
 public SledNetworkPluginTargetFormSettings CreateSettingsControl(ISledTarget target)
 {
     return new SledTcpSettingsControl(target);
 }
Example #27
0
        public bool Save(ISledTarget target, XmlElement elem)
        {
            if (elem == null)
                return false;

            var tcpTarget = target as SledTcpTarget;
            if (tcpTarget == null)
                return false;

            elem.SetAttribute("name", tcpTarget.Name);
            elem.SetAttribute("ipaddress", tcpTarget.EndPoint.Address.ToString());
            elem.SetAttribute("port", tcpTarget.EndPoint.Port.ToString());

            return true;
        }
Example #28
0
        public bool Load(out ISledTarget target, XmlElement elem)
        {
            target = null;

            if (elem == null)
                return false;

            var bSuccessful = false;

            try
            {
                var name = elem.GetAttribute("name");
                if (string.IsNullOrEmpty(name))
                    return false;

                var ipaddress = elem.GetAttribute("ipaddress");
                if (string.IsNullOrEmpty(ipaddress))
                    return false;

                IPAddress ipAddr;
                if (!IPAddress.TryParse(ipaddress, out ipAddr))
                    return false;

                int port;
                if (!int.TryParse(elem.GetAttribute("port"), out port))
                    return false;

                target = CreateAndSetup(name, new IPEndPoint(ipAddr, port), null);
                bSuccessful = target != null;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(SledMessageType.Error, "{0}: Exception loading settings: {1}", this, ex.Message);
                target = null;
            }
            
            return bSuccessful;
        }
Example #29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 /// <param name="scmp">SLED Control Message Protocol (SCMP) payload</param>
 public SledDebugServiceEventArgs(ISledTarget target, Scmp.IScmp scmp)
     : this(target, null, scmp)
 {
 }
Example #30
0
 private static int CompareTargetToTarget(ISledTarget target1, ISledTarget target2)
 {
     return
         target1.Plugin == target2.Plugin
             ? string.Compare(target1.Name, target2.Name)
             : string.Compare(target1.Plugin.Protocol, target2.Plugin.Protocol);
 }
Example #31
0
 private SledDebugServiceEventArgs(ISledTarget target, string[] msg, Scmp.IScmp scmp)
 {
     m_target = target;
     m_msg    = msg;
     m_scmp   = scmp;
 }
Example #32
0
 public SledNetworkPluginTargetFormSettings CreateSettingsControl(ISledTarget target)
 {
     return(new SledTcpSettingsControl(target));
 }
Example #33
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 /// <param name="scmp">SLED Control Message Protocol (SCMP) payload</param>
 public SledDebugServiceEventArgs(ISledTarget target, Scmp.IScmp scmp)
     : this(target, null, scmp)
 {
 }
Example #34
0
 private SledDebugServiceEventArgs(ISledTarget target, string[] msg, Scmp.IScmp scmp)
 {
     m_target = target;
     m_msg = msg;
     m_scmp = scmp;
 }
Example #35
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 /// <param name="msg">Message</param>
 public SledDebugServiceEventArgs(ISledTarget target, string[] msg)
     : this(target, msg, null)
 {
 }
Example #36
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 public SledDebugServiceEventArgs(ISledTarget target)
     : this(target, null, null)
 {
 }
Example #37
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 public SledDebugServiceEventArgs(ISledTarget target)
     : this(target, null, null)
 {
 }
Example #38
0
        private static ListViewItem CreateItemFromTarget(ISledTarget target)
        {
            var lstItem =
                new ListViewItem(
                    new[]
                    {
                        target.Name,
                        target.EndPoint.Address.ToString(),
                        target.EndPoint.Port.ToString()
                    }) { Tag = target };

            return lstItem;
        }
Example #39
0
        private void OnConnect(ISledTarget trg)
        {
            var handler = Connected;
            m_curTarget = trg;

            if (handler != null)
            {
                m_cctx.Send(delegate
                {
                    handler(this, trg);
                }, null);
            }
        }
Example #40
0
        private void BtnOkClick(object sender, EventArgs e)
        {
            // Verify name not empty
            if (string.IsNullOrEmpty(m_txtName.Text.Trim()))
            {
                ShowFailureAndDontClose(
                    "Name can't be empty!",
                    m_txtName);

                return;
            }

            // Verify host not empty
            if (string.IsNullOrEmpty(m_txtHost.Text))
            {
                ShowFailureAndDontClose(
                    "Host can't be empty!",
                    m_txtHost);

                return;
            }

            // Verify host actual host
            IPAddress ipAddr;
            if (!IPAddress.TryParse(m_txtHost.Text, out ipAddr))
            {
                try
                {
                    var hostEntry = Dns.GetHostEntry(m_txtHost.Text);
                    ipAddr = hostEntry.AddressList.FirstOrDefault();
                }
                catch (ArgumentNullException) { }
                catch (ArgumentException) { }
                catch (System.Net.Sockets.SocketException) { }
            }

            if (ipAddr == null)
            {
                ShowFailureAndDontClose(
                    "Invalid host!",
                    m_txtHost);

                return;
            }

            // Verify port not empty
            if (string.IsNullOrEmpty(m_txtPort.Text))
            {
                ShowFailureAndDontClose(
                    "Port can't be empty!",
                    m_txtPort);

                return;
            }

            // Verify port is a valid number
            int port;
            if (!int.TryParse(m_txtPort.Text, out port))
            {
                ShowFailureAndDontClose(
                    "Port isn't a number!",
                    m_txtPort);

                return;
            }

            // Make sure port within valid range
            if ((port < IPEndPoint.MinPort) || (port > IPEndPoint.MaxPort))
            {
                ShowFailureAndDontClose(
                    string.Format(
                        "Port must be within the range {0} to {1}!",
                        IPEndPoint.MinPort,
                        IPEndPoint.MaxPort),
                    m_txtPort);

                return;
            }

            // Make sure valid protocol selected
            var assoc = m_cmbProtocol.SelectedItem as PluginTextAssociation;
            if (assoc == null)
            {
                ShowFailureAndDontClose(
                    "A valid protocol must be selected!",
                    m_cmbProtocol);

                return;
            }

            // Verify network plugin still available
            var bFoundPlugin =
                m_networkPluginService.Get.NetworkPlugins.Any(
                    netPlugin => assoc.NetworkPlugin == netPlugin);

            if (!bFoundPlugin)
            {
                ShowFailureAndDontClose(
                    "The selected protocol is no longer valid!",
                    m_cmbProtocol);

                return;
            }

            SledNetworkPluginTargetFormSettings settings;
            if (!TryGetSettings(assoc.NetworkPlugin, out settings))
            {
                ShowFailureAndDontClose(
                    "The selected protocol is no longer valid!",
                    m_cmbProtocol);

                return;
            }

            string settingsMsg;
            Control settingsControl;
            if (settings.ContainsErrors(out settingsMsg, out settingsControl))
            {
                ShowFailureAndDontClose(
                    settingsMsg,
                    settingsControl);

                return;
            }

            // Finally create the target
            Target =
                assoc.NetworkPlugin.CreateAndSetup(
                    m_txtName.Text.Trim(),
                    new IPEndPoint(ipAddr, port),
                    settings.GetDataBlob());
        }
Example #41
0
 private void SocketDisconnected(object sender, ISledTarget target)
 {
     if (DisconnectedEvent != null)
         DisconnectedEvent(this, target);
 }
Example #42
0
        private void BtnOkClick(object sender, EventArgs e)
        {
            // Verify name not empty
            if (string.IsNullOrEmpty(m_txtName.Text.Trim()))
            {
                ShowFailureAndDontClose(
                    "Name can't be empty!",
                    m_txtName);

                return;
            }

            // Verify host not empty
            if (string.IsNullOrEmpty(m_txtHost.Text))
            {
                ShowFailureAndDontClose(
                    "Host can't be empty!",
                    m_txtHost);

                return;
            }

            // Verify host actual host
            IPAddress ipAddr;

            if (!IPAddress.TryParse(m_txtHost.Text, out ipAddr))
            {
                try
                {
                    var hostEntry = Dns.GetHostEntry(m_txtHost.Text);
                    ipAddr = hostEntry.AddressList.FirstOrDefault();
                }
                catch (ArgumentNullException) { }
                catch (ArgumentException) { }
                catch (System.Net.Sockets.SocketException) { }
            }

            if (ipAddr == null)
            {
                ShowFailureAndDontClose(
                    "Invalid host!",
                    m_txtHost);

                return;
            }

            // Verify port not empty
            if (string.IsNullOrEmpty(m_txtPort.Text))
            {
                ShowFailureAndDontClose(
                    "Port can't be empty!",
                    m_txtPort);

                return;
            }

            // Verify port is a valid number
            int port;

            if (!int.TryParse(m_txtPort.Text, out port))
            {
                ShowFailureAndDontClose(
                    "Port isn't a number!",
                    m_txtPort);

                return;
            }

            // Make sure port within valid range
            if ((port < IPEndPoint.MinPort) || (port > IPEndPoint.MaxPort))
            {
                ShowFailureAndDontClose(
                    string.Format(
                        "Port must be within the range {0} to {1}!",
                        IPEndPoint.MinPort,
                        IPEndPoint.MaxPort),
                    m_txtPort);

                return;
            }

            // Make sure valid protocol selected
            var assoc = m_cmbProtocol.SelectedItem as PluginTextAssociation;

            if (assoc == null)
            {
                ShowFailureAndDontClose(
                    "A valid protocol must be selected!",
                    m_cmbProtocol);

                return;
            }

            // Verify network plugin still available
            var bFoundPlugin =
                m_networkPluginService.Get.NetworkPlugins.Any(
                    netPlugin => assoc.NetworkPlugin == netPlugin);

            if (!bFoundPlugin)
            {
                ShowFailureAndDontClose(
                    "The selected protocol is no longer valid!",
                    m_cmbProtocol);

                return;
            }

            SledNetworkPluginTargetFormSettings settings;

            if (!TryGetSettings(assoc.NetworkPlugin, out settings))
            {
                ShowFailureAndDontClose(
                    "The selected protocol is no longer valid!",
                    m_cmbProtocol);

                return;
            }

            string  settingsMsg;
            Control settingsControl;

            if (settings.ContainsErrors(out settingsMsg, out settingsControl))
            {
                ShowFailureAndDontClose(
                    settingsMsg,
                    settingsControl);

                return;
            }

            // Finally create the target
            Target =
                assoc.NetworkPlugin.CreateAndSetup(
                    m_txtName.Text.Trim(),
                    new IPEndPoint(ipAddr, port),
                    settings.GetDataBlob());
        }
Example #43
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="target">Target</param>
 /// <param name="msg">Message</param>
 public SledDebugServiceEventArgs(ISledTarget target, string[] msg)
     : this(target, msg, null)
 {
 }
 public SledTcpSettingsControl(ISledTarget target)
 {
     InitializeComponent();
 }
Example #45
0
 private static int ComparePluginToTarget(ISledNetworkPlugin plugin, ISledTarget target)
 {
     return
         string.Compare(
             plugin.Protocol,
             target.Plugin.Protocol);
 }
Example #46
0
 /// <summary>
 /// Constructor with parameters
 /// </summary>
 /// <param name="gfx">GDI+ drawing surface</param>
 /// <param name="bounds">Bounding rectangle for drawing</param>
 /// <param name="font">Font</param>
 /// <param name="selected">Whether item selected</param>
 /// <param name="item">ISledTarget item being rendered</param>
 /// <param name="textColor">Text color</param>
 /// <param name="highlightTextColor">Highlight text color</param>
 /// <param name="highlightBackColor">Highlight background color</param>
 public SledNetworkTargetsFormRenderArgs(Graphics gfx, Rectangle bounds, Font font, bool selected, ISledTarget item, Color textColor, Color highlightTextColor, Color highlightBackColor)
 {
     Graphics = gfx;
     Bounds = bounds;
     Font = font;
     Selected = selected;
     Item = item;
     DrawDefault = false;
     TextColor = textColor;
     HighlightTextColor = highlightTextColor;
     HighlightBackColor = highlightBackColor;
 }
Example #47
0
        /// <summary>
        /// Connects using IPEndPoint</summary>
        /// <param name="target">Target</param>
        public void Connect(ISledTarget target)
        {
            lock (m_syncSocket)
            {
                if (m_connectionInProgress)
                    return;
            }

            if (IsConnected)
                return;

            lock (m_syncSocket)
            {
                if (m_theSocket != null)
                {
                    m_theSocket.Close();
                    m_theSocket = null;
                    m_curTarget = null;
                }
            }

            // try to connect;
            try
            {
                lock (m_syncSocket)
                {
                    var ipaddr = target.EndPoint.Address;
                    m_theSocket = new Socket(ipaddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                    {
                        Blocking = true,
                        SendTimeout = 5000
                    };

                    //m_theSocket.ExclusiveAddressUse = true;
                    m_theSocket.BeginConnect(ipaddr, target.EndPoint.Port, m_connectClb, target);
                    m_connectionInProgress = true;
                }

            }
            catch (Exception ex)
            {
                lock (m_syncSocket)
                {
                    if (m_theSocket != null)
                    {
                        m_theSocket.Close();
                        m_theSocket = null;
                        m_curTarget = null;
                    }
                }
                OnUnHandledException(ex);
            }
        }