using System; using System.Collections.Generic; using System.IO; 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"); if (fi.Length > MAXSENDLEN) throw new Exception($"Le fichier ne passe pas, trop gros ({MAXSENDLEN})."); var fparams = new Dictionary { { "userid", "9" } }; using (var fss = fi.OpenRead()) { try { byte[] buffer = new byte[MAXSENDLEN]; var form_bytes_read = fss.Read(buffer, 0, MAXSENDLEN); report.UploadFilesToServer(new Uri(source), fparams, fi.Name, "application/octet-stream", apikey, buffer); } catch (Exception ex) { await Console.Error.WriteLineAsync(ex.Message); throw; } } report.Executed = true; return report; } } }