Skip to content

Commit

Permalink
New: RZ Proxy Plugins to host RZ_Server as Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
rzander committed Feb 24, 2019
1 parent d8cea7d commit 67d55d7
Show file tree
Hide file tree
Showing 26 changed files with 1,412 additions and 27 deletions.
2 changes: 2 additions & 0 deletions RZ.Server/RZ.Catalog.Plugin.Proxy/RZ.Catalog.Plugin.Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public JArray GetCatalog(string customerid = "", bool nocache = false)
//Try to get value from Memory
if (_cache.TryGetValue("swcat", out jResult))
{
Console.WriteLine("GetCatalog...");
return jResult;
}
}
Expand All @@ -67,6 +68,7 @@ public JArray GetCatalog(string customerid = "", bool nocache = false)
var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(30)); //cache catalog for 30 Minutes
_cache.Set("swcat", jResult, cacheEntryOptions);

Console.WriteLine("GetCatalog...");
return jResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="3.3.2" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Fody" Version="4.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 4 additions & 0 deletions RZ.Server/RZ.Plugin.Feedback.Proxy/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
111 changes: 111 additions & 0 deletions RZ.Server/RZ.Plugin.Feedback.Proxy/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
86 changes: 86 additions & 0 deletions RZ.Server/RZ.Plugin.Feedback.Proxy/RZ.Plugin.Feedback.Proxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Microsoft.Azure.ServiceBus;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using RZ.Server;
using RZ.Server.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace RZ.Plugin.Feedback.Azure
{
public class Plugin_Feedback : IFeedback
{
private IMemoryCache _cache;

public string Name
{
get
{
return Assembly.GetExecutingAssembly().ManifestModule.Name;
}
}

public Dictionary<string, string> Settings { get; set; }

public void Init(string PluginPath)
{
//Check if MemoryCache is initialized
if (_cache != null)
{
_cache.Dispose();
}

_cache = new MemoryCache(new MemoryCacheOptions());

if (Settings == null)
Settings = new Dictionary<string, string>();

}

public Task<bool> StoreFeedback(string name = "", string ver = "", string man = "", string shortname = "", string feedback = "", string user = "", bool? failure = null)
{
var tFeedback = Task.Run(() =>
{
string ok = "false";
if (failure == false)
ok = "true";

if(failure == true)
{
Console.WriteLine("Failure: " + name + " " + ver + " Error:" + feedback);
}
else
{
Console.WriteLine("Success: " + name + " " + ver);
}

RZRestAPIv2.StoreFeedback(name, ver, man, ok, user, feedback);
return true;
});

return tFeedback;
}

public void PushBullet(string Message, string Body)
{
}

public Task<bool> SendNotification(string message = "", string body = "")
{
Task<bool> t = Task<bool>.Run(() =>
{
PushBullet(message, body);
return true;
});

return t;
}
}
}
20 changes: 20 additions & 0 deletions RZ.Server/RZ.Plugin.Feedback.Proxy/RZ.Plugin.Feedback.Proxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="3.3.2" />
<PackageReference Include="Fody" Version="4.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RZ.Server.Interfaces\RZ.Server.Interfaces.csproj" />
</ItemGroup>

</Project>
65 changes: 65 additions & 0 deletions RZ.Server/RZ.Plugin.Feedback.Proxy/RZRestAPIv2_min.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RZ.Plugin.Feedback.Azure
{
class RZRestAPIv2
{
private static string _sURL = "";
private static HttpClient oClient = new HttpClient(); //thx https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

public static string sURL
{
get
{
if (!string.IsNullOrEmpty(_sURL))
return _sURL;

_sURL = GetURL("");
return _sURL;
}
set
{
_sURL = value;
}
}

public static string GetURL(string customerid)
{
using (HttpClient hClient = new HttpClient())
{
Task<string> tReq;
if (string.IsNullOrEmpty(customerid))
tReq = hClient.GetStringAsync("https://ruckzuck.tools/rest/v2/geturl");
else
tReq = hClient.GetStringAsync("https://ruckzuck.tools/rest/v2/geturl?customerid=" + customerid);

tReq.Wait(5000); //wait max 5s

if (tReq.IsCompleted)
{
_sURL = tReq.Result;
return _sURL;
}
else
{
_sURL = "https://ruckzuck.azurewebsites.net";
return _sURL;
}
}
}

public static bool StoreFeedback(string name, string ver, string man, string ok, string user, string text)
{
oClient.GetStringAsync(sURL + "/rest/v2/feedback?name=" + name + "&ver=" + ver + "&man=" + man + "&text=" + text + "&user=" + user + "&ok=" + ok);

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private void UpdateURLs(ref JArray jSource)
if (FileNames.Contains(oFiles["FileName"].Value<string>().ToLower()))
{
//oFiles["URL"] = Base.localURL + "/rest/v2/GetFile/" + sContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");
oFiles["URL"] = "https://ruckzuck.azureedge.net/rest/v2/GetFile/" + sContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");
oFiles["URL"] = "https://cdn.ruckzuck.tools/rest/v2/GetFile/" + sContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");

}
}
Expand Down
4 changes: 4 additions & 0 deletions RZ.Server/RZ.Plugin.Software.Proxy/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
Loading

0 comments on commit 67d55d7

Please sign in to comment.