<commit_before>﻿using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using ServiceStack.Common.Utils;

namespace WebDavClientTest
{
    public class WebDavClient
    {
        public static string Put(string url, string filename, string content)
        {
            string log = "";

            ServicePointManager.ServerCertificateValidationCallback +=
                ValidateRemoteCertificate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            try
            {
                // Create an HTTP request for the URL.
                HttpWebRequest httpPutRequest =
                    (HttpWebRequest) WebRequest.Create(url);

                // Set up new credentials.
                //httpPutRequest.Credentials =
                // new NetworkCredential(szUsername, szPassword);

                // Pre-authenticate the request.
                httpPutRequest.PreAuthenticate = true;

                // Define the HTTP method.
                httpPutRequest.Method = @"PUT";

                // Specify that overwriting the destination is allowed.
                httpPutRequest.Headers.Add(@"Overwrite", @"T");

                // Specify the content length.
                httpPutRequest.ContentLength = content.Length;

                // Optional, but allows for larger files.
                httpPutRequest.SendChunked = true;

                // Retrieve the request stream.
                Stream requestStream =
                    httpPutRequest.GetRequestStream();

                // Write the string to the destination as a text file.
                requestStream.Write(
                    Encoding.UTF8.GetBytes((string) content),
                    0, content.Length);

                // Close the request stream.
                requestStream.Close();

                // Retrieve the response.
                HttpWebResponse httpPutResponse =
                    (HttpWebResponse) httpPutRequest.GetResponse();

                // Write the response status to the console.
                log += @"PUT Response: " + httpPutResponse.StatusDescription;
                return log;
            }
            catch (Exception e)
            {
                log += "PUT Response: Exception" + e.Message + " StackTrace:" + e.StackTrace;
                return log;
            }
        }

        public static string Get(string url, string filename)
        {
            
            string content = "";
// Create an HTTP request for the URL.
            ServicePointManager.ServerCertificateValidationCallback +=
                ValidateRemoteCertificate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            try
            {
                HttpWebRequest httpGetRequest =
                    (HttpWebRequest) WebRequest.Create(url + "/" + filename);

                // Set up new credentials.
                //httpGetRequest.Credentials =
                //    new NetworkCredential(szUsername, szPassword);

                // Pre-authenticate the request.
                httpGetRequest.PreAuthenticate = true;

                // Define the HTTP method.
                httpGetRequest.Method = @"GET";

                // Specify the request for source code.
                httpGetRequest.Headers.Add(@"Translate", "F");

                // Retrieve the response.
                HttpWebResponse httpGetResponse =
                    (HttpWebResponse) httpGetRequest.GetResponse();

                // Retrieve the response stream.
                Stream responseStream =
                    httpGetResponse.GetResponseStream();

                // Retrieve the response length.
                long responseLength =
                    httpGetResponse.ContentLength;

                // Create a stream reader for the response.
                StreamReader streamReader =
                    new StreamReader(responseStream, Encoding.UTF8);

                // Write the response status to the console.
                Console.WriteLine(
                    @"GET Response: {0}",
                    httpGetResponse.StatusDescription);
                Console.WriteLine(
                    @"  Response Length: {0}",
                    responseLength);
                content = streamReader.ReadToEnd();
                Console.WriteLine(@"  Response Text: {0}", content);

                // Close the response streams.
                streamReader.Close();
                responseStream.Close();

                return content;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message+e.StackTrace);
                return (e.Message+e.StackTrace);
            }
        }

        static string Delete(string url, string filename)
        {
            string log = "";
            
            return log;            
        }
        
        public static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain,
            SslPolicyErrors policyErrors)
        {<commit_msg>UPDATE: curl<commit_after>﻿using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using ServiceStack.Common.Utils;

namespace WebDavClientTest
{
    public class WebDavClient
    {
        public static string Put(string url, string filename, string content)
        {
            string log = "";

            ServicePointManager.ServerCertificateValidationCallback +=
                ValidateRemoteCertificate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            try
            {
                // Create an HTTP request for the URL.
                HttpWebRequest httpPutRequest =
                    (HttpWebRequest) WebRequest.Create(url+'/'+filename);

                // Set up new credentials.
                //httpPutRequest.Credentials =
                // new NetworkCredential(szUsername, szPassword);

                // Pre-authenticate the request.
                httpPutRequest.PreAuthenticate = true;

                // Define the HTTP method.
                httpPutRequest.Method = @"PUT";

                // Specify that overwriting the destination is allowed.
                httpPutRequest.Headers.Add(@"Overwrite", @"T");

                // Specify the content length.
                httpPutRequest.ContentLength = content.Length;

                // Optional, but allows for larger files.
                httpPutRequest.SendChunked = true;

                // Retrieve the request stream.
                Stream requestStream =
                    httpPutRequest.GetRequestStream();

                // Write the string to the destination as a text file.
                requestStream.Write(
                    Encoding.UTF8.GetBytes((string) content),
                    0, content.Length);

                // Close the request stream.
                requestStream.Close();

                // Retrieve the response.
                HttpWebResponse httpPutResponse =
                    (HttpWebResponse) httpPutRequest.GetResponse();

                // Write the response status to the console.
                log += @"PUT Response: " + httpPutResponse.StatusDescription;
                return log;
            }
            catch (Exception e)
            {
                
                Console.WriteLine("PUT Response: Exception" + e.Message + " StackTrace:" + e.StackTrace);
                
            }
            
            log += "curl response:"+CurlPutData(url+"/"+filename,content);
            return log;
        }

        public static string Get(string url, string filename)
        {
            
            string content = "";
// Create an HTTP request for the URL.
            ServicePointManager.ServerCertificateValidationCallback +=
                ValidateRemoteCertificate;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            try
            {
                HttpWebRequest httpGetRequest =
                    (HttpWebRequest) WebRequest.Create(url + "/" + filename);

                // Set up new credentials.
                //httpGetRequest.Credentials =
                //    new NetworkCredential(szUsername, szPassword);

                // Pre-authenticate the request.
                httpGetRequest.PreAuthenticate = true;

                // Define the HTTP method.
                httpGetRequest.Method = @"GET";

                // Specify the request for source code.
                httpGetRequest.Headers.Add(@"Translate", "F");

                // Retrieve the response.
                HttpWebResponse httpGetResponse =
                    (HttpWebResponse) httpGetRequest.GetResponse();

                // Retrieve the response stream.
                Stream responseStream =
                    httpGetResponse.GetResponseStream();

                // Retrieve the response length.
                long responseLength =
                    httpGetResponse.ContentLength;

                // Create a stream reader for the response.
                StreamReader streamReader =
                    new StreamReader(responseStream, Encoding.UTF8);

                // Write the response status to the console.
                Console.WriteLine(
                    @"GET Response: {0}",
                    httpGetResponse.StatusDescription);
                Console.WriteLine(
                    @"  Response Length: {0}",
                    responseLength);
                content = streamReader.ReadToEnd();
                Console.WriteLine(@"  Response Text: {0}", content);

                // Close the response streams.
                streamReader.Close();
                responseStream.Close();

                return content;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message+e.StackTrace);
                //return (e.Message+e.StackTrace);
            }
            return CurlGetData(url + "/" + filename);
        }
        
        public static string CurlPutData(string url, string data)
        {
            Process p = null;
            try
            {
                var psi = new ProcessStartInfo
                {
                    FileName = "curl",
                    Arguments = string.Format("-X PUT {0} --data \"{1}\"", url, data),
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = false,
                };

                p = Process.Start(psi);

                return p.StandardOutput.ReadToEnd();
            }
            finally
            {
                if (p != null && p.HasExited == false)
                    p.Kill();
            }
        }

        public static string CurlGetData(string url)
        {
            Process p = null;
            try
            {
                var psi = new ProcessStartInfo
                {
                    FileName = "curl",
                    Arguments = string.Format("{0}", url),
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = false,
                };

                p = Process.Start(psi);

                return p.StandardOutput.ReadToEnd();
            }
            finally
            {
                if (p != null && p.HasExited == false)
                    p.Kill();
            }
        }

        static string Delete(string url, string filename)
        {
            string log = "";
            
            return log;            
        }
        
        public static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain,
            SslPolicyErrors policyErrors)
        {
{'fraction_non_alphanumeric': 0.07657770017460713, 'fraction_numerical': 0.0030764114076660847, 'mean_word_length': 1.3139669103501346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2561415', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2503, 'n_words': 669}