Skip to content

Commit

Permalink
API Fixes
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
rzander committed Sep 9, 2017
1 parent 7c750a5 commit 6792f8d
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 112 deletions.
4 changes: 2 additions & 2 deletions RZ.OneGetProvider/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
45 changes: 25 additions & 20 deletions RZ.OneGetProvider/RZRestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,37 @@ public static string GetAuthToken(string Username, string Password)

public static List<GetSoftware> SWGet(string Shortname)
{
/*using (var oClient = new HttpClient())
List<GetSoftware> lResult = new List<GetSoftware>();

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<GetSoftware> lRes = ser.Deserialize<List<GetSoftware>>(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<GetSoftware> lRes = ser.Deserialize<List<GetSoftware>>(response.Result);
return lRes;
}
}
catch { }
}
catch { }
}*/

try
{
return SWResults("").Where(t => t.Shortname == Shortname).ToList();
}
catch { }


return new List<GetSoftware>();
return lResult;
}

public static List<GetSoftware> SWGet(string PackageName, string PackageVersion)
Expand Down Expand Up @@ -206,7 +211,7 @@ public static List<GetSoftware> 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"));
Expand Down Expand Up @@ -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 { }
}
Expand Down
2 changes: 1 addition & 1 deletion RZUpdate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
43 changes: 24 additions & 19 deletions RZUpdate/RZRestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,37 @@ public static string GetAuthToken(string Username, string Password)

public static List<GetSoftware> SWGet(string Shortname)
{
/*using (var oClient = new HttpClient())
List<GetSoftware> lResult = new List<GetSoftware>();

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<GetSoftware> lRes = ser.Deserialize<List<GetSoftware>>(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<GetSoftware> lRes = ser.Deserialize<List<GetSoftware>>(response.Result);
return lRes;
}
}
catch { }
}
catch { }
}*/

try
{
return SWResults("").Where(t => t.Shortname == Shortname).ToList();
}
catch { }


return new List<GetSoftware>();
return lResult;
}

public static List<GetSoftware> SWGet(string PackageName, string PackageVersion)
Expand Down Expand Up @@ -206,7 +211,7 @@ public static List<GetSoftware> 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"));
Expand Down
6 changes: 3 additions & 3 deletions RuckZuck_Tool/InstallSwPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
<Image Source="Images/Star.ico" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="btIssue" Header="Issues" ToolTip="Get 10 Software-Items with worst success ratio" Click="btIssue_Click" Height="24">
<MenuItem x:Name="btIssue" Header="Issues" ToolTip="Get 10 Software-Items with worst success ratio" Click="btIssue_Click" Height="24" Visibility="Collapsed">
<MenuItem.Icon>
<Image Source="Images/Star.ico" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="btBadRatio" Click="btBadRatio_Click" Height="24" Header="Bad success ratio" ToolTip="Get 10 Software-Items with worst success ratio">
<MenuItem x:Name="btBadRatio" Click="btBadRatio_Click" Height="24" Header="Bad success ratio" ToolTip="Get 10 Software-Items with worst success ratio" Visibility="Collapsed">
<MenuItem.Icon>
<Image Source="Images/Star.ico" />
</MenuItem.Icon>
Expand All @@ -44,7 +44,7 @@
<Image Source="Images/Star.ico" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="btApproval" Height="24" Header="Waiting for Approval" ToolTip="Waiting for Approval" Click="btApproval_Click">
<MenuItem x:Name="btApproval" Height="24" Header="Waiting for Approval" ToolTip="Waiting for Approval" Click="btApproval_Click" Visibility="Collapsed">
<MenuItem.Icon>
<Image Source="Images/Star.ico" />
</MenuItem.Icon>
Expand Down
2 changes: 1 addition & 1 deletion RuckZuck_Tool/InstallSwPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
4 changes: 2 additions & 2 deletions RuckZuck_Tool/NewSWPanelxaml.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<DockPanel DockPanel.Dock="Bottom">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Center">
<Button x:Name="btUpload" Content="Upload" Width="130" Height="30" Click="Button_Click" IsEnabled="False" ToolTip="URL must be specified before SW upload is possible." Margin="0,0,5,0" />
<Button x:Name="btSaveAsXML" Content="Save as XML..." Width="130" Height="30" ToolTip="Save settings as XML..." Click="btSaveAsXML_Click" Margin="0,0,5,0" />
<Button x:Name="btOpenXML" Content="Open an XML..." Width="130" Height="30" ToolTip="Open settings from XML..." Click="btOpenXML_Click" Margin="0,0,5,0" />
<Button x:Name="btSaveAsXML" Content="Save..." Width="130" Height="30" ToolTip="Save settings as JSON file..." Click="btSaveAsXML_Click" Margin="0,0,5,0" />
<Button x:Name="btOpenXML" Content="Open..." Width="130" Height="30" ToolTip="Open settings from JSON file..." Click="btOpenXML_Click" Margin="0,0,5,0" />
<Button x:Name="btCreateEXE" Content="Create EXE..." Width="130" Height="30" ToolTip="Create a Setup.EXE without dependency to RuckZuck.tools" Margin="0,0,5,0" Click="btCreateEXE_Click" />
<Button x:Name="btTest" Content="Test Install" Width="130" Height="30" ToolTip="Open settings from XML..." Click="btTest_Click" />
</StackPanel>
Expand Down
59 changes: 18 additions & 41 deletions RuckZuck_Tool/NewSWPanelxaml.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using RZUpdate;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Web.Script.Serialization;

namespace RuckZuck_Tool
{
Expand Down Expand Up @@ -427,8 +428,8 @@ private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)

private void btSaveAsXML_Click(object sender, RoutedEventArgs e)
{
string sFilename = "EXP_" + tbProductName.Text + tbVersion.Text + tbArchitecture.Text + ".xml";
var ofd = new Microsoft.Win32.SaveFileDialog() { Filter = "XML Files (*.xml)|*.xml" };
string sFilename = "EXP_" + tbProductName.Text + tbVersion.Text + tbArchitecture.Text.Trim() + ".json";
var ofd = new Microsoft.Win32.SaveFileDialog() { Filter = "JSON Files (*.json)|*.json" };
ofd.FileName = sFilename;
var result = ofd.ShowDialog();
if (result != false)
Expand All @@ -440,8 +441,8 @@ private void btSaveAsXML_Click(object sender, RoutedEventArgs e)
private void SaveAsXML(string sFile)
{
AddSoftware oSoftware = new AddSoftware();
oSoftware.Architecture = tbArchitecture.Text;
oSoftware.ContentID = tbContentId.Text;
oSoftware.Architecture = tbArchitecture.Text.Trim();
oSoftware.ContentID = tbContentId.Text.Trim();
oSoftware.Description = tbDescription.Text;
try
{
Expand All @@ -458,49 +459,29 @@ private void SaveAsXML(string sFile)
oSoftware.Files = ((List<contentFiles>)dgSourceFiles.ItemsSource);
}
catch { }
oSoftware.Manufacturer = tbManufacturer.Text;
oSoftware.Manufacturer = tbManufacturer.Text.Trim();
oSoftware.MSIProductID = tbMSIId.Text;
oSoftware.ProductName = tbProductName.Text;
oSoftware.ProductVersion = tbVersion.Text;
oSoftware.ProductName = tbProductName.Text.Trim();
oSoftware.ProductVersion = tbVersion.Text.Trim();
oSoftware.PSDetection = tbPSDetection.Text;
oSoftware.PSInstall = tbPSInstall.Text;
oSoftware.PSPreReq = tbPSPrereq.Text;
oSoftware.PSUninstall = tbPSUnInstall.Text;
oSoftware.ProductURL = tbProductURL.Text;
oSoftware.ProductURL = tbProductURL.Text.Trim();
oSoftware.Author = Properties.Settings.Default.UserKey;
oSoftware.PSPreInstall = tbPSPreInstall.Text;
oSoftware.PSPostInstall = tbPSPostInstall.Text;
oSoftware.PreRequisites = tbPreReq.Text.Split(';');
oSoftware.Shortname = tbShortname.Text.Trim();
oSoftware.Category = tbCategories.Text.Trim();

if (imgIcon.Tag != null)
oSoftware.Image = imgIcon.Tag as byte[];


System.Xml.Serialization.XmlSerializerNamespaces ns = new System.Xml.Serialization.XmlSerializerNamespaces();
ns.Add("", "");
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(oSoftware.GetType(), "");

StreamWriter file = new System.IO.StreamWriter(sFile);
x.Serialize(file, oSoftware, ns);
file.Close();


//remove all namespaces
XDocument doc = XDocument.Load(sFile);
foreach (var node in doc.Root.Descendants())
{
try
{
// If we have an empty namespace...
if (node.Name.NamespaceName != "")
{
node.Attributes("xmlns").Remove();
node.Name = node.Parent.Name.Namespace + node.Name.LocalName;
}
}
catch { }
}
doc.Save(sFile);
//Convert to JSON
JavaScriptSerializer ser = new JavaScriptSerializer();
string sJson = ser.Serialize(oSoftware);
File.WriteAllText(sFile, sJson);
}

private void btOpenXML_Click(object sender, RoutedEventArgs e)
Expand All @@ -517,16 +498,14 @@ private void btOpenXML_Click(object sender, RoutedEventArgs e)

public void OpenXML(AddSoftware oSoftware)
{
tbArchitecture.Text = oSoftware.Architecture;
tbArchitecture.Text = oSoftware.Architecture.Trim();
tbContentId.Text = oSoftware.ContentID;

if (string.IsNullOrEmpty(tbContentId.Text))
tbContentId.Text = Guid.NewGuid().ToString();

tbDescription.Text = oSoftware.Description;



if (oSoftware.Files != null)
{
foreach (contentFiles vFiles in oSoftware.Files)
Expand All @@ -543,8 +522,6 @@ public void OpenXML(AddSoftware oSoftware)
dgSourceFiles.Items.Clear();
}



tbManufacturer.Text = oSoftware.Manufacturer;
tbMSIId.Text = oSoftware.MSIProductID;
tbProductName.Text = oSoftware.ProductName;
Expand All @@ -567,8 +544,8 @@ public void OpenXML(AddSoftware oSoftware)
}
catch { }

tbCategories.Text = oSoftware.Category;
tbShortname.Text = oSoftware.Shortname;
tbCategories.Text = oSoftware.Category ?? "";
tbShortname.Text = oSoftware.Shortname ?? "";
}

private void tbContentId_MouseDoubleClick(object sender, MouseButtonEventArgs e)
Expand Down
Loading

0 comments on commit 6792f8d

Please sign in to comment.