public MainChat(Login loginWindow) { InitializeComponent(); this.WindowParent = loginWindow; SelfClient = loginWindow.SelfClient; heartPackageData = Encoding.UTF8.GetBytes( JsonData.ConvertToText( JsonData.Create(new TransPackage() { Name = WindowParent.NickName, Content = null, ClientGuid = WindowParent.ClientGuid, PackageType = ConstDef.HeartPackage }))); getOnlineInfoPackageData = Encoding.UTF8.GetBytes( JsonData.ConvertToText( JsonData.Create(new TransPackage() { Name = WindowParent.NickName, Content = null, ClientGuid = WindowParent.ClientGuid, PackageType = ConstDef.ReportChannelOnline }))); DataObject.AddPastingHandler(InputBox, InputBox_OnPaste); }
public void DynamicTypeSystemDemo() { DynamicData twin = JsonData.Create(s_demo_payload); string original = twin.ToString(); Assert.IsTrue(ReferenceEquals(s_demo_payload, original)); Assert.AreEqual(123, twin["CreatedAt"]); Assert.AreEqual(72, twin["Temperature"]); Assert.AreEqual("F", twin["Unit"]); int numberOfProperties = 0; foreach (string property in twin.PropertyNames) { numberOfProperties++; } Assert.AreEqual(5, numberOfProperties); dynamic dynamicTwin = twin; Assert.AreEqual(72, dynamicTwin.Temperature); Assert.AreEqual("F", dynamicTwin.Unit); Assert.AreEqual("ID0001", dynamicTwin.Id); }
private bool TrySendPackage(TransPackage package) { JsonData jsonToSend = JsonData.Create(package); string textToSend = JsonData.ConvertToText(jsonToSend); byte[] bytesToSend = Encoding.UTF8.GetBytes(textToSend); return TrySendData(bytesToSend); }
public void Setup() { var properties = new Dictionary <string, object>(StringComparer.Ordinal); dictionary = properties; jsonData = JsonData.Create(s_demo_payload); dynamicJsonData = jsonData; data = new DynamicData(); dynamicData = data; foreach (var property in jsonData.PropertyNames) { properties.Add(property, jsonData[property]); data[property] = jsonData[property]; } searchDocument = new SearchDocument(properties); dynamicSearchDocument = searchDocument; staticObject = (Payload)dynamicJsonData; dynamicObject = staticObject; handcraftedHash = new DynamicData(new PerfectStore(properties)); dynamicHandcraftedHash = handcraftedHash; perfectHash = new DynamicData(PerfectHashStore.Create(properties)); dynamicPerfectHash = perfectHash; }
public void ArrayOfArrays() { var data = $"[[{s_contact1},{s_contact2}]]"; dynamic json = JsonData.Create(data); dynamic contacts = json[0]; dynamic contact = contacts[0]; Assert.AreEqual(25, contact.Age); }
public void PrimitiveArray() { var data = "[5,10,20]"; dynamic json = JsonData.Create(data); Assert.AreEqual(5, json[0]); Assert.AreEqual(20, json[2]); int[] array = (int[])json; Assert.AreEqual(5, array[0]); Assert.AreEqual(20, array[2]); }
public void Dictionary() { DynamicData contact = JsonData.Create(s_contact1); Assert.AreEqual("John", contact["First"]); Assert.AreEqual("Smith", contact["Last"]); Assert.AreEqual(25, contact["Age"]); var address = (DynamicData)contact["Address"]; Assert.AreEqual(98052, address["Zip"]); Assert.AreEqual("Redmond", address["City"]); //var phones = (string[])contact["Phones"]; //Assert.AreEqual("425-999-9999", phones[0]); //Assert.AreEqual("425-999-9998", phones[1]); }
public void Deserialize() { dynamic json = JsonData.Create(s_contact1); var contact = (Contact)json; Assert.AreEqual("John", contact.First); Assert.AreEqual("Smith", contact.Last); Assert.AreEqual(25, contact.Age); Assert.AreEqual(98052, json.Address.Zip); Assert.AreEqual("Redmond", json.Address.City); var address = (Address)json.Address; Assert.AreEqual(98052, address.Zip); Assert.AreEqual("Redmond", address.City); var phones = (string[])json.Phones; Assert.AreEqual("425-999-9999", phones[0]); Assert.AreEqual("425-999-9998", phones[1]); }
public void ReadJson() { DynamicData json = JsonData.Create(s_contact1); dynamic contact = json; Assert.AreEqual("John", contact.First); Assert.AreEqual("Smith", contact.Last); Assert.AreEqual(25, contact.Age); Assert.AreEqual(98052, contact.Address.Zip); Assert.AreEqual("Redmond", contact.Address.City); dynamic address = contact.Address; Assert.AreEqual(98052, address.Zip); Assert.AreEqual("Redmond", address.City); dynamic phones = contact.Phones; Assert.AreEqual("425-999-9999", phones[0]); Assert.AreEqual("425-999-9998", phones[1]); }
public static JsonData <TType> Create() { return(JsonData.Create <JsonData <TType>, TType>()); }