App.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Resources;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Data;
  12. using ComPDFKit.NativeMethod;
  13. using Compdfkit_Tools.Helper;
  14. using PDFViewer.Properties;
  15. namespace PDFViewer
  16. {
  17. /// <summary>
  18. /// Interaction logic for App.xaml
  19. /// </summary>
  20. public partial class App : Application
  21. {
  22. public static string CurrentCulture = Settings.Default.Cultrue;
  23. public static List<string> SupportedCultureList = new List<string>()
  24. {
  25. "en-US", "zh-CN"
  26. };
  27. public static FilePathList OpenedFilePathList = new FilePathList();
  28. public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly());
  29. public static bool LicenseVerify()
  30. {
  31. if (!CPDFSDKVerifier.LoadNativeLibrary())
  32. {
  33. return false;
  34. }
  35. LicenseErrorCode status = CPDFSDKVerifier.OnlineLicenseVerify("NjViOWE2YzY0ZDdhOA==");
  36. return status == LicenseErrorCode.E_LICENSE_SUCCESS;
  37. }
  38. protected override void OnStartup(StartupEventArgs e)
  39. {
  40. if (string.IsNullOrEmpty(CurrentCulture))
  41. {
  42. CurrentCulture = CultureInfo.CurrentCulture.Name;
  43. if (!SupportedCultureList.Contains(CurrentCulture))
  44. {
  45. CurrentCulture = "en-US";
  46. }
  47. Settings.Default.Cultrue = CurrentCulture;
  48. Settings.Default.Save();
  49. }
  50. Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture);
  51. Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
  52. base.OnStartup(e);
  53. LicenseVerify();
  54. CPDFSDKVerifier.PrintPermissions();
  55. CPDFSDKVerifier.LicenseRefreshed -= CPDFSDKVerifier_LicenseRefreshed;
  56. CPDFSDKVerifier.LicenseRefreshed += CPDFSDKVerifier_LicenseRefreshed;
  57. HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf");
  58. FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
  59. }
  60. private void CPDFSDKVerifier_LicenseRefreshed(object sender, ResponseModel e)
  61. {
  62. if(e != null)
  63. {
  64. string message = string.Format("{0} {1}", e.Code, e.Message);
  65. Trace.WriteLine(message);
  66. }
  67. else
  68. {
  69. Trace.WriteLine("Network not connected.");
  70. }
  71. }
  72. private void HistoryFile(string item)
  73. {
  74. PDFFileInfo fileInfo = new PDFFileInfo();
  75. fileInfo.FilePath = item;
  76. fileInfo.FileName = Path.GetFileName(item);
  77. fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
  78. fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  79. FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
  80. FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
  81. }
  82. }
  83. public class FilePathList : List<string>
  84. {
  85. public new void Add(string item)
  86. {
  87. base.Add(item);
  88. }
  89. }
  90. public class ResourceConverter : IValueConverter
  91. {
  92. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  93. {
  94. if (parameter == null || string.IsNullOrEmpty(parameter.ToString()))
  95. {
  96. return string.Empty;
  97. }
  98. return App.MainResourceManager.GetString(parameter.ToString());
  99. }
  100. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  101. {
  102. throw new NotSupportedException();
  103. }
  104. }
  105. }