public ICollection <IEntity> ReadData() { var serializer = new MediaSerializer(contentType); var result = serializer.Deserialize(content); return(result); }
private Target RenderTarget(HttpContext httpContext) { var req = httpContext.Request; var method = req.Method; var prefix = req.PathBase.Value; var path = req.Path.Value; var requestUri = new UriString(req.GetDisplayUrl()); if (method.EqualsAnyIgnoreCase(MethodNames.Post, MethodNames.Put, MethodNames.Patch)) { var serializer = new MediaSerializer(req.ContentType); var entity = serializer.Deserialize(req.Body); Debug.WriteLine(Json.Beautify(serializer.SerializeToJson(entity))); } switch (path.ToLower()) { case "": return(requestUri.Combine(prefix).Combine("Index").ToUri()); case "/status": return(SandboxEntities.GetStatus(requestUri, prefix)); case "/index": return(SandboxEntities.GetIndex(requestUri, prefix)); case "/blueprint": return(SandboxEntities.GetBlueprint(requestUri, prefix)); default: return(FindEmbeddedResource(path)); } }
public static Entity ParseEntity(Stream inputStream) { var serializer = new MediaSerializer(); var entity = serializer.Deserialize(inputStream); return(entity); }
public static void Main(string[] commandArgs) { try { var record = new Record(); record.Add(new Property("title", "My Title")); record.Add(new Property("header", "My Header")); var link = new Link(); link.Add(new Property("title", "My Title")); link.Add(new Property("href", "My #ref")); link.Add(new Property("header", "My Header")); link.Add(new Class("header")); link.Add(new Rel("header")); record.Add(link); var file = new ResourceRef(); file.Add(new Property("title", "My Title")); file.Add(new Property("href", "My #ref")); file.Add(new Property("header", "My Header")); file.Add(new Class("header")); file.Add(new Rel("header")); record.Add(file); record.Add(new Property("__meta", Value.CreateObject(new { Tables = new { Headers = new VName[] { "Id", "Name" } } }))); var p1 = record.GetProperty <VArray>("__meta.tables.headers"); record.SetProperty("__meta.tables.headers.id", new[] { 10 }); var p2 = record.GetProperty <VArray>("__meta.tables.headers.id"); var serializer = new MediaSerializer(MimeType.JsonSiren); var step1 = serializer.Serialize(record); var target = serializer.Deserialize(step1); var step2 = serializer.Serialize(record); Debug.WriteLine(Json.Beautify(step1)); Debug.WriteLine(Json.Beautify(step2)); } catch (Exception ex) { ex.Trace(); } }
public static async Task <Entity> ReadEntityAsync(this IRequest request) { var contentHeader = new ContentHeader(request.Headers); var mimeType = contentHeader.Type; var encoding = contentHeader.Encoding; var serializer = new MediaSerializer(mimeType); var entity = serializer.Deserialize(request.Body, encoding); return(await Task.FromResult(entity)); }
private Target FindEmbeddedResource(string path) { var name = path.Replace("/", "-") + ".json"; var text = GetType().GetResourceText(name); if (text == null) { return(null); } var media = new MediaSerializer("json"); var entity = media.Deserialize(text); return(entity); }
private async Task <object> DeserializeAsync(Stream source, string type, string charset) { using (var memory = new MemoryStream()) { await source.CopyToAsync(memory); memory.Position = 0; if (memory.Length == 0) { return(null); } if (type.Contains("siren")) { var serializer = new MediaSerializer(type); var entity = serializer.Deserialize(memory, charset); return(entity); } return(memory.ToArray()); } }