Exemplo n.º 1
0
        public static IGraph AsRdf(this BrowserResponseBodyWrapper body)
        {
            IGraph graph = new Graph();

            using (var reader = new StreamReader(body.AsStream()))
            {
                new VDS.RDF.Parsing.TurtleParser().Load(graph, reader);
            }

            return(graph);
        }
Exemplo n.º 2
0
        public static IGraph AsRdf(this BrowserResponseBodyWrapper body)
        {
            IGraph graph = new Graph();

            graph.NamespaceMap.AddNamespace("hydra", new Uri(global::Hydra.Hydra.BaseUri));
            graph.NamespaceMap.AddNamespace("ex", new Uri("http://example.api/o#"));

            using (var reader = new StreamReader(body.AsStream()))
            {
                new VDS.RDF.Parsing.TurtleParser().Load(graph, reader);
            }

            return(graph);
        }
        public static T[] AsArrayDataFormat <T>(this BrowserResponseBodyWrapper body, DataFormat format)
        {
            switch (format)
            {
            case DataFormat.Json:
                return(JsonConvert.DeserializeObject <T[]>(body.AsString()));

            case DataFormat.Proto:
                var descriptor = ProtobufResponse.GetDescriptor(typeof(T));
                var stream     = new MemoryStream();
                body.AsStream().CopyTo(stream);
                return(descriptor.ReadLenDelimitedStream(stream.ToArray()).Cast <T>().ToArray());

            default:
                throw new NotImplementedException();
            }
        }
        public static T AsDataFormat <T>(this BrowserResponseBodyWrapper body, DataFormat format)
        {
            switch (format)
            {
            case DataFormat.Json:
                return(JsonConvert.DeserializeObject <T>(body.AsString()));

            case DataFormat.Proto:
                var descriptor = ProtobufResponse.GetDescriptor(typeof(T));
                var stream     = new MemoryStream();
                body.AsStream().CopyTo(stream);
                object result = null;
                if (typeof(T).IsArray)
                {
                    result = descriptor.ReadLenDelimitedStream(stream.ToArray());
                }
                else
                {
                    result = descriptor.Read(stream.ToArray());
                }

                switch (result)
                {
                case T model:
                    return(model);

                case SimpleValue <T> simple:
                    return(simple.Value);

                default:
                    throw new NotImplementedException();
                }

            default:
                throw new NotImplementedException();
            }
        }