isn/src/nuget-cli/PushCommand.cs
Paul Schneider c2f38800aa ...
2021-05-13 23:05:19 +01:00

54 lines
No EOL
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace nuget_cli
{
internal class PushCommand
{
private static readonly int MAXSENDLEN = 0xffff;
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
{
var report = new PushReport
{
PkgName = pkg
};
FileInfo fi = new FileInfo(pkg);
if (!fi.Exists)
throw new Exception("Le fichier n'existe pas");
var fparams = new Dictionary<string, string> { };
try
{
report.UploadFilesToServer(new Uri(source),
fparams, fi, "application/octet-stream",
apikey);
}
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();
}
}
catch (Exception ex)
{
await Console.Error.WriteLineAsync(ex.Message);
throw;
}
report.Executed = true;
return report;
}
}
}