private void deserializing() { using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Sensemaking.Serialization.Specs.Payload.json"))) deserializedByExtensionMethod = reader.ReadToEnd().Deserialize <DeserializedObject>(); using (var reader = new JsonTextReader(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Sensemaking.Serialization.Specs.Payload.json")))) deserializedByJsonSerializer = new JsonSerializer().Deserialize <DeserializedObject>(reader); }
private void Load(char c)//(double x, double y) { //Console.WriteLine("ROZPOCZĘTO CZYTANIE DRZEW O Wsporzednych " + x + "||" + y); Console.WriteLine("ROZPOCZĘTO CZYTANIE DRZEW " + c); string json; using (WebClient webClient = new WebClient()) { // string filters = @"&filters={""wiek_w_dni"":""" + a + @"""}"; //string filters = "circle=21.02,52.21,1000"; // string filters = "circle="+y+","+x+",0.0001"; // filters += "&limit=50000"; string filters = "&q=" + c; filters += "&limit=50000"; json = webClient.DownloadString(apiUri + "&" + filters).Replace(@"\ufeff", ""); } DeserializedObject result = (DeserializedObject)JsonConvert.DeserializeObject(json, typeof(DeserializedObject)); var trees = result.result.records; Console.WriteLine("Znaleziono {0} drzew", trees.Count); int i = 1; using (ApplicationDbContext ctx = new ApplicationDbContext()) { foreach (var tree in trees) { InsertTree(tree, ctx, ref i); if (i % 500 == 0) { Console.WriteLine("SaveChanges"); ctx.SaveChanges(); } } Console.WriteLine("SaveChanges"); ctx.SaveChanges(); } Console.WriteLine("ZAKOŃCZONO CZYTANIE OBSZARU DRZEW "); }
private dynamic GetAttributeValue(string AttributeName) { return(DeserializedObject.GetType().GetProperty(AttributeName).GetValue(DeserializedObject, null)); }
protected override void before_each() { base.before_each(); deserializedByExtensionMethod = null; deserializedByJsonSerializer = null; }
private void serializing_and_deserialising() { var serialize = the_object.Serialize(); deserializedByExtensionMethod = serialize.Deserialize <DeserializedObject>(); }
public DeserializedObject <T> Deserialize(string jsonObject) { if (string.IsNullOrEmpty(jsonObject)) { throw new ArgumentNullException(nameof(jsonObject)); } var instance = Activator.CreateInstance(typeof(T)); var properties = typeof(T).GetProperties().ToList();; JObject json = JObject.Parse(jsonObject); var dateTag = json.SelectToken($"CreationDate"); var dateValue = dateTag.Value <string>(); var attribute = typeof(T).GetCustomAttributes(typeof(CachedAttribute), true); var resultDeserialization = new DeserializedObject <T>(); if (attribute == null || attribute.Length == 0) { throw new ArgumentException($"Object is not cached"); } var attr = attribute[0] as CachedAttribute; var exprTime = attr.ExpirationTimeMiliSeconds; DateTime dt = DateTime.ParseExact(dateValue, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); resultDeserialization.CreateTime = dt; resultDeserialization.ExprTime = exprTime; if (DateTime.UtcNow.Millisecond - dt.Millisecond > exprTime) { resultDeserialization.Object = null; return(resultDeserialization); } foreach (var property in properties) { var location = json.SelectToken($"Object.{property.Name}"); if (property.PropertyType.IsValueType || property.PropertyType == typeof(string)) { Type propertyType = property.PropertyType; var propertyValue = location.Value <string>(); TypeConverter converter = TypeDescriptor.GetConverter(propertyType); var value = converter.ConvertFromString(propertyValue); property.SetValue(instance, value); } else if (property.PropertyType.IsArray) { if (property.PropertyType.GetElementType().IsValueType || property.PropertyType.GetElementType().IsValueType is string) { Type propertyType = property.PropertyType; if (location.HasValues) { var values = location?.Values <string>(); if (values != null) { var typedArray = Array.CreateInstance(property.PropertyType.GetElementType(), values.ToList().Count); TypeConverter converter = TypeDescriptor.GetConverter(propertyType.GetElementType()); int i = 0; foreach (var element in values) { var value = converter.ConvertFromString(element); typedArray.SetValue(value, i); } property.SetValue(instance, typedArray); } } } else { //TODO Not implements for innner not value type } } else { var desObj = DeserializeObject(property, json, $"Object.{property.Name}"); property.SetValue(instance, desObj); } } resultDeserialization.Object = (T)instance; return(resultDeserialization); }