示例#1
0
        public void testZipMsg()
        {
            byte[] outBytes = null;
            uint   outSize  = 0;

            byte[] inBytes = null;
            uint   inSize  = 0;

            ByteBuffer     pByteBuffer  = new ByteBuffer();
            UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd();

            // 发送第一个数据包
            pUnitTestCmd.testStr = "测试数据";
            pByteBuffer.clear();
            pUnitTestCmd.serialize(pByteBuffer);

            Compress.CompressData(pByteBuffer.dynBuff.buff, 0, pByteBuffer.length, ref outBytes, ref outSize);
            Compress.DecompressData(outBytes, 0, outSize, ref inBytes, ref inSize);

            pByteBuffer.clear();
            pByteBuffer.writeBytes(inBytes, 0, inSize);
            pByteBuffer.position = 0;
            pUnitTestCmd.derialize(pByteBuffer);

            UAssert.DebugAssert(pUnitTestCmd.testStr != "测试数据");
        }
示例#2
0
        internal void SaveAppeal(string fullName, string inputPhone, string currentDay, int currentHour, string currentMinute, string email, string company, string participantRole, string appeal, string additionalInfo)
        {
            if (File.Exists(_pathToZipAppeals))
            {
                compress.DecompressData(_pathToZipAppeals);
            }
            else
            {
                using (FileStream fs = File.Create(_pathToAppeals))
                {
                    fs.Close();
                }
            }

            using (StreamWriter str = new StreamWriter(_pathToAppeals, true, Encoding.Unicode))
            {
                str.WriteLine($"{fullName}%%#%%");
                str.WriteLine($"{inputPhone}%%#%%");
                str.WriteLine($"{currentDay}%%#%%");
                str.WriteLine($"{currentHour}%%#%%");
                str.WriteLine($"{currentMinute}%%#%%");
                str.WriteLine($"{email}%%#%%");
                str.WriteLine($"{company}%%#%%");
                str.WriteLine($"{participantRole}%%#%%");
                str.WriteLine($"{appeal}%%#%%");
                str.WriteLine($"{additionalInfo}%%#%%");
                str.WriteLine($"{StaticData.User}%%#%%");
            }

            fileWorker.GetUserStatus();
            File.Delete(_pathToZipAppeals);
            compress.CompressData(_pathToAppeals, _pathToZipAppeals);
            File.Delete(_pathToAppeals);
        }
示例#3
0
        public void TestCompression()
        {
            const string TestBytes = "Testing 123546 99999999999999999999999999999999999999999999999 8888888888888888888888888888888";

            byte[] data = Encoding.Unicode.GetBytes(TestBytes);

            byte[] cdata = Compress.CompressData(data);
            byte[] udata = Compress.UncompressData(cdata);

            Assert.AreEqual(TestBytes, Encoding.Unicode.GetString(udata));
        }
示例#4
0
        public void WriteAppealToFile(string fullName, string phoneNumber, string date, string currentHour, string currentMinute, string status, string role, string email, string company, string appeal, string additionalInfo)
        {
            if (File.Exists(pathToAppeals))
            {
                File.Delete(pathToAppeals);
            }
            if (!File.Exists(pathToZipAppeals))
            {
                XDocument appeals = new XDocument(
                    new XComment("Обращения в службу поддержки ГИИС ДМДК"),
                    new XElement("Appeals",
                                 new XElement("Appeal",
                                              new XElement("fullName", fullName),
                                              new XElement("phoneNumber", phoneNumber),
                                              new XElement("date", date),
                                              new XElement("currentHour", currentHour),
                                              new XElement("currentMinute", currentMinute),
                                              new XElement("status", status),
                                              new XElement("role", role),
                                              new XElement("email", email),
                                              new XElement("company", company),
                                              new XElement("appeal", appeal),
                                              new XElement("additionalInfo", additionalInfo),
                                              new XElement("user", StaticData.User))
                                 )
                    );
                appeals.Save(pathToAppeals);
            }
            else
            {
                fileArchiving.DecompressData(pathToZipAppeals);
                XDocument appeals = XDocument.Load(pathToAppeals);

                XElement root = new XElement("Appeal");
                root.Add(new XElement("fullName", fullName));
                root.Add(new XElement("phoneNumber", phoneNumber));
                root.Add(new XElement("date", date));
                root.Add(new XElement("currentHour", currentHour));
                root.Add(new XElement("currentMinute", currentMinute));
                root.Add(new XElement("status", status));
                root.Add(new XElement("role", role));
                root.Add(new XElement("email", email));
                root.Add(new XElement("company", company));
                root.Add(new XElement("appeal", appeal));
                root.Add(new XElement("additionalInfo", additionalInfo));
                root.Add(new XElement("user", StaticData.User));
                appeals.Element("Appeals").Add(root);
                appeals.Save(pathToAppeals);
            }

            fileArchiving.CompressData(pathToAppeals, pathToZipAppeals);
            File.Delete(pathToAppeals);
        }
示例#5
0
        /** 生成完整的数据包: 加密 压缩 计算包头 **/
        public void Build(CrypTea pCryp)
        {
            m_pPacketHeader[0] = 0;
            m_pPacketHeader[1] = 0;
            m_pPacketHeader[2] = 0;
            m_pPacketHeader[3] = 0;
            m_pPacketHeader[4] = 0;
            m_pPacketHeader[5] = 0;

            SetDataSize();

            /// 进行压缩
            if (m_wCurWritePos >= 96)
            {
                // 当前有效数据
                byte[] pValidData = new byte[GetCurDataSize()];
                Array.Copy(m_pData, 0, pValidData, 0, pValidData.Length);
                // 压缩后的数据
                //byte[] pData = Compress.Compression(pValidData);
                byte[] pData;
                Compress.CompressData(pValidData, out pData);
                // 将压缩后的数据拷贝到数据数组中
                Array.Copy(pData, 0, m_pData, 0, pData.Length);
                // 重新设置写位置
                SetCurDataSize((ushort)pData.Length);
                // 设置整个包实际的长度
                SetPacketSize();
                SetZip(true);
            }
            else
            {
                SetZip(false);
            }
            /// 进行加密
            byte[] pKey = pCryp.GetKey();
            if (null == pKey)
            {
                return;
            }
            // 按8字节对齐
            uint wTemp = (uint)(8 - (GetCurDataSize() & 7)); //

            if (8 != wTemp)
            {
                WriteBytes(ref pKey, (uint)0, (uint)wTemp);
            }
            pCryp.Encryption(m_pData, GetDataSize());
            SetCryp(true);

            SetPacketSize();
            SetVerCode();
        }
示例#6
0
        protected void testCompress()
        {
            //string testStr = "利用进行字符串的压缩和解压缩利用进行字符串的压缩和解压缩";
            string testStr = "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdasfasdfasdfasdf";

            byte[] inBytes  = System.Text.Encoding.UTF8.GetBytes(testStr);
            byte[] outBytes = null;
            uint   inSize   = 0;
            uint   outSize  = 0;

            Compress.CompressData(inBytes, 0, (uint)inBytes.Length, ref outBytes, ref outSize);

            writeFile("e:\\log.zip", outBytes);

            Compress.DecompressData(outBytes, 0, outSize, ref inBytes, ref inSize);

            string str = System.Text.Encoding.UTF8.GetString(inBytes);

            UAssert.DebugAssert(str == testStr);
        }
        internal void RegistrationUser(string loginRegistration, string passwordRegistration)
        {
            if (!File.Exists(_zipPathToLogins))
            {
                using (FileStream fs = File.Create(PathToLogins))
                {
                    fs.Close();
                }
            }
            else
            {
                compress.DecompressData(_zipPathToLogins);
            }

            using (StreamWriter str = new StreamWriter(PathToLogins, true, Encoding.Unicode))
            {
                str.WriteLine($"{loginRegistration}-{passwordRegistration}");
            }
            compress.CompressData(PathToLogins, _zipPathToLogins);
            File.Delete(PathToLogins);
        }