Esempio n. 1
0
        private int CheckReporting(string p_invoicerId, int p_noIssuing, string p_where, PgDatParameters p_dbps)
        {
            int _noReporting = 0;

            lock (SyncEngine)
                _noReporting = CheckReEnter(p_invoicerId, p_where, p_dbps);

            if (_noReporting > 0)
            {
                ReportArgs _args = new ReportArgs()
                {
                    invoicerId  = p_invoicerId,
                    noIssuing   = p_noIssuing,
                    noReporting = _noReporting,
                    where       = p_where,
                    dbps        = p_dbps
                };

                // Do not use using statement
                ThreadPoolWait _doneEvent = new ThreadPoolWait();
                _doneEvent.QueueUserWorkItem(DoReporting, _args);

                if (Environment.UserInteractive == true)
                {
                    _doneEvent.WaitOne();
                }
            }

            return(_noReporting);
        }
Esempio n. 2
0
        private int CheckMailing(string p_invoicerId, int p_noInvoicee, string p_where, PgDatParameters p_dbps)
        {
            int _noSending = 0;

            lock (SyncEngine)
                _noSending = CheckReEnter(p_invoicerId, p_where, p_dbps);

            if (_noSending > 0)
            {
                MailingArgs _args = new MailingArgs()
                {
                    reSending     = false,
                    invoiceeEMail = "",
                    invoicerId    = p_invoicerId,
                    noInvoicee    = p_noInvoicee,
                    noSending     = _noSending,
                    where         = p_where,
                    dbps          = p_dbps
                };

                // Do not use using statement
                ThreadPoolWait _doneEvent = new ThreadPoolWait();
                _doneEvent.QueueUserWorkItem(DoMailing, _args);

                if (Environment.UserInteractive == true)
                {
                    _doneEvent.WaitOne();
                }
            }

            return(_noSending);
        }
Esempio n. 3
0
        private void CollectorWakeup(object stateInfo)
        {
            var _autoEvent = (AutoResetEvent)stateInfo;

            try
            {
                ICollector.WriteDebug("wakeup...");

                int _norec = 1;

                var _doneEvents = new ThreadPoolWait[_norec];
                for (int i = 0; i < _norec; i++)
                {
                    _doneEvents[i] = new ThreadPoolWait();
                    _doneEvents[i].QueueUserWorkItem(CollectorCallback, null);

                    if (Environment.UserInteractive == true)
                    {
                        _doneEvents[i].WaitOne();
                    }
                }

                ThreadPoolWait.WaitForAll(_doneEvents);
            }
            catch (CollectException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                ICollector.WriteDebug("sleep...");

                CollectTimer.Change(UAppHelper.CollectorDueTime, Timeout.Infinite);
                _autoEvent.Set();
            }
        }
Esempio n. 4
0
        private void SenderWakeup(object stateInfo)
        {
            var _autoEvent = (AutoResetEvent)stateInfo;

            try
            {
                IMailer.WriteDebug("wakeup...");

                DateTime _fromDay = UTextHelper.SNG.GetFirstDayOfLastMonth();
                DateTime _tillDay = UTextHelper.SNG.GetLastDayOfThisMonth();

                UTextHelper.SNG.GetSendingRange(ref _fromDay, ref _tillDay);

                // check table for auto-mailing
                var _sqlstr
                    = "SELECT b.invoicerId, COUNT(b.invoicerId) as norec, @fromDay as fromDay, @tillDay as tillDay "
                      + "  FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b "
                      + "    ON a.issueId=b.issueId "
                      + " WHERE (a.isInvoiceeMail != @isInvoiceeMail OR a.isProviderMail != @isProviderMail) "
                      + "   AND b.issueDate>=@fromDay AND b.issueDate<=@tillDay "
                      + " GROUP BY b.invoicerId";

                var _dbps = new PgDatParameters();
                {
                    _dbps.Add("@isInvoiceeMail", NpgsqlDbType.Varchar, "T");
                    _dbps.Add("@isProviderMail", NpgsqlDbType.Varchar, "T");
                    _dbps.Add("@fromDay", NpgsqlDbType.TimestampTz, _fromDay);
                    _dbps.Add("@tillDay", NpgsqlDbType.TimestampTz, _tillDay);
                }

                var _ds = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _dbps);
                if (LSQLHelper.IsNullOrEmpty(_ds) == false)
                {
                    var _rows = _ds.Tables[0].Rows;
                    ELogger.SNG.WriteLog(String.Format("selected invoicer(s): {0} ", _rows.Count));

                    var _doneEvents = new ThreadPoolWait[_rows.Count];
                    for (int i = 0; i < _rows.Count; i++)
                    {
                        _doneEvents[i] = new ThreadPoolWait();
                        _doneEvents[i].QueueUserWorkItem(MailerCallback, _rows[i]);

                        if (Environment.UserInteractive == true)
                        {
                            _doneEvents[i].WaitOne();
                        }
                    }

                    ThreadPoolWait.WaitForAll(_doneEvents);
                }
            }
            catch (MailerException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                IMailer.WriteDebug("sleep...");

                SendingTimer.Change(UAppHelper.MailerDueTime, Timeout.Infinite);
                _autoEvent.Set();
            }
        }
Esempio n. 5
0
        private void DoReporting(object p_args)
        {
            ReportArgs _args = (ReportArgs)p_args;

            _args.noIssuing   = _args.noReporting;
            _args.noReporting = 0;

            try
            {
                int _toprow = 100;

                int _chunkCount = _args.noIssuing / _toprow + 1;
                if (_chunkCount > UAppHelper.NoThreadOfReporter)
                {
                    _chunkCount = UAppHelper.NoThreadOfReporter;
                }

                string _issueid = "";

                var _sqlstr
                    = "SELECT a.issueId, a.document, a.rvalue "
                      + "  FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b "
                      + "    ON a.issueId=b.issueId "
                      + " WHERE a.isNTSSending=@isNTSSendingX "
                      + "   AND ( "
                      + "         (RIGHT(b.typeCode, 2) IN ('01', '02', '04') AND b.invoicerId=@invoicerId) "
                      + "         OR "
                      + "         (RIGHT(b.typeCode, 2) IN ('03', '05') AND b.brokerId=@invoicerId) "
                      + "       ) "
                      + "   AND a.issueId > @issueId "
                      + _args.where
                      + " ORDER BY a.issueId"
                      + " LIMIT " + _toprow;
                {
                    _args.dbps.Add("@isNTSSendingX", NpgsqlDbType.Varchar, "X");
                    _args.dbps.Add("@invoicerId", NpgsqlDbType.Varchar, _args.invoicerId);
                }

                //if (LogCommands == true)
                //    ELogger.SNG.WriteLog(String.Format("begin: invoicerId->'{0}', noIssuing->{1}", _args.invoicerId, _args.noIssuing));

                // 만약 InsertDeltaSet을 처리하는 중에 오류가 발생하면 무한 loop를 발생 하게 되므로,
                // 'X'로 marking한 레코드의 총 갯수를 감소하여 '0'보다 큰 경우에만 반복한다.
                while (_args.noIssuing > 0)
                {
                    int _rowsCount = 0;

                    IssuingTbl.Clear();
                    ResponseTbl.Clear();

                    var _doneEvents = new ThreadPoolWait[_chunkCount];
                    for (int i = 0; i < _chunkCount; i++)
                    {
                        _args.dbps.Add("@issueId", NpgsqlDbType.Varchar, _issueid);       // 100건 까지를 한 묶음으로 전송하기 위해 기준이 되는 승인번호

                        var _workingSet = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _args.dbps);
                        if (LSQLHelper.IsNullOrEmpty(_workingSet) == true)
                        {
                            break;
                        }

                        var _rows = _workingSet.Tables[0].Rows;
                        _issueid = Convert.ToString(_rows[_rows.Count - 1]["issueId"]); // 다음 100건의 기준 (>) 승인번호

                        _doneEvents[i] = new ThreadPoolWait();

                        Updater _worker = new Updater(IssuingTbl, ResponseTbl);
                        _doneEvents[i].QueueUserWorkItem(_worker.ReporterCallback, _rows);

                        if (Environment.UserInteractive == true)
                        {
                            _doneEvents[i].WaitOne();
                        }

                        _rowsCount += _rows.Count;
                    }

                    ThreadPoolWait.WaitForAll(_doneEvents);

                    // 처리된 레코드가 한개 이하 인 경우는 종료한다. (문제가 있는 경우로 보여 짐)
                    if (_rowsCount < 1)
                    {
                        break;
                    }

                    //if (LogCommands == true)
                    //    ELogger.SNG.WriteLog(String.Format("loop: invoicerId->'{0}', noIssuing->{1}, noReporting->{2}", _args.invoicerId, _args.noIssuing, _rowsCount));

                    _args.noIssuing   -= _rowsCount;
                    _args.noReporting += IssuingTbl.Rows.Count;

                    LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, ResponseSet);
                }
            }
            catch (ReporterException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                if (LogCommands == true)
                {
                    ELogger.SNG.WriteLog(String.Format("end: invoicerId->'{0}', noIssuing->{1}, noReporting->{2}", _args.invoicerId, _args.noIssuing, _args.noReporting));
                }

                int _noClearing = ClearXFlag(_args.invoicerId);
                if (_noClearing > 0)
                {
                    if (LogCommands == true)
                    {
                        ELogger.SNG.WriteLog(String.Format("clearX: invoicerId->'{0}', noClear->{1}", _args.invoicerId, _noClearing));
                    }
                }
            }
        }
Esempio n. 6
0
        private void DoSignature(object p_args)
        {
            var _args = (SignatureArgs)p_args;

            _args.noInvoicee = _args.noIssuing;
            _args.noIssuing  = 0;

            try
            {
                int _toprow = 800;

                var _sqlstr
                    = "SELECT a.issueId, a.typeCode, a.invoicerId, a.invoicerEMail, a.invoiceeId, a.invoiceeEMail1 as invoiceeEMail, "
                      + "               a.brokerId, a.brokerEMail, b.providerId, c.aspEMail as providerEMail "
                      + "  FROM TB_eTAX_INVOICE a "
                      + "       LEFT JOIN TB_eTAX_CUSTOMER b ON a.invoiceeId=b.customerId "
                      + "       LEFT JOIN (SELECT * FROM TB_eTAX_PROVIDER WHERE NULLIF(providerId, '') IS NOT NULL) c ON b.providerId=c.providerId "
                      + " WHERE a.isIssued=@isIssuedX "         // to avoid infinite loop, do check isIssued here.
                      + "   AND ( "
                      + "         (RIGHT(a.typeCode, 2) IN ('01', '02', '04') AND a.invoicerId=@invoicerId) "
                      + "         OR "
                      + "         (RIGHT(a.typeCode, 2) IN ('03', '05') AND a.brokerId=@invoicerId) "
                      + "       ) "
                      + _args.where
                      + " ORDER BY a.issueId"
                      + " LIMIT " + _toprow;
                {
                    _args.dbps.Add("@isIssuedX", NpgsqlDbType.Varchar, "X");
                    _args.dbps.Add("@invoicerId", NpgsqlDbType.Varchar, _args.invoicerId);
                }

                //if (LogCommands == true)
                //    ELogger.SNG.WriteLog(String.Format("begin: invoicerId->'{0}', noInvoicee->{1}", _args.invoicerId, _args.noInvoicee));

                // 만약 InsertDeltaSet을 처리하는 중에 오류가 발생하면 무한 loop를 발생 하게 되므로,
                // 'X'로 marking한 레코드의 총 갯수를 감소하여 '0'보다 큰 경우에만 반복한다.
                while (_args.noInvoicee > 0)
                {
                    InvoiceTbl.Clear();
                    IssuingTbl.Clear();

                    var _workingSet = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _args.dbps);
                    if (LSQLHelper.IsNullOrEmpty(_workingSet) == true)
                    {
                        break;
                    }

                    var _rows = _workingSet.Tables[0].Rows;

                    var _doneEvents = new ThreadPoolWait[_rows.Count];
                    for (int i = 0; i < _rows.Count; i++)
                    {
                        _doneEvents[i] = new ThreadPoolWait();

                        Updater _worker = new Updater(_args.invoicerCert, IssuingTbl, InvoiceTbl);
                        _doneEvents[i].QueueUserWorkItem(_worker.SignatureCallBack, _rows[i]);

                        if (Environment.UserInteractive == true)
                        {
                            _doneEvents[i].WaitOne();
                        }
                    }

                    ThreadPoolWait.WaitForAll(_doneEvents);

                    // 처리된 레코드가 한개 이하 인 경우는 종료한다. (문제가 있는 경우로 보여 짐)
                    if (_rows.Count < 1)
                    {
                        break;
                    }

                    //if (LogCommands == true)
                    //    ELogger.SNG.WriteLog(String.Format("loop: invoicerId->'{0}', noInvoicee->{1}, noIssuing->{2}", _args.invoicerId, _args.noInvoicee, _rows.Count));

                    _args.noInvoicee -= _rows.Count;
                    _args.noIssuing  += IssuingTbl.Rows.Count;

                    LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, IssuingSet);
                }
            }
            catch (SignerException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                if (LogCommands == true)
                {
                    ELogger.SNG.WriteLog(String.Format("end: invoicerId->'{0}', noInvoicee->{1}, noIssuing->{2}", _args.invoicerId, _args.noInvoicee, _args.noIssuing));
                }

                int _noClearing = ClearXFlag(_args.invoicerId);
                if (_noClearing > 0)
                {
                    if (LogCommands == true)
                    {
                        ELogger.SNG.WriteLog(String.Format("clearX: invoicerId->'{0}', noClear->{1}", _args.invoicerId, _noClearing));
                    }
                }
            }
        }
Esempio n. 7
0
        private void ReporterWakeup(object stateInfo)
        {
            var _autoEvent = (AutoResetEvent)stateInfo;

            try
            {
                IReporter.WriteDebug("wakeup...");

                var      _nday = DateTime.Now;
                DateTime _pday = _nday.AddDays(-1);

                DateTime _fromDay = new DateTime(_pday.Year, _pday.Month, _pday.Day);
                DateTime _tillDay = new DateTime(_nday.Year, _nday.Month, _nday.Day);

                // check table for auto-reporting
                var _sqlstr
                    = "SELECT b.invoicerId, COUNT(b.invoicerId) as norec, @fromDay as fromDay, @tillDay as tillDay "
                      + "  FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b "
                      + "    ON a.issueId=b.issueId "
                      + " WHERE a.isNTSReport != @isNTSReport "
                      + "   AND b.issueDate>=@fromDay AND b.issueDate<@tillDay "
                      + " GROUP BY b.invoicerId";

                var _dbps = new PgDatParameters();
                {
                    _dbps.Add("@isNTSReport", NpgsqlDbType.Varchar, "T");
                    _dbps.Add("@fromDay", NpgsqlDbType.TimestampTZ, _fromDay);
                    _dbps.Add("@tillDay", NpgsqlDbType.TimestampTZ, _tillDay);
                }

                var _ds = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _dbps);
                if (LSQLHelper.IsNullOrEmpty(_ds) == false)
                {
                    var _rows = _ds.Tables[0].Rows;
                    ELogger.SNG.WriteLog(String.Format("selected invoicer(s): {0} ", _rows.Count));

                    var _doneEvents = new ThreadPoolWait[_rows.Count];
                    for (int i = 0; i < _rows.Count; i++)
                    {
                        _doneEvents[i] = new ThreadPoolWait();
                        _doneEvents[i].QueueUserWorkItem(ReporterBackWork, _rows[i]);

                        if (Environment.UserInteractive == true)
                        {
                            _doneEvents[i].WaitOne();
                        }
                    }

                    ThreadPoolWait.WaitForAll(_doneEvents);
                }
            }
            catch (ReporterException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                IReporter.WriteDebug("sleep...");

                ReportingTimer.Change(UAppHelper.ReporterDueTime, Timeout.Infinite);
                _autoEvent.Set();
            }
        }
Esempio n. 8
0
        private void DoMailing(object p_args)
        {
            MailingArgs _args = (MailingArgs)p_args;

            _args.noInvoicee = _args.noSending;
            _args.noSending  = 0;

            try
            {
                int _toprow = 800;

                var _sqlstr
                    = "SELECT a.issueId, a.document, a.securityId, b.issueDate, b.typeCode, b.invoiceeKind, "
                      + "               b.chargeTotal, b.taxTotal, b.grandTotal, b.description, a.isMailSending, "
                      + "               b.invoicerId, b.invoicerEMail, b.invoicerName, b.invoicerPerson, b.invoicerPhone, "
                      + "               a.isInvoiceeMail, b.invoiceeId, b.invoiceeEMail1 as invoiceeEMail, b.invoiceeName, "
                      + "               b.invoiceePerson, b.invoiceePhone1 as invoiceePhone, a.isProviderMail, a.providerId, "
                      + "               a.providerEMail, a.sendMailCount, a.mailSendingDate "
                      + "  FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b "
                      + "    ON a.issueId=b.issueId "
                      + " WHERE a.isMailSending=@isMailSendingX "     // to avoid infinite loop, do check isMailSending here.
                      + "   AND ( "
                      + "         (RIGHT(b.typeCode, 2) IN ('01', '02', '04') AND b.invoicerId=@invoicerId) "
                      + "         OR "
                      + "         (RIGHT(b.typeCode, 2) IN ('03', '05') AND b.brokerId=@invoicerId) "
                      + "       ) "
                      + _args.where
                      + " ORDER BY a.providerEMail"
                      + " LIMIT " + _toprow;
                {
                    _args.dbps.Add("@isMailSendingX", NpgsqlDbType.Varchar, "X");
                    _args.dbps.Add("@invoicerId", NpgsqlDbType.Varchar, _args.invoicerId);
                }

                //if (LogCommands == true)
                //    ELogger.SNG.WriteLog(String.Format("begin: invoicerId->'{0}', noInvoicee->{1}", _args.invoicerId, _args.noInvoicee));

                var _random = new Random();

                // 만약 InsertDeltaSet을 처리하는 중에 오류가 발생하면 무한 loop를 발생 하게 되므로,
                // 'X'로 marking한 레코드의 총 갯수를 감소하여 '0'보다 큰 경우에만 반복한다.
                while (_args.noInvoicee > 0)
                {
                    IssuingTbl.Clear();
                    ResultTbl.Clear();

                    var _workingSet = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _args.dbps);
                    if (LSQLHelper.IsNullOrEmpty(_workingSet) == true)
                    {
                        break;
                    }

                    var _rows = _workingSet.Tables[0].Rows;

                    var _doneEvents = new ThreadPoolWait[_rows.Count];
                    for (int i = 0; i < _rows.Count; i++)
                    {
                        if (String.IsNullOrEmpty(Convert.ToString(_rows[i]["securityId"])) == true)
                        {
                            _rows[i]["securityId"] = Convert.ToString(_random.Next(100000, 999999));
                        }

                        if (_args.reSending == true)
                        {
                            _rows[i]["invoiceeEMail"] = _args.invoiceeEMail;
                        }

                        _doneEvents[i] = new ThreadPoolWait();

                        AsyncWorker _worker = new AsyncWorker(IssuingTbl, ResultTbl);
                        _doneEvents[i].QueueUserWorkItem(_worker.MailerCallback, _rows[i]);

                        if (Environment.UserInteractive == true)
                        {
                            _doneEvents[i].WaitOne();
                        }
                    }

                    ThreadPoolWait.WaitForAll(_doneEvents);

                    // 처리된 레코드가 한개 이하 인 경우는 종료한다. (문제가 있는 경우로 보여 짐)
                    if (_rows.Count < 1)
                    {
                        break;
                    }

                    //if (LogCommands == true)
                    //    ELogger.SNG.WriteLog(String.Format("loop: invoicerId->'{0}', noInvoicee->{1}, noSending->{2}", _args.invoicerId, _args.noInvoicee, _rows.Count));

                    _args.noInvoicee -= _rows.Count;
                    _args.noSending  += IssuingTbl.Rows.Count;

                    LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, IssuingSet);
                }
            }
            catch (MailerException ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            catch (Exception ex)
            {
                ELogger.SNG.WriteLog(ex);
            }
            finally
            {
                if (LogCommands == true)
                {
                    ELogger.SNG.WriteLog(String.Format("end: invoicerId->'{0}', noInvoicee->{1}, noSending->{2}", _args.invoicerId, _args.noInvoicee, _args.noSending));
                }

                int _noClearing = ClearXFlag(_args.invoicerId);
                if (_noClearing > 0)
                {
                    if (LogCommands == true)
                    {
                        ELogger.SNG.WriteLog(String.Format("clearX: invoicerId->'{0}', noClear->{1}", _args.invoicerId, _noClearing));
                    }
                }
            }
        }