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()); }
public void TestTypeBinder() { CompactSerializer cs = new CompactSerializer(); Assert.AreEqual("binderedClass&", cs.Serialize(new BinderedClass())); Assert.AreEqual(1, cs.Deserialize <BinderedClass>("binderedClass&").a); }
public CustomShipInitializerModel(string model, ShipDriver driver) { var cs = new CompactSerializer(); this.model = cs.Deserialize <ShipSystemModel>(model); this.driver = driver; }
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); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
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); }
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]); }
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)); }
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])); }
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)); } }
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); }
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); }
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()); }
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()); }
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); }
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>(); } }
public static IEnumerable <T> LoadAll <T>(string path, string extend) { var cs = new CompactSerializer(); return(LoadAll(path, extend, sr => cs.Deserialize <T>(sr))); }
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 { } } }