Ejemplo n.º 1
0
        public void TestEqualBindersOnType()
        {
            CompactSerializer cs = new CompactSerializer();

            Assert.AreEqual("a&", cs.Serialize(new classWithBinder1()));
            Assert.AreEqual("1&", cs.Serialize(new classWithBinder2()));
            Assert.AreEqual(1, cs.Deserialize <classWithBinder1>("a&").a);
        }
Ejemplo n.º 2
0
        public void TestTypeBinder()
        {
            CompactSerializer cs = new CompactSerializer();

            Assert.AreEqual("binderedClass&", cs.Serialize(new BinderedClass()));
            Assert.AreEqual(1, cs.Deserialize <BinderedClass>("binderedClass&").a);
        }
Ejemplo n.º 3
0
        public static Appclasses.Core.Data.NameValueObject SetObject(string table, Appclasses.Core.Data.NameValueObject data, out string error)
        {
            string result;
            var    startedAt = DateTime.Now;
            var    serData   = CompactSerializer.Serialize <Appclasses.Core.Data.NameValueObject> (data);

            QRScanner.Appclasses.Log.Write(new QRScanner.Appclasses.LogEntry("END REQUEST: [Device/SerializeObject];" + (DateTime.Now - startedAt).TotalMilliseconds.ToString()));
            if (WebApp.Post("mode=setObj&table=" + table, serData, out result))
            {
                try
                {
                    startedAt = DateTime.Now;
                    var nvo = CompactSerializer.Deserialize <Appclasses.Core.Data.NameValueObject>(result);
                    QRScanner.Appclasses.Log.Write(new QRScanner.Appclasses.LogEntry("END REQUEST: [Device/DeserializeObject];" + (DateTime.Now - startedAt).TotalMilliseconds.ToString()));
                    error = nvo == null ? "Zapis objekta ni uspel!" : "";
                    return(nvo);
                }
                catch (Exception ex)
                {
                    error = "Napaka pri tolmačenju odziva web strežnika: " + ex.Message;
                    return(null);
                }
            }
            else
            {
                error = "Napaka pri klicu web strežnika: " + result;
                return(null);
            }
        }
Ejemplo n.º 4
0
        public static void Save(string path, object data, Func <bool> fileExistsDiolog)
        {
            var cs = new CompactSerializer();

            path = GetPath(path);

            var dir = new string(path.Reverse().SkipWhile(c => c != '\\').Reverse().ToArray());

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (File.Exists(path))
            {
                if (!fileExistsDiolog())
                {
                    return;
                }
            }

            using (StreamWriter sw = File.CreateText(path))
            {
                cs.Serialize(data, sw);
            }
        }
Ejemplo n.º 5
0
        public void TestAbstract()
        {
            abs[]             a  = new abs[] { new sba(13), new sba(24), new sba(48) };
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            Assert.AreEqual(48, ((sba)cs.Deserialize <abs[]>(d)[2]).a);
        }
Ejemplo n.º 6
0
        public void TestAbstractInShell()
        {
            ShellAbstract[]   a  = new ShellAbstract[] { new ShellAbstract() };
            CompactSerializer cs = new CompactSerializer();
            string            r  = cs.Serialize(a);

            Assert.AreEqual(1, cs.Deserialize <ShellAbstract[]>(r)[0].field.a);
        }
Ejemplo n.º 7
0
        public void TestEmptyClass()
        {
            empty[]           a  = new empty[] { new empty(), new empty(), new empty() };
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            Assert.AreEqual(3, cs.Deserialize <empty[]>(d).Length);
        }
Ejemplo n.º 8
0
        public void TestSerializeable()
        {
            sable[]           a  = new sable[] { new sable(), new sable(), new sable() };
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            Assert.AreEqual(1, cs.Deserialize <sable[]>(d)[2].a);
        }
Ejemplo n.º 9
0
        public static void Serialize(object data, string path, SerializeBinders binders)
        {
            CompactSerializer cs = new CompactSerializer(binders);

            using (StreamWriter sw = new StreamWriter(path))
            {
                cs.Serialize(data, sw);
            }
        }
Ejemplo n.º 10
0
        public void TestStringNumerablesObject()
        {
            object[]          a  = new object[] { 1.2, 2 };
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            //Assert.AreEqual(":2&System.Double:1,2&System.Int32:2&", d);
            Assert.AreEqual(2, (int)((cs.Deserialize <object[]>(d))[1]));
        }
Ejemplo n.º 11
0
        public void TestStringNumerables()
        {
            int[]             a  = new int[] { 1, 2 };
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            Assert.AreEqual("2&1&2&", d);
            Assert.AreEqual(2, cs.Deserialize <int[]>(d)[1]);
        }
Ejemplo n.º 12
0
        public void TestStringSerialization()
        {
            string            s  = "qwerty";
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(s);

            Assert.AreEqual("qwerty&", d);
            Assert.AreEqual("qwerty", cs.Deserialize <string>(d));
        }
Ejemplo n.º 13
0
        public static void Save()
        {
            CompactSerializer cs = new CompactSerializer();

            using (StreamWriter sw = new StreamWriter("GameConfig.txt"))
            {
                cs.Serialize(options, sw, typeof(DictionaryBinder <string, string>));
            }
        }
Ejemplo n.º 14
0
        public void TestSimpleDataSerialization()
        {
            int a = 10;
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(a);

            Assert.AreEqual("10&", d);
            a = cs.Deserialize <int>(d);
            Assert.AreEqual(10, a);
        }
Ejemplo n.º 15
0
        public void TestSerializationBinderInNumerables()
        {
            bar[] b = new bar[] { new bar(), new bar(), new bar() };
            b[2].dict.Add("vasya", 12);
            CompactSerializer cs = new CompactSerializer(CSOptions.WithTypes);

            string d = cs.Serialize(b);

            cs.Deserialize <bar[]>(d);
        }
Ejemplo n.º 16
0
        public void TestMultiLine()
        {
            SafeStrings ss = new SafeStrings()
            {
                s1 = "111", s2 = "222"
            };
            CompactSerializer cs = new CompactSerializer('\n');
            string            d  = cs.Serialize(ss);

            Assert.AreEqual("111222", cs.Deserialize <SafeStrings>(d).ToString());
        }
Ejemplo n.º 17
0
        public void TestSafeStrings()
        {
            SafeStrings ss = new SafeStrings()
            {
                s1 = "111&", s2 = "222&"
            };
            CompactSerializer cs = new CompactSerializer(CSOptions.SafeString);
            string            d  = cs.Serialize(ss);

            Assert.AreEqual("111&222&", cs.Deserialize <SafeStrings>(d).ToString());
        }
Ejemplo n.º 18
0
        public void TestSerializationBinder()
        {
            bar b = new bar();

            b.dict.Add("vasya", 12);

            CompactSerializer cs = new CompactSerializer();

            string d = cs.Serialize(b);

            cs.Deserialize <bar>(d);
        }
Ejemplo n.º 19
0
        public void TestDictionaryArrayBinder()
        {
            CompactSerializer cs = new CompactSerializer();
            string            d  = cs.Serialize(new Dictionary <int, int>[] { new Dictionary <int, int>()
                                                                              {
                                                                                  { 1, 1 }
                                                                              }, new Dictionary <int, int>()
                                                                              {
                                                                                  { 1, 1 }
                                                                              } }, typeof(DictionaryArrayBinder <int, int>));

            Assert.AreEqual("2&1&1&1&1&1&1&", d);
        }
Ejemplo n.º 20
0
        public void DoCopy(bool verbose = false)
        {
            var h = _graph.InducedSubgraph(_graph.SelectedVertices);
            var s = verbose ? h.Serialize() : CompactSerializer.Serialize(h);

            if (!string.IsNullOrEmpty(s))
            {
                try
                {
                    Canvas.SetClipboardText(s);
                }
                catch { }
            }
        }
Ejemplo n.º 21
0
        public static bool TryLock(string lockID, out string error)
        {
            if (obtainedLocks.FirstOrDefault(x => x == lockID) != null)
            {
                error = "OK!"; return(true);
            }

            var wf = new WaitForm();

            try
            {
                //            wf.Start("Pridobivam dostop");

                var obj = new Appclasses.Core.Data.NameValueObject("Lock");
                obj.SetString("LockID", lockID);
                obj.SetString("LockInfo", UserName());
                obj.SetInt("Locker", UserID());
                var serObj = CompactSerializer.Serialize <QRScanner.Appclasses.Core.Data.NameValueObject>(obj);
                if (WebApp.Post("mode=tryLock", serObj, out error))
                {
                    if (error == "OK!")
                    {
                        obtainedLocks.Add(lockID);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                //             wf.Stop();
            }
        }
Ejemplo n.º 22
0
        public string DoCopy(bool verbose = false)
        {
            var h = _graph.InducedSubgraph(_graph.SelectedVertices);

            return(CompactSerializer.Serialize(h));
        }