public void UnPackTest2()
        {
            KPPDataHead  head   = new KPPDataHead();
            MemoryStream stream = new MemoryStream();

            head.SetField("CRC", 100L);
            head.SetField("SectionCount", (ushort)1);
            head.Pack(stream);
            byte[] buffer = stream.ToArray();
            byte[] data   = new byte[stream.Length];
            Buffer.BlockCopy(buffer, 0, data, 0, data.Length);
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length == 21);
            Assert.IsTrue(data[0] == 'K');
            Assert.IsTrue(data[1] == 'P');
            Assert.IsTrue(data[2] == 'P');
            //reset postition.
            stream.Position = 0;
            KPPDataHead newHead = new KPPDataHead();

            newHead.UnPack(stream);
            Assert.IsTrue(newHead.GetField <ulong>("TotalSize") == 0UL);
            Assert.IsTrue(newHead.GetField <long>("CRC") == 100L);
            Assert.IsTrue(newHead.GetField <ushort>("SectionCount") == 1);
        }
Exemple #2
0
        public void UnPackTest()
        {
            DateTime    now      = DateTime.Now;
            string      fileName = DateTime.Now.Ticks + ".kpp";
            Guid        guid     = Guid.NewGuid();
            KPPDataHead head     = new KPPDataHead();
            PackageAttributeDataSection section = new PackageAttributeDataSection();

            section.SetField("PackName", "test.package");
            section.SetField("PackDescription", "test package description.");
            section.SetField("EnvironmentFlag", (byte)0x01);
            section.SetField("Version", "1.0.0");
            section.SetField("PackTime", now);
            section.SetField("ApplicationMainFileName", "1.txt");
            section.SetField("GlobalUniqueIdentity", guid);
            string tmpPath = PrepareTestFiles("res-files");

            KPPResource.Pack(tmpPath, fileName, head, true, section);
            Assert.IsTrue(File.Exists(fileName));

            KPPDataStructure structure = KPPResource.UnPack(fileName);

            Assert.IsTrue(structure.GetSectionField <string>(0x00, "PackName") == "test.package");
            Assert.IsTrue(structure.GetSectionField <string>(0x00, "PackDescription") == "test package description.");
            Assert.IsTrue(structure.GetSectionField <string>(0x00, "Version") == "1.0.0");
            Assert.IsTrue(structure.GetSectionField <string>(0x00, "ApplicationMainFileName") == "1.txt");
            Assert.IsTrue(structure.GetSectionField <DateTime>(0x00, "PackTime") == now);
            Assert.IsTrue(structure.GetSectionField <byte>(0x00, "EnvironmentFlag") == 0x01);
            Assert.IsTrue(structure.GetSectionField <Guid>(0x00, "GlobalUniqueIdentity") == guid);
            Assert.IsNotNull(structure);


            File.Delete(fileName);
            Directory.Delete(tmpPath, true);
        }
        public void PackTest()
        {
            KPPDataHead  head   = new KPPDataHead();
            MemoryStream stream = new MemoryStream();

            head.Pack(stream);
            byte[] buffer = stream.ToArray();
            byte[] data   = new byte[stream.Length];
            Buffer.BlockCopy(buffer, 0, data, 0, data.Length);
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length == 21);
            Assert.IsTrue(data[0] == 'K');
            Assert.IsTrue(data[1] == 'P');
            Assert.IsTrue(data[2] == 'P');
        }
Exemple #4
0
        public void PackNonCompletedEnvironmentTestWithoutDelete()
        {
            DateTime    now      = DateTime.Now;
            string      fileName = DateTime.Now.Ticks + ".kpp";
            Guid        guid     = Guid.NewGuid();
            KPPDataHead head     = new KPPDataHead();
            PackageAttributeDataSection section = new PackageAttributeDataSection();

            section.SetField("PackName", "test.package");
            section.SetField("PackDescription", "test package description.");
            section.SetField("EnvironmentFlag", (byte)0x01);
            section.SetField("Version", "1.0.0");
            section.SetField("PackTime", now);
            section.SetField("ApplicationMainFileName", "KJFramework.ApplicationEngine.ApplicationTest.dll");
            section.SetField("GlobalUniqueIdentity", guid);
            section.SetField("IsCompletedEnvironment", false);
            string tmpPath = PrepareTestFiles("res-files");

            KPPResource.Pack(tmpPath, fileName, head, false, section);
            Assert.IsTrue(File.Exists(fileName));
            Directory.Delete(tmpPath, true);
        }
 /// <summary>
 ///    KPP文件数据格式
 /// </summary>
 /// <param name="head">KPP资源文件头</param>
 /// <param name="sections">KPP数据节集合</param>
 /// <param name="files">KPP资源包内部所包含的文件集合</param>
 public KPPDataStructure(KPPDataHead head, IDictionary <byte, IKPPDataResource> sections, IDictionary <string, byte[]> files)
 {
     _head     = head;
     _sections = sections;
     _files    = files;
 }