Esempio n. 1
0
        public async Task <IActionResult> result(PlagiarismCheckingMeta dto)  // PlagiarismCheckingMeta dto
        {
            try {
                var    BearerToken = Request.Headers["Authorization"];                      // get the bearer token
                string tokenStr    = BearerToken.ToString().Split(" ")[1].ToString();       // separate bearer part from token, and only retrieve the token
                string uid         = _deserializeToken.deserializedToken(tokenStr).user_id; // get the user id of the authenticated user.

                if (!(await _auth.UserExist(uid, tokenStr)))
                {
                    return(BadRequest("User doesn't exist"));
                }

                string XMLResult = await _plagiarismChecking.plagiarismResult(dto.content, dto.depth);

                string jsonResult = _xMLtoJSON.getJson(XMLResult);

                return(Ok(jsonResult));
            } catch (Exception error) {
                return(BadRequest(error.Message));
            }
        }
Esempio n. 2
0
        public async Task <string> plagiarismResult(string content, string depth)
        {
            if (content.Length <= 0 || depth.Length <= 0)
            {
                return("Neither content nor depth can be blank");
            }

            try {
                PlagiarismCheckingMeta jsonContent = new PlagiarismCheckingMeta {
                    t = content,
                    c = depth
                };

                List <KeyValuePair <string, string> > Postbody = new List <KeyValuePair <string, string> >();
                Postbody.Add(new KeyValuePair <string, string>("e", jsonContent.e));
                Postbody.Add(new KeyValuePair <string, string>("f", jsonContent.f));
                Postbody.Add(new KeyValuePair <string, string>("k", jsonContent.k));
                Postbody.Add(new KeyValuePair <string, string>("o", jsonContent.o));
                Postbody.Add(new KeyValuePair <string, string>("t", jsonContent.t));
                Postbody.Add(new KeyValuePair <string, string>("u", jsonContent.u));
                Postbody.Add(new KeyValuePair <string, string>("c", jsonContent.c));

                FormUrlEncodedContent contentBody = new FormUrlEncodedContent(Postbody);

                using (HttpClient client = _clientFactory.CreateClient()) {
                    using (HttpResponseMessage response = await client.PostAsync(url, contentBody)) {
                        using (HttpContent xmlcontent = response.Content) {
                            string value = await xmlcontent.ReadAsStringAsync();

                            return(value);
                        }
                    }
                }
            } catch (HttpRequestException exception) {
                return(exception.Message);
            }
        }