/// <summary>
        /// Logs an Exception and a StackTrace to the Server logfile.
        /// </summary>
        /// <param name="AException">The Exception to log.</param>
        /// <param name="ALogText">Additional Text to be logged.</param>
        /// <returns>void</returns>
        public static void LogException(Exception AException, String ALogText)
        {
            String LogentryText;

            LogentryText = "PetraServer Caught an Unhandled Exception.\r\n" + ALogText + "\r\n" + AException.ToString();

            // Check if logging is already initialised; if not, initialise it with a fallback log file
            if (TLogging.GetLogFileName() == "")
            {
                new TLogging(Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                             Path.DirectorySeparatorChar + FALLBACK_LOGFILE_NAME);
            }

            TLogging.Log(LogentryText);
            TLogging.LogStackTrace(TLoggingType.ToLogfile);
        }
        private void SaveDataLabelUseChanges(TTypedDataTable ASubmitChanges)
        {
            // Submit changes to the PETRAServer for the DataLabelUse table
            // This code is basically lifted from a typical auto-generated equivalent
            // TODO: If the standard code changes because TODO's get done, we will need to change this manual code
            TSubmitChangesResult          SubmissionResult;
            TVerificationResultCollection VerificationResult;

            try
            {
                SubmissionResult = TDataCache.SaveChangedCacheableDataTableToPetraServer("DataLabelUseList",
                                                                                         ref ASubmitChanges,
                                                                                         out VerificationResult);
            }
            catch (ESecurityDBTableAccessDeniedException Exp)
            {
                FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                this.Cursor = Cursors.Default;

                TMessages.MsgSecurityException(Exp, this.GetType());

                return;
            }
            catch (EDBConcurrencyException Exp)
            {
                FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                this.Cursor = Cursors.Default;

                TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                return;
            }
            catch (Exception exp)
            {
                TLogging.Log(
                    "An error occured while saving the 'used by' data" + Environment.NewLine + exp.ToString(),
                    TLoggingType.ToLogfile);
                MessageBox.Show(
                    Catalog.GetString("An error occured while saving the 'used by' data") + Environment.NewLine +
                    Catalog.GetString("For details see the log file: ") + TLogging.GetLogFileName(),
                    Catalog.GetString("Failed to Save 'Used By' Data"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            switch (SubmissionResult)
            {
            case TSubmitChangesResult.scrOK:

                // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                FExtraDS.PDataLabelUse.AcceptChanges();

                // Merge back with data from the Server (eg. for getting Sequence values)
                ASubmitChanges.AcceptChanges();
                FExtraDS.PDataLabelUse.Merge(ASubmitChanges, false);

                // need to accept the new modification ID
                FExtraDS.PDataLabelUse.AcceptChanges();

                // need to refresh the cacheable DataTable 'DataLabelsForPartnerClassesList' (used by Partner Find's Maintain Menu)
                TDataCache.TMPartner.RefreshCacheablePartnerTable(TCacheablePartnerTablesEnum.DataLabelsForPartnerClassesList);

                return;

            case TSubmitChangesResult.scrNothingToBeSaved:

                return;

            case TSubmitChangesResult.scrError:

                MessageBox.Show(Catalog.GetString(
                                    "The 'UsedBy' part of the data could not be saved! There has been an error while making changes to the table."),
                                Catalog.GetString("Submit Changes to Table Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                break;

            case TSubmitChangesResult.scrInfoNeeded:

                MessageBox.Show(Catalog.GetString(
                                    "The 'UsedBy' part of the data could not be saved! Insufficient information was provided when making changes to the table."),
                                Catalog.GetString("Submit Changes to Table Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                break;
            }
        }
        /// <summary>
        /// save the changes on the screen (code is copied from auto-generated code)
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            if (FPetraUtilsObject.VerificationResultCollection.Count == 0)
            {
                foreach (DataRow InspectDR in FMainDS.MExtract.Rows)
                {
                    InspectDR.EndEdit();
                }

                if (!FPetraUtilsObject.HasChanges)
                {
                    return(true);
                }
                else
                {
                    FPetraUtilsObject.WriteToStatusBar("Saving data...");
                    this.Cursor = Cursors.WaitCursor;

                    TSubmitChangesResult SubmissionResult;

                    //Ict.Common.Data.TTypedDataTable SubmitDT = FMainDS.MExtract.GetChangesTyped();
                    MExtractTable SubmitDT = new MExtractTable();
                    SubmitDT.Merge(FMainDS.MExtract.GetChangesTyped());

                    if (SubmitDT == null)
                    {
                        // There is nothing to be saved.
                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved."));
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        return(true);
                    }

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtract
                                               (FExtractId, ref SubmitDT);
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        FPetraUtilsObject.WriteToStatusBar("Data could not be saved!");
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("The PETRA Server cannot be reached! Data cannot be saved!",
                                        "No Server response",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
                        bool ReturnValue = false;

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }

                    /* TODO ESecurityDBTableAccessDeniedException
                     *                  catch (ESecurityDBTableAccessDeniedException Exp)
                     *                  {
                     *                      FPetraUtilsObject.WriteToStatusBar("Data could not be saved!");
                     *                      this.Cursor = Cursors.Default;
                     *                      // TODO TMessages.MsgSecurityException(Exp, this.GetType());
                     *                      bool ReturnValue = false;
                     *                      // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                     *                      return ReturnValue;
                     *                  }
                     */
                    catch (EDBConcurrencyException)
                    {
                        FPetraUtilsObject.WriteToStatusBar("Data could not be saved!");
                        this.Cursor = Cursors.Default;

                        // TODO TMessages.MsgDBConcurrencyException(Exp, this.GetType());
                        bool ReturnValue = false;

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar("Data could not be saved!");
                        this.Cursor = Cursors.Default;
                        TLogging.Log(
                            Catalog.GetString(
                                "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                            TLoggingType.ToLogfile);
                        MessageBox.Show(
                            Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine +
                            "For details see the log file: " + TLogging.GetLogFileName(),
                            "Server connection error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop);

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(false);
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.MExtract.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.MExtract.Merge(SubmitDT, false);

                        // need to accept the new modification ID
                        FMainDS.MExtract.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar("Data successfully saved.");
                        this.Cursor = Cursors.Default;

                        // TODO EnableSave(false);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        SetPrimaryKeyReadOnly(true);

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(true);

                    case TSubmitChangesResult.scrError:

                        // TODO scrError
                        this.Cursor = Cursors.Default;
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:

                        // TODO scrNothingToBeSaved
                        this.Cursor = Cursors.Default;
                        return(true);

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
            }

            return(false);
        }
Beispiel #4
0
        private bool ConnectToPetraServer(String AUserName, String APassWord, out String AError)
        {
            eLoginEnum ReturnValue = eLoginEnum.eLoginFailedForUnspecifiedError;

            ReturnValue = ((TConnectionManagement)TConnectionManagement.GConnectionManagement).ConnectToServer(AUserName, APassWord,
                                                                                                               out FProcessID,
                                                                                                               out FWelcomeMessage,
                                                                                                               out FSystemEnabled,
                                                                                                               out AError);

            if (ReturnValue == eLoginEnum.eLoginSucceeded)
            {
                return(true);
            }
            else if (ReturnValue == eLoginEnum.eLoginVersionMismatch)
            {
                DisplayLoginFailedMessage(Catalog.GetString("OpenPetra Client/Server Program Version Mismatch!"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginServerTooBusy)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "The OpenPetra Server is too busy to accept the Login request.\r\n\r\nPlease try again after a short time!"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginExceedingConcurrentUsers)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Too many users are logged in."));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginServerNotReachable)
            {
                string Message = Catalog.GetString("The OpenPetra Server cannot be reached!");
                string Title   = null;

                // on Standalone, we can find the Server.log file, and check the last 10 lines for "System.Exception: Unsupported upgrade"
                string ServerLog = Path.GetDirectoryName(TLogging.GetLogFileName()) + Path.DirectorySeparatorChar + "Server.log";

                if (File.Exists(ServerLog))
                {
                    int    countExceptionLine = 0;
                    string ErrorMessage       = string.Empty;

                    StreamReader sr = new StreamReader(ServerLog);

                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.Contains("Unsupported upgrade"))
                        {
                            countExceptionLine = 12;
                            ErrorMessage       = line.Substring(line.IndexOf("Unsupported upgrade"));
                        }
                        else
                        {
                            countExceptionLine--;
                        }
                    }

                    sr.Close();

                    if (countExceptionLine > 0)
                    {
                        Message = ErrorMessage.Replace('/', Path.DirectorySeparatorChar);
                        Title   = Catalog.GetString("Unsupported upgrade");
                    }
                    else
                    {
                        Message =
                            Catalog.GetString(
                                "The OpenPetra Server cannot be reached!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                            ServerLog;
                        Title = Catalog.GetString("No Server Response");
                    }
                }

                DisplayLoginFailedMessage(Message, Title);

                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginAuthenticationFailed)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Wrong username or password"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginUserIsRetired)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "User is retired"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginUserRecordLocked)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "User record is locked at the moment"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginSystemDisabled)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "The system is disabled at the moment for maintenance"));
                return(false);
            }
            else if (ReturnValue == eLoginEnum.eLoginVersionMismatch)
            {
                DisplayLoginFailedMessage(
                    Catalog.GetString(
                        "Please update the client, the version does not match the server version!"));
                return(false);
            }

            // catching all other login failures, eg. eLoginEnum.eLoginFailedForUnspecifiedError
            DisplayLoginFailedMessage(
                Catalog.GetString(
                    "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                TLogging.GetLogFileName());
            return(false);
        }
Beispiel #5
0
        private bool ConnectToPetraServer(String AUserName, String APassWord, out String AError)
        {
            bool ReturnValue = false;

            AError = "";
            try
            {
                ReturnValue = ((TConnectionManagement)TConnectionManagement.GConnectionManagement).ConnectToServer(AUserName, APassWord,
                                                                                                                   out FProcessID,
                                                                                                                   out FWelcomeMessage,
                                                                                                                   out FSystemEnabled,
                                                                                                                   out AError);
            }
            catch (EClientVersionMismatchException exp)
            {
                MessageBox.Show(exp.Message, Catalog.GetString("OpenPetra Client/Server Program Version Mismatch!"),
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            catch (ELoginFailedServerTooBusyException)
            {
#if TESTMODE
                TLogging.Log("The OpenPetra Server is too busy to accept the Login request.");
#endif
#if  TESTMODE
#else
                MessageBox.Show(Catalog.GetString(
                                    "The OpenPetra Server is too busy to accept the Login request.\r\n\r\nPlease try again after a short time!"),
                                Catalog.GetString("OpenPetra Server Busy"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
#endif
                return(false);
            }
            catch (EDBConnectionNotEstablishedException exp)
            {
                if (exp.Message.IndexOf("Exceeding permissible number of connections") != -1)
                {
                    TLogging.Log("Login failed because too many users are logged in.");
#if  TESTMODE
#else
                    MessageBox.Show(
                        Catalog.GetString("Too many users are logged in."),
                        Catalog.GetString("Too Many Users"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
#endif
                }
                else
                {
                    TLogging.Log(
                        Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                        TLoggingType.ToLogfile);
#if  TESTMODE
#else
                    MessageBox.Show(
                        Catalog.GetString(
                            "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + StrDetailsInLogfile +
                        ": " +
                        TLogging.GetLogFileName(),
                        Catalog.GetString("Server Connection Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
#endif
                }

                return(false);
            }
            catch (EServerConnectionServerNotReachableException)
            {
#if TESTMODE
                TLogging.Log("The OpenPetra Server cannot be reached!");
#endif
#if  TESTMODE
#else
                // on Standalone, we can find the Server.log file, and check the last 10 lines for "System.Exception: Unsupported upgrade"
                string ServerLog = Path.GetDirectoryName(TLogging.GetLogFileName()) + Path.DirectorySeparatorChar + "Server.log";

                if (File.Exists(ServerLog))
                {
                    int    countExceptionLine = 0;
                    string ErrorMessage       = string.Empty;

                    StreamReader sr = new StreamReader(ServerLog);

                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();

                        if (line.Contains("Unsupported upgrade"))
                        {
                            countExceptionLine = 12;
                            ErrorMessage       = line.Substring(line.IndexOf("Unsupported upgrade"));
                        }
                        else
                        {
                            countExceptionLine--;
                        }
                    }

                    sr.Close();

                    if (countExceptionLine > 0)
                    {
                        MessageBox.Show(ErrorMessage.Replace('/', Path.DirectorySeparatorChar),
                                        Catalog.GetString("Unsupported upgrade"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
                    }
                    else
                    {
                        MessageBox.Show(
                            Catalog.GetString(
                                "The OpenPetra Server cannot be reached!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                            ServerLog,
                            Catalog.GetString("No Server Response"),
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop);
                    }

                    return(false);
                }

                MessageBox.Show(Catalog.GetString("The OpenPetra Server cannot be reached!"),
                                Catalog.GetString("No Server Response"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
#endif
                return(false);
            }
            catch (EServerConnectionGeneralException exp)
            {
                TLogging.Log(
                    Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                    TLoggingType.ToLogfile);
#if  TESTMODE
#else
                MessageBox.Show(Catalog.GetString(
                                    "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                                TLogging.GetLogFileName(),
                                "Server Connection Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Stop);
#endif
                return(false);
            }
            catch (Exception exp)
            {
                TLogging.Log(
                    Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                    TLoggingType.ToLogfile);
#if  TESTMODE
#else
                MessageBox.Show(
                    Catalog.GetString(
                        "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + StrDetailsInLogfile + ": " +
                    TLogging.GetLogFileName(),
                    Catalog.GetString("Server Connection Error"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Stop);
#endif
                return(false);
            }

            // TODO: exception for authentication failure
            // TODO: exception for retired user
            return(ReturnValue);
        }
Beispiel #6
0
        /// <summary>
        /// save the changes on the screen
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            Boolean ReturnValue;

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            // Don't allow saving if user is still editing a Detail of a List
            if (FPetraUtilsObject.InDetailEditMode())
            {
                ReturnValue = false;
                return(ReturnValue);
            }

            // Clear any validation errors so that the following call to ValidateAllData starts with a 'clean slate'.
            FPetraUtilsObject.VerificationResultCollection.Clear();

            if (ValidateAllData(false, true))
            {
                FMainDS.AApSupplier.Rows[0].BeginEdit();
                GetDataFromControls(FMainDS.AApSupplier[0]);

                if (FMainDS.AApSupplier[0].IsDefaultApAccountNull())
                {
                    MessageBox.Show(Catalog.GetString("Please select an AP account (eg. 9100)"));
                    FMainDS.AApSupplier.Rows[0].EndEdit();

                    ReturnValue = false;
                    return(ReturnValue);
                }

                // The account would usually be 9100-AP account.
                if (FMainDS.AApSupplier[0].DefaultApAccount != "9100")
                {
                    if (MessageBox.Show(Catalog.GetString("You are not using the standard AP account (9100) - is this OK?"),
                                        "Verification", MessageBoxButtons.YesNo)
                        != System.Windows.Forms.DialogResult.Yes)
                    {
                        FMainDS.AApSupplier.Rows[0].EndEdit();
                        return(false);
                    }
                }

                // Don't store with invalid currency value.
                //
                if (FMainDS.AApSupplier[0].CurrencyCode == "")
                {
                    FMainDS.AApSupplier[0].CurrencyCode = FLedgerRow.BaseCurrency;
                }

                // If this is a foreign currency supplier, it must be linked to accounts in that currency.
                // (And if it's not, it mustn't be!)
                if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultBankAccount, "Bank"))
                {
                    return(false);
                }

                /*
                 * If we wanted to have only expense accounts in a single currency, we could have this,
                 * but that's probably not what we want...
                 *
                 *          if (!ValidateAccountCurrency(FMainDS.AApSupplier[0].DefaultExpAccount, "Expense"))
                 *          {
                 *              return false;
                 *          }
                 */
            }

            ReturnValue = TDataValidation.ProcessAnyDataValidationErrors(false, FPetraUtilsObject.VerificationResultCollection,
                                                                         this.GetType());

            if (ReturnValue)
            {
                foreach (DataTable InspectDT in FMainDS.Tables)
                {
                    foreach (DataRow InspectDR in InspectDT.Rows)
                    {
                        InspectDR.EndEdit();
                    }
                }

                if (FPetraUtilsObject.HasChanges)
                {
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataInProgress);
                    this.Cursor = Cursors.WaitCursor;

                    AccountsPayableTDS SubmitDS = FMainDS.GetChangesTyped(true);

                    TSubmitChangesResult          SubmissionResult;
                    TVerificationResultCollection VerificationResult = new TVerificationResultCollection();

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = FUIConnector.SubmitChanges(ref SubmitDS);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;
                        TLogging.Log(
                            Catalog.GetString(
                                "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(),
                            TLoggingType.ToLogfile);
                        MessageBox.Show(
                            Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine +
                            "For details see the log file: " + TLogging.GetLogFileName(),
                            "Server connection error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop);

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.Merge(SubmitDS, false);

                        // need to accept the new modification ID
                        FMainDS.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataSuccessful);
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrError:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataErrorOccured);

                        MessageBox.Show(Messages.BuildMessageFromVerificationResult(null, VerificationResult));

                        FPetraUtilsObject.SubmitChangesContinue = false;

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:
                        this.Cursor = Cursors.Default;
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        ReturnValue = true;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        break;

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
                else
                {
                    // Update UI
                    FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataNothingToSave);
                    this.Cursor = Cursors.Default;
                    FPetraUtilsObject.DisableSaveButton();

                    // We don't have unsaved changes anymore
                    FPetraUtilsObject.HasChanges = false;

                    ReturnValue = true;
                    FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                }
            }
            else
            {
                FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(false));
            }

            return(ReturnValue);
        }
Beispiel #7
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);

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