public void SerializeDeserializeVirtualMachine() { var helper = new JsonHelpers<VirtualMachine>(); var toSerialize = new VirtualMachine { ID = Guid.NewGuid(), StampId = Guid.NewGuid(), CreationTime = DateTime.Now, PerfDiskBytesRead = 500, Name = @"This is a test 这是一个测试 㐀㐁㐂㐃㐄㐅" }; var serialized = helper.Serialize(toSerialize); var vmList = helper.Deserialize(serialized); Assert.NotNull(vmList); Assert.Equal(vmList.Count, 1); Assert.True(vmList[0] is VirtualMachine); Assert.Equal(toSerialize.ID, vmList[0].ID); Assert.Equal(toSerialize.StampId, vmList[0].StampId); Assert.Equal(toSerialize.CreationTime, vmList[0].CreationTime); Assert.Equal(toSerialize.PerfDiskBytesRead, vmList[0].PerfDiskBytesRead); Assert.Equal(toSerialize.Name, vmList[0].Name); }
public async Task <List <Character> > GetCharacters() { //load local json file Uri uri = new Uri("ms-appx:///assets/Data.json"); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(uri); using (var storageStream = await storageFile.OpenReadAsync()) { using (Stream stream = storageStream.AsStreamForRead()) { using (StreamReader reader = new StreamReader(stream)) { var jsonText = reader.ReadToEnd(); List <Character> myList = JsonHelpers.Deserialize <List <Character> >(jsonText); //Configure portrait. Ussually this wouldn't be done here foreach (var character in myList) { StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(String.Format("ms-appx:///Assets/Portraits/{0}.jpg", character.portraitID))); using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { character.portrait = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); character.portrait.SetSource(fileStream); } } return(myList); } } } }
public void SerializeDeserializeVirtualMachine() { var helper = new JsonHelpers <VirtualMachine>(); var toSerialize = new VirtualMachine { ID = Guid.NewGuid(), StampId = Guid.NewGuid(), CreationTime = DateTime.Now, PerfDiskBytesRead = 500, Name = @"This is a test 这是一个测试 㐀㐁㐂㐃㐄㐅" }; var serialized = helper.Serialize(toSerialize); var vmList = helper.Deserialize(serialized); Assert.NotNull(vmList); Assert.Equal(vmList.Count, 1); Assert.True(vmList[0] is VirtualMachine); Assert.Equal(toSerialize.ID, vmList[0].ID); Assert.Equal(toSerialize.StampId, vmList[0].StampId); Assert.Equal(toSerialize.CreationTime, vmList[0].CreationTime); Assert.Equal(toSerialize.PerfDiskBytesRead, vmList[0].PerfDiskBytesRead); Assert.Equal(toSerialize.Name, vmList[0].Name); }
public static IReadOnlyList <RootObjectJson> LoadJsonFromDirectory(string folderPath, bool staticCache = true) { var result = new List <RootObjectJson>(); var data = GetJsonFiles(folderPath); foreach (var(name, path, content) in data) { var json = JsonHelpers.Deserialize <RootObjectJson>(content); if (json.Culture == null && CultureHelper.Exists(name)) { json.Culture = name; } else if (!CultureHelper.Exists(json.Culture)) { continue; } if (json.Culture == null) { json.Culture = LocalizationConstants.Invariant; } if (staticCache) { _cachedJsons.AddOrUpdate(name, json, (jsonName, tuple) => json); } result.Add(json); } return(result); }
public void ThenFollowingShouldBeAvailableInTheResponseContent(string result) { //Assert Assert.AreEqual(HttpStatusCode.OK, RestManager.Status); var responseObjects = JsonHelpers.Deserialize <CitiesInRectangleZone>(RestManager.ResponseContent); Assert.AreEqual(15, responseObjects.List.Count); }
private void Initialize(HarmonyInstance harmonyInstance, string settings) { Logger.Debug("Initializing Features..."); ModSettings = JsonHelpers.Deserialize <TModSettings>(settings) ?? new TModSettings(); Logger.LogLevel = ModSettings.LogLevel; var jsonSettings = JsonHelpers.Deserialize(settings); ModFeatures.ForEach( feature => feature.Initialize( harmonyInstance, jsonSettings?[feature.Name]?.ToString(), Logger, Directory)); Logger.Debug("Feature initialization complete."); }
public JsonResult Index(int?id, string search) { InforSearch se = null; Logger.Info($"Search for user {AppUserState.UserName}"); if (AppUserState == null || AppUserState.Connected == false) { return(null); } if (!string.IsNullOrEmpty(search)) { se = JsonHelpers.Deserialize <InforSearch>(search); } var conn = new InforConnection(tu: _tu, tup: _tup); var s = new InforSearch { SearchType = InforSearches.Favourites, Name = InforSearches.Favourites.GetAttribute <DescriptionAttribute>().Description, Function = InforSearches.Favourites.GetAttribute <SearchStringAttribute>().Term, App = InforSearches.Favourites.GetAttribute <ApplicationAttribute>().Application, IsAdminable = false, //Icon = new BitmapImage(new Uri(@"/Images/SearchIcons/favourite.jpg", UriKind.RelativeOrAbsolute)), RunAsAdmin = false }; if (se != null) { s = se; } return (this.Jsonp(id == null ? conn.SearchWeb(s, AppUserState.UserName, AppUserState.Wgs, AppUserState.Ds) : conn.GetRecordChildrenWeb((int)id, AppUserState.UserName, AppUserState.Wgs, AppUserState.Ds))); //return this.Jsonp(recs); }
internal IList <T> DeserializeClientPayload <T>(string payload) { var jsonHelper = new JsonHelpers <T>(); return(jsonHelper.Deserialize(payload)); }
private WeatherData ToWeatherData(string responseJson) { return(JsonHelpers.Deserialize <WeatherData>(RestManager.ResponseContent)); }
public static async Task <T> DeserializeAsType <T>(this HttpResponseMessage response) { var responseContent = await response.Content.ReadAsStringAsync(); return(JsonHelpers.Deserialize <T>(responseContent)); }