This commit is contained in:
Paul Schneider 2022-04-11 01:48:43 +01:00
commit ee07affbbd
13 changed files with 102 additions and 17 deletions

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net4.7.2</TargetFramework>
<TargetFramework>net45</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -7,7 +7,7 @@ using Newtonsoft.Json;
namespace isn
{
partial class Program
public partial class Program
{
public static IEnumerable<IsnSourceSettings> Sources { get; protected set; }
@ -155,7 +155,6 @@ namespace isn
var pushCmd = new Command(push)
{
Run = async sargs =>
{
var pargs = pushoptions.Parse(sargs);
@ -172,11 +171,11 @@ namespace isn
}
};
commandSet.Add(pushCmd);
var setapikey = new Command("set-api-key")
{
Run = sargs => StoreApiKey(sargs)
};
commandSet.Add(pushCmd);
commandSet.Add(setapikey);
commandSet.Add(srcCmd);
commandSet.Add(showCommand);

View file

@ -1,3 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using isn.Abstract;
@ -10,12 +13,50 @@ namespace isn
public static async Task<ApiIndexViewModel> GetServerResourcesAsync(string url)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("content-type","application/json; utf-8");
using (var indexResponse = await client.GetAsync(url))
// var json = await client.GetStringAsync(new System.Uri(url));
try
{
var json = await indexResponse.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<ApiIndexViewModel>(json);
var response = await client.GetStringAsync(url);
// var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<ApiIndexViewModel>(response);
}
catch(Exception ex)
{
throw;
}
}
public static async Task<ApiIndexViewModel> GetServerResourcesUsingWebRequestAsync(string url)
{
ApiIndexViewModel viewModel=null;
var uri = new Uri(url);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "GET";
httpWebRequest.AllowAutoRedirect = false;
try{
using (var resp = await httpWebRequest.GetResponseAsync())
{
using (var stream = resp.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
var json = await reader.ReadToEndAsync();
Console.Write("got json : "+json);
viewModel = JsonConvert.DeserializeObject<ApiIndexViewModel>(json);
}
}
}
}
catch(Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
return viewModel;
}
}
}

View file

@ -7,9 +7,9 @@ using Newtonsoft.Json;
namespace isn
{
internal class PushCommand
public class PushCommand
{
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
static public async Task<PushReport> RunAsync(string pkg, string source, string apikey)
{
FileInfo fi = new FileInfo(pkg);
var report = new PushReport
@ -39,7 +39,8 @@ namespace isn
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");
wrqueryHandler.UploadFilesToServer(report, new Uri(source), fi, apikey);
Console.WriteLine(JsonConvert.SerializeObject(resources));
wrqueryHandler.UploadFilesToServer(report, new Uri(resources.Resources[0].Id), fi, apikey);
}
catch (WebException ex)
{

View file

@ -9,7 +9,7 @@ namespace isn
partial class Program
{
private static async Task<List<PushReport>> PushPkgAsync(IEnumerable<string> pkgs)
public static async Task<List<PushReport>> PushPkgAsync(IEnumerable<string> pkgs)
{
List<PushReport> pushReports = new List<PushReport>();

View file

@ -28,7 +28,12 @@ namespace isn
public static void EnsureKeyStored()
{
if (source == null) return;
if (source == null)
{
if (Settings.DefaultSource == null)
return;
source = Settings.DefaultSource;
}
if (Settings.Sources.ContainsKey(source))
{
@ -52,7 +57,6 @@ namespace isn
string ptd = Protector.Protect(apiKey);
Settings.Sources.Add(source, new SourceSettings { ApiKey = ptd });
}
else return;
SaveConfig();
}
public static void SaveConfig()

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<TargetFrameworks>net45;netcoreapp2.1;net6</TargetFrameworks>
<RootNamespace>nuget_cli</RootNamespace>
<UserSecretsId>45b74c62-05bc-4603-95b4-3e80ae2fdf50</UserSecretsId>
<PackageVersion>1.0.1</PackageVersion>