示例#1
0
        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;
                Pointel.Logger.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                                                         "STF").Error("--- Unhandled exception ---");

                Pointel.Logger.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                                                         "STF").Error("Exception : " + ((ex.InnerException == null) ? ex.Message : ex.InnerException.ToString()));

                if (ex.TargetSite != null)
                {
                    Pointel.Logger.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                                                             "STF").Error("Exception Module : " + ex.TargetSite.Module.Name + " - Exception Method : " + ex.TargetSite.Name);
                }

                Views.MessageBox msgbox;
                ViewModels.MessageBoxViewModel mboxvmodel;
                msgbox     = new Views.MessageBox();
                mboxvmodel = new MessageBoxViewModel("Alert",
                                                     "StatTickerFive has encountered a problem. \nThe application will exit now, please contact your Administrator.",
                                                     msgbox, "Exception", Settings.GetInstance().Theme);
                msgbox.DataContext = mboxvmodel;
                msgbox.ShowDialog();
            }
            catch
            {
            }
        }
        /// <summary>
        /// Shows the gadget.
        /// </summary>
        /// <param name="isStartup"></param>
        public void ShowGadget(bool isStartup)
        {
            bool isOpened = false;

            StatisticsBase.GetInstance().isPlugin      = true;
            StatisticsBase.GetInstance().isGadgetClose = false;

            try
            {
                logger.Debug("PluginContainer : ShowGadget : Method Entry");

                if (StatisticsBase.GetInstance().IsMandatoryFieldsMissing)
                {
                    if (!isStartup)
                    {
                        string Message            = string.Empty;
                        int    CurrentErrrorCount = 1;
                        foreach (string MissingKeys in StatisticsBase.GetInstance().ListMissedValues)
                        {
                            if (CurrentErrrorCount <= (StatisticsBase.GetInstance().ErrorCount == 0 ? 3 : StatisticsBase.GetInstance().ErrorCount))
                            {
                                if (Message == string.Empty)
                                {
                                    Message = "'" + MissingKeys + "' value is Missing";
                                }
                                else
                                {
                                    Message = Message + "\n '" + MissingKeys + "' value is Missing";
                                }
                            }
                            CurrentErrrorCount++;
                        }
                        Views.MessageBox    msgbox        = new Views.MessageBox();
                        MessageBoxViewModel mboxviewmodel = new MessageBoxViewModel("Problem Encountered in Statistics", Message, msgbox, "MainWindow", Settings.GetInstance().Theme);
                        msgbox.DataContext = mboxviewmodel;
                        msgbox.ShowDialog();
                    }
                }
                else if (!isAuthenticated)
                {
                    if (!isStartup)
                    {
                        Views.MessageBox    msgbox        = new Views.MessageBox();
                        MessageBoxViewModel mboxviewmodel = new MessageBoxViewModel("Problem Encountered in Statistics", Settings.GetInstance().DictErrorValues["user.authorization"].ToString(), msgbox, "MainWindow", Settings.GetInstance().Theme);
                        msgbox.DataContext = mboxviewmodel;
                        msgbox.ShowDialog();
                    }
                }
                else
                {
                    Application.Current.Dispatcher.BeginInvoke((Action)(delegate
                    {
                        //foreach (Window appwindow in Application.Current.Windows)
                        //{
                        //    if (appwindow.Title == "StatGadget")
                        //    {
                        //        //
                        //        isOpened = true;
                        //        if (Settings.GetInstance().isMinimized)
                        //        {
                        //            Settings.GetInstance().isMinimized = false;

                        //            appwindow.WindowState = WindowState.Maximized;
                        //            appwindow.Show();
                        //        }
                        //        else
                        //            appwindow.Show();
                        //        stat.ShowGadgetState(Pointel.Statistics.Core.Utility.StatisticsEnum.GadgetState.Opened);

                        //        break;
                        //    }
                        //}

                        MainWindow mainview = new MainWindow();
                        MainWindowViewModel mainVm = new MainWindowViewModel();
                        mainview.DataContext = mainVm;

                        mainview.Show();
                        mainVm.dragwindowInitialize(mainview);


                        if (!isOpened)
                        {
                            // MainWindow mainview = new MainWindow();
                            mainVm = new MainWindowViewModel();
                            mainview.DataContext = mainVm;
                            mainview.Show();
                            stat.ShowGadgetState(Pointel.Statistics.Core.Utility.StatisticsEnum.GadgetState.Opened);
                            // Window window = Application.Current.Windows[0];
                            //comment removed
                            // if (window != null)
                            mainVm.dragwindowInitialize(mainview);
                        }
                    }), DispatcherPriority.Background);
                }
            }
            catch (Exception GeneralException)
            {
                logger.Error("PluginContainer : ShowGadget Method : Exception Caught : " + GeneralException.Message);
            }
            finally
            {
                logger.Debug("PluginContainer : ShowGadget : Method Exit");
            }
        }