Exemplo n.º 1
0
        private static SReportResultRow GetReportResult(string AReportID, TDataBase ADataBase)
        {
            SReportResultRow Row = null;
            TDBTransaction   t   = new TDBTransaction();
            TDataBase        db  = DBAccess.Connect("GetReportResult", ADataBase);

            db.ReadTransaction(ref t,
                               delegate
            {
                SReportResultTable resultTable = SReportResultAccess.LoadByPrimaryKey(AReportID, t);

                if (resultTable.Rows.Count == 1)
                {
                    Row = resultTable[0];
                }
            });

            if (ADataBase == null)
            {
                db.CloseDBConnection();
            }

            return(Row);
        }
Exemplo n.º 2
0
        /// <summary>
        /// run the report
        /// </summary>
        private static void Run(string AConfigFileName, string ASessionID, string AReportID, TRptDataCalculator ADatacalculator, TParameterList AParameterList)
        {
            // need to initialize the database session
            TSession.InitThread("Reporting Webconnector", AConfigFileName, ASessionID);

            TDataBase db = DBAccess.Connect("TReportGeneratorWebConnector");

            TDBTransaction Transaction  = new TDBTransaction();
            bool           Success      = false;
            bool           Submit       = true;
            string         HTMLOutput   = String.Empty;
            HtmlDocument   HTMLDocument = new HtmlDocument();
            string         ErrorMessage = String.Empty;

            try
            {
                db.ReadTransaction(ref Transaction,
                                   delegate
                {
                    Exception myException = null;
                    if (ADatacalculator.GenerateResult(ref AParameterList, ref HTMLOutput, out HTMLDocument, ref ErrorMessage, ref myException, Transaction))
                    {
                        Success = true;
                    }
                    else
                    {
                        TLogging.Log(ErrorMessage);
                    }
                });
            }
            catch (Exception Exc)
            {
                TLogging.Log("Problem calculating report: " + Exc.ToString());
                TLogging.Log(Exc.StackTrace, TLoggingType.ToLogfile);

                Success      = false;
                ErrorMessage = Exc.Message;
            }

/*
 *          if (TDBExceptionHelper.IsTransactionSerialisationException(FException))
 *          {
 *              // do nothing - we want this exception to bubble up
 *          }
 *          else if (FException is Exception && FException.InnerException is EOPDBException)
 *          {
 *              EOPDBException DbExc = (EOPDBException)FException.InnerException;
 *
 *              if (DbExc.InnerException is Exception)
 *              {
 *                  if (DbExc.InnerException is PostgresException)
 *                  {
 *                      PostgresException PgExc = (PostgresException)DbExc.InnerException;
 *
 *                      if (PgExc.SqlState == "57014") // SQL statement timeout problem
 *                      {
 *                          FErrorMessage = Catalog.GetString(
 *                              "Error - Database took too long to respond. Try different parameters to return fewer results.");
 *                      }
 *                  }
 *                  else
 *                  {
 *                      FErrorMessage = DbExc.InnerException.Message;
 *                  }
 *
 *                  FException = null;
 *              }
 *          }
 */

            try
            {
                // store the report result
                db.WriteTransaction(ref Transaction,
                                    ref Submit,
                                    delegate
                {
                    // delete report results that are expired.
                    string sql = "DELETE FROM PUB_s_report_result WHERE s_valid_until_d < NOW()";
                    db.ExecuteNonQuery(sql, Transaction);

                    // TODO: only keep maximum of 10 report results per user (s_created_by_c)

                    // store success, store parameter list, store html document
                    SReportResultTable table = new SReportResultTable();
                    SReportResultRow row     = table.NewRowTyped();
                    row.ReportId             = AReportID;
                    row.SessionId            = TSession.GetSessionID();
                    row.ValidUntil           = DateTime.Now.AddHours(12);
                    row.ParameterList        = AParameterList.ToJson();
                    row.ResultHtml           = HTMLOutput;
                    row.Success      = Success;
                    row.ErrorMessage = ErrorMessage;
                    table.Rows.Add(row);
                    SReportResultAccess.SubmitChanges(table, Transaction);
                    Submit = true;
                });
            }
            catch (Exception Exc)
            {
                TLogging.Log("Problem storing report result: " + Exc.ToString());
                TLogging.Log(Exc.StackTrace, TLoggingType.ToLogfile);

                Success      = false;
                ErrorMessage = Exc.Message;
            }

            db.CloseDBConnection();

            TProgressTracker.FinishJob(AReportID);
        }