Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialises the internal variables that hold the Server Settings, using the current config file.
        ///
        /// </summary>
        /// <returns>void</returns>
        public TSrvSetting()
        {
            if (USingletonSrvSetting == null)
            {
                USingletonSrvSetting = this;
            }

            FConfigurationFile = TAppSettingsManager.ConfigFileName;
            FExecutingOS       = Utilities.DetermineExecutingOS();

            // Server.RDBMSType
            FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql"));

            FDatabaseHostOrFile = TAppSettingsManager.GetValue("Server.DBHostOrFile", "localhost");
            FDatabasePort       = TAppSettingsManager.GetValue("Server.DBPort", "5432");
            FDatabaseName       = TAppSettingsManager.GetValue("Server.DBName", "openpetra");
            FDBUsername         = TAppSettingsManager.GetValue("Server.DBUserName", "petraserver");
            FDBPassword         = TAppSettingsManager.GetValue("Server.DBPassword", string.Empty, false);

            FApplicationBinFolder = TAppSettingsManager.GetValue("Server.ApplicationBinDirectory", string.Empty, false);

            if (FDBPassword == "PG_OPENPETRA_DBPWD")
            {
                // get the password from the file ~/.pgpass. This currently only works for PostgreSQL on Linux
                using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                                                          Path.DirectorySeparatorChar + ".pgpass"))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith(FDatabaseHostOrFile + ":" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":") ||
                            line.StartsWith("*:" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":"))
                        {
                            FDBPassword = line.Substring(line.LastIndexOf(':') + 1);
                            break;
                        }
                    }
                }
            }

            if (TAppSettingsManager.HasValue("Server.LogFile"))
            {
                FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false);
            }
            else
            {
                // maybe the log file has already been set, eg. by the NUnit Server Test
                FServerLogFile = TLogging.GetLogFileName();

                if (FServerLogFile.Length == 0)
                {
                    // this is effectively the bin directory (current directory)
                    FServerLogFile = "Server.log";
                }
            }

            // Server.Port
            FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 9000);

            FRunAsStandalone = TAppSettingsManager.GetBoolean("Server.RunAsStandalone", false);

            // Server.ClientIdleStatusAfterXMinutes
            FClientIdleStatusAfterXMinutes = TAppSettingsManager.GetInt32("Server.ClientIdleStatusAfterXMinutes", 5);

            // Server.ClientKeepAliveCheckIntervalInSeconds
            FClientKeepAliveCheckIntervalInSeconds = TAppSettingsManager.GetInt32("Server.ClientKeepAliveCheckIntervalInSeconds", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_LAN
            FClientKeepAliveTimeoutAfterXSecondsLAN = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_LAN", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_Remote
            FClientKeepAliveTimeoutAfterXSecondsRemote =
                TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_Remote", (ClientKeepAliveTimeoutAfterXSecondsLAN * 2));

            // Server.ClientConnectionTimeoutAfterXSeconds
            FClientConnectionTimeoutAfterXSeconds = TAppSettingsManager.GetInt32("Server.ClientConnectionTimeoutAfterXSeconds", 20);

            // Server.ClientAppDomainShutdownAfterKeepAliveTimeout
            FClientAppDomainShutdownAfterKeepAliveTimeout = TAppSettingsManager.GetBoolean("Server.ClientAppDomainShutdownAfterKeepAliveTimeout",
                                                                                           true);

            FSMTPServer = TAppSettingsManager.GetValue("Server.SMTPServer", "localhost");

            // This is disabled in processing at the moment, so we reflect that here. When it works change to true
            FAutomaticIntranetExportEnabled = TAppSettingsManager.GetBoolean("Server.AutomaticIntranetExportEnabled", false);

            // The following setting specifies the email address where the Intranet Data emails are sent to when "Server.AutomaticIntranetExportEnabled" is true.
            FIntranetDataDestinationEmail = TAppSettingsManager.GetValue("Server.IntranetDataDestinationEmail", "???@???.org");

            // The following setting is temporary - until we have created a GUI where users can specify the email address for the
            // responsible Personnel and Finance persons themselves. Those will be stored in SystemDefaults then.
            FIntranetDataSenderEmail = TAppSettingsManager.GetValue("Server.IntranetDataSenderEmail", "???@???.org");

            // Determine network configuration of the Server
            Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses);

            FApplicationVersion = TFileVersionInfo.GetApplicationVersion();
        }
Esempio n. 3
0
 /// <summary>
 /// Reset the ticket number to 0
 /// </summary>
 public static void ResetTicket()
 {
     TLogging.Log("Resetting ticket number ...");
     TicketNum = 0;
 }
Esempio n. 4
0
        /// <summary>
        /// Initialises the internal variables that hold the Server Settings, using the current config file.
        ///
        /// </summary>
        /// <returns>void</returns>
        public TSrvSetting()
        {
            if (USingletonSrvSetting == null)
            {
                USingletonSrvSetting = this;
            }

            FConfigurationFile = TAppSettingsManager.ConfigFileName;
            FExecutingOS       = Utilities.DetermineExecutingOS();

            // Server.RDBMSType
            FRDBMSType = CommonTypes.ParseDBType(TAppSettingsManager.GetValue("Server.RDBMSType", "postgresql"));

            FDatabaseHostOrFile        = TAppSettingsManager.GetValue("Server.DBHostOrFile", "localhost");
            FDatabasePort              = TAppSettingsManager.GetValue("Server.DBPort", "5432");
            FDatabaseName              = TAppSettingsManager.GetValue("Server.DBName", "openpetra");
            FDBUsername                = TAppSettingsManager.GetValue("Server.DBUserName", "petraserver");
            FDBPassword                = TAppSettingsManager.GetValue("Server.DBPassword", string.Empty, false);
            FDBConnectionCheckInterval = TAppSettingsManager.GetInt32("Server.DBConnectionCheckInterval", 0);

            FApplicationBinFolder = TAppSettingsManager.GetValue("Server.ApplicationBinDirectory", string.Empty, false);

            if (FDBPassword == "PG_OPENPETRA_DBPWD")
            {
                // get the password from the file ~/.pgpass. This currently only works for PostgreSQL on Linux
                using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                                                          Path.DirectorySeparatorChar + ".pgpass"))
                {
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith(FDatabaseHostOrFile + ":" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":") ||
                            line.StartsWith("*:" + FDatabasePort + ":" + FDatabaseName + ":" + FDBUsername + ":"))
                        {
                            FDBPassword = line.Substring(line.LastIndexOf(':') + 1);
                            break;
                        }
                    }
                }
            }

            if (TAppSettingsManager.HasValue("Server.LogFile"))
            {
                FServerLogFile = TAppSettingsManager.GetValue("Server.LogFile", false);
            }
            else
            {
                // maybe the log file has already been set, eg. by the NUnit Server Test
                FServerLogFile = TLogging.GetLogFileName();

                if (FServerLogFile.Length == 0)
                {
                    // this is effectively the bin directory (current directory)
                    FServerLogFile = "Server.log";
                }
            }

            // Server.Port
            FIPBasePort = TAppSettingsManager.GetInt16("Server.Port", 9000);

            FRunAsStandalone = TAppSettingsManager.GetBoolean("Server.RunAsStandalone", false);

            // Server.ClientIdleStatusAfterXMinutes
            FClientIdleStatusAfterXMinutes = TAppSettingsManager.GetInt32("Server.ClientIdleStatusAfterXMinutes", 5);

            // Server.ClientKeepAliveCheckIntervalInSeconds
            FClientKeepAliveCheckIntervalInSeconds = TAppSettingsManager.GetInt32("Server.ClientKeepAliveCheckIntervalInSeconds", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_LAN
            FClientKeepAliveTimeoutAfterXSecondsLAN = TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_LAN", 60);

            // Server.ClientKeepAliveTimeoutAfterXSeconds_Remote
            FClientKeepAliveTimeoutAfterXSecondsRemote =
                TAppSettingsManager.GetInt32("Server.ClientKeepAliveTimeoutAfterXSeconds_Remote", (ClientKeepAliveTimeoutAfterXSecondsLAN * 2));

            // Server.ClientConnectionTimeoutAfterXSeconds
            FClientConnectionTimeoutAfterXSeconds = TAppSettingsManager.GetInt32("Server.ClientConnectionTimeoutAfterXSeconds", 20);

            // Server.ClientAppDomainShutdownAfterKeepAliveTimeout
            FClientAppDomainShutdownAfterKeepAliveTimeout = TAppSettingsManager.GetBoolean("Server.ClientAppDomainShutdownAfterKeepAliveTimeout",
                                                                                           true);

            FSmtpHost               = TAppSettingsManager.GetValue("SmtpHost", "");
            FSmtpPort               = TAppSettingsManager.GetInt32("SmtpPort", 25);
            FSmtpUser               = TAppSettingsManager.GetValue("SmtpUser", "YourSmtpUser");
            FSmtpPassword           = TAppSettingsManager.GetValue("SmtpPassword", "YourSmtpPassword");
            FSmtpEnableSsl          = TAppSettingsManager.GetBoolean("SmtpEnableSsl", true);
            FSmtpAuthenticationType = TAppSettingsManager.GetValue("SmtpAuthenticationType", "config").ToLower();
            FSmtpIgnoreServerCertificateValidation = TAppSettingsManager.GetBoolean("IgnoreServerCertificateValidation", false);

            // Determine network configuration of the Server
            Networking.DetermineNetworkConfig(out FHostName, out FHostIPAddresses);

            FApplicationVersion = TFileVersionInfo.GetApplicationVersion();
        }