Пример #1
0
        static void Main()
        {
            AppManager.AjustVideoSetting();
            try
            {
                Form form = null;
                try
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    if (!AppManager.CheckForSingleInstance())
                    {
                        return;
                    }
                    //Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");
                    log = Log.GetLogger();
                    //http://stackoverflow.com/questions/8137070/force-application-close-on-system-shutdown
                    //SystemEvents can help you. The SessionEnding occurs when the user is trying to log off or shut down the system.
                    Microsoft.Win32.SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                    //If you don't want to cancel the event, but just react to it appropriately, you should handle the SystemEvents.SessionEnded event instead.
                    Microsoft.Win32.SystemEvents.SessionEnded += SystemEvents_SessionEnded;

                    //create instances of manager classes
                    FrwConfig.Instance  = new FrwSimpleWinCRUDConfig(); //WebAccountConfig();
                    Dm.Instance         = new WebAccountDm();
                    AppManager.Instance = new WebAccountLibAppManager();
                    AppManager.Instance.MainAppFormType       = typeof(WebAccountMainForm);
                    AppManager.Instance.DefaultViewWindowType = typeof(BrowserViewWindow);

                    //force load dlls with entities
                    VpnSelectorLibLoader.Load();
                    WebAccountLibLoader.Load();

                    AppManager.Instance.InitApplication();

                    JSetting setting = FrwConfig.Instance.CreatePropertyIfNotExist(new JSetting()
                    {
                        Name                 = "RunAppInWindowsTray",
                        Description          = VpnSelectorLibRes.Run_application_in_windows_system_tray__next_run_,
                        Value                = true,
                        IsUser               = true,
                        IsAttachedToComputer = false
                    });
                    if (FrwConfig.Instance.GetPropertyValueAsBool(setting.Name, true))
                    {
                        applicationContext = new BaseApplicationContext();
                        applicationContext.DefaultTooltip = VpnSelectorLibRes.VPN_selector;
                        applicationContext.IconFileName   = "bookmark_icon.ico";
                        applicationContext.Load();
                        BaseApplicationContext.NotifyIcon.Icon = VpnSelectorLibRes.vpn_off;
                        applicationContext.ThreadExit         += ApplicationContext_ThreadExit;
                        Application.Run(applicationContext);
                    }
                    else
                    {
                        form              = AppManager.Instance.LoadDocPanelContainersState(true);
                        form.FormClosing += Form_FormClosing;
                        form.FormClosed  += Form_FormClosed;
                    }
                }
                catch (Exception ex)
                {
                    Log.ShowError("Error start app", ex);
                    Application.Exit();
                }
                if (form != null && !form.IsDisposed)
                {
                    Application.ThreadException += Application_ThreadException;
                    Application.Run(form);
                }
            }
            catch (Exception ex)
            {
                Log.ShowError("Error running main app form", ex);
                MessageBox.Show("Unexpected error: " + ex);
                Application.Exit();
            }
        }
Пример #2
0
        static void Main()
        {
            MainAppUtils.AjustVideoSetting();
            try
            {
                Form form = null;
                try
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    if (!MainAppUtils.CheckForSingleInstance())
                    {
                        return;
                    }
                    log = Log.GetLogger();
                    //http://stackoverflow.com/questions/8137070/force-application-close-on-system-shutdown
                    //SystemEvents can help you. The SessionEnding occurs when the user is trying to log off or shut down the system.
                    Microsoft.Win32.SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                    //If you don't want to cancel the event, but just react to it appropriately, you should handle the SystemEvents.SessionEnded event instead.
                    Microsoft.Win32.SystemEvents.SessionEnded += SystemEvents_SessionEnded;

                    //for testing, remove this lines in real app
                    //var culture = new CultureInfo("en-US");
                    //CultureInfo.DefaultThreadCurrentCulture = culture;
                    //CultureInfo.DefaultThreadCurrentUICulture = culture;

                    //create instances of manager classes
                    FrwConfig.Instance  = new VpnSelectorConfig();
                    AppManager.Instance = new VpnSelectorAppManager();
                    AppManager.Instance.MainAppFormType = typeof(VpnSelectorMainForm);
                    Dm.Instance = new VpnSelectorDm();
                    //force load dlls with entities
                    //...
                    VpnSelectorLibLoader.Load();
                    //BaseProxyServer.CurrentType = typeof(FProxyServer);
                    //BaseProxyProvider.CurrentType = typeof(FProxyProvider);

                    MainAppUtils.InitAppPaths();

                    JSetting setting = FrwConfig.Instance.CreatePropertyIfNotExist(new JSetting()
                    {
                        Name                 = "RunAppInWindowsTray",
                        Description          = VpnSelectorLibRes.Run_application_in_windows_system_tray__next_run_,
                        Value                = true,
                        IsUser               = true,
                        IsAttachedToComputer = false
                    });

                    if (FrwConfig.Instance.GetPropertyValueAsBool(setting.Name, true))
                    {
                        applicationContext = new BaseApplicationContext();
                        applicationContext.DefaultTooltip = VpnSelectorLibRes.VPN_selector;
                        applicationContext.IconFileName   = "icon_vpn_selector.ico";
                        applicationContext.Load();
                        BaseApplicationContext.NotifyIcon.Icon = VpnSelectorLibRes.vpn_off;
                        applicationContext.ThreadExit         += ApplicationContext_ThreadExit;
                        Application.Run(applicationContext);
                    }
                    else
                    {
                        form              = AppManager.Instance.LoadDocPanelContainersState(true);
                        form.FormClosing += Form_FormClosing;
                        form.FormClosed  += Form_FormClosed;
                    }
                }
                catch (Exception ex)
                {
                    Log.ShowError("Error start app", ex);
                    Application.Exit();
                }
                if (form != null && !form.IsDisposed)
                {
                    Application.ThreadException += Application_ThreadException;
                    Application.Run(form);
                }
            }
            catch (Exception ex)
            {
                Log.ShowError("Error start app", ex);
                Application.Exit();
            }
        }