Пример #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        /// <summary>
        /// Main method for sending a management message to Open Petra Web Servers.  Responses are handled by OnWebServerResponse.
        /// </summary>
        /// <param name="AMessage">Message to send</param>
        /// <param name="ASendToPort">Port to send to.  If -1 the message will be sent to our complete range of ports</param>
        private void SendMessage(string AMessage, int ASendToPort = -1)
        {
            PrepareToListen();

            _availableCommands = new Dictionary <string, Dictionary <string, string> >();

            // Create a new listener to handle the responses
            _webServerListener = new WebServerListener(this);
            _webServerListener.StartListening();

            // Check if the message needs completing, now that we know the listener port
            if (AMessage.Contains("{0}"))
            {
                AMessage = String.Format(AMessage, _webServerListener.Port);
            }

            System.Diagnostics.Trace.WriteLine("Starting listener ... Message sent: " + AMessage);

            // Send a message on the loopback address to all the ports in our range (because there may be multiple web servers listening on different ports)
            UdpClient udpClient = new UdpClient();

            byte[] bytes = Encoding.ASCII.GetBytes(AMessage);

            if (ASendToPort == -1)
            {
                for (int i = 0; i < Program.WEB_SERVER_TARGET_PORT_RANGE; i++)
                {
                    IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, Program.WEB_SERVER_TARGET_PORT_BASE + i);
                    udpClient.Send(bytes, bytes.Length, ep);
                }
            }
            else
            {
                IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, ASendToPort);
                udpClient.Send(bytes, bytes.Length, ep);
            }

            // Finished sending
            udpClient.Close();

            System.Diagnostics.Trace.WriteLine("Finished sending...");
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        /// <summary>
        /// Main method for sending a management message to Open Petra Web Servers.  Responses are handled by OnWebServerResponse.
        /// </summary>
        /// <param name="AMessage">Message to send</param>
        /// <param name="ASendToPort">Port to send to.  If -1 the message will be sent to our complete range of ports</param>
        private void SendMessage(string AMessage, int ASendToPort = -1)
        {
            PrepareToListen();

            _availableCommands = new Dictionary <string, Dictionary <string, string>>();

            // Create a new listener to handle the responses
            _webServerListener = new WebServerListener(this);
            _webServerListener.StartListening();

            // Check if the message needs completing, now that we know the listener port
            if (AMessage.Contains("{0}"))
            {
                AMessage = String.Format(AMessage, _webServerListener.Port);
            }

            System.Diagnostics.Trace.WriteLine("Starting listener ... Message sent: " + AMessage);

            // Send a message on the loopback address to all the ports in our range (because there may be multiple web servers listening on different ports)
            UdpClient udpClient = new UdpClient();
            byte[] bytes = Encoding.ASCII.GetBytes(AMessage);

            if (ASendToPort == -1)
            {
                for (int i = 0; i < Program.WEB_SERVER_TARGET_PORT_RANGE; i++)
                {
                    IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, Program.WEB_SERVER_TARGET_PORT_BASE + i);
                    udpClient.Send(bytes, bytes.Length, ep);
                }
            }
            else
            {
                IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, ASendToPort);
                udpClient.Send(bytes, bytes.Length, ep);
            }

            // Finished sending
            udpClient.Close();

            System.Diagnostics.Trace.WriteLine("Finished sending...");
        }
Пример #3
0
        /// <summary>
        /// The form has been displayed so we take initial actions here
        /// </summary>
        private void ImmediateExecuteForm_Shown(object sender, EventArgs e)
        {
            progressResponses.Value = 0;
            _tickCount = 0;
            _responses = new List <string>();
            responseTimer.Start();

            System.Diagnostics.Trace.WriteLine("Starting listener...");

            // Create a new listener to handle the responses
            _webServerListener = new WebServerListener(this);
            _webServerListener.StartListening();

            string messageToSend = String.Empty;

            switch (_runtimeAction)
            {
            case ImmediateActions.ShutdownAll:
                messageToSend  = String.Format("GeneralShutdownRequest;ReplyTo={0};EOF=1", _webServerListener.Port.ToString());
                lblStatus.Text = "Trying to shutdown all Open Petra web servers";
                break;

            case ImmediateActions.Shutdown:
                messageToSend  = String.Format("ShutdownRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                lblStatus.Text = "Trying to shutdown the Open Petra web server on port " + _port.ToString();
                break;

            case ImmediateActions.Start:
                messageToSend  = String.Format("StartRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                lblStatus.Text = "Trying to start the Open Petra web server on port " + _port.ToString();
                break;

            case ImmediateActions.Stop:
                messageToSend  = String.Format("StopRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                lblStatus.Text = "Trying to stop the Open Petra web server on port " + _port.ToString();
                break;
            }

            if (messageToSend == String.Empty)
            {
                lblStatus.Text = "Unknown command.  Cannot send message ...";
                _tickCount     = 2000;
            }
            else
            {
                // Send a message on the loopback address to all the ports in our range (because there may be multiple web servers listening on different ports)
                UdpClient udpClient = new UdpClient();
                byte[]    bytes     = Encoding.ASCII.GetBytes(messageToSend);
                _awaitingResponses = true;

                for (int i = 0; i < Program.WEB_SERVER_TARGET_PORT_RANGE; i++)
                {
                    IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, Program.WEB_SERVER_TARGET_PORT_BASE + i);
                    udpClient.Send(bytes, bytes.Length, ep);
                }

                // Finished sending
                udpClient.Close();
            }

            System.Diagnostics.Trace.WriteLine("Finished sending...");
        }
Пример #4
0
        /// <summary>
        /// The form has been displayed so we take initial actions here
        /// </summary>
        private void ImmediateExecuteForm_Shown(object sender, EventArgs e)
        {
            progressResponses.Value = 0;
            _tickCount = 0;
            _responses = new List <string>();
            responseTimer.Start();

            System.Diagnostics.Trace.WriteLine("Starting listener...");

            // Create a new listener to handle the responses
            _webServerListener = new WebServerListener(this);
            _webServerListener.StartListening();

            string messageToSend = String.Empty;

            switch (_runtimeAction)
            {
                case ImmediateActions.ShutdownAll:
                    messageToSend = String.Format("GeneralShutdownRequest;ReplyTo={0};EOF=1", _webServerListener.Port.ToString());
                    lblStatus.Text = "Trying to shutdown all Open Petra web servers";
                    break;

                case ImmediateActions.Shutdown:
                    messageToSend = String.Format("ShutdownRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                    lblStatus.Text = "Trying to shutdown the Open Petra web server on port " + _port.ToString();
                    break;

                case ImmediateActions.Start:
                    messageToSend = String.Format("StartRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                    lblStatus.Text = "Trying to start the Open Petra web server on port " + _port.ToString();
                    break;

                case ImmediateActions.Stop:
                    messageToSend = String.Format("StopRequest;WebPort={0};ReplyTo={1};EOF=1", _port, _webServerListener.Port.ToString());
                    lblStatus.Text = "Trying to stop the Open Petra web server on port " + _port.ToString();
                    break;
            }

            if (messageToSend == String.Empty)
            {
                lblStatus.Text = "Unknown command.  Cannot send message ...";
                _tickCount = 2000;
            }
            else
            {
                // Send a message on the loopback address to all the ports in our range (because there may be multiple web servers listening on different ports)
                UdpClient udpClient = new UdpClient();
                byte[] bytes = Encoding.ASCII.GetBytes(messageToSend);
                _awaitingResponses = true;

                for (int i = 0; i < Program.WEB_SERVER_TARGET_PORT_RANGE; i++)
                {
                    IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, Program.WEB_SERVER_TARGET_PORT_BASE + i);
                    udpClient.Send(bytes, bytes.Length, ep);
                }

                // Finished sending
                udpClient.Close();
            }

            System.Diagnostics.Trace.WriteLine("Finished sending...");
        }