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 { static internal async Task RunAsync(string pkg, string source, string apikey) { FileInfo fi = new FileInfo(pkg); var report = new PushReport { PkgName = fi.Name }; if (!fi.Exists) { report.StatusCode = "local"; report.Message = "Le fichier n'existe pas"; return report; } try { await Task.Run(() => 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()) { StreamReader sr = new StreamReader(respStream); report.Message = sr.ReadToEnd(); } } catch (Exception ex) { await Console.Error.WriteLineAsync(ex.Message); throw; } report.Executed = true; return report; } } }