isn/src/nuget-cli/PushCommand.cs

49 lines
1.4 KiB
C#
Raw Normal View History

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
{
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
{
2021-05-14 01:41:52 +01:00
FileInfo fi = new FileInfo(pkg);
2021-05-11 02:38:52 +01:00
var report = new PushReport
{
2021-05-14 01:41:52 +01:00
PkgName = fi.Name
2021-05-11 02:38:52 +01:00
};
2021-05-10 23:03:59 +01:00
if (!fi.Exists)
2021-05-14 01:41:52 +01:00
{
report.StatusCode = "local";
report.Message = "Le fichier n'existe pas";
return report;
}
2021-05-11 02:38:52 +01:00
2021-05-14 01:41:52 +01:00
try
{
await report.UploadFilesToServer(new Uri(source), fi, apikey);
}
catch (WebException ex)
{
await Console.Error.WriteLineAsync(ex.Message);
report.StatusCode = ex.Status.ToString();
using (var respStream = ex.Response.GetResponseStream())
2021-05-11 02:38:52 +01:00
{
2021-05-14 01:41:52 +01:00
StreamReader sr = new StreamReader(respStream);
report.Message = sr.ReadToEnd();
2021-05-11 02:38:52 +01:00
}
2021-05-14 01:41: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;
}
}
}