private void Form_Load(Object sender, EventArgs e)
        {
            if (FWhatToOpen.Equals("Server.log"))
            {
                //the client doen't know the serverlog file - unless in standalone use and development environment
                //-> check if there is a Server.log in the same location where the client log is and then display it

                FLogFileLocation = TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "Server.log";

                Clipboard.SetDataObject(FLogFileLocation);
                try
                {
                    StreamReader TLogFileReader = new StreamReader(FLogFileLocation);
                    FLogFileContent = TLogFileReader.ReadToEnd();
                    TLogFileReader.Close();
                    txtLogFileContent.AppendText(Catalog.GetString(
                                                     "The Server log file:") + "\r\n " + FLogFileLocation + "\r\n\r\n" + FLogFileContent);
                }
                catch (Exception)
                {
                    txtLogFileContent.AppendText(Catalog.GetString(
                                                     "Problem on opening logfile. The server log can (at the moment) only be displayed in this window if you are using the standalone version or the development environment."));
                }
            }
            else if (FWhatToOpen.Equals("PetraClient.log"))
            {
                FLogFileLocation = TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "PetraClient.log";

                try
                {
                    StreamReader TLogFileReader = new StreamReader(FLogFileLocation);
                    FLogFileContent = TLogFileReader.ReadToEnd();
                    TLogFileReader.Close();
                    txtLogFileContent.AppendText(Catalog.GetString(
                                                     "The Client log file:") + "\r\n " + FLogFileLocation + "\r\n\r\n" + FLogFileContent);
                }
                catch (Exception)
                {
                    txtLogFileContent.AppendText(Catalog.GetString("Problem on opening logfile"));
                }
            }
            else
            {
                txtLogFileContent.AppendText(
                    String.Format(Catalog.GetString("An error ocurred. The logfile you are looking for \r\n({0})\r\nis not available!"), FWhatToOpen));
            }
        }
Пример #2
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
                // 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.ConnectorType         = typeof(TConnector);
                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();
            }

            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();
            }

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