123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Resources;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Data;
- using System.Windows.Threading;
- using System.Xml;
- using ComPDFKit.NativeMethod;
- using Compdfkit_Tools.Helper;
- using PDFViewer.Properties;
- namespace PDFViewer
- {
- /// <summary>
- /// Interaction logic for App.xaml
- /// </summary>
- public partial class App: Application
- {
- public static string CurrentCulture = Settings.Default.Cultrue;
- public static List<string> SupportedCultureList= new List<string>()
- {
- "en-US", "zh-CN"
- };
- public static FilePathList OpenedFilePathList = new FilePathList();
- public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly());
- public App()
- {
- this.DispatcherUnhandledException += App_DispatcherUnhandledException;
- AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
- }
- private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
- {
- var ex = e.Exception as Exception;
- if (ex != null)
- {
- MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- if (e.ExceptionObject is System.Exception)
- {
- Exception ex = (System.Exception)e.ExceptionObject;
- MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- e.Handled = true;
- MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- protected override void OnStartup(StartupEventArgs e)
- {
- if (string.IsNullOrEmpty(CurrentCulture))
- {
- CurrentCulture = CultureInfo.CurrentCulture.Name;
- if (!SupportedCultureList.Contains(CurrentCulture))
- {
- CurrentCulture = "en-US";
- }
- Settings.Default.Cultrue = CurrentCulture;
- Settings.Default.Save();
- }
-
- Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture);
- Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
- base.OnStartup(e);
- LicenseVerify();
- HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf");
- FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
- }
-
- private static bool LicenseVerify()
- {
- if (!CPDFSDKVerifier.LoadNativeLibrary())
- return false;
- LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("license_key_windows.txt", true);
- return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
- }
-
- private void HistoryFile(string item)
- {
- PDFFileInfo fileInfo = new PDFFileInfo();
- fileInfo.FilePath = item;
- fileInfo.FileName = Path.GetFileName(item);
- fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
- fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
- FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
- }
- }
- public class FilePathList : List<string>
- {
- public new void Add(string item)
- {
- base.Add(item);
- }
- }
-
- public class ResourceConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (parameter == null || string.IsNullOrEmpty(parameter.ToString()))
- {
- return string.Empty;
- }
- return App.MainResourceManager.GetString(parameter.ToString());
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotSupportedException();
- }
- }
- }
|