Ejemplo n.º 1
0
        private void SendReport()
        {
            if (exceptionObject != null)
            {
                lock (exceptionObject)
                {
                    try
                    {
                        string exceptionMessage  = ExceptionWindow.GetExceptionMessage(exceptionObject);
                        string userMessage       = string.Empty;
                        string systemInformation = ExceptionWindow.GetSystemInformation();
#if DEBUG || TEST
                        Debug.WriteLine(systemInformation);
                        Debug.WriteLine(exceptionMessage);
#else
                        ExceptionWindow.SendReport(exceptionMessage, userMessage, systemInformation);
#endif
                    }
                    catch { }
                    Process.GetCurrentProcess().Kill();
                }
            }
        }
Ejemplo n.º 2
0
	    public App()
		{
			//只允许运行一个实例
			bool createdNew = false;
			mutex = new Mutex(true, "{DBFE3F28-BA77-4FF6-9EBF-4FED90151A3E}", out createdNew);
			if (!createdNew)
			{
				Channel channel = Channel.FromCommandLineArgs(System.Environment.GetCommandLineArgs().ToList());
				try
				{
					if (channel != null)
					{
						WriteStringToMappedFile(channel.ToCommandLineArgs());
					}
					else
					{
						WriteStringToMappedFile("-show");
					}
				}
				catch { }
				Debug.WriteLine("检测到已有一个豆瓣电台在运行,程序将关闭");
				Shutdown(0);
				return;
			}

			//设置调试输出
			Debug.AutoFlush = true;
			Debug.Listeners.Add(new TextWriterTraceListener("DoubanFM.log"));

			Debug.WriteLine(string.Empty);
			Debug.WriteLine("**********************************************************************");
			Debug.WriteLine("豆瓣电台启动时间:" + App.GetPreciseTime(DateTime.Now));
			Debug.WriteLine("**********************************************************************");
			Debug.WriteLine(string.Empty);

			//出现未处理的异常时,弹出错误报告窗口,让用户发送错误报告
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) =>
			{
				if (mutex != null)
				{
					mutex.Close();
					mutex = null;
				}
				if (exceptionObject == null)
				{
					exceptionObject = e.ExceptionObject;
					Debug.WriteLine("**********************************************************************");
					Debug.WriteLine("豆瓣电台出现错误:" + App.GetPreciseTime(DateTime.Now));
					Debug.WriteLine("**********************************************************************");

					try
					{
						StringBuilder sb = new StringBuilder();
						sb.AppendLine(DateTime.Now.ToString());
						sb.AppendLine(ExceptionWindow.GetSystemInformation());
						sb.AppendLine(ExceptionWindow.GetExceptionMessage(exceptionObject));

						string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"K.F.Storm\豆瓣电台\error.log");
						string directory = Path.GetDirectoryName(path);
						if (!Directory.Exists(directory))
						{
							Directory.CreateDirectory(directory);
						}
						File.WriteAllText(path, sb.ToString());

						DeleteSettingsIfEmergant();
					}
					catch { }

					Dispatcher.Invoke(new Action(() =>
					{
						try
						{
							SaveSettings();
							var mainWindow = MainWindow as DoubanFMWindow;
							if (mainWindow != null)
							{
								if (mainWindow.NotifyIcon != null) mainWindow.NotifyIcon.Dispose();
							}
							var window = new ExceptionWindow();
							window.ExceptionObject = exceptionObject;
							window.ShowDialog();
							Process.GetCurrentProcess().Kill();
						}
						catch
						{
							SendReport();
						}
					}));
				}
				else
				{
					DeleteSettingsIfEmergant();
					SendReport();
				}
			});

			Exit += new ExitEventHandler((sender, e) =>
			{
				if (mutex != null)
				{
					mutex.Close();
					mutex = null;
				}
				Debug.WriteLine(App.GetPreciseTime(DateTime.Now) + " 程序结束,返回代码为" + e.ApplicationExitCode);
			});

            InitializeComponent();

            var player = FindResource("Player") as Player;
            if (player.Settings.CultureInfo != null)
            {
                Thread.CurrentThread.CurrentCulture = player.Settings.CultureInfo;
                Thread.CurrentThread.CurrentUICulture = player.Settings.CultureInfo;
            }

            //System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

			/* 这句话可以使Global User Interface这个默认的组合字体按当前系统的区域信息选择合适的字形。
			 * 只对FrameworkElement有效。对于FlowDocument,由于是从FrameworkContentElement继承,
			 * 而且FrameworkContentElement.LanguageProperty.OverrideMetadata()无法再次执行,
			 * 目前我知道的最好的办法是在使用了FlowDocument的XAML的根元素上加上xml:lang="zh-CN",
			 * 这样就能强制Global User Interface在FlowDocument上使用大陆的字形。
			 * */
			FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name)));
		}
Ejemplo n.º 3
0
        public App()
        {
            //只允许运行一个实例
            bool createdNew = false;

            mutex = new Mutex(true, "{DBFE3F28-BA77-4FF6-9EBF-4FED90151A3E}", out createdNew);
            if (!createdNew)
            {
                Channel channel = Channel.FromCommandLineArgs(System.Environment.GetCommandLineArgs().ToList());
                try
                {
                    if (channel != null)
                    {
                        WriteStringToMappedFile(channel.ToCommandLineArgs());
                    }
                    else
                    {
                        WriteStringToMappedFile("-show");
                    }
                }
                catch { }
                Debug.WriteLine("检测到已有一个豆瓣电台在运行,程序将关闭");
                Shutdown(0);
                return;
            }

            //设置调试输出
            Debug.AutoFlush = true;
            Debug.Listeners.Add(new TextWriterTraceListener("DoubanFM.log"));

            Debug.WriteLine(string.Empty);
            Debug.WriteLine("**********************************************************************");
            Debug.WriteLine("豆瓣电台启动时间:" + App.GetPreciseTime(DateTime.Now));
            Debug.WriteLine("**********************************************************************");
            Debug.WriteLine(string.Empty);

            //出现未处理的异常时,弹出错误报告窗口,让用户发送错误报告
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) =>
            {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
                if (exceptionObject == null)
                {
                    exceptionObject = e.ExceptionObject;
                    Debug.WriteLine("**********************************************************************");
                    Debug.WriteLine("豆瓣电台出现错误:" + App.GetPreciseTime(DateTime.Now));
                    Debug.WriteLine("**********************************************************************");
                    Debug.WriteLine(e.ExceptionObject.ToString());

                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(DateTime.Now.ToString());
                        sb.AppendLine(ExceptionWindow.GetSystemInformation());
                        sb.AppendLine(ExceptionWindow.GetExceptionMessage(exceptionObject));

                        string path      = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"K.F.Storm\豆瓣电台\error.log");
                        string directory = Path.GetDirectoryName(path);
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        File.WriteAllText(path, sb.ToString());

                        DeleteSettingsIfEmergant();
                    }
                    catch { }

                    Dispatcher.Invoke(new Action(() =>
                    {
                        try
                        {
                            SaveSettings();
                            var mainWindow = MainWindow as DoubanFMWindow;
                            if (mainWindow != null)
                            {
                                if (mainWindow.NotifyIcon != null)
                                {
                                    mainWindow.NotifyIcon.Dispose();
                                }
                            }
                            var window             = new ExceptionWindow();
                            window.ExceptionObject = exceptionObject;
                            window.ShowDialog();
                            Process.GetCurrentProcess().Kill();
                        }
                        catch
                        {
                            SendReport();
                        }
                    }));
                }
                else
                {
                    DeleteSettingsIfEmergant();
                    SendReport();
                }
            });

            Exit += new ExitEventHandler((sender, e) =>
            {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
                Debug.WriteLine(App.GetPreciseTime(DateTime.Now) + " 程序结束,返回代码为" + e.ApplicationExitCode);
            });

            InitializeComponent();

            var player = FindResource("Player") as Player;

            if (player.Settings.CultureInfo != null)
            {
                Thread.CurrentThread.CurrentCulture   = player.Settings.CultureInfo;
                Thread.CurrentThread.CurrentUICulture = player.Settings.CultureInfo;
            }

            //System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

            /* 这句话可以使Global User Interface这个默认的组合字体按当前系统的区域信息选择合适的字形。
             * 只对FrameworkElement有效。对于FlowDocument,由于是从FrameworkContentElement继承,
             * 而且FrameworkContentElement.LanguageProperty.OverrideMetadata()无法再次执行,
             * 目前我知道的最好的办法是在使用了FlowDocument的XAML的根元素上加上xml:lang="zh-CN",
             * 这样就能强制Global User Interface在FlowDocument上使用大陆的字形。
             * */
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name)));
        }