App.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Bridge;
  2. using Bridge.Html5;
  3. using System;
  4. namespace CefBridgeDataExchange.Tests
  5. {
  6. public static class App
  7. {
  8. public static void Main()
  9. {
  10. Document.Body.InnerHTML = "Bind...ExternalDataExchangeDispatcher";
  11. var externalDataExchangeDispatcher = Script.Get<ExternalDataExchangeDispatcher>(nameof(CefBridgeDataExchange));
  12. Document.Body.InnerHTML = "Bind...DataExchangeServiceFactory";
  13. var dataExchangeServiceFactory = new DataExchangeServiceFactory(externalDataExchangeDispatcher);
  14. Document.Body.InnerHTML = "Bind...IWindowControlService";
  15. var windowControlService = dataExchangeServiceFactory.Create<IWindowControlService>();
  16. Document.Body.InnerHTML = "Bind...ICefDevService";
  17. var cefDevService = dataExchangeServiceFactory.Create<ICefDevService>();
  18. Document.Body.InnerHTML = "";
  19. new HTMLDivElement()
  20. .With(p => p.TextContent = "msg:")
  21. .With(p => p.OwnerDocument.Body.AppendChild(p));
  22. var label = new HTMLDivElement()
  23. .With(p => p.TextContent = "...")
  24. .With(p => p.OwnerDocument.Body.AppendChild(p));
  25. Window.OnResize += delegate { label.TextContent = windowControlService.GetWindowState().ToString(); };
  26. new HTMLInputElement { Type = InputType.Button, Value = "F12" }
  27. .With(p => p.OnClick += delegate { cefDevService.ShowF12(); })
  28. .With(p => Document.Body.AppendChild(p));
  29. new HTMLInputElement { Type = InputType.Button, Value = "Refresh" }
  30. .With(p => p.OnClick += delegate { cefDevService.Refresh(); })
  31. .With(p => Document.Body.AppendChild(p));
  32. new HTMLInputElement { Type = InputType.Button, Value = "Move" }
  33. .With(p => p.OnMouseDown += delegate { windowControlService.DragMove(); })
  34. .With(p => Document.Body.AppendChild(p));
  35. new HTMLInputElement { Type = InputType.Button, Value = "Max" }
  36. .With(p => p.OnClick += delegate { windowControlService.SetWindowState(WindowState.Maximized); })
  37. .With(p => Document.Body.AppendChild(p));
  38. new HTMLInputElement { Type = InputType.Button, Value = "Min" }
  39. .With(p => p.OnClick += delegate { windowControlService.SetWindowState(WindowState.Minimized); })
  40. .With(p => Document.Body.AppendChild(p));
  41. new HTMLInputElement { Type = InputType.Button, Value = "Restore" }
  42. .With(p => p.OnClick += delegate { windowControlService.SetWindowState(WindowState.Normal); })
  43. .With(p => Document.Body.AppendChild(p));
  44. new HTMLInputElement { Type = InputType.Button, Value = "Close" }
  45. .With(p => p.OnClick += delegate { windowControlService.Close(); })
  46. .With(p => Document.Body.AppendChild(p));
  47. }
  48. private static T With<T>(this T me, Action<T> action)
  49. {
  50. action(me);
  51. return me;
  52. }
  53. }
  54. }