Esempio n. 1
0
        public async Task <StatementsResultLRSResponse> MoreStatements(StatementsResult result)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method   = HttpMethod.Get;
            req.resource = endpoint.Authority;
            if (!req.resource.EndsWith("/", StringComparison.Ordinal))
            {
                req.resource += "/";
            }
            req.resource += result.more;

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content, 0, res.content.Length)));

            return(r);
        }
Esempio n. 2
0
        public async Task <StatementsResultLRSResponse> QueryStatements(StatementsQuery query)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method      = HttpMethod.Get;
            req.resource    = "statements";
            req.queryParams = query.ToParameterMap(version);

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content, 0, res.content.Length)));

            return(r);
        }
Esempio n. 3
0
        public StatementsResultLRSResponse MoreStatements(StatementsResult result)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method   = "GET";
            req.resource = endpoint.GetLeftPart(UriPartial.Authority);
            if (!req.resource.EndsWith("/"))
            {
                req.resource += "/";
            }
            req.resource += result.more;

            var res = MakeSyncRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content)));

            return(r);
        }
Esempio n. 4
0
        public async Task <StatementsResultLRSResponse> SaveStatements(List <Statement> statements)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.resource    = "statements";
            req.method      = HttpMethod.Post;
            req.contentType = "application/json";

            var jarray = new JArray();

            foreach (Statement st in statements)
            {
                jarray.Add(st.ToJObject(version));
            }
            req.content = Encoding.UTF8.GetBytes(jarray.ToString());

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            var ids = JArray.Parse(Encoding.UTF8.GetString(res.content, 0, res.content.Length));

            for (int i = 0; i < ids.Count; i++)
            {
                statements[i].id = new Guid((string)ids[i]);
            }

            r.success = true;
            r.content = new StatementsResult(statements);

            return(r);
        }