Exemplo n.º 1
0
        public static void EncodePackedFile(string xml, out byte[] bytes)
        {
            var PS = new Packed_Section();

            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xml);

            var          f      = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(f);

            //header
            writer.Write(Packed_Section.Packed_Header);
            writer.Write((sbyte)0);

            //dictionary
            var newDict = GetXmlDict(xDoc);

            PS.writeDictionary(writer, newDict);

            //records
            PS.WriteElement(writer, xDoc.FirstChild, xDoc, newDict);

            f.Flush();

            bytes = f.ToArray();

            f.Close();
        }
Exemplo n.º 2
0
        public static void EncodePackedFile(string path, string xml)
        {
            var PS = new Packed_Section();

            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xml);

            File.Delete(path);
            var          f      = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter writer = new BinaryWriter(f);

            //header
            writer.Write(Packed_Section.Packed_Header);
            writer.Write((sbyte)0);

            //dictionary
            var newDict = GetXmlDict(xDoc);

            PS.writeDictionary(writer, newDict);

            //records
            PS.WriteElement(writer, xDoc.FirstChild, xDoc, newDict);

            f.Flush();
            f.Close();
        }
Exemplo n.º 3
0
        public static string DecodePackedFile(BinaryReader reader, string rootName)
        {
            XmlDocument xDoc = new XmlDocument();

            var sb = reader.ReadSByte();

            var PS = new Packed_Section();

            var dictionary = PS.readDictionary(reader);

            var xmlroot = xDoc.CreateNode(XmlNodeType.Element, rootName, "");

            //pos202
            PS.readElement(reader, xmlroot, xDoc, dictionary);
            var xml_string = xmlroot.OuterXml;

            xml_string = NXMLFormatter.Formatter.Format(xml_string);

            xDoc.LoadXml(xml_string);
            var newDict = GetXmlDict(xDoc);

            var x = Enumerable.SequenceEqual(dictionary, newDict);

            return(xml_string);
        }
Exemplo n.º 4
0
    private void DecodePackedFile(BinaryReader reader)
    {
        reader.ReadSByte();
        Packed_Section packedSection = new Packed_Section();

        List <string> dictionary = packedSection.readDictionary(reader);
        XmlNode       xmlroot    = xDoc.CreateNode(XmlNodeType.Element, PackedFileName, "");

        packedSection.readElement(reader, xmlroot, xDoc, dictionary);
        xDoc.AppendChild(xmlroot);
    }
Exemplo n.º 5
0
        public static string DecodePackedFile(BinaryReader reader, string rootName)
        {
            XmlDocument xDoc = new XmlDocument();

            var sb = reader.ReadSByte();

            var PS = new Packed_Section();

            var dictionary = PS.readDictionary(reader);

            var xmlroot = xDoc.CreateNode(XmlNodeType.Element, rootName, "");

            //pos202
            PS.readElement(reader, xmlroot, xDoc, dictionary);

            return(xmlroot.OuterXml);
        }
Exemplo n.º 6
0
        public void ReadDictionary()
        {
            List <string> expected = null;

            using (var fileStream = File.OpenRead(encodedFile))
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    binaryReader.ReadInt32(); //header
                    binaryReader.ReadSByte(); //skip byte

                    var PS = new Packed_Section();

                    expected = PS.readDictionary(binaryReader);
                }
            using (var reader = new PackedXml.PackedXmlReader(encodedFile, originalFile))
            {
                reader.ReadHeader();
                var actual = reader.ReadDictionary();

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Count, actual.Count);
                CollectionAssert.AreEqual(expected, actual);
            }
        }