예제 #1
0
 protected override void OnStop()
 {
     try
     {
         _shutdownEvents.Set();
         if (!_thread.Join(3000))
         {
             _thread.Abort();
             _client.Close();
         }
     }
     catch (Exception)
     {
     }
 }
예제 #2
0
            public void Close()
            {
                if (running)
                {
                    running = false;
                    Thread.Sleep(500);
                }

                foreach (Transfer transfer in fileTransfers)
                {
                    transfer.Close();
                }

                try
                {
                    client.Close();
                }
                catch (Exception) { }
            }
예제 #3
0
        private void btSave_Click(object sender, EventArgs e)
        {
            InIFileControler ini    = new InIFileControler(iniFilePath);
            String           errMsg = "";

            try
            {
                localServer.Close();
            }
            catch (Exception) { }

            lblStatus.Text = "Saving configuration...";

            TcpComm.Client testClient = new TcpComm.Client(delegate(string tag, byte[] buffer, int numBytesContained, string sessionId)
            {
                // Do nothing here!
            }, tbUniqueId.Text.Trim() != "" ? tbUniqueId.Text.Trim() : "TransferSessionSettings");

            lblStatus.Text = "Attempting to verify the configured server...";
            if (!testClient.Connect(ushort.Parse(tbServerPort.Text.Trim()), tbServerIp.Text.Trim(), ref errMsg))
            {
                lblStatus.Text = "Could not connect to the configured server.";
            }

            testClient.Close();

            if (!Directory.Exists(tbSourcefolder.Text.Trim()))
            {
                MessageBox.Show("The source folder you entered doesn't exist. Please check your configuration and try again.",
                                "Problem saving configuration!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tbTargetFolder.Text.Trim().Equals(""))
            {
                MessageBox.Show("A target folder is required.",
                                "Problem saving configuration!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!ini.ClearINI(ref errMsg))
            {
                MessageBox.Show("Could not access the ini file: " + iniFilePath + Environment.NewLine + Environment.NewLine +
                                ". The error returned is: " + errMsg, "Problem saving configuration!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ini.WriteEntry("ID", tbUniqueId.Text.Trim());
            ini.WriteEntry("SourceFolder", tbSourcefolder.Text.Trim());
            ini.WriteEntry("TargetFolder", tbTargetFolder.Text.Trim());
            ini.WriteEntry("Interval", cbInterval.Text);
            ini.WriteEntry("ServerIp", tbServerIp.Text.Trim());
            ini.WriteEntry("ServerPort", tbServerPort.Text.Trim());
            ini.WriteEntry("Filter", tbFilter.Text.Trim());
            ini.WriteEntry("Speed", tbSpeed.Text.Trim());
            ini.WriteEntry("FilesAtOnce", tbFilesAtOnce.Text.Trim());
            ini.WriteEntry("SkipLatency", tbSkipLatency.Text.Trim());
            ini.WriteEntry("FileCopyLatency", tbFileCopyLatency.Text.Trim());
            ini.WriteEntry("LocalServerIp", cbLocalIpAddresses.Text.Trim());
            ini.WriteEntry("LocalServerPort", tbLocalPort.Text.Trim());

            if (!UInt16.TryParse(tbLocalPort.Text.Trim(), out localServerPort))
            {
                MessageBox.Show("There's a problem with the port you configured for incomming files! Please have a look and try again...", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (cbLocalIpAddresses.SelectedIndex > -1)
            {
                if (!IPAddress.TryParse(cbLocalIpAddresses.Items[cbLocalIpAddresses.SelectedIndex].ToString(), out localServerAddress))
                {
                    MessageBox.Show("There's a problem with the IP Address you have configured for incomming files! Please have a look and try again...", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Start the local server:
            if (!localServer.Start(localServerPort, localServerAddress, ref errMsg))
            {
                lblStatus.Text = errMsg;
                MessageBox.Show(errMsg, "Could not listen for incomming files!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            lblStatus.Text = "Saved: Listening for incomming files on " + localServerAddress.ToString() + ":" + localServerPort.ToString();
        }