コード例 #1
0
        public bool GetParametersConnect()
        {
            try
            {
                if (!File.Exists(SystemArgs.Path.ConnectApplicationPath))
                {
                    throw new Exception();
                }

                using (StreamReader sr = new StreamReader(File.Open(SystemArgs.Path.ConnectApplicationPath, FileMode.Open)))
                {
                    _Port = sr.ReadLine();
                }

                return(true);
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                return(false);
            }
        }
コード例 #2
0
        private void OK_B_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(IP_TB.Text))
                {
                    IP_TB.Focus();
                    throw new Exception("Необходимо ввести IP - адрес");
                }

                if (String.IsNullOrEmpty(Port_TB.Text))
                {
                    Port_TB.Focus();
                    throw new Exception("Необходимо ввести порт");
                }
                Int32 Port = Convert.ToInt32(Port_TB.Text);

                SystemArgs.Server._Port = Port_TB.Text.Trim();

                if (SystemArgs.Server.SetParametersConnect())
                {
                    SystemArgs.PrintLog("Обновлены параметры сервера порт: " + SystemArgs.Server._Port + " " + DateTime.Now.ToString());
                    MessageBox.Show("Параметры подключения успешно обновлены", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (FormatException)
            {
                Port_TB.Focus();
                MessageBox.Show("Порт подключения должен состоять из целых цифр", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            catch (Exception E)
            {
                SystemArgs.PrintLog(E.Message);
                MessageBox.Show(E.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #3
0
 public bool Start()
 {
     try
     {
         if (CreateTempDirectory())
         {
             listener = new TcpListener(IPAddress.Any, Convert.ToInt32(SystemArgs.Server._Port));
             listener.Start();
             ListeningAsync();
             SystemArgs.PrintLog("Запущено слушание клиентов и найдена директория темповых файлов");
             return(true);
         }
         else
         {
             SystemArgs.PrintLog("Ошибка создания директории темповых файлов");
             return(false);
         }
     }
     catch (Exception e)
     {
         SystemArgs.PrintLog(e.Message);
         return(false);
     }
 }
コード例 #4
0
        public bool SetParametersConnect()
        {
            try
            {
                String Dir = SystemArgs.Path.GetDirectory(SystemArgs.Path.ConnectApplicationPath);

                if (!Directory.Exists(Dir))
                {
                    Directory.CreateDirectory(Dir);
                }

                using (StreamWriter sw = new StreamWriter(File.Open(SystemArgs.Path.ConnectApplicationPath, FileMode.Create)))
                {
                    sw.WriteLine(_Port);
                }

                return(true);
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                return(false);
            }
        }
コード例 #5
0
ファイル: Decode.cs プロジェクト: Tysha1337/SZMK_Decode
        public String TIFF(string path)
        {
            try
            {
                using (Reader reader = new Reader())
                {
                    reader.BarcodeTypesToFind.DataMatrix = true;
                    Image  myImage = Image.FromFile(path);
                    Bitmap source  = new Bitmap(myImage);
                    myImage.Dispose();

                    int imgw = 0;
                    int imgh = 0;

                    string cash = null;

                    for (int i = 250; i < source.Width; i = i + 20)
                    {
                        for (int j = 300; j < source.Height; j = j + 20)
                        {
                            imgw = i; imgh = j;

                            Bitmap bmp = source.Clone(new System.Drawing.Rectangle(source.Width - imgw, source.Height - imgh, 250, 300), source.PixelFormat);

                            FoundBarcode[] barcodes = reader.ReadFrom(bmp);

                            foreach (FoundBarcode code in barcodes)
                            {
                                if (code.Value.Split('_').Length == 6)
                                {
                                    cash = code.Value;
                                }
                            }

                            if (cash != null)
                            {
                                var fromEncodind = Encoding.GetEncoding("ISO-8859-1"); //из какой кодировки
                                var bytes        = fromEncodind.GetBytes(cash);
                                var toEncoding   = Encoding.GetEncoding(1251);         //в какую кодировку

                                cash = toEncoding.GetString(bytes);

                                while (cash.IndexOf("<FNC1>") != -1)
                                {
                                    cash = cash.Replace("<FNC1>", "и");
                                }

                                cash = cash.Remove(cash.IndexOf('>'), cash.IndexOf('<') - cash.IndexOf('>') + 1);

                                String[] ExistingCharaterEnglish = new String[] { "A", "a", "B", "C", "c", "E", "e", "H", "K", "M", "O", "o", "P", "p", "T" };

                                String[] ExistingCharaterRussia = new String[] { "А", "а", "В", "С", "с", "Е", "е", "Н", "К", "М", "О", "о", "Р", "р", "Т" };

                                String[] Temp = cash.Split('_');

                                String ReplaceMark = "";

                                for (int k = 0; k < ExistingCharaterRussia.Length; k++)
                                {
                                    ReplaceMark = Temp[2].Replace(ExistingCharaterRussia[k], ExistingCharaterEnglish[k]);
                                }

                                String[] Splitter = Temp[1].Split('и');

                                while (Splitter[0][0] == '0')
                                {
                                    Splitter[0] = Splitter[0].Remove(0, 1);
                                }

                                if (Splitter.Length != 1)
                                {
                                    Temp[1] = Splitter[0] + "и" + Splitter[1];
                                }
                                else
                                {
                                    Temp[1] = Splitter[0];
                                }

                                cash = Temp[0] + "_" + Temp[1] + "_" + ReplaceMark + "_" + Temp[3] + "_" + Temp[4] + "_" + Temp[5];

                                source.Dispose();
                                bmp.Dispose();

                                return(cash);
                            }
                            bmp.Dispose();
                        }
                    }
                    source.Dispose();
                    cash = "Не правильно";
                    return(cash);
                }
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.ToString());
                return(e.Message);
            }
        }
コード例 #6
0
        private void Listening()
        {
            try
            {
                while (true)
                {
                    String    User   = "";
                    TcpClient client = listener.AcceptTcpClient();
                    using (NetworkStream inputStream = client.GetStream())
                    {
                        using (BinaryReader reader = new BinaryReader(inputStream))
                        {
                            if (reader.ReadBoolean())
                            {
                                Load?.Invoke("Была проведена проверка соединения пользователем " + reader.ReadString());
                                client.Close();
                                continue;
                            }
                            else
                            {
                                User = reader.ReadString();
                                Load?.Invoke("Был присоединен пользователь " + User);
                            }
                            string OldFilename = reader.ReadString();
                            string FileName    = reader.ReadString();
                            long   lenght      = reader.ReadInt64();
                            using (FileStream outputStream = File.Open(Path.Combine(SystemArgs.Path.TempFile, Index + ".png"), FileMode.Create))
                            {
                                long   totalBytes = 0;
                                int    readBytes  = 0;
                                byte[] buffer     = new byte[8192];

                                do
                                {
                                    readBytes = inputStream.Read(buffer, 0, buffer.Length);
                                    outputStream.Write(buffer, 0, readBytes);
                                    totalBytes += readBytes;
                                } while (client.Connected && totalBytes < lenght);
                                Load?.Invoke("Был получен файл: " + OldFilename);
                            }
                            String Data         = SystemArgs.Decode.TIFF(SystemArgs.Path.TempFile + @"\" + Index + ".png");
                            Byte[] responseData = Encoding.UTF8.GetBytes(Data);
                            inputStream.Write(responseData, 0, responseData.Length);
                            Load?.Invoke("Были отправлены данные: " + Data);
                            Index++;
                        }
                    }
                    client.Close();
                    DirectoryInfo TempFiles = new DirectoryInfo(SystemArgs.Path.TempFile);
                    if (TempFiles.GetFiles().Length >= 50)
                    {
                        foreach (FileInfo File in TempFiles.GetFiles())
                        {
                            File.Delete();
                        }
                    }
                    Load?.Invoke("Был отключен пользователь " + User);
                }
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                ListeningAsync();
            }
        }
コード例 #7
0
ファイル: Decode_F.cs プロジェクト: Tysha1337/SZMK_Decode
 private void notifyIcon1_Click(object sender, EventArgs e)
 {
     this.ShowInTaskbar = true;
     this.WindowState   = FormWindowState.Normal;
     SystemArgs.PrintLog("Сервер развернут из трея");
 }
コード例 #8
0
ファイル: Decode_F.cs プロジェクト: Tysha1337/SZMK_Decode
 private void Exit_TSM_Click(object sender, EventArgs e)
 {
     SystemArgs.PrintLog("Закрытие сервера");
     Environment.Exit(0);
 }