sharee.bike-App/LastenradBayern/TINK/ViewModel/ViewModelResourceHelper.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2023-05-09 08:47:52 +02:00
using System.IO;
2021-11-07 19:42:59 +01:00
using System.Reflection;
using System.Text;
2022-08-30 15:42:25 +02:00
using Serilog;
2021-11-07 19:42:59 +01:00
namespace TINK.ViewModel
{
2022-09-06 16:08:19 +02:00
public static class ViewModelResourceHelper
{
2023-05-09 08:47:52 +02:00
/// <summary> Get resource prefix depending on platform.</summary>
public static string ResourcePrefix
2022-09-06 16:08:19 +02:00
{
get
{
2021-11-07 19:42:59 +01:00
#if __IOS__
2022-09-06 16:08:19 +02:00
return "TINK.iOS.";
2021-11-07 19:42:59 +01:00
#endif
#if __ANDROID__
2022-09-06 16:08:19 +02:00
return "TINK.Droid.";
2021-11-07 19:42:59 +01:00
#endif
#if WINDOWS_UWP
return "TINK.WinPhone.";
#endif
2022-09-06 16:08:19 +02:00
}
}
2021-11-07 19:42:59 +01:00
2023-05-09 08:47:52 +02:00
/// <summary> Gets an embedded html resource.</summary>
2022-09-06 16:08:19 +02:00
/// <param name="resrouceName">Name of resource to get.</param>
/// <returns></returns>
public static string GetSource(string resrouceName)
{
2023-05-09 08:47:52 +02:00
var resourceName = ResourcePrefix + resrouceName;
Log.Verbose($"Using this resource prefix {ResourcePrefix}.");
2022-09-06 16:08:19 +02:00
// note that the prefix includes the trailing period '.' that is required
var assembly = typeof(ViewModelResourceHelper).GetTypeInfo().Assembly;
2023-05-09 08:47:52 +02:00
var stream = assembly.GetManifestResourceStream(resourceName);
2022-09-06 16:08:19 +02:00
return stream != null
? (new StreamReader(stream, Encoding.UTF8)).ReadToEnd()
2023-05-09 08:47:52 +02:00
: string.Format("<!DOCTYPE html><html lang=\"de\"><body>An error occurred loading html- resource {0}.</body>", resourceName);
2022-09-06 16:08:19 +02:00
}
}
2021-11-07 19:42:59 +01:00
}