Ejemplo n.º 1
0
        public static Appclasses.Core.Data.NameValueObject GetObject(string table, string id, out string error)
        {
            string result;

            if (WebApp.Get("mode=getObj&table=" + table + "&id=" + id, out result))
            {
                try
                {
                    var 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 ? "Ne obstaja (" + table + "; " + id + ")!" : "";
                    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.º 2
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.º 3
0
    public CustomShipInitializerModel(string model, ShipDriver driver)
    {
        var cs = new CompactSerializer();

        this.model  = cs.Deserialize <ShipSystemModel>(model);
        this.driver = driver;
    }
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 static bool IsValidUser(string password, out string error)
        {
            string result;

            if (WebApp.Get("mode=loginUser&password="******"Success").BoolValue == true)
                    {
                        nvl.Items.ForEach(nv => UserInfo.Add(nv));
                        error = "";
                        return(true);
                    }
                    else
                    {
                        error = nvl.Get("Error").StringValue;
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    error = "Napaka pri tolmačenju odziva web strežnika: " + ex.Message;
                    return(false);
                }
            }
            else
            {
                error = "Napaka pri klicu web strežnika: " + result;
                return(false);
            }
        }
Ejemplo n.º 6
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.º 7
0
        public static ShipSystemModel[] GetAllShips()
        {
            var cs = new CompactSerializer();

            return(Resources.LoadAll <TextAsset>("Ships").Select(t => cs.Deserialize <ShipSystemModel>(t.text))
                   .Concat(LoadAll("Ships", "txt", sr => cs.Deserialize <ShipSystemModel>(sr)))
                   .ToArray());
        }
Ejemplo n.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
0
        public static T Deserialize <T>(string path, SerializeBinders binders)
        {
            CompactSerializer cs = new CompactSerializer(binders);

            using (StreamReader sr = new StreamReader(path, encoding))
            {
                return(cs.Deserialize <T>(sr));
            }
        }
Ejemplo n.º 16
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.º 17
0
        public void TestActualSerialize()
        {
            //using BClass
            string r = new CompactSerializer().Serialize(new MainClass());

            Assert.AreEqual("2&1,5&", r);

            Assert.AreEqual(1.5f, new CompactSerializer().Deserialize <MainClass>(r).value);
        }
Ejemplo n.º 18
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.º 19
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.º 20
0
        public void TestNullBinderSerializationNull()
        {
            var tc = new TestClassWithNullField();

            tc.nullField = null;
            string r = new CompactSerializer().Serialize(tc);

            Assert.AreEqual("0&&", r);
            Assert.AreEqual(null, new CompactSerializer().Deserialize <TestClassWithNullField>(r).nullField);
        }
Ejemplo n.º 21
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.º 22
0
        public void TestNullBinderSerializationValue()
        {
            var tc = new TestClassWithNullField();

            tc.nullField = "Hello";
            string r = new CompactSerializer().Serialize(tc);

            Assert.AreEqual("1&Hello~&", r);
            Assert.AreEqual("Hello", new CompactSerializer().Deserialize <TestClassWithNullField>(r).nullField);
        }
Ejemplo n.º 23
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.º 24
0
        public void TestTypesCollecting()
        {
            Dynamic d = new Dynamic();
            var     t = new DRLib.TreeNode <int>(1);

            t.AddNode(3);
            d.value = t;
            var r = CompactSerializer.CollectDynamicTypes(d);

            Assert.IsTrue(true);
        }
Ejemplo n.º 25
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.º 26
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.º 27
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.º 28
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.º 29
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.º 30
0
 static GameConfig()
 {
     try {
         CompactSerializer cs = new CompactSerializer();
         using (StreamReader sr = new StreamReader("GameConfig.txt"))
         {
             options = cs.Deserialize <Dictionary <string, string> >(sr, typeof(DictionaryBinder <string, string>));
         }
     }
     catch
     {
         options = new Dictionary <string, string>();
     }
 }