mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-22 15:06:26 +01:00
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Serilog;
|
|
|
|
namespace ShareeBike.ViewModel
|
|
{
|
|
public static class ViewModelResourceHelper
|
|
{
|
|
/// <summary> Get resource prefix depending on platform.</summary>
|
|
public static string ResourcePrefix
|
|
{
|
|
get
|
|
{
|
|
#if __IOS__
|
|
return "ShareeBike.iOS.";
|
|
#endif
|
|
#if __ANDROID__
|
|
return "ShareeBike.Droid.";
|
|
#endif
|
|
#if WINDOWS_UWP
|
|
return "ShareeBike.WinPhone.";
|
|
#endif
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets an embedded html resource.</summary>
|
|
/// <param name="resrouceName">Name of resource to get.</param>
|
|
/// <returns></returns>
|
|
public static string GetSource(string resrouceName)
|
|
{
|
|
var resourceName = ResourcePrefix + resrouceName;
|
|
Log.Verbose($"Using this resource prefix {ResourcePrefix}.");
|
|
// note that the prefix includes the trailing period '.' that is required
|
|
var assembly = typeof(ViewModelResourceHelper).GetTypeInfo().Assembly;
|
|
var stream = assembly.GetManifestResourceStream(resourceName);
|
|
return stream != null
|
|
? (new StreamReader(stream, Encoding.UTF8)).ReadToEnd()
|
|
: string.Format("<!DOCTYPE html><html lang=\"de\"><body>An error occurred loading html- resource {0}.</body>", resourceName);
|
|
}
|
|
}
|
|
}
|