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 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 { }; 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; } } }