Beispiel #1
0
        private void SendUpdate()
        {
            try
            {
                FileTransmitViaWireless FTVW = new FileTransmitViaWireless(FullUpdatePath);
                var    package = FTVW.CreateAlertAboutFile();
                Byte[] answer  = package.GetPackage();
                Console.WriteLine("FileTransmit. Thread: {0}", Thread.CurrentThread.GetHashCode());


                const int BlockSize = FileTransmitViaWireless.BlockSize;
                Byte[]    buffer    = new Byte[BlockSize];

                // Чтение и передача файла
                int totalRead = 100;
                lock (this)
                {
                    FileStream FileForTransmit = File.Open(FullUpdatePath, FileMode.Open, FileAccess.Read);
                    // Отправка предупреждения клиенту о том, что будет передаваться файл
                    WriteStream(answer, package.PackageID);
                    while (totalRead > 0)
                    {
                        try
                        {
                            totalRead = FileForTransmit.Read(buffer, 0, BlockSize);
                            TCPStream.Write(buffer, 0, totalRead);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error 1 File Transmit. Thread: {0} \t Message: {1}", Thread.CurrentThread.GetHashCode(), e.Message);
                            FileForTransmit.Close();
                            return;
                        }
                    }
                    FileForTransmit.Close();
                    NeedToUpdate = false;
                    Console.WriteLine("Update has sent to machine: [{0}] ", IPAddress);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error 2 File Transmit. Thread: {0}\t  Message: {1}", Thread.CurrentThread.GetHashCode(), e.Message);
                if (!File.Exists(FullUpdatePath))
                {
                    InformAboutUpdateComplete("$FileDeleted$");
                    NeedToUpdate = false;
                }
            }
        }
Beispiel #2
0
        private void SendUpdate()
        {
            try
                {

                FileTransmitViaWireless FTVW = new FileTransmitViaWireless(FullUpdatePath);
                var package = FTVW.CreateAlertAboutFile();
                Byte[] answer = package.GetPackage();
                Console.WriteLine("FileTransmit. Thread: {0}", Thread.CurrentThread.GetHashCode());

                const int BlockSize = FileTransmitViaWireless.BlockSize;
                Byte[] buffer = new Byte[BlockSize];

                // Чтение и передача файла
                int totalRead = 100;
                lock (this)
                    {
                    FileStream FileForTransmit = File.Open(FullUpdatePath, FileMode.Open, FileAccess.Read);
                    // Отправка предупреждения клиенту о том, что будет передаваться файл
                    WriteStream(answer, package.PackageID);
                    while (totalRead > 0)
                        {
                        try
                            {
                            totalRead = FileForTransmit.Read(buffer, 0, BlockSize);
                            TCPStream.Write(buffer, 0, totalRead);
                            }
                        catch (Exception e)
                            {
                            Console.WriteLine("Error 1 File Transmit. Thread: {0} \t Message: {1}", Thread.CurrentThread.GetHashCode(), e.Message);
                            FileForTransmit.Close();
                            return;
                            }
                        }
                    FileForTransmit.Close();
                    NeedToUpdate = false;
                    Console.WriteLine("Update has sent to machine: [{0}] ", IPAddress);
                    }
                }
            catch (Exception e)
                {
                Console.WriteLine("Error 2 File Transmit. Thread: {0}\t  Message: {1}", Thread.CurrentThread.GetHashCode(), e.Message);
                if (!File.Exists(FullUpdatePath))
                    {
                    InformAboutUpdateComplete("$FileDeleted$");
                    NeedToUpdate = false;
                    }
                }
        }