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.

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