Esempio n. 1
0
        public void __start_up(ExecuteArgs __args)
        {
            this.__args = __args;

            // Test cross thread communication
            Task.Run(() =>
            {
                try
                {
                    __show_common_event("Strucured Data Proxy Starting Up");
                }
                catch (Exception e)
                {
                    __show_error_event(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message));
                    __logger.Log(__log_level, "Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message);
                }
            });

            // Generic listener setup
            try
            {
                Console.WriteLine("__start_listener: {0}", Thread.CurrentThread.ManagedThreadId);

                int __lp = Convert.ToInt32(__args.__listen_port);
                __listener = new motSocket(__lp, __parse_data);

                __worker      = new Thread(new ThreadStart(__listener.listen));
                __worker.Name = "listener";
                __worker.Start();

                __show_common_event("Started listening to on port: " + __args.__listen_port);

                __gateway = new motSocket(__args.__gateway_address, Convert.ToInt32(__args.__gateway_port));
                __show_common_event(string.Format("Sending data to: {0}:{1}", __args.__gateway_address, __args.__gateway_port));
            }
            catch (Exception e)
            {
                __show_error_event(string.Format("Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message));
                __logger.Log(__log_level, "Failed to start on {0}:{1}, Error: {2}", __args.__listen_address, __args.__listen_port, e.Message);
            }
        }
        //---------------------------------------------------------------
        #endregion

        #region StartStop
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Start Runtime
            var __args = new ExecuteArgs();

            __args.__gateway_address = txtTargetIP.Text;
            __args.__gateway_port    = txtTargetPort.Text;
            __args.__gateway_uname   = txtTargetUname.Text;
            __args.__gateway_pwd     = txtTargetPwd.Text;
            __args.__listen_address  = txtSourceIP.Text;
            __args.__listen_port     = txtSourcePort.Text;
            __args.__listen_uname    = txtSourceUname.Text;
            __args.__listen_pwd      = txtSourcePwd.Text;

            __args.__error_level   = __error_level;
            __args.__auto_truncate = chkAutoTruncate.Checked;

            __execute.__start_up(__args);

            btnStop.Enabled  = true;
            btnStart.Enabled = false;

            __listening = true;
        }