Ejemplo n.º 1
0
        private static async Task <double> GetPlagiarismScore(string article)
        {
            var token = await GetToken();

            using var scansApi = new CopyleaksScansApi(eProduct.Businesses, token);
            var credits = await scansApi.CreditBalanceAsync();

            Console.WriteLine($"{credits} credits left.");

            var fileDocument = await GetFileDocument(article);

            var scanId = $"{Guid.NewGuid()}";
            await scansApi.SubmitFileAsync(scanId, fileDocument);

            uint progress;

            do
            {
                progress = await scansApi.ProgressAsync(scanId);

                Console.WriteLine($"Progress: {progress}%");
                Thread.Sleep(1000);
            } while (progress != 100);

            var result = await scansApi.ResultAsync(scanId);

            var score = result.Results.Score.AggregatedScore;

            return(score);
        }
        static CopyleaksSDKHttpClients()
        {
            HttpClientHandler handler = new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
            };

            _HttpClient     = new HttpClient(handler);
            _IdentityClient = new CopyleaksIdentityApi(_HttpClient);
            _APIClient      = new CopyleaksScansApi(_HttpClient);
        }
        public SubmitFileTest()
        {
            HttpClientHandler handler = new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
            };

            Client         = new HttpClient(handler);
            IdentityClient = new CopyleaksIdentityApi(Client);
            APIClient      = new CopyleaksScansApi(Client);
        }
        public async Task <IActionResult> Submit(SubmitModel submitModel)
        {
            // A unique scan ID for the scan
            // In case this scan ID already exists for this user Copyleaks API will return HTTP 409 Conflict result
            string scanId   = Guid.NewGuid().ToString();
            var    response = new SubmitResponse()
            {
                ScanId = scanId,
                Token  = submitModel.Token
            };

            try
            {
                using (var api = new CopyleaksScansApi())
                {
                    // Submit a file for scan in https://api.copyleaks.com
                    await api.SubmitFileAsync(scanId, new FileDocument
                    {
                        // The text to scan in base64 format
                        Base64 = TextToBase64(submitModel.Text),
                        // The file name is it will appear in the scan result
                        Filename          = "text.txt",
                        PropertiesSection = GetScanProperties(scanId, submitModel)
                    },
                                              submitModel.Token).ConfigureAwait(false);
                }
                var checkResult = new CheckResultsResponse
                {
                    ScanId = scanId
                };
                return(View("CheckResult", checkResult));
            }
            catch (CopyleaksHttpException cfe)
            {
                response.ErrorMessage = cfe.Message;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.Message;
            }
            return(View(response));
        }