public static void StartCommand(string[] args)
        {
            if (m_server == null)
            {
                if (m_targets.Count > 0)
                {
                    KeyValuePairList <string, string> parameters = ParseParameters(args, 1);
                    if (!VerifyParameters(parameters, "port", "log"))
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid parameter");
                        HelpStart();
                        return;
                    }

                    int port = DefaultISCSIPort;
                    if (parameters.ContainsKey("port"))
                    {
                        port = Conversion.ToInt32(parameters.ValueOf("port"), DefaultISCSIPort);
                    }
                    string logFile = String.Empty;
                    if (parameters.ContainsKey("log"))
                    {
                        logFile = parameters.ValueOf("log");
                    }
                    m_server = new ISCSIServer(m_targets, port, logFile);
                    try
                    {
                        ISCSIServer.Log("Starting Server");
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("Could not append to log file");
                        return;
                    }

                    try
                    {
                        m_server.Start();
                        Console.WriteLine("Server started, listening on port {0}", port);
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Could not start iSCSI server");
                        m_server.Stop();
                        m_server = null;
                    }
                }
                else
                {
                    Console.WriteLine("No disks have been attached");
                }
            }
        }
 public static void StopCommand(string[] args)
 {
     if (m_server != null)
     {
         m_server.Stop();
         m_server = null;
         Console.WriteLine("iSCSI target is stopping");
     }
     else
     {
         Console.WriteLine("iSCSI target has not been started");
     }
 }
Пример #3
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     if (!m_started)
     {
         IPAddress serverAddress = (IPAddress)comboIPAddress.SelectedValue;
         int       port          = Conversion.ToInt32(txtPort.Text, 0);
         if (port <= 0 || port > UInt16.MaxValue)
         {
             MessageBox.Show("Invalid TCP port", "Error");
             return;
         }
         IPEndPoint endpoint = new IPEndPoint(serverAddress, port);
         try
         {
             m_server.Start(endpoint);
         }
         catch (SocketException ex)
         {
             MessageBox.Show("Cannot start server, " + ex.Message, "Error");
             return;
         }
         btnStart.Text          = "Stop";
         txtPort.Enabled        = false;
         comboIPAddress.Enabled = false;
         m_started = true;
         UpdateUI();
     }
     else
     {
         m_server.Stop();
         lblStatus.Text         = String.Empty;
         m_started              = false;
         btnStart.Text          = "Start";
         txtPort.Enabled        = true;
         comboIPAddress.Enabled = true;
     }
 }