2021-05-10 23:03:59 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2021-05-11 23:01:11 +01:00
|
|
|
using System.Net;
|
2021-05-10 23:03:59 +01:00
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace nuget_cli
|
|
|
|
|
{
|
|
|
|
|
internal class PushCommand
|
|
|
|
|
{
|
2021-05-11 02:38:52 +01:00
|
|
|
private static readonly int MAXSENDLEN = 0xffff;
|
|
|
|
|
|
2021-05-10 23:03:59 +01:00
|
|
|
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
|
|
|
|
|
{
|
2021-05-11 02:38:52 +01:00
|
|
|
var report = new PushReport
|
|
|
|
|
{
|
|
|
|
|
PkgName = pkg
|
|
|
|
|
};
|
2021-05-10 23:03:59 +01:00
|
|
|
FileInfo fi = new FileInfo(pkg);
|
|
|
|
|
if (!fi.Exists)
|
|
|
|
|
throw new Exception("Le fichier n'existe pas");
|
2021-05-11 23:01:11 +01:00
|
|
|
var fparams = new Dictionary<string, string> { };
|
2021-05-11 02:38:52 +01:00
|
|
|
|
2021-05-13 23:05:19 +01:00
|
|
|
|
2021-05-11 02:38:52 +01:00
|
|
|
try
|
|
|
|
|
{
|
2021-05-13 23:05:19 +01:00
|
|
|
|
2021-05-11 23:01:11 +01:00
|
|
|
report.UploadFilesToServer(new Uri(source),
|
2021-05-13 23:05:19 +01:00
|
|
|
fparams, fi, "application/octet-stream",
|
|
|
|
|
apikey);
|
2021-05-11 02:38:52 +01:00
|
|
|
|
|
|
|
|
}
|
2021-05-11 23:01:11 +01:00
|
|
|
catch (WebException ex)
|
|
|
|
|
{
|
|
|
|
|
await Console.Error.WriteLineAsync(ex.Message);
|
|
|
|
|
report.StatusCode = ex.Status.ToString();
|
|
|
|
|
using (var respStream = ex.Response.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
StreamReader sr = new StreamReader(respStream);
|
|
|
|
|
report.Message = sr.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-11 02:38:52 +01:00
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await Console.Error.WriteLineAsync(ex.Message);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2021-05-10 23:03:59 +01:00
|
|
|
report.Executed = true;
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|