You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using System.Reflection;
  2. using CDPShared;
  3. using CircleViewerMaui.Popups;
  4. using CommunityToolkit.Maui.Views;
  5. using Syncfusion.Maui.PdfViewer;
  6. namespace CircleViewerMaui;
  7. public partial class MainPage : ContentPage
  8. {
  9. int count = 0;
  10. // private CDPWorker _cdp;
  11. Timer _timer;
  12. Boolean _bConnected = false;
  13. public MainPage()
  14. {
  15. using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name))
  16. {
  17. InitializeComponent();
  18. _timer = new Timer(IsReady, null, 250, 250);
  19. }
  20. }
  21. void IsReady(object state)
  22. {
  23. if (_bConnected != App.CDP.Ready)
  24. {
  25. _bConnected = App.CDP.Ready;
  26. OnReady();
  27. _timer = null;
  28. }
  29. }
  30. void OnReady()
  31. {
  32. // Device.InvokeOnMainThreadAsync(() => { lblConnected.Text = "Connected"; });
  33. }
  34. public async Task<string> OpenCirFileAsync()
  35. {
  36. var fileTypes = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
  37. {
  38. { DevicePlatform.iOS, new[] { "public.cir" } },
  39. { DevicePlatform.Android, new[] { "application/cir" } },
  40. { DevicePlatform.WinUI, new[] { ".cir" } },
  41. { DevicePlatform.macOS, new[] { ".cir" } }
  42. });
  43. var options = new PickOptions
  44. {
  45. FileTypes = fileTypes,
  46. PickerTitle = "Open .cir File"
  47. };
  48. var result = await FilePicker.PickAsync(options);
  49. if (result != null)
  50. {
  51. return result.FullPath;
  52. }
  53. return null;
  54. }
  55. async Task TestPopup()
  56. {
  57. var popup = new NewInvite("AS3RT3", "POEW");
  58. popup.CanBeDismissedByTappingOutsideOfPopup = false;
  59. this.ShowPopup(popup);
  60. }
  61. private async void onOpenClicked(object sender, EventArgs e)
  62. {
  63. // await TestPopup();
  64. var filePath = await OpenCirFileAsync();
  65. if (filePath != null)
  66. {
  67. ViewFileAsync(filePath);
  68. }
  69. }
  70. async void ViewFileAsync(string fileToLoad)
  71. {
  72. using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name))
  73. {
  74. var result = await App.CDP.Decrypt(fileToLoad);
  75. if (result.Status.Result.GetValueOrDefault(false))
  76. {
  77. byte[] buf = Convert.FromBase64String(result.DecryptedData);
  78. string ext = Path.GetExtension(result.FileName);
  79. PdfViewer.DocumentSource = new MemoryStream(buf);
  80. }
  81. }
  82. }
  83. }