Esempio n. 1
0
        public static void Main()
        {
            Console.WriteLine("Start Experiments.");

            string path = "../../";

            // Файл
            FileStream fs = new FileStream(path + "tn.jpg", FileMode.Open, FileAccess.Read);

            PType tp_complex = new PTypeRecord(
                new NamedType("f1", new PType(PTypeEnumeration.integer)),
                new NamedType("f2", new PTypeSequence(new PType(PTypeEnumeration.@byte))));
            PxCell xcell = new PxCell(tp_complex, path + "xcell.bin", false);

            // Способ внедрения файла
            xcell.Clear();
            Write(xcell, fs);

            //object obval = xcell.Root.Get();
            //Console.WriteLine(tp_complex.Interpret(obval));

            PxEntry xentry = xcell.Root.Field(1);
            long llen = xentry.Count();
            PxEntry zelement = xentry.Element(0);
            Stream stream = xcell.BasicStream;
            long offset = zelement.offset;
            Console.WriteLine("{0} {1}", llen, offset);

            // Файл записи
            FileStream fsout = new FileStream(path + "tn_out.jpg", FileMode.Create, FileAccess.Write);

            stream.Position = offset;
            stream.CopyTo(fsout);
            fsout.Close();
        }
        public void Fill2VolumedSeqRecordWithRestTest()
        {
            var seqtriplets = new PTypeSequence(new PType(PTypeEnumeration.integer));
            var testdb = new object[] { 1, 2, 3, 5, 15, 19, 21, 90, 100, 13 };

            string testpacfilename = "test.pxc";
            PxCell xCell = new PxCell(seqtriplets, testpacfilename, false);
            xCell.Fill2(testdb);

            try
            {
                Assert.AreEqual(10, xCell.Root.Count());
                Assert.AreEqual(1, (int)xCell.Root.Element(0).Get().Value);
                Assert.AreEqual(3, (int)xCell.Root.Element(2).Get().Value);
                Assert.AreEqual(5, (int)xCell.Root.Element(3).Get().Value);
                Assert.AreEqual(15, (int)xCell.Root.Element(4).Get().Value);
                Assert.AreEqual(19, (int)xCell.Root.Element(5).Get().Value);
                Assert.AreEqual(90, (int)xCell.Root.Element(7).Get().Value);
                Assert.AreEqual(13, (int)xCell.Root.Element(9).Get().Value);

                var objects = xCell.Root.Elements().Select(e => e.Get().Value).ToArray();
                Assert.AreEqual(1, (int)xCell.Root.Elements().ToArray()[0].Get().Value);
                Assert.AreEqual(19, (int)xCell.Root.Elements().ToArray()[5].Get().Value);
                Assert.AreEqual(90, (int)xCell.Root.Elements().ToArray()[7].Get().Value);
                Assert.AreEqual(100, (int)xCell.Root.Elements().ToArray()[8].Get().Value);

            }
            finally
            {
                xCell.Close();
            }
        }
Esempio n. 3
0
 private static void Write(PxCell xcell, FileStream fs)
 {
     xcell.Root.Set(new object[] {99, new object[0]});
     xcell.Root.Field(1).SetRepeat(fs.Length);
     PxEntry zel = xcell.Root.Field(1).Element(0);
     fs.Position = 0L;
     xcell.BasicStream.Position = zel.offset;
     fs.CopyTo(xcell.BasicStream);
     xcell.BasicStream.Flush();
 }
Esempio n. 4
0
        public void SimpleSortRecordTest()
        {
            PType tp_seq = new PTypeSequence(new PTypeRecord(
                new NamedType("name", new PType(PTypeEnumeration.sstring)),
                new NamedType("id", new PType(PTypeEnumeration.sstring))));

            object[] testdb = new object[] {
                new object[] { "Petr", "0120"},
                new object[] { "Dan", "12"},
                new object[] { "Ivan", "54"},
                new object[] { "Jim", "13"},
                new object[] { "Wai", "1"},
                new object[] { "Ken", "15"},
                new object[] { "Aby", "916"},
            };

            string testpacfilename = "test.pxc";
            PxCell xCell = new PxCell(tp_seq, testpacfilename, false);
            try
            {
                xCell.Fill2(testdb);

                Assert.AreEqual(7, xCell.Root.Count());
                Assert.AreEqual("Ivan", xCell.Root.Element(2).Field(0).Get().Value.ToString());
                Assert.AreEqual("Jim", xCell.Root.Element(3).Field(0).Get().Value.ToString());
                Assert.AreEqual("Ken", xCell.Root.Element(5).Field(0).Get().Value.ToString());
                Assert.AreEqual("Aby", xCell.Root.Element(6).Field(0).Get().Value.ToString());

                xCell.Root.Sort(e =>
                {
                    return (string)e.Field(0).Get().Value;
                });

                Assert.AreEqual(7, xCell.Root.Count());
                Assert.AreEqual("Ivan", xCell.Root.Element(2).Field(0).Get().Value.ToString());
                Assert.AreEqual("Jim", xCell.Root.Element(3).Field(0).Get().Value.ToString());
                Assert.AreEqual("Petr", xCell.Root.Element(5).Field(0).Get().Value.ToString());
                Assert.AreEqual("Wai", xCell.Root.Element(6).Field(0).Get().Value.ToString());
            }
            finally
            {
                xCell.Close();
            }
        }
        public void Fill2SeqWithVolumeTest()
        {
            var seqtriplets = new PTypeSequence(
                    new PTypeUnion(
                        new NamedType("op",
                            new PTypeRecord(
                                new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                new NamedType("char", new PType(PTypeEnumeration.character))
                            )),
                        new NamedType("dp",
                            new PTypeRecord(
                                new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                                new NamedType("integer", new PType(PTypeEnumeration.integer)),
                                new NamedType("bool", new PType(PTypeEnumeration.boolean))
                            )
                        )
                    ));

            var testdb = new object[] {
                new object[] { 0, new object[] {"a", 'c'}},
                new object[] { 0, new object[] {"a1", 'c'}},
                new object[] { 1, new object[] {"da", 3, true}},
                new object[] { 0, new object[] {"a1", '1'}},
                new object[] { 1, new object[] {"da1", 7, true}},
                new object[] { 0, new object[] {"a2", '2'}},
                new object[] { 1, new object[] {"da2", 9, false}},
                new object[] { 1, new object[] {"da2", 11, true}},
                new object[] { 1, new object[] {"da3", 13, false}}
            };

            string testpacfilename = "test.pxc";
            PxCell xCell = new PxCell(seqtriplets, testpacfilename, false);

            xCell.Fill2(testdb);

            CheckSequence(xCell);
        }
Esempio n. 6
0
 public void FillTest()
 {
     string testpacfilename = "test.pxc";
     PxCell xCell = new PxCell(seqtriplets, testpacfilename, false);
     try
     {
         xCell.Fill(testdb);
         Assert.AreEqual(3, xCell.Root.Count());
         var e = (object[])xCell.Root.Element(2).Get().Value;
         Assert.AreEqual(e.Length, 2);
         Assert.AreEqual(e[0], 2);
         Assert.IsInstanceOfType(e[1], typeof(object[]));
         var o = (object[])e[1];
         Assert.AreEqual(o.Length, 4);
         Assert.AreEqual(o[0], "da");
         Assert.AreEqual(o[1], "db");
         Assert.AreEqual(o[2], "dc");
         Assert.AreEqual(o[3], "lang");
     }
     finally
     {
         xCell.Close();
     }
 }
        private static void CheckSequence(PxCell xCell)
        {
            try
            {
                Assert.AreEqual(9, xCell.Root.Count());

                var e = (object[])xCell.Root.Element(0).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 0);
                var o = (object[])e[1];
                Assert.AreEqual(o[0], "a");
                Assert.AreEqual(o[1], 'c');

                e = (object[])xCell.Root.Element(2).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 1);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "da");
                Assert.AreEqual(o[1], 3);
                Assert.AreEqual(o[2], true);

                e = (object[])xCell.Root.Element(3).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a1");
                Assert.AreEqual(o[1], '1');

                e = (object[])xCell.Root.Element(4).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 1);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "da1");
                Assert.AreEqual(o[1], 7);
                Assert.AreEqual(o[2], true);

                e = (object[])xCell.Root.Element(5).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a2");
                Assert.AreEqual(o[1], '2');

                e = (object[])xCell.Root.Element(7).Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 1);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "da2");
                Assert.AreEqual(o[1], 11);
                Assert.AreEqual(o[2], true);

                e = (object[])xCell.Root.Elements().ToArray()[0].Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a");
                Assert.AreEqual(o[1], 'c');

                e = (object[])xCell.Root.Elements().ToArray()[5].Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 0);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "a2");
                Assert.AreEqual(o[1], '2');

                e = (object[])xCell.Root.Elements().ToArray()[7].Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 1);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "da2");
                Assert.AreEqual(o[1], 11);
                Assert.AreEqual(o[2], true);

                e = (object[])xCell.Root.Elements().Last().Get().Value;
                Assert.IsInstanceOfType(e[1], typeof(object[]));
                Assert.AreEqual(e[0], 1);
                o = (object[])e[1];
                Assert.AreEqual(o[0], "da3");
                Assert.AreEqual(o[1], 13);
                Assert.AreEqual(o[2], false);

            }
            finally
            {
                xCell.Close();
            }
        }
Esempio n. 8
0
        public void TestFillPxCellWhenRecordHasLongValue()
        {
            seqtriplets = new PTypeSequence(
                new PTypeUnion(
                    new NamedType("op",
                        new PTypeRecord(
                            new NamedType("test1", new PType(PTypeEnumeration.sstring)))),
                    new NamedType("testindex", new PType(PTypeEnumeration.longinteger)),
                    new NamedType("dp",
                        new PTypeRecord(
                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                            new NamedType("lang", new PType(PTypeEnumeration.sstring)))))
                            );

            testdb = new object[] {
                new object[] { 0, new object[] {"a"}},
                new object[] { 1, 4L},
                new object[] { 2, new object[] {"da", "lang"}}
            };

            string testpacfilename = "test1.pxc";
            PxCell xCell = new PxCell(seqtriplets, testpacfilename, false);

            try
            {
                xCell.Fill2(testdb);
                Assert.AreEqual(3, xCell.Root.Count());
                var e = (object[])xCell.Root.Element(0).Get().Value;
                Assert.AreEqual(e.Length, 2);
                Assert.AreEqual(((object[])e[1])[0], "a");
                var e1 = (object[])xCell.Root.Element(1).Get().Value;
                Assert.AreEqual(e1.Length, 2);
                Assert.AreEqual(e1[0], 1);
                Assert.AreEqual(e1[1], 4L);

                var e2 = (object[])xCell.Root.Element(2).Get().Value;
                Assert.AreEqual(e2.Length, 2);
                Assert.AreEqual(((object[])e2[1])[0], "da");
                Assert.AreEqual(((object[])e2[1])[1], "lang");
            }
            finally
            {
                xCell.Close();
            }
        }
Esempio n. 9
0
        public void TestFillPxCell2()
        {
            seqtriplets = new PTypeSequence(
                   new PTypeRecord(
                            new NamedType("test1", new PType(PTypeEnumeration.sstring)),
                            new NamedType("subject", new PType(PTypeEnumeration.sstring)),
                            new NamedType("lang", new PType(PTypeEnumeration.sstring))
                    )
               );

            testdb = new object[] {
                new object[] {
                        "a",
                        "1L",
                        "dalang"},
                new object[] {
                        "b",
                        "2L",
                        "dalang"},
                new object[] {
                        "c",
                        "3L",
                        "dalang"}
            };

            string testpacfilename = "test.pxc";
            PxCell xCell = new PxCell(seqtriplets, testpacfilename, false);

            try
            {
                xCell.Fill2(testdb);
                var i = xCell.Root.Count();
                var e = (object[])xCell.Root.Element(0).Get().Value;
            }
            finally
            {
                xCell.Close();
            }
        }