示例#1
0
        public static MidiData Parse(FileStream inputFileStream)
        {
            var inputBinaryReader = new BinaryReader(inputFileStream);


            // Order of ReadBytes() ist critical!
            var headerChunkId   = StringEncoder.GetString(inputBinaryReader.ReadBytes(4));
            var headerChunkSize = BitConverter.ToInt32(inputBinaryReader.ReadBytes(4).Reverse().ToArray(), 0);
            var headerChunkData = inputBinaryReader.ReadBytes(headerChunkSize);

            var formatType     = BitConverter.ToUInt16(headerChunkData.Take(2).Reverse().ToArray(), 0);
            var numberOfTracks = BitConverter.ToUInt16(headerChunkData.Skip(2).Take(2).Reverse().ToArray(), 0);
            var timeDivision   = BitConverter.ToUInt16(headerChunkData.Skip(4).Take(2).Reverse().ToArray(), 0);

            var headerChunk = new HeaderChunk(formatType, timeDivision)
            {
                ChunkId = headerChunkId
            };

            var tracks =
                Enumerable.Range(0, numberOfTracks).Select(trackNumber =>
            {
                // ReSharper disable once UnusedVariable
                var trackChunkId   = StringEncoder.GetString(inputBinaryReader.ReadBytes(4));
                var trackChunkSize = BitConverter.ToInt32(inputBinaryReader.ReadBytes(4).Reverse().ToArray(), 0);
                var trackChunkData = inputBinaryReader.ReadBytes(trackChunkSize);

                return(Tuple.Create(trackChunkSize, trackChunkData));
            }).ToList()
                .Select(rawTrack => new TrackChunk(ParseEvents(rawTrack.Item2.ToList(), rawTrack.Item1))).ToList();

            return(new MidiData(headerChunk, tracks));
        }
        public void RFC1642_Example2()
        {
            string UniCodeString = "\u0048\u0069\u0020\u004D\u006F\u004D\u0020\u263A\u0021";

            char[] expected = UniCodeString.ToCharArray();

            byte[] UTF7Bytes = new byte[] { 0x48, 0x69, 0x20, 0x4D, 0x6F, 0x4D, 0x20, 0x2B, 0x4A, 0x6A, 0x6F, 0x41, 0x49, 0x51, 0x2D };

            UTF7Encoding UTF7enc = new UTF7Encoding();

            char[] actual = UTF7enc.GetChars(UTF7Bytes);

            // "Hi Mom +Jjo-!" is decoded as "Hi Mom <WHITE SMILING FACE>!"
            Assert.AreEqual(expected [0], actual [0], "UTF #1");
            Assert.AreEqual(expected [1], actual [1], "UTF #2");
            Assert.AreEqual(expected [2], actual [2], "UTF #3");
            Assert.AreEqual(expected [3], actual [3], "UTF #4");
            Assert.AreEqual(expected [4], actual [4], "UTF #5");
            Assert.AreEqual(expected [5], actual [5], "UTF #6");
            Assert.AreEqual(expected [6], actual [6], "UTF #7");
            Assert.AreEqual(expected [7], actual [7], "UTF #8");
            Assert.AreEqual(expected [8], actual [8], "UTF #9");

            Assert.AreEqual(UniCodeString, UTF7enc.GetString(UTF7Bytes), "GetString");
        }
        public void RFC1642_Example4()
        {
            string UniCodeString = "\u0049\u0074\u0065\u006D\u0020\u0033\u0020\u0069\u0073\u0020\u00A3\u0031\u002E";

            char[] expected = UniCodeString.ToCharArray();

            byte[] UTF7Bytes = new byte[] { 0x49, 0x74, 0x65, 0x6D, 0x20, 0x33, 0x20, 0x69, 0x73, 0x20, 0x2B, 0x41, 0x4B, 0x4D, 0x2D, 0x31, 0x2E };

            UTF7Encoding UTF7enc = new UTF7Encoding();

            char[] actual = UTF7enc.GetChars(UTF7Bytes);

            // "Item 3 is +AKM-1." is decoded as "Item 3 is <POUND SIGN>1."
            Assert.AreEqual(expected [0], actual [0], "UTF #1");
            Assert.AreEqual(expected [1], actual [1], "UTF #2");
            Assert.AreEqual(expected [2], actual [2], "UTF #3");
            Assert.AreEqual(expected [3], actual [3], "UTF #4");
            Assert.AreEqual(expected [4], actual [4], "UTF #5");
            Assert.AreEqual(expected [5], actual [5], "UTF #6");
            Assert.AreEqual(expected [6], actual [6], "UTF #7");
            Assert.AreEqual(expected [7], actual [7], "UTF #8");
            Assert.AreEqual(expected [8], actual [8], "UTF #9");
            Assert.AreEqual(expected [9], actual [9], "UTF #10");
            Assert.AreEqual(expected [10], actual [10], "UTF #11");
            Assert.AreEqual(expected [11], actual [11], "UTF #12");
            Assert.AreEqual(expected [12], actual [12], "UTF #13");

            Assert.AreEqual(UniCodeString, UTF7enc.GetString(UTF7Bytes), "GetString");
        }
示例#4
0
    public static void Main()
    {
        // Create a UTF-7 encoding.
        UTF7Encoding utf7 = new UTF7Encoding();

        // A Unicode string with two characters outside a 7-bit code range.
        String unicodeString =
            "This Unicode string contains two characters " +
            "with codes outside a 7-bit code range, " +
            "Pi (\u03a0) and Sigma (\u03a3).";

        Console.WriteLine("Original string:");
        Console.WriteLine(unicodeString);

        // Encode the string.
        Byte[] encodedBytes = utf7.GetBytes(unicodeString);
        Console.WriteLine();
        Console.WriteLine("Encoded bytes:");
        foreach (Byte b in encodedBytes)
        {
            Console.Write("[{0}]", b);
        }
        Console.WriteLine();

        // Decode bytes back to string.
        // Notice Pi and Sigma characters are still present.
        String decodedString = utf7.GetString(encodedBytes);

        Console.WriteLine();
        Console.WriteLine("Decoded bytes:");
        Console.WriteLine(decodedString);
    }
示例#5
0
 public void NegTest1()
 {
     Byte[] bytes = null;
     UTF7Encoding utf7 = new UTF7Encoding();
     Assert.Throws<ArgumentNullException>(() =>
     {
         string str = utf7.GetString(bytes, 0, 2);
     });
 }
示例#6
0
 public void PosTest1()
 {
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     UTF7Encoding utf7 = new UTF7Encoding();
     string str = utf7.GetString(bytes, 0, bytes.Length);
 }
示例#7
0
        public void NegTest1()
        {
            Byte[]       bytes = null;
            UTF7Encoding utf7  = new UTF7Encoding();

            Assert.Throws <ArgumentNullException>(() =>
            {
                string str = utf7.GetString(bytes, 0, 2);
            });
        }
示例#8
0
 public void PosTest1()
 {
     Byte[] bytes = new Byte[] {
         85, 84, 70, 56, 32, 69, 110,
         99, 111, 100, 105, 110, 103, 32,
         69, 120, 97, 109, 112, 108, 101
     };
     UTF7Encoding utf7 = new UTF7Encoding();
     string       str  = utf7.GetString(bytes, 0, bytes.Length);
 }
    private string FromASCIIByteArray(byte[] characters)
    {
        //ASCIIEncoding encoding = new ASCIIEncoding();
        UTF7Encoding encoding = new UTF7Encoding();
        //UTF8Encoding encoding = new UTF8Encoding();
        //UTF32Encoding encoding = new UTF32Encoding();
        //UnicodeEncoding encoding = new UnicodeEncoding();
        string constructedString = encoding.GetString(characters);

        return(constructedString);
    }
示例#10
0
 public void NegTest3()
 {
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     UTF7Encoding utf7 = new UTF7Encoding();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         string str = utf7.GetString(bytes, 0, -1);
     });
 }
示例#11
0
 protected string Encode7Bit(byte[] data)
 {
     try
     {
         var utf7 = new UTF7Encoding();
         return(utf7.GetString(data));
     }
     catch
     {
         return(null);
     }
 }
        private void get_bfile(OracleConnection con)
        {
            // this helper gets the bfile from the database
            // table, displays the property values and
            // writes the content of the file to the console
            string sqlText = "select file_loc from bfile_test";

            // the command object
            OracleCommand cmd = new OracleCommand(sqlText, con);

            // get a data reader for the command object
            OracleDataReader dataReader = cmd.ExecuteReader();

            OracleBFile bfile = null;

            if (dataReader.Read())
            {
                // use the typed accessor to get the bfile
                bfile = dataReader.GetOracleBFile(0);
            }

            // open the file
            // try
            // {
            //   bfile.OpenFile();
            // }
            // catch(OracleException ex)
            // {
            //   Console.WriteLine(ex.ToString());
            // }

            // display the property values
            Console.WriteLine("Retrieved bfile from database...");
            Console.WriteLine("  CanRead = " + bfile.CanRead.ToString());
            Console.WriteLine("  CanSeek = " + bfile.CanSeek.ToString());
            Console.WriteLine("  CanWrite = " + bfile.CanWrite.ToString());
            Console.WriteLine("  Connection = " + bfile.Connection.ConnectionString);
            Console.WriteLine("  DirectoryName = " + bfile.DirectoryName.ToString());
            Console.WriteLine("  FileExists = " + bfile.FileExists.ToString());
            Console.WriteLine("  FileName = " + bfile.FileName.ToString());
            Console.WriteLine("  Length = " + bfile.Length.ToString());
            Console.WriteLine("  Position = " + bfile.Position.ToString());
            Console.WriteLine("  Value = " + bfile.Value.ToString());

            // convert the byte array to a string
            UTF7Encoding utf = new UTF7Encoding();

            byte[] bf = new byte[bfile.Length];
            bfile.Read(bf, 0, Convert.ToInt16(bfile.Length));
            bfile.Close();
            Console.WriteLine("  Value = \n" + utf.GetString(bf));
        }
示例#13
0
 public void PosTest2()
 {
     int startIndex = 0;
     int count = 0;
     Byte[] bytes = new Byte[] {
                      85,  84,  70,  56,  32,  69, 110,
                      99, 111, 100, 105, 110, 103,  32,
                      69, 120,  97, 109, 112, 108, 101};
     startIndex = _generator.GetInt32(-55) % bytes.Length;
     count = _generator.GetInt32(-55) % (bytes.Length - startIndex) + 1;
     UTF7Encoding utf7 = new UTF7Encoding();
     string str = utf7.GetString(bytes, startIndex, count);
 }
示例#14
0
        public static int GetChatPacketSize(byte[] bytes, int index, int size)
        {
            UTF7Encoding uTF7Encoding = new UTF7Encoding();
            string       text         = "";
            string       text2        = "";

            checked
            {
                int num = index + 10;
                while (bytes[num] != 0)
                {
                    text += uTF7Encoding.GetString(bytes, num, 1);
                    num++;
                }
                num++;
                while (bytes[num] != 0)
                {
                    text2 += uTF7Encoding.GetString(bytes, num, 1);
                    num++;
                }
                return(10 + text.Length + 1 + text2.Length + 1);
            }
        }
示例#15
0
        public void NegTest4()
        {
            Byte[] bytes = new Byte[] {
                85, 84, 70, 56, 32, 69, 110,
                99, 111, 100, 105, 110, 103, 32,
                69, 120, 97, 109, 112, 108, 101
            };
            UTF7Encoding utf7 = new UTF7Encoding();

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                string str = utf7.GetString(bytes, 1, bytes.Length);
            });
        }
示例#16
0
        public void PosTest2()
        {
            int startIndex = 0;
            int count      = 0;

            Byte[] bytes = new Byte[] {
                85, 84, 70, 56, 32, 69, 110,
                99, 111, 100, 105, 110, 103, 32,
                69, 120, 97, 109, 112, 108, 101
            };
            startIndex = TestLibrary.Generator.GetInt32(-55) % bytes.Length;
            count      = TestLibrary.Generator.GetInt32(-55) % (bytes.Length - startIndex) + 1;
            UTF7Encoding utf7 = new UTF7Encoding();
            string       str  = utf7.GetString(bytes, startIndex, count);
        }
示例#17
0
        public void WriteUTF7String_Theory(string testString)
        {
            DjvuWriter writer = null;

            using (MemoryStream stream = new MemoryStream())
                using (writer = new DjvuWriter(stream))
                {
                    long   length     = writer.WriteUTF7String(testString);
                    byte[] buffer     = stream.GetBuffer();
                    byte[] testBuffer = new byte[length];
                    Buffer.BlockCopy(buffer, 0, testBuffer, 0, (int)length);
                    UTF7Encoding encoding = new UTF7Encoding(false);
                    string       result   = encoding.GetString(testBuffer);
                    Assert.Equal(testString, result);
                    Assert.Equal <long>(length, stream.Position);
                    Assert.Equal <long>(stream.Position, writer.Position);
                }
        }
示例#18
0
        public bool conectorPDV_aut_serial()
        {
            alwaysVariables.Serie_Valido = false;
            if (File.Exists(folderMFDGrand + "\\MD5" + ".enc"))
            {
                descryptFile(folderMFDGrand + "\\MD5" + ".enc", "\\MD5");
                if (File.Exists(folderMFDGrand + "\\MD5" + ".txt"))
                {
                    retorno = "";
                    string mensagem = "";
                    using (FileStream fs = File.OpenRead(folderMFDGrand + "\\MD5" + ".txt"))
                    {
                        byte[]       b    = new byte[1024];
                        UTF7Encoding temp = new UTF7Encoding(true);
                        while (fs.Read(b, 0, b.Length) > 0)
                        {
                            retorno = temp.GetString(b).Replace("\0", "").Trim();
                            StringReader strReader = new StringReader(retorno);

                            while ((mensagem = strReader.ReadLine()) != null)
                            {
                                if (alwaysVariables.Serie_Hash == mensagem && alwaysVariables.Serie_Hash_Hard == mensagem)
                                {
                                    alwaysVariables.Serie_Valido = true;    //Verifica serie impressora valido
                                    break;
                                }
                                if (alwaysVariables.Serie.Replace("\"", "").Trim() == "\"EMULADOR       \"".Replace("\"", "").Trim())
                                {
                                    alwaysVariables.Serie_Valido = true;    //Verifica serie impressora valido
                                    break;
                                }
                            }
                        }
                        fs.Close();
                    }
                }
                File.Delete(folderMFDGrand + "\\MD5" + ".txt");
            }
            else
            {
                conectorPDV_aut(alwaysVariables.CNPJ, folderMFDGrand + "\\MD5" + ".txt");    //cryptografia.encryptFile(alwaysVariables.MD5_Main, "\\MD5", 0);
            }
            return(alwaysVariables.Serie_Valido);
        }
        public void RFC1642_Example3()
        {
            string UniCodeString = "\u65E5\u672C\u8A9E";

            char[] expected = UniCodeString.ToCharArray();

            byte[] UTF7Bytes = new byte[] { 0x2B, 0x5A, 0x65, 0x56, 0x6E, 0x4C, 0x49, 0x71, 0x65, 0x2D };

            UTF7Encoding UTF7enc = new UTF7Encoding();

            char[] actual = UTF7enc.GetChars(UTF7Bytes);

            // "+ZeVnLIqe-" is decoded as Japanese "nihongo"
            Assert.AreEqual(expected [0], actual [0], "UTF #1");
            Assert.AreEqual(expected [1], actual [1], "UTF #2");
            Assert.AreEqual(expected [2], actual [2], "UTF #3");

            Assert.AreEqual(UniCodeString, UTF7enc.GetString(UTF7Bytes), "GetString");
        }
        public void RFC1642_Example1()
        {
            string UniCodeString = "\u0041\u2262\u0391\u002E";

            char[] expected = UniCodeString.ToCharArray();

            byte[]       UTF7Bytes = new byte [] { 0x41, 0x2B, 0x49, 0x6D, 0x49, 0x44, 0x6B, 0x51, 0x2D, 0x2E };
            UTF7Encoding UTF7enc   = new UTF7Encoding();

            char[] actual = UTF7enc.GetChars(UTF7Bytes);

            // "A+ImIDkQ-." is decoded as "A<NOT IDENTICAL TO><ALPHA>." see RFC 1642
            Assert.AreEqual(expected [0], actual [0], "UTF #1");
            Assert.AreEqual(expected [1], actual [1], "UTF #2");
            Assert.AreEqual(expected [2], actual [2], "UTF #3");
            Assert.AreEqual(expected [3], actual [3], "UTF #4");

            Assert.AreEqual(UniCodeString, UTF7enc.GetString(UTF7Bytes), "GetString");
        }
示例#21
0
 /*
  * GetString
  *
  * Syntax:
  *		byte[] GetString(
  *			string Name			// Name of file
  *		)
  *
  * Explanation:
  *		Load a text file.
  *
  * Return Value:
  *		string of entire file; null otherwise
  */
 public string GetString(Encoding _Encoding, string Name)
 {
     byte[] _Buffer = GetBytes(Name);
     if (_Buffer.Length == 0)
     {
         Console.Write("Attempting to read from an uninitialized buffer, aborting...\r\n"); return(null);
     }
     try
     {
         if (_Encoding == Encoding.ASCII)
         {
             ASCIIEncoding enc = new ASCIIEncoding();
             return(enc.GetString(_Buffer));
         }
         else if (_Encoding == Encoding.Unicode)
         {
             UnicodeEncoding enc = new UnicodeEncoding();
             return(enc.GetString(_Buffer));
         }
         else if (_Encoding == Encoding.UTF32)
         {
             UTF32Encoding enc = new UTF32Encoding();
             return(enc.GetString(_Buffer));
         }
         else if (_Encoding == Encoding.UTF7)
         {
             UTF7Encoding enc = new UTF7Encoding();
             return(enc.GetString(_Buffer));
         }
         else if (_Encoding == Encoding.UTF8)
         {
             UTF8Encoding enc = new UTF8Encoding();
             return(enc.GetString(_Buffer));
         }
     }
     catch (Exception Error)
     {
         Console.Write("{0}\r\n", Error.Message);
         return(null);
     }
     return(null);
 }
示例#22
0
    public static void Main()
    {
        // Create an instance of UTF7Encoding.
        UTF7Encoding u7 = new UTF7Encoding(true);

        // Create byte arrays from the same string containing the following characters:
        //    Latin Small Letter Z (U+007A)
        //    Latin Small Letter A (U+0061)
        //    Combining Breve (U+0306)
        //    Latin Small Letter AE With Acute (U+01FD)
        //    Greek Small Letter Beta (U+03B2)
        String myStr = "za\u0306\u01FD\u03B2";

        // Encode the string.
        byte[] myBArr = new byte[u7.GetByteCount(myStr)];
        u7.GetBytes(myStr, 0, myStr.Length, myBArr, 0);

        // Decode the byte array.
        Console.WriteLine("The new string is: {0}", u7.GetString(myBArr, 0, myBArr.Length));
    }
示例#23
0
        public string descryptFile(string path, string name)
        {
            string retorno = "";
            // Create instance of Rijndael for
            // symetric decryption of the data.
            RijndaelManaged rjndl = new RijndaelManaged();

            rjndl.KeySize   = 256;
            rjndl.BlockSize = 256;
            rjndl.Mode      = CipherMode.CBC; //Obtém ou define o modo de operação do algoritmo simétrico.

            // Create byte arrays to get the length of
            // the encrypted key and IV.
            // These values were stored as 4 bytes each
            // at the beginning of the encrypted package.
            byte[] LenK  = new byte[4];
            byte[] LenIV = new byte[4];

            // Consruct the file name for the decrypted file.
            string outFile = path.Substring(0, path.LastIndexOf(".")) + ".txt";

            try
            {
                // Use FileStream objects to read the encrypted
                // file (inFs) and save the decrypted file (outFs).
                using (FileStream inFs = new FileStream(path.Substring(0, path.LastIndexOf(".")) + ".enc", FileMode.Open))
                {
                    inFs.Seek(0, SeekOrigin.Begin);
                    inFs.Seek(0, SeekOrigin.Begin);
                    inFs.Read(LenK, 0, 3);
                    inFs.Seek(4, SeekOrigin.Begin);
                    inFs.Read(LenIV, 0, 3);

                    // Convert the lengths to integer values.
                    int lenK  = BitConverter.ToInt32(LenK, 0);
                    int lenIV = BitConverter.ToInt32(LenIV, 0);

                    // Determine the start postition of
                    // the ciphter text (startC)
                    // and its length(lenC).
                    int startC = lenK + lenIV + 8;
                    int lenC   = (int)inFs.Length - startC;

                    // Create the byte arrays for
                    // the encrypted Rijndael key,
                    // the IV, and the cipher text.
                    byte[] KeyEncrypted = new byte[lenK];
                    byte[] IV           = new byte[lenIV];

                    // Extract the key and IV
                    // starting from index 8
                    // after the length values.
                    inFs.Seek(8, SeekOrigin.Begin);
                    inFs.Read(KeyEncrypted, 0, lenK);
                    inFs.Seek(8 + lenK, SeekOrigin.Begin).ToString().TrimEnd();
                    inFs.Read(IV, 0, lenIV);
                    //Directory.CreateDirectory(path.Substring(0, path.LastIndexOf(".")));
                    // Use RSACryptoServiceProvider
                    // to decrypt the Rijndael key.
                    //rsa = new RSACryptoServiceProvider();
                    byte[] KeyDecrypted = rsa.Decrypt(KeyEncrypted, false);
                    // Decrypt the key.
                    ICryptoTransform transform = rjndl.CreateDecryptor(KeyDecrypted, IV);

                    // Decrypt the cipher text from
                    // from the FileSteam of the encrypted
                    // file (inFs) into the FileStream
                    // for the decrypted file (outFs).
                    using (FileStream outFs = new FileStream(outFile, FileMode.Create))
                    {
                        int count  = 0;
                        int offset = 0;

                        // blockSizeBytes can be any arbitrary size.
                        int    blockSizeBytes = rjndl.BlockSize / 8;
                        byte[] data           = new byte[blockSizeBytes];


                        // By decrypting a chunk a time,
                        // you can save memory and
                        // accommodate large files.

                        // Start at the beginning
                        // of the cipher text.
                        inFs.Seek(startC, SeekOrigin.Begin);
                        using (CryptoStream outStreamDecrypted = new CryptoStream(outFs, transform, CryptoStreamMode.Write))
                        {
                            do
                            {
                                count   = inFs.Read(data, 0, blockSizeBytes);
                                offset += count;
                                outStreamDecrypted.Write(data, 0, count);
                            }while (count > 0);

                            outStreamDecrypted.FlushFinalBlock();
                            outStreamDecrypted.Close();
                        }
                        outFs.Close();
                    }
                    //Open the stream and read it back.
                    using (FileStream fs = File.OpenRead(outFile))
                    {
                        byte[]       b    = new byte[1024];
                        UTF7Encoding temp = new UTF7Encoding(true);
                        while (fs.Read(b, 0, b.Length) > 0)
                        {
                            retorno += temp.GetString(b);
                        }
                    }


                    if (File.Exists(folderMFDGrand + name + ".txt"))
                    {
                        alwaysVariables.ArqTotal = new List <string>();
                        using (StreamReader texto = new StreamReader(folderMFDGrand + name + ".txt", System.Text.Encoding.Default, true))
                        {
                            while ((LinhaArquivo = texto.ReadToEnd()) != null)
                            {
                                //alwaysVariables.ArqTotal.Add(LinhaArquivo);
                                string rte = LinhaArquivo;
                                if (name == "\\MD5")
                                {
                                    rte = rte.Replace("\r\n", "").Trim();
                                }
                                int i       = 0;
                                int j       = 0;
                                int count   = rte.Length;
                                int inverso = count / 42;
                                while (inverso > j)
                                {
                                    alwaysVariables.ArqTotal.Add(rte.Substring(i, 42));
                                    i = i + 42;
                                    j++;
                                }
                                if (rte.Length == 82)
                                {//Preenche o CRZ, CRO e VENDA BRUTA do arquivo arquivo GT
                                    alwaysVariables.ArqTotal.Add(rte.Substring(44, 38));
                                }
                                break;
                            }
                        }
                        if (name != "\\MD5")
                        {
                            System.IO.File.Copy(folderMFDGrand + name + ".txt", folderMFDGrand + "temp" + ".txt");
                            File.Delete(folderMFDGrand + name + ".txt");
                        }
                    }


                    inFs.Close();
                }
            }
            catch (Exception erro)
            {
                File.Delete(folderMFDGrand + "\\temp" + ".txt");
                if ("\\MD5" == name)
                {
                    File.Delete(folderMFDGrand + "MD5.enc");
                    msgInfo msg = new msgInfo(1, "CARO USUÁRIO - " + "ELIMINANDO FONTE CORROMPIDA. \n"); msg.ShowDialog();
                }
                return("000000000000000000000");//msgInfo msg = new msgInfo(1,"Caro Cliente - " + "ERRO FATAL GRANDE TOTAL INVÁLIDO! SOLICITE A AUTORIZAÇÃO PARA GERAÇÃO DO GRANDE TOTAL. \n"+ "\n  ANALISE: " + erro.ToString()); msg.ShowDialog();
            }
            if (retorno == "")
            {
                File.Delete(folderMFDGrand + "\\temp" + ".txt");
                retorno = "000000000000000000000";
            }

            return(retorno);
        }
示例#24
0
        public bool conectorPDV_aut_grandTotal(string gt)
        {
            alwaysVariables.Gt_Valido = false;
            File.Delete(folderMFDGrand + "\\temp" + ".txt");
            if (File.Exists(folderMFDGrand + "\\grandFullPDV" + ".enc"))
            {
                descryptFile(folderMFDGrand + "\\grandFullPDV" + ".enc", "\\grandFullPDV");
                if (File.Exists(folderMFDGrand + "\\temp" + ".txt"))
                {
                    retorno = "";
                    import  = new List <string>();
                    //Conversao de Carateres
                    using (StreamReader texto = new StreamReader(folderMFDGrand + "\\temp.txt", System.Text.Encoding.Default, true))
                    {
                        while ((LinhaArquivo = texto.ReadToEnd()) != null)
                        {
                            string rte     = LinhaArquivo;
                            int    i       = 0;
                            int    j       = 0;
                            int    count   = rte.Length;
                            int    inverso = count / 42;
                            while (inverso > j)
                            {
                                import.Add(rte.Substring(i, 42));
                                i = i + 42;
                                j++;
                            }
                            break;
                        }
                    }


                    using (FileStream fs = File.OpenRead(folderMFDGrand + "\\temp" + ".txt"))
                    {
                        fiscal_GT_compare = new string('\x20', 18);
                        byte[]       b    = new byte[1024];
                        UTF7Encoding temp = new UTF7Encoding(true);
                        while (fs.Read(b, 0, b.Length) > 0)
                        {
                            retorno = temp.GetString(b).Replace("\0", "").Trim();
                            functionECF.conectorECF_GrandeTotalDescriptografado(alwaysVariables.ModeloEcf, alwaysVariables.ArqTotal[j].Substring(24, alwaysVariables.ArqTotal[j].Length - 24), ref fiscal_GT_compare, ref fiscal_MSG, ref fiscal_retorno, alwaysVariables.ECF_Ligada);
                            //fiscal_retorno = conectorECF.Bematech_FI_GrandeTotalDescriptografado(import[j].Substring(24, import[j].Length - 24), ref fiscal_GT_compare);

                            if (gt == fiscal_GT_compare)
                            {
                                alwaysVariables.Gt_Valido = true;
                            }
                        }
                        fs.Close();
                    }
                }
                File.Delete(folderMFDGrand + "\\temp" + ".txt");
            }
            else
            {
                if (Convert.ToDouble(gt) == Convert.ToDouble(alwaysVariables.GT_BANCO) && fiscal_last_reducao_cro == alwaysVariables.GT_CRO &&
                    fiscal_last_reducao_crz == alwaysVariables.GT_CRZ)
                {
                    fiscal_GT_Crypt = new string('\x20', 20);
                    functionECF.conectorECF_GrandeTotal_Crypt(alwaysVariables.ModeloEcf, ref fiscal_GT_Crypt, ref fiscal_MSG, ref fiscal_retorno, alwaysVariables.ECF_Ligada);
                    //fiscal_retorno = conectorECF.Bematech_FI_GrandeTotalCriptografado(ref fiscal_GT_Crypt);
                    conectorPDV_serie(alwaysVariables.PAF_total + "\\grandFullPDV" + ".txt", "0");
                    File.Delete(alwaysVariables.PAF_total + "\\grandFullPDV" + ".txt");
                    if (File.Exists(folderMFDGrand + "\\grandFullPDV" + ".enc"))
                    {
                        msgInfo msg = new msgInfo(1, "Caro Usuário: Foi identifica uma inconsistencia com o grande e reparado pos conferencia entre hardware e sistema, com isso você volta a operar sem problemas. " + folderMFDGrand + "\\grandFullPDV" + ".enc"); msg.ShowDialog();
                    }
                    alwaysVariables.Gt_Valido = true;
                }
            }

            return(alwaysVariables.Gt_Valido);
        }
示例#25
0
        public bool conectorPDV_verifica_serial()
        {
            alwaysVariables.Serie_Valido = false;
            if (File.Exists(folderMFDGrand + "\\MD5" + ".enc"))
            {
                string retorno = descryptFile(folderMFDGrand + "\\MD5" + ".enc", "\\MD5");
                if (retorno != "" && retorno != null && retorno != "" && retorno != "000000000000000000000")
                {
                    if (File.Exists(folderMFDGrand + "\\MD5" + ".enc"))
                    {
                        string mensagem = "";
                        using (FileStream fs = File.OpenRead(folderMFDGrand + "\\MD5" + ".txt"))
                        {
                            byte[]       b    = new byte[1024];
                            UTF7Encoding temp = new UTF7Encoding(true);
                            while (fs.Read(b, 0, b.Length) > 0)
                            {
                                retorno = temp.GetString(b).Replace("\0", "").Trim();
                                StringReader strReader = new StringReader(retorno);

                                while ((mensagem = strReader.ReadLine()) != null)
                                {
                                    if (alwaysVariables.Serie_Hash == mensagem && alwaysVariables.Serie_Hash_Hard == mensagem)
                                    {
                                        alwaysVariables.Serie_Valido = true;//Verifica serie impressora valido
                                    }
                                    if (alwaysVariables.Serie.Replace("\"", "").Trim() == "\"EMULADOR       \"".Replace("\"", "").Trim())
                                    {
                                        alwaysVariables.Serie_Valido = true;//Verifica serie impressora valido
                                    }
                                }
                            }
                            fs.Close();
                        }

                        /*using (FileStream fs = File.OpenRead(folderMFDGrand + "\\MD5" + ".txt"))
                         * {
                         *  byte[] b = new byte[1024];
                         *  UTF7Encoding temp = new UTF7Encoding(true);
                         *  retorno = temp.GetString(b).Replace("\0", "").Trim();
                         *  StringReader strReader = new StringReader(retorno);
                         *
                         *  while (fs.Read(b, 0, b.Length) > 0)
                         *  {
                         *      if (alwaysVariables.Serie_Hash == retorno && alwaysVariables.Serie_Hash_Hard == retorno)
                         *      {
                         *          alwaysVariables.Serie_Valido = true;
                         *      }
                         *  }
                         *  fs.Close();
                         * }*/
                    }
                    else
                    {
                        return(alwaysVariables.Serie_Valido = false); //erro de registro não conseguiu descryt
                    }
                }
                else
                {
                    File.Delete(folderMFDGrand + "\\MD5" + ".txt");
                    File.Delete(folderMFDGrand + "\\temp" + ".txt");
                    return(alwaysVariables.Serie_Valido = false);
                }
                File.Delete(folderMFDGrand + "\\MD5" + ".txt");
                File.Delete(folderMFDGrand + "\\temp" + ".txt");
            }
            else
            {
                return(alwaysVariables.Serie_Valido = false);
            }
            return(alwaysVariables.Serie_Valido);
        }