Example #1
0
        private void ThreadListener( ThreadObject thObj )
        {
            try
            {
                TcpClient tcpClient = null;
                NetworkStream netStream = null;

                tcpClient = listener.AcceptTcpClient();
                netStream = tcpClient.GetStream();
                UpdateConnectionList(
                    tcpClient.Client.RemoteEndPoint.ToString() +
                    " Logging in...");
                //Reading From Client
                byte[] rcvBuffer = new byte[BUFFSIZE];
                int bytesReceived = 0;

                while ((bytesReceived = netStream.Read(
                            rcvBuffer, 0, rcvBuffer.Length)) > 0)
                {
                    UpdateConnectionList(
                        tcpClient.Client.RemoteEndPoint.ToString() +
                        Encoding.ASCII.GetString(rcvBuffer, 0, bytesReceived));

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void ThreadListener(ThreadObject thObj)
        {
            try
            {
                TcpClient     tcpClient = null;
                NetworkStream netStream = null;


                tcpClient = listener.AcceptTcpClient();
                netStream = tcpClient.GetStream();
                UpdateConnectionList(
                    tcpClient.Client.RemoteEndPoint.ToString() +
                    " Logging in...");
                //Reading From Client
                byte[] rcvBuffer     = new byte[BUFFSIZE];
                int    bytesReceived = 0;

                while ((bytesReceived = netStream.Read(
                            rcvBuffer, 0, rcvBuffer.Length)) > 0)
                {
                    UpdateConnectionList(
                        tcpClient.Client.RemoteEndPoint.ToString() +
                        Encoding.ASCII.GetString(rcvBuffer, 0, bytesReceived));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public void Add(string id)
 {
     ThreadObject to = new ThreadObject();
     to.thread = new Thread(new ParameterizedThreadStart(ThreadExecute));
     to.id = id;
     to.Signal = Signal;
     to.EventWaitHandle = new EventWaitHandle(false, System.Threading.EventResetMode.AutoReset, id);
     to.thread.Start(to);
     Threads.Add(id, to);            
 }
Example #4
0
 internal static void SendToAndroidx(ThreadObject tObject)
 {
     try
     {
         SendRequest(tObject);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #5
0
        public void DoWork(object obj)
        {
            try
            {
                string fullName = null;

                ThreadObject threadObject = (ThreadObject)obj;
                string       pdfFile      = threadObject.PDFFile;

                System.IO.DirectoryInfo di = null;

                Settings.WorkingFolder = String.Format("{0:yyMMdd}", DateTime.Now);

                if (Tools.GetEnvValue("IOSTABLET").Trim() == "1")
                {
                    di = new DirectoryInfo(Path.Combine(Settings.TargetFolder, threadObject.Folder));
                    SendRequestIOS(threadObject);
                }
                else
                {
                    if (Tools.GetEnvValue("USBCONNECT").Trim() == "1")
                    {
                        di = new DirectoryInfo(Settings.TargetFolder + @"\" + Settings.WorkingFolder);
                        SendToAndroid(pdfFile);
                    }
                    else
                    {
                        di = new DirectoryInfo(Path.Combine(Settings.TargetFolder, threadObject.Folder));

                        SendRequest(threadObject);
                    }
                }

                string wildCard = threadObject.FileName;

                do
                {
                    foreach (FileInfo file in di.EnumerateFiles(wildCard))
                    {
                        fullName = file.FullName;
                        break;
                    }

                    Thread.Sleep(300);
                }while (fullName == null);

                threadObject.CloseSign(fullName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #6
0
        private void StartServerButton_Click(object sender, EventArgs e)
        {
            int PortNumber = 8080;

            try
            {
                listener = new TcpListener(IPAddress.Any, PortNumber);
                listener.Start();

                thObject = ThreadMaster.Instance.GetNewThread("ListenerThread");
                thObject.ThreadTimeout = 0;
                thObject.threadDelegateObject = new ThreadObject.ThreadDelegate(
                            ThreadListener );
                thObject.Start( );
            }
            catch( Exception ex )
            {
                MessageBox.Show( ex.Message );
            }
        }
Example #7
0
        private void StartServerButton_Click(object sender, EventArgs e)
        {
            int PortNumber = 8080;

            try
            {
                listener = new TcpListener(IPAddress.Any, PortNumber);
                listener.Start();

                thObject = ThreadMaster.Instance.GetNewThread("ListenerThread");
                thObject.ThreadTimeout        = 0;
                thObject.threadDelegateObject = new ThreadObject.ThreadDelegate(
                    ThreadListener);
                thObject.Start( );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #8
0
        private void StartInternalThread()
        {
            Dispose();

            _InternalThread = new ThreadObject(() =>
            {
                ChangeStatus(JobStatus.Executing);

                try
                {
                    Implement();
                }
                catch (Exception)
                {
                    // log here
                }

                ChangeStatus(JobStatus.Stopped);
            }).Start();
        }
Example #9
0
        internal static void SendRequest(ThreadObject tObject)
        {
            string destFolder = "";
            string pdf        = "";

            try
            {
                //ClearRecords();


                //D:/OpentecApps/RedBerry/ReaderV2/EReg/Target/181028
                destFolder = Path.Combine(Settings.TargetFolder, tObject.Folder);
                //destFolder = destFolder.Replace(@"\", @"/");

                //"D:/OpentecApps/RedBerry/ReaderV2/EReg/Monitor/181028/58785_1.pdf"
                pdf = tObject.PDFFile;
                //pdf = pdf.Replace(@"\", @"/");

                var parms = new Dictionary <string, string>();
                var url   = "http://" + Settings.APIURL + ":" + Settings.APIPORT + "/api/file_transfer";
                parms.Add("device_id", Settings.DeviceID);
                parms.Add("file_upload_path", destFolder);
                parms.Add("file_download_path", pdf);

                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    client.DefaultRequestHeaders.Add("Authorization", "8f16771f9f8851b26f4d460fa17de93e2711c7e51337cb8a608a0f81e1c1b6ae");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
                    HttpResponseMessage response = client.PostAsync(url, new FormUrlEncodedContent(parms)).Result;
                    var tokne = response.Content.ReadAsStringAsync().Result;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }