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.

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