MarkdownRendererMain.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using CefSharpWrap;
  2. using CefSharpWrap.CustomResource;
  3. using System;
  4. using System.IO;
  5. using System.Reflection;
  6. namespace MarkdownRenderer
  7. {
  8. public static class MarkdownRendererMain
  9. {
  10. internal static readonly string CustomResourcePath = $"{nameof(MarkdownRenderer)}-{Guid.NewGuid()}";
  11. static MarkdownRendererMain()
  12. {
  13. InitReferenceAssembly();
  14. }
  15. private static void InitReferenceAssembly()
  16. {
  17. CefSharpWrapFactory.AddCustomResource($"/{CustomResourcePath}/", "text/html"
  18. #if DEBUG
  19. , new FileByteProvider(Path.Combine(MarkdownRendererDebugSupport.MrResourceDir, "TemplatePage.html"))
  20. #else
  21. , new BytesProvider(System.Text.Encoding.UTF8.GetBytes(Properties.Resources.TemplatePage))
  22. #endif
  23. );
  24. }
  25. #if DEBUG
  26. private class FileByteProvider : IBytesProvider
  27. {
  28. private readonly string _path;
  29. public FileByteProvider(string path) => _path = path;
  30. public int Length => (int)new FileInfo(_path).Length;
  31. public byte[] GetBytes() => File.ReadAllBytes(_path);
  32. }
  33. #endif
  34. internal static IConfigStore ConfigStore { get; private set; }
  35. public static void Init(IConfigStore configStore = null)
  36. {
  37. //ensure static ctor fire and
  38. ConfigStore = configStore;
  39. }
  40. public static void Quit()
  41. {
  42. ConfigStore?.Flush();
  43. CefSharpWrapFactory.Shutdown();
  44. }
  45. }
  46. }