예제 #1
0
        private void DoWork()
        {
            _client.SetMachineID(_config.MachineId);
            while (!_shutdownEvents.WaitOne(0))
            {
                try
                {
                    if (!_isInitialized)
                    {
                        _client        = new TcpComm.Client(Update, true, 30);
                        _isInitialized = true;
                    }

                    if (!_isConnected)
                    {
                        string errMsg = string.Empty;
                        _isConnected = _client.Connect(_config.ServerAddress,
                                                       Convert.ToUInt16(_config.ServerPort),
                                                       _config.MachineId, ref errMsg);
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
예제 #2
0
            public void Connect()
            {
                String errMsg = "";

                if (!client.Connect(port, ipAddress, ref errMsg))
                {
                    throw new Exception(errMsg);
                }
            }
예제 #3
0
        public MEUService()
        {
            InitializeComponent();
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            _configPath = Path.Combine(Environment.CurrentDirectory, DefaultConfigFileName);

            InitializeDirectories();
            _client = new TcpComm.Client(Update, true, 30);
            _config = InitializeConfiguration();

            string errMsg = string.Empty;

            _isConnected = _client.Connect(_config.ServerAddress, Convert.ToUInt16(_config.ServerPort), _config.MachineId, ref errMsg);
            _client.SetReceivedFilesFolder(_receivedFilesPath);

            InitializeCommandHandlers();
        }
예제 #4
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();
        }