コード例 #1
0
ファイル: Program.cs プロジェクト: petes05/openpetra
        /// <summary>
        /// Creates Sample Data using the raw data provided and exports this to the Petra Server
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            TLogging.Log("Running Sample Data Constructor");

            try
            {
                TLogging.Log("(1) Initialize (check availability of resources, start the server)");

                TLogging.Log("\tStarting the server...");

                // use the config file defined on the command line with -C:
                TPetraServerConnector.Connect(string.Empty);

                // data directory containing the raw data files created by benerator
                string datadirectory = TAppSettingsManager.GetValue("dir.data.generated");

                string operation = TAppSettingsManager.GetValue("operation", "importPartners");

                if ((operation == "importPartners") || (operation == "all"))
                {
                    TLogging.Log("(2) Import partners");
                    SampleDataBankPartners.GenerateBanks(
                        Path.Combine(datadirectory, "banks.csv"));

                    SampleDataDonors.GenerateFamilyPartners(
                        Path.Combine(datadirectory, "people.csv"));

                    TLogging.Log("(3) Import organisations");
                    SampleDataOrganisations.GenerateOrganisationPartners(
                        Path.Combine(datadirectory, "organisations.csv"));
                }

                TLogging.Log("(4) Import recipients");

                operation = TAppSettingsManager.GetValue("operation", "importRecipients");

                if ((operation == "importRecipients") || (operation == "all"))
                {
                    // parse random data generated by benerator
                    SampleDataUnitPartners.GenerateFields(
                        Path.Combine(datadirectory, "fields.csv"));
                    SampleDataUnitPartners.GenerateKeyMinistries(
                        Path.Combine(datadirectory, "keymins.csv"));
                    SampleDataWorkers.GenerateWorkers(
                        Path.Combine(datadirectory, "workers.csv"));
                }

                operation = TAppSettingsManager.GetValue("operation", "populateFirstLedger");

                if ((operation == "populateFirstLedger") || (operation == "all"))
                {
                    SampleDataLedger.FLedgerNumber          = 43;
                    SampleDataLedger.FNumberOfClosedPeriods = TAppSettingsManager.GetInt32("NumberOfClosedPeriods", 26);
                    SampleDataLedger.InitCalendar();
                    SampleDataLedger.InitExchangeRate();
                    SampleDataLedger.PopulateData(datadirectory);
                }

                if (operation == "secondLedger")
                {
                    TLogging.Log("creating a second ledger");

                    SampleDataLedger.FLedgerNumber          = 44;
                    SampleDataLedger.FNumberOfClosedPeriods = 6;
                    SampleDataLedger.CreateNewLedger();
                    SampleDataLedger.InitExchangeRate();

                    SampleDataUnitPartners.FLedgerNumber = SampleDataLedger.FLedgerNumber;
                    SampleDataUnitPartners.GenerateFieldsFinanceOnly(
                        Path.Combine(datadirectory, "fields.csv"));

                    SampleDataLedger.PopulateData(datadirectory);
                }
                else
                {
                    TLogging.Log("Please explicitely run nant importDemodata -D:operation=secondLedger");
                }

                TLogging.Log("(9) Creating applications for conference");

                operation = TAppSettingsManager.GetValue("operation", "conferenceApplications");

                if (operation == "conferenceApplications")
                {
                    SampleDataConferenceApplicants.GenerateApplications(Path.Combine(datadirectory, "conferenceApplications.csv"));
                }
                else
                {
                    TLogging.Log("Please explicitely run nant importDemodata -D:operation=conferenceApplications");
                }

                TLogging.Log("Completed.");
            }
            catch (Exception e)
            {
                TLogging.Log(e.Message);
                TLogging.Log(e.StackTrace);
                Environment.Exit(-1);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ip-config/openpetra
        /// <summary>
        /// Creates Sample Data using the raw data provided and exports this to the Petra Server
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            TLogging.Log("Running Sample Data Constructor");

            try
            {
                TLogging.Log("(1) Initialize (check availability of resources, start the server)");

                TLogging.Log("\tStarting the server...");

                // use the config file defined on the command line with -C:
                TPetraServerConnector.Connect(string.Empty);

                // data directory containing the raw data files created by benerator
                string datadirectory = TAppSettingsManager.GetValue("dir.data.generated");

                eOperations operation = eOperations.importPartners | eOperations.importRecipients | eOperations.ledgerOneYear;

                if (TAppSettingsManager.GetValue("operation", false) == "secondLedger")
                {
                    operation = eOperations.secondLedger;
                }
                else if (TAppSettingsManager.GetValue("operation", false) == "ledgerMultipleYears")
                {
                    operation = eOperations.importPartners | eOperations.importRecipients | eOperations.ledgerMultipleYears;
                }

                if ((int)(operation & eOperations.importPartners) > 0)
                {
                    TLogging.Log("(2) Import partners");
                    SampleDataBankPartners.GenerateBanks(
                        Path.Combine(datadirectory, "banks.csv"));

                    SampleDataDonors.GenerateFamilyPartners(
                        Path.Combine(datadirectory, "people.csv"));

                    TLogging.Log("(3) Import organisations");
                    SampleDataOrganisations.GenerateOrganisationPartners(
                        Path.Combine(datadirectory, "organisations.csv"));
                }

                TLogging.Log("(4) Import recipients");

                if ((int)(operation & eOperations.importRecipients) > 0)
                {
                    // parse random data generated by benerator
                    SampleDataUnitPartners.GenerateFields(
                        Path.Combine(datadirectory, "fields.csv"));
                    SampleDataUnitPartners.GenerateKeyMinistries(
                        Path.Combine(datadirectory, "keymins.csv"));
                    SampleDataWorkers.GenerateWorkers(
                        Path.Combine(datadirectory, "workers.csv"));
                }

                if ((int)(operation & eOperations.ledgerOneYear) > 0)
                {
                    SampleDataLedger.FLedgerNumber          = 43;
                    SampleDataLedger.FNumberOfClosedPeriods = CalculatedNumberOfClosedPeriods(0);
                    SampleDataLedger.InitCalendar();
                    SampleDataLedger.InitExchangeRate();
                    SampleDataLedger.PopulateData(datadirectory, true);
                    TLogging.Log("Please explicitely run nant importDemodata -D:operation=secondLedger");
                    TLogging.Log("   or                  nant importDemodata -D:operation=ledgerMultipleYears");
                }

                if ((int)(operation & eOperations.ledgerMultipleYears) > 0)
                {
                    SampleDataLedger.FLedgerNumber          = 43;
                    SampleDataLedger.FNumberOfClosedPeriods = TAppSettingsManager.GetInt32("NumberOfClosedPeriods", CalculatedNumberOfClosedPeriods(2));
                    SampleDataLedger.InitCalendar();
                    SampleDataLedger.InitExchangeRate();
                    SampleDataLedger.PopulateData(datadirectory, true);
                }

                if ((int)(operation & eOperations.secondLedger) > 0)
                {
                    TLogging.Log("creating a second ledger");

                    // this ledger starts in period 4
                    SampleDataLedger.FLedgerNumber          = 44;
                    SampleDataLedger.FNumberOfClosedPeriods = CalculatedNumberOfClosedPeriods(0) - 3;
                    SampleDataLedger.CreateNewLedger();
                    SampleDataLedger.InitExchangeRate();

                    SampleDataUnitPartners.FLedgerNumber = SampleDataLedger.FLedgerNumber;

                    SampleDataLedger.PopulateData(datadirectory);
                }

                TLogging.Log("Completed.");
            }
            catch (Exception e)
            {
                TLogging.Log(e.Message);
                TLogging.Log(e.StackTrace);
                Environment.Exit(-1);
            }
        }
コード例 #3
0
ファイル: GenerateLedger.cs プロジェクト: lxhelp/openpetra
        /// <summary>
        /// Populate ledger with gifts and invoices, post batches, close periods and years, according to FNumberOfClosedPeriods
        /// </summary>
        public static void PopulateData(string datadirectory, bool smallNumber = false)
        {
            int periodOverall = 0;
            int yearCounter   = 0;
            int period        = 1;
            int YearAD        = DateTime.Today.Year - (FNumberOfClosedPeriods / 12);

            SampleDataGiftBatches.FLedgerNumber     = FLedgerNumber;
            SampleDataAccountsPayable.FLedgerNumber = FLedgerNumber;
            SampleDataGiftBatches.LoadBatches(Path.Combine(datadirectory, "donations.csv"), smallNumber);
            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);

            while (periodOverall <= FNumberOfClosedPeriods)
            {
                TLogging.LogAtLevel(1, "working on year " + yearCounter.ToString() + " / period " + period.ToString());

                SampleDataGiftBatches.CreateGiftBatches(period);

                if (!SampleDataGiftBatches.PostBatches(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post gift batches");
                }

                if (!SampleDataAccountsPayable.PostAndPayInvoices(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post invoices");
                }

                TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber);

                if (periodOverall < FNumberOfClosedPeriods)
                {
                    TAccountPeriodInfo AccountingPeriodInfo =
                        new TAccountPeriodInfo(FLedgerNumber, period);
                    TLogging.Log("closing period at " + AccountingPeriodInfo.PeriodEndDate.ToShortDateString());

                    // run month end
                    TMonthEnd MonthEndOperator = new TMonthEnd(LedgerInfo);
                    MonthEndOperator.SetNextPeriod(null);


                    if (period == 12)
                    {
                        TDBTransaction transaction  = null;
                        bool           SubmissionOK = false;

                        DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(
                            IsolationLevel.Serializable,
                            TEnforceIsolationLevel.eilMinimum,
                            ref transaction,
                            ref SubmissionOK,
                            delegate
                        {
                            TYearEnd YearEndOperator = new TYearEnd(LedgerInfo);
                            // run year end
                            TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                            List <Int32> glBatches     = new List <int>();
                            TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction);
                            reallocation.VerificationResultCollection = verificationResult;
                            reallocation.IsInInfoMode = false;
                            reallocation.RunOperation();

                            TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, yearCounter, YearEndOperator, transaction);
                            glmNewYearInit.VerificationResultCollection = verificationResult;
                            glmNewYearInit.IsInInfoMode = false;
                            glmNewYearInit.RunOperation();
                            YearEndOperator.SetNextPeriod(transaction);

                            SampleDataLedger.InitExchangeRate();

                            YearAD++;
                            yearCounter++;
                            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);
                            period       = 0;
                            SubmissionOK = true;
                        });
                    }
                }

                period++;
                periodOverall++;
            }
        }