Пример #1
0
        /// <summary>
        /// start the client
        /// </summary>
        public static void StartUp()
        {
            // for the moment default to english, because translations are not fully supported, and the layout does not adjust
            string UsersLanguageCode = "en-EN";
            string UsersCultureCode = CultureInfo.CurrentCulture.Name;

            try
            {
                new TAppSettingsManager();

                ExceptionHandling.GApplicationShutdownCallback = Shutdown.SaveUserDefaultsAndDisconnectAndStop;

                TLogging Logger = new TLogging(TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "PetraClient.log");
                String LogFileMsg;

                if (!Logger.CanWriteLogFile(out LogFileMsg))
                {
                    MessageBox.Show(LogFileMsg, Catalog.GetString("Failed to open logfile"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                Catalog.Init();
#if DEBUG
                TApplicationVCSInfo.DetermineApplicationVCSInfo();
#endif

                UserInfo.RunningOnClientSide = true;

                // Register Types that can throw Error Codes (Ict.Common.CommonErrorCodes is automatically added)
                ErrorCodeInventory.RegisteredTypes.Add(new Ict.Petra.Shared.PetraErrorCodes().GetType());
                ErrorCodeInventory.RegisteredTypes.Add(new Ict.Common.Verification.TStringChecks().GetType());

                // Initialize the client
                TClientTasksQueue.ClientTasksInstanceType = typeof(TClientTaskInstance);

                TConnectionManagementBase.GConnectionManagement = new TConnectionManagement();
                new TCallForwarding();


//            System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00001V").ShortDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00001V").FullDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00001V").Category.ToString("G") + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00001V").HelpID);
//            System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00002V").ShortDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00002V").FullDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00002V").ErrorMessageText + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00002V").ErrorMessageTitle + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00002V").Category.ToString("G") + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00002V").HelpID);
//            System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GEN.00004E").ShortDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GEN.00004E").FullDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GEN.00004E").Category.ToString("G") + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GEN.00004E").HelpID);
//            System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("PARTN.00005V").ShortDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("PARTN.00005V").FullDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("PARTN.00005V").Category.ToString("G") + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("PARTN.00005V").HelpID);
//            System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00017V").ShortDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00017V").FullDescription + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00017V").Category.ToString("G") + Environment.NewLine + Environment.NewLine +
//                                                 ErrorCodes.GetErrorInfo("GENC.00017V").HelpID);

//MessageBox.Show(ErrorCodes.GetErrorInfo(ERR_EMAILADDRESSINVALID).ShortDescription);

                // TODO another Catalog.Init("org", "./locale") for organisation specific words?
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return;
            }

            /* Show Splash Screen.
             * This is non-blocking since it is done in a separate Thread, that means
             * that the startup procedure continues while the Splash Screen is initialised and shown!!! */
            FSplashScreen = new TSplashScreenManager(new TSplashScreenCallback(SplashScreenInfoCallback));
            FSplashScreen.Show();

            /*
             * IMPORTANT: Always use FSplashScreen.ShowMessageBox instead of MessageBox.Show
             * as long as the Splash Screen is displayed to show the MessageBox on the correct
             * Thread and in front of the Splash Screen!!!
             */

            try
            {
                InitialiseClasses();
            }
            catch (Exception e)
            {
                FSplashScreen.Close();
                TLogging.Log(e.ToString());
                MessageBox.Show(e.Message);
                Shutdown.StopPetraClient(false);
            }

            if (!LoadClientSettings())
            {
                Environment.Exit(0);
            }

            /*
             *  Initialise Application Help
             */
            Ict.Common.HelpLauncher.LocalHTMLHelp = TClientSettings.LocalHTMLHelp;

            if (TClientSettings.LocalHTMLHelp)
            {
                Ict.Common.HelpLauncher.HelpHTMLBaseURL = TClientSettings.HTMLHelpBaseURLLocal;
            }
            else
            {
                Ict.Common.HelpLauncher.HelpHTMLBaseURL = TClientSettings.HTMLHelpBaseURLOnInternet;

                if (Ict.Common.HelpLauncher.HelpHTMLBaseURL.EndsWith("/"))
                {
                    Ict.Common.HelpLauncher.HelpHTMLBaseURL = Ict.Common.HelpLauncher.HelpHTMLBaseURL.Substring(0,
                        Ict.Common.HelpLauncher.HelpHTMLBaseURL.Length - 1);
                }
            }

            Ict.Common.HelpLauncher.DetermineHelpTopic += new Ict.Common.HelpLauncher.TDetermineHelpTopic(
                Ict.Petra.Client.App.Core.THelpContext.DetermineHelpTopic);

            /*
             * Specific information about this Petra installation can only be shown in the
             * Splash Screen after Client settings are loaded (done in LoadClientSettings).
             */
            FSplashScreen.UpdateTexts();

            // only do automatic patch installation on remote situation
            // needs to be done before login, because the login connects to the updated server, and could go wrong because of changed interfaces
            if (TClientSettings.RunAsRemote == true)
            {
                try
                {
                    CheckForPatches();
                }
                catch (Exception e)
                {
                    TLogging.Log("Problem during checking for patches: " + e.Message);
                    TLogging.Log(e.StackTrace);
                }
            }

            if (TClientSettings.RunAsStandalone == true)
            {
                FSplashScreen.ProgressText = "Starting OpenPetra Server Environment...";

                if (!StartServer())
                {
                    Environment.Exit(0);
                }
            }

            FSplashScreen.ProgressText = "Connecting to your OpenPetra.org Server...";

            /*
             * Show Petra Login screen.
             * Connections to PetraServer are established in here as well.
             */
            try
            {
                PerformLogin();
            }
            catch (Exception)
            {
#if TESTMODE
                // in Testmode, if no connection to applink, just stop here
                Environment.Exit(0);
#endif
#if  TESTMODE
#else
                throw;
#endif
            }

            if (FLoginSuccessful)
            {
                try
                {
                    // Set Application Help language to the User's preferred language
                    TRemote.MSysMan.Maintenance.WebConnectors.GetLanguageAndCulture(ref UsersLanguageCode, ref UsersCultureCode);

                    if (UsersLanguageCode != String.Empty)
                    {
                        Ict.Common.HelpLauncher.HelpLanguage = UsersLanguageCode;
                    }

                    if (TClientSettings.RunAsStandalone == true)
                    {
                        ProcessReminders.StartStandaloneRemindersProcessing();
                    }

                    DataTable CurrencyFormatTable = TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.CurrencyCodeList);

                    StringHelper.CurrencyFormatTable = CurrencyFormatTable;

                    // This loads the Main Window of Petra
                    Form MainWindow;

                    MainWindow = new TFrmMainWindowNew(null);

                    // TODO: user defined constructor with more details
                    //                    FProcessID, FWelcomeMessage, FSystemEnabled);

                    Application.Run(MainWindow);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    TLogging.Log(e.Message);
                    TLogging.Log(e.StackTrace);
                }
                finally
                {
                    /*
                     * This code gets executed only after the Main Window of Petra has
                     * closed.
                     * At the moment, we will never get here, since we call Environment.Exit in the MainWindow (both old and new navigation)
                     */
                    Shutdown.SaveUserDefaultsAndDisconnect();
                }
            }
            else
            {
                // No successful login

                // APPLICATION STOPS IN THIS PROCEDURE !!!
                Shutdown.StopPetraClient(false);
            }

            // APPLICATION STOPS IN THIS PROCEDURE !!!
            Shutdown.StopPetraClient(false);
        }
Пример #2
0
        /// <summary>
        /// Display the Login Dialog, and get the permissions of the user that just has logged in
        /// </summary>
        /// <returns>void</returns>
        public static void PerformLogin()
        {
            try
            {
                TLoginForm AConnectDialog;

                // TODO: close current connection if it is open
                FLoginSuccessful = false;

                // Need to show and hide Connect Dialog before closing the Splash Screen so that it can receive input focus!
                AConnectDialog = new TLoginForm();

                // this causes a bug on Mono. see bug #590. inactive login screen
                // and it is not needed because the splashscreen is disabled for the moment anyway
                // AConnectDialog.Show();
                // AConnectDialog.Visible = false;

                // Close Splash Screen
                FSplashScreen.Close();
                FSplashScreen = null;

                // Show the Connect Dialog
                if (AConnectDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    FLoginSuccessful = false;
                }
                else
                {
                    // TODO reset any caches
                    // TODO AConnectDialog.GetReturnedParameters(out FProcessID, out FWelcomeMessage, out FSystemEnabled);

                    // get Connection Dialog out of memory
                    AConnectDialog.Dispose();

                    FLoginSuccessful = true;

                    Ict.Petra.Client.MSysMan.Gui.TUC_GeneralPreferences.InitLanguageAndCulture();
                }
            }
            catch (Exception exp)
            {
                if (FSplashScreen == null)
                {
                    MessageBox.Show("Exception caught in Method PerformLogin: "******"Exception caught in Method PerformLogin: " + exp.ToString());
                }
            }
        }