예제 #1
0
        private void QueueWorker()
        {
            string       queuePath = ConfigurationManager.AppSettings["qPath"];
            MessageQueue queue     = null;

            if (!MessageQueue.Exists(queuePath))
            {
                queue = MessageQueue.Create(queuePath);
            }
            else
            {
                queue = new MessageQueue(queuePath);
            }
            queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
            while (true)
            {
                System.Messaging.Message message = queue.Receive();
                if (message.Label == "Key")
                {
                    RecievingHandler.SendEncryptedSymmetricalKey(message.Body.ToString());
                }
                else if (message.Label == "Data")
                {
                    string input  = Encryptor.DecryptSymmetrical(message.Body.ToString(), ConfigurationManager.AppSettings["tdesKey"]);
                    int    result = RecievingHandler.RecieveData(input);
                    tbInput.Invoke((MethodInvoker) delegate
                    {
                        tbInput.AppendText("\r\n" + result.ToString() + " новых записей добавлено.");
                    });
                }
            }
        }
예제 #2
0
        private void SocketWorker()
        {
            string    ipString = ConfigurationManager.AppSettings["ip"];
            IPAddress ip       = new IPAddress(long.Parse(ipString));
            int       port     = 11000;

            IPEndPoint endPoint = new IPEndPoint(ip, port);

            byte[]      buf;
            List <byte> data;

            serverListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                serverListener.Bind(endPoint);
                serverListener.Listen(10);

                while (true)
                {
                    Socket handler = serverListener.Accept();
                    data = new List <byte>();

                    while (data.Count() % 1024 == 0)
                    {
                        buf = new byte[1024];
                        int    recievedBytes = handler.Receive(buf);
                        byte[] temp          = new byte[recievedBytes];
                        Array.Copy(buf, temp, recievedBytes);
                        data.AddRange(temp);
                    }

                    string recieved  = Convert.ToBase64String(data.ToArray());
                    string decrypted = Encryptor.DecryptSymmetrical(recieved, ConfigurationManager.AppSettings["tdesKey"]);
                    int    result    = RecievingHandler.RecieveData(decrypted);
                    tbInput.Invoke((MethodInvoker) delegate
                    {
                        tbInput.AppendText("\r\n" + result.ToString() + " новых объектов добавлено.");
                    });
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Close();
                }
            }
            catch (ThreadAbortException)
            {
                Thread.CurrentThread.Abort();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }