From 6792f8d55794ad918fb3edadd48798443d6bb1a3 Mon Sep 17 00:00:00 2001 From: Roger Zander Date: Sat, 9 Sep 2017 13:33:26 +0200 Subject: [PATCH] API Fixes allign REST API on all tools to support latest web backend service. - RZTool changed to import/export json instead of xml - Cache RZCatalog for 30 min on client (%TEMP%\rzcat.json) --- RZ.OneGetProvider/Properties/AssemblyInfo.cs | 4 +- RZ.OneGetProvider/RZRestAPI.cs | 45 ++++++++------- RZUpdate/Properties/AssemblyInfo.cs | 2 +- RZUpdate/RZRestAPI.cs | 43 +++++++------- RuckZuck_Tool/InstallSwPanel.xaml | 6 +- RuckZuck_Tool/InstallSwPanel.xaml.cs | 2 +- RuckZuck_Tool/NewSWPanelxaml.xaml | 4 +- RuckZuck_Tool/NewSWPanelxaml.xaml.cs | 59 ++++++-------------- RuckZuck_Tool/RZRestAPI.cs | 43 +++++++------- RuckZuck_Tool/RZScan.cs | 2 +- RuckZuck_Tool/RZUpdate.cs | 44 ++++++++++++++- 11 files changed, 142 insertions(+), 112 deletions(-) diff --git a/RZ.OneGetProvider/Properties/AssemblyInfo.cs b/RZ.OneGetProvider/Properties/AssemblyInfo.cs index 55e2bb9..08d7366 100644 --- a/RZ.OneGetProvider/Properties/AssemblyInfo.cs +++ b/RZ.OneGetProvider/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.0.0")] -[assembly: AssemblyFileVersion("1.6.0.0")] +[assembly: AssemblyVersion("1.6.0.2")] +[assembly: AssemblyFileVersion("1.6.0.2")] diff --git a/RZ.OneGetProvider/RZRestAPI.cs b/RZ.OneGetProvider/RZRestAPI.cs index b296750..7b91169 100644 --- a/RZ.OneGetProvider/RZRestAPI.cs +++ b/RZ.OneGetProvider/RZRestAPI.cs @@ -103,32 +103,37 @@ public static string GetAuthToken(string Username, string Password) public static List SWGet(string Shortname) { - /*using (var oClient = new HttpClient()) + List lResult = new List(); + + try { - try + lResult = SWResults("").Where(t => t.Shortname == Shortname).ToList(); + } + catch { } + + if (lResult.Count() == 0) + { + using (var oClient = new HttpClient()) { - oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token); - oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - var response = oClient.GetStringAsync(sURL + "/rest/SWGetShort?name=" + WebUtility.UrlEncode(Shortname)); - response.Wait(5000); - if (response.IsCompleted) + try { - JavaScriptSerializer ser = new JavaScriptSerializer(); - List lRes = ser.Deserialize>(response.Result); - return lRes; + oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token); + oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); + var response = oClient.GetStringAsync(sURL + "/rest/SWGetShort?name=" + WebUtility.UrlEncode(Shortname)); + response.Wait(5000); + if (response.IsCompleted) + { + JavaScriptSerializer ser = new JavaScriptSerializer(); + List lRes = ser.Deserialize>(response.Result); + return lRes; + } } + catch { } } - catch { } - }*/ - - try - { - return SWResults("").Where(t => t.Shortname == Shortname).ToList(); } - catch { } - return new List(); + return lResult; } public static List SWGet(string PackageName, string PackageVersion) @@ -206,7 +211,7 @@ public static List SWResults(string Searchstring) try { DateTime dCreationDate = File.GetCreationTime(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "rzcat.json")); - if ((DateTime.Now - dCreationDate) < new TimeSpan(1, 0, 0)) + if ((DateTime.Now - dCreationDate) < new TimeSpan(0, 30, 0)) { //return cached Content string jRes = File.ReadAllText(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "rzcat.json")); @@ -375,7 +380,7 @@ public static async void TrackDownloads2(long SWId, string Architecture) { oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token); oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() +"&arch=" + WebUtility.UrlEncode(Architecture)); + await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture)); } catch { } } diff --git a/RZUpdate/Properties/AssemblyInfo.cs b/RZUpdate/Properties/AssemblyInfo.cs index 4f2400f..feb22f3 100644 --- a/RZUpdate/Properties/AssemblyInfo.cs +++ b/RZUpdate/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.6.0.*")] -[assembly: AssemblyFileVersion("1.6.0.0")] +[assembly: AssemblyFileVersion("1.6.0.2")] diff --git a/RZUpdate/RZRestAPI.cs b/RZUpdate/RZRestAPI.cs index 85c471d..7b91169 100644 --- a/RZUpdate/RZRestAPI.cs +++ b/RZUpdate/RZRestAPI.cs @@ -103,32 +103,37 @@ public static string GetAuthToken(string Username, string Password) public static List SWGet(string Shortname) { - /*using (var oClient = new HttpClient()) + List lResult = new List(); + + try { - try + lResult = SWResults("").Where(t => t.Shortname == Shortname).ToList(); + } + catch { } + + if (lResult.Count() == 0) + { + using (var oClient = new HttpClient()) { - oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token); - oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); - var response = oClient.GetStringAsync(sURL + "/rest/SWGetShort?name=" + WebUtility.UrlEncode(Shortname)); - response.Wait(5000); - if (response.IsCompleted) + try { - JavaScriptSerializer ser = new JavaScriptSerializer(); - List lRes = ser.Deserialize>(response.Result); - return lRes; + oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token); + oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType)); + var response = oClient.GetStringAsync(sURL + "/rest/SWGetShort?name=" + WebUtility.UrlEncode(Shortname)); + response.Wait(5000); + if (response.IsCompleted) + { + JavaScriptSerializer ser = new JavaScriptSerializer(); + List lRes = ser.Deserialize>(response.Result); + return lRes; + } } + catch { } } - catch { } - }*/ - - try - { - return SWResults("").Where(t => t.Shortname == Shortname).ToList(); } - catch { } - return new List(); + return lResult; } public static List SWGet(string PackageName, string PackageVersion) @@ -206,7 +211,7 @@ public static List SWResults(string Searchstring) try { DateTime dCreationDate = File.GetCreationTime(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "rzcat.json")); - if ((DateTime.Now - dCreationDate) < new TimeSpan(1, 0, 0)) + if ((DateTime.Now - dCreationDate) < new TimeSpan(0, 30, 0)) { //return cached Content string jRes = File.ReadAllText(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), "rzcat.json")); diff --git a/RuckZuck_Tool/InstallSwPanel.xaml b/RuckZuck_Tool/InstallSwPanel.xaml index a25a41e..32fa1c7 100644 --- a/RuckZuck_Tool/InstallSwPanel.xaml +++ b/RuckZuck_Tool/InstallSwPanel.xaml @@ -29,12 +29,12 @@ - + - + @@ -44,7 +44,7 @@ - + diff --git a/RuckZuck_Tool/InstallSwPanel.xaml.cs b/RuckZuck_Tool/InstallSwPanel.xaml.cs index 97a426b..03d217d 100644 --- a/RuckZuck_Tool/InstallSwPanel.xaml.cs +++ b/RuckZuck_Tool/InstallSwPanel.xaml.cs @@ -563,7 +563,7 @@ private void btNew_Click(object sender, RoutedEventArgs e) try { tSearch.Stop(); - var badSW = RZRestAPI.SWResults("--NEW--").Distinct().Select(x => new GetSoftware() { Categories = x.Categories.ToList(), Description = x.Description, Downloads = x.Downloads, IconId = x.IconId, Image = x.Image, Manufacturer = x.Manufacturer, ProductName = x.ProductName, ProductURL = x.ProductURL, ProductVersion = x.ProductVersion, Quality = x.Quality, Shortname = x.Shortname, isInstalled = false }).ToList(); + var badSW = RZRestAPI.SWResults("--NEW--").ToList(); tbSearch.Text = ""; //Mark all installed... diff --git a/RuckZuck_Tool/NewSWPanelxaml.xaml b/RuckZuck_Tool/NewSWPanelxaml.xaml index a33e42b..55f5b7e 100644 --- a/RuckZuck_Tool/NewSWPanelxaml.xaml +++ b/RuckZuck_Tool/NewSWPanelxaml.xaml @@ -20,8 +20,8 @@