コード例 #1
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());
        }
コード例 #2
0
        public void TestTypeBinder()
        {
            CompactSerializer cs = new CompactSerializer();

            Assert.AreEqual("binderedClass&", cs.Serialize(new BinderedClass()));
            Assert.AreEqual(1, cs.Deserialize <BinderedClass>("binderedClass&").a);
        }
コード例 #3
0
    public CustomShipInitializerModel(string model, ShipDriver driver)
    {
        var cs = new CompactSerializer();

        this.model  = cs.Deserialize <ShipSystemModel>(model);
        this.driver = driver;
    }
コード例 #4
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);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
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]);
        }
コード例 #13
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));
        }
コード例 #14
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]));
        }
コード例 #15
0
ファイル: GameSerializer.cs プロジェクト: Danil20-8/FlyOn
        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));
            }
        }
コード例 #16
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);
        }
コード例 #17
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);
        }
コード例 #18
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());
        }
コード例 #19
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());
        }
コード例 #20
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);
        }
コード例 #21
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>();
     }
 }
コード例 #22
0
        public static IEnumerable <T> LoadAll <T>(string path, string extend)
        {
            var cs = new CompactSerializer();

            return(LoadAll(path, extend, sr => cs.Deserialize <T>(sr)));
        }
コード例 #23
0
        public void DoPaste()
        {
            var s = Canvas.GetClipboardText() ?? "";

            Graph g;

            if (s.Contains("tikzpicture"))
            {
                g = TeXConverter.FromTikz(s);
            }
            else if (CompactSerializer.LooksLikeASerializedGraph(s))
            {
                g = CompactSerializer.Deserialize(s);
            }
            else
            {
                g = Graph.Deserialize(s);
            }

            if (g != null)
            {
                _graph.DisjointUnion(g);

                Invalidate();
                GraphChanged();
            }
            else if (s.Trim().Split(' ').All(x =>
            {
                int d;
                return(x.StartsWith("[") || int.TryParse(x, out d));
            }))
            {
                try
                {
                    g = GraphIO.GraphFromEdgeWeightString(s);
                    if (g != null)
                    {
                        _graph.DisjointUnion(g);

                        Invalidate();
                        GraphChanged();
                    }
                }
                catch { }
            }
            else
            {
                try
                {
                    g = GraphIO.GraphFromGraph6(s.Trim());

                    if (g != null)
                    {
                        var empty = _graph.Vertices.Count <= 0;
                        _graph.DisjointUnion(g);

                        if (empty)
                        {
                            NameModified(g.Name);
                        }

                        Invalidate();
                        GraphChanged();
                    }
                }
                catch { }
            }
        }