Response status code does not indicate success: 500 (Internal Server Error).
This commit is contained in:
17
.build
Normal file
17
.build
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="Hello World" default="build" basedir=".">
|
||||
<description>The Hello World of build files.</description>
|
||||
<property name="debug" value="true" overwrite="false" />
|
||||
<target name="clean" description="remove all generated files">
|
||||
<delete file="HelloWorld.exe" failonerror="false" />
|
||||
<delete file="HelloWorld.pdb" failonerror="false" />
|
||||
</target>
|
||||
<target name="build" description="compiles the source code">
|
||||
<solution configuration="release">
|
||||
<referenceprojects>
|
||||
<include name="test/isn.tests/isn.tests.csproj" />
|
||||
FreeSpeech FreeSpeech.Droid FreeSpeech.Gtk FreeSpeech.iOS FreeSpeech.UWP
|
||||
</referenceprojects>
|
||||
</solution>
|
||||
</target>
|
||||
</project>
|
@ -16,7 +16,7 @@ nonreg:
|
||||
echo "setting : $ISND_TESTING_SETTINGS"
|
||||
cd test/isnd.tests/
|
||||
dotnet build
|
||||
cat $ISND_TESTING_SETTINGS > bin/Debug/netcoreapp2.1/appsettings.Testing.json
|
||||
cat $ISND_TESTING_SETTINGS > appsettings.Testing.json
|
||||
ASPNETCORE_ENVIRONMENT=Testing dotnet test
|
||||
publish:
|
||||
tags:
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -19,6 +19,7 @@ namespace isn
|
||||
{
|
||||
var json = File.ReadAllText(cfgSettingIf.FullName);
|
||||
settings = JsonConvert.DeserializeObject<Settings>(json);
|
||||
source = settings.DefaultSource;
|
||||
}
|
||||
}
|
||||
static OptionSet storeoptions = new OptionSet {
|
||||
@ -165,7 +166,7 @@ namespace isn
|
||||
pushoptions.WriteOptionDescriptions(Console.Out);
|
||||
return;
|
||||
}
|
||||
List<PushReport> reports = await PushPkgAsync(pargs);
|
||||
List<PushReport> reports = PushPkg(pargs);
|
||||
Console.WriteLine(JsonConvert.SerializeObject(reports));
|
||||
pushKO = reports.Count(r => !r.OK && !r.AlreadyPresent);
|
||||
}
|
||||
@ -205,9 +206,7 @@ namespace isn
|
||||
}
|
||||
|
||||
int runCode = commandSet.Run(args);
|
||||
if (runCode == 0) if (pushKO > 0) return 3;
|
||||
|
||||
return runCode;
|
||||
return (runCode == 0 && pushKO > 0) ? 500 : runCode;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,24 @@ namespace isn
|
||||
{
|
||||
public static class SourceHelpers
|
||||
{
|
||||
public static async Task<ApiIndexViewModel> GetServerResourcesAsync(string url)
|
||||
public static ApiIndexViewModel GetServerResources(string url)
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
ApiIndexViewModel result = null;
|
||||
// var json = await client.GetStringAsync(new System.Uri(url));
|
||||
try
|
||||
{
|
||||
var response = await client.GetStringAsync(url);
|
||||
// var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<ApiIndexViewModel>(response);
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var response = await client.GetStringAsync(url);
|
||||
result = JsonConvert.DeserializeObject<ApiIndexViewModel>(response);
|
||||
}).Wait();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<ApiIndexViewModel> GetServerResourcesUsingWebRequestAsync(string url)
|
||||
|
52
src/isn/UploadFilesToServerUsingHttpClient.cs
Normal file
52
src/isn/UploadFilesToServerUsingHttpClient.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace isn
|
||||
{
|
||||
public static class UploadFilesToServerUsingHttpClient
|
||||
{
|
||||
public static PushReport UploadFilesToServer(Uri uri, FileInfo fi,
|
||||
string apikey)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("X-NuGet-Client-Version", Constants.ClientVersion);
|
||||
client.DefaultRequestHeaders.Add("X-NuGet-ApiKey", apikey);
|
||||
using (var multipartFormDataContent = new MultipartFormDataContent())
|
||||
{
|
||||
/* var values = new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("Id", Guid.NewGuid().ToString()),
|
||||
new KeyValuePair<string, string>("Key", "awesome"),
|
||||
new KeyValuePair<string, string>("From", "khalid@home.com")
|
||||
//other values
|
||||
};foreach (var keyValuePair in values)
|
||||
{
|
||||
multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
|
||||
String.Format("\"{0}\"", keyValuePair.Key));
|
||||
} */
|
||||
multipartFormDataContent.Add(new ByteArrayContent(File.ReadAllBytes(fi.FullName)),
|
||||
'"' + "File" + '"',
|
||||
'"' + fi.Name + '"');
|
||||
|
||||
var result = client.PutAsync(uri, multipartFormDataContent).Result;
|
||||
result.EnsureSuccessStatusCode();
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
Task.Run(async ()=>
|
||||
{
|
||||
string report = await result.Content.ReadAsStringAsync();
|
||||
Console.WriteLine(report);
|
||||
}).Wait();
|
||||
|
||||
}
|
||||
return new PushReport();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace isn
|
||||
|
||||
public class UploadFilesToServerUsingWebRequest
|
||||
{
|
||||
internal void UploadFilesToServer(PushReport report, Uri uri, FileInfo fi,
|
||||
public void UploadFilesToServer(PushReport report, Uri uri, FileInfo fi,
|
||||
string apikey)
|
||||
{
|
||||
// string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
|
||||
@ -26,7 +26,7 @@ namespace isn
|
||||
byte[] fileheaderbytes = Encoding.ASCII.GetBytes(fileheader);
|
||||
var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
|
||||
var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--");
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
|
||||
|
||||
httpWebRequest.Method = "PUT";
|
||||
httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
||||
|
@ -9,63 +9,81 @@ namespace isn
|
||||
{
|
||||
public class PushCommand
|
||||
{
|
||||
static public async Task<PushReport> RunAsync(string pkg, string source, string apikey)
|
||||
static public PushReport Run(string pkg, string source)
|
||||
{
|
||||
if (source == null) source = Program.Settings.DefaultSource;
|
||||
if (source == null) throw new InvalidOperationException("source is null");
|
||||
string apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
||||
var resources = SourceHelpers.GetServerResources(source);
|
||||
if (resources.Resources == null)
|
||||
throw new InvalidOperationException("source gave no resource");
|
||||
if (!resources.Resources.Any(res => res.Type == "PackagePublish/2.0.0"))
|
||||
throw new InvalidOperationException("Source won't serve the expected push command");
|
||||
var pubRes = resources.Resources.First(res => res.Type == "PackagePublish/2.0.0");
|
||||
FileInfo fi = new FileInfo(pkg);
|
||||
var report = new PushReport
|
||||
{
|
||||
PkgName = fi.Name
|
||||
};
|
||||
if (!fi.Exists)
|
||||
{
|
||||
report.Message = "Le fichier n'existe pas";
|
||||
var report = new PushReport
|
||||
{
|
||||
PkgName = fi.Name,
|
||||
Message = "Le fichier n'existe pas"
|
||||
};
|
||||
return report;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var wrqueryHandler = new UploadFilesToServerUsingWebRequest();
|
||||
// await wrqueryHandler.UploadFilesToServerAsync(report, new Uri(source), fi, apikey);
|
||||
if (source == null)
|
||||
{
|
||||
source = Program.Settings.DefaultSource;
|
||||
if (apikey is null) if (source!=null)
|
||||
apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
||||
}
|
||||
if (apikey is null) if (source!=null)
|
||||
if (Program.Settings.Sources.ContainsKey(source))
|
||||
apikey = Program.Protector.UnProtect(Program.Settings.Sources[source].ApiKey);
|
||||
if (source == null) throw new InvalidOperationException("source is null");
|
||||
var resources = await SourceHelpers.GetServerResourcesAsync(source);
|
||||
if (resources.Resources==null || resources.Resources.Any(res => res.Id == "" ))
|
||||
throw new InvalidOperationException("Source won't serve the expected push command");
|
||||
Console.WriteLine(JsonConvert.SerializeObject(resources));
|
||||
wrqueryHandler.UploadFilesToServer(report, new Uri(resources.Resources[0].Id), fi, apikey);
|
||||
Console.WriteLine("Connecting to "+pubRes.Id);
|
||||
return UploadFilesToServerUsingHttpClient.UploadFilesToServer(new Uri(pubRes.Id), fi, apikey);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync(ex.Message);
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
var report = new PushReport
|
||||
{
|
||||
PkgName = fi.Name
|
||||
};
|
||||
report.StatusCode = ex.Status.ToString();
|
||||
report.OK = false;
|
||||
using (Stream respStream = ex.Response.GetResponseStream())
|
||||
if (ex.Response != null)
|
||||
{
|
||||
StreamReader sr = new StreamReader(respStream);
|
||||
string json = sr.ReadToEnd();
|
||||
var res = JsonConvert.DeserializeObject<IsndErrorMessage>(json);
|
||||
// ecode == 1 => package already present server side.
|
||||
report.AlreadyPresent = res.ecode == 1;
|
||||
report.Message = res.msg;
|
||||
try
|
||||
{
|
||||
using (Stream respStream = ex.Response.GetResponseStream())
|
||||
{
|
||||
StreamReader sr = new StreamReader(respStream);
|
||||
string json = sr.ReadToEnd();
|
||||
var res = JsonConvert.DeserializeObject<IsndErrorMessage>(json);
|
||||
report.Message = res.msg;
|
||||
|
||||
// ecode == 1 => package already present server side.
|
||||
report.AlreadyPresent = res.ecode == 1;
|
||||
}
|
||||
}
|
||||
catch (Exception iex)
|
||||
{
|
||||
report.Message = iex.Message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
report.Message = ex.Message;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
report.Message = ex.Message;
|
||||
report.StackTrace = ex.StackTrace;
|
||||
await Console.Error.WriteLineAsync(ex.Message);
|
||||
var report = new PushReport
|
||||
{
|
||||
PkgName = fi.Name,
|
||||
Message = ex.Message,
|
||||
StackTrace = ex.StackTrace
|
||||
};
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
throw;
|
||||
}
|
||||
report.Executed = true;
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,13 +9,13 @@ namespace isn
|
||||
|
||||
partial class Program
|
||||
{
|
||||
public static async Task<List<PushReport>> PushPkgAsync(IEnumerable<string> pkgs)
|
||||
public static List<PushReport> PushPkg(IEnumerable<string> pkgs)
|
||||
{
|
||||
List<PushReport> pushReports = new List<PushReport>();
|
||||
|
||||
foreach (string pkg in pkgs)
|
||||
{
|
||||
var report = await PushCommand.RunAsync(pkg, source, apiKey);
|
||||
var report = PushCommand.Run(pkg, source);
|
||||
|
||||
pushReports.Add(report);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net45;netcoreapp2.1;net6</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||
<RootNamespace>nuget_cli</RootNamespace>
|
||||
<UserSecretsId>45b74c62-05bc-4603-95b4-3e80ae2fdf50</UserSecretsId>
|
||||
<PackageVersion>1.0.1</PackageVersion>
|
||||
@ -13,8 +13,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mono.Options" Version="5.3.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="unleash.client" Version="1.6.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<Reference Include="System.Net.Http" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -57,10 +57,10 @@ dataTable.Rows.Add(dataRow);
|
||||
Assert.NotNull(vm.Resources);
|
||||
}
|
||||
[Fact]
|
||||
public async Task TestPush()
|
||||
public void TestPush()
|
||||
{
|
||||
Program.LoadConfig();
|
||||
var report = await Program.PushPkgAsync(new string[] { "bin/Debug/isn.1.0.1.nupkg" });
|
||||
var report = Program.PushPkg(new string[] { "/home/paul/Nupkgs/Yavsc.Abstract.1.0.8.nupkg" });
|
||||
}
|
||||
|
||||
[Fact]
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
@ -14,6 +14,7 @@ namespace isnd.host.tests
|
||||
public class UnitTestWebHost
|
||||
{
|
||||
const string testingUrl = "http://localhost:5000";
|
||||
[Fact]
|
||||
|
||||
|
||||
public void TestHaveTestDbContextAndMigrate()
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>d7144e46-4e63-4391-ba86-64b61f6e7be4</UserSecretsId>
|
||||
|
Reference in New Issue
Block a user