コード例 #1
0
 public void Init()
 {
     Program.LogSafe("BtRetryService: RetryWorker started.", EventLogEntryType.Information);
     m_Rules     = m_da.GetExportRules();
     m_Countries = m_da.GetAllCountries();
 }
コード例 #2
0
ファイル: RetryWorker.cs プロジェクト: rrossenbg/vprint
        public override void RunOnce()
        {
            if (m_dates.Count == 0)
            {
                FireCompleted();
            }

            DateTime date = m_dates.Count != 0 ? m_dates.Dequeue().cast <DateTime>() : DateTime.Now.Yesterday();

            var da = new TransferDBDataAccess();

            var rules     = da.GetExportRules();
            var countries = da.GetAllCountries();

            foreach (int iso in countries)
            {
                Trace.WriteLine("check iso_id {0}  date {1}".format(iso, date), "RETRY");

                var vouchers = da.GetListOfVouchers(iso, date);

                foreach (var v in vouchers)
                {
                    if (da.CheckVoucherForStatusOK(v.Item1, v.Item2, v.Item3))
                    {
                        thread.Yield();
                        continue;
                    }

                    Trace.WriteLine("date {0:dd-MM-yy}  country id {1}  v_number {2}  v_type_id {3}".format(date, v.Item1, v.Item2, v.Item3), "RETRY");
                    var desc = da.GetVoucherTransDescriptiont(v.Item1, v.Item2, v.Item3);

                    string rule;

                    if (desc.Count >= MAX_RETRIES)
                    {
                        Trace.WriteLine("Too many retries. Skip it.", "RETRY");
                    }
                    else if (rules.Exists(desc, (r, i) => i != null && r != null && i.Contains(r), out rule))
                    {
                        var xml = da.GetVoucher(v.Item1, v.Item2, v.Item3).First();

                        try
                        {
                            string fileName     = "DbExport_".concat(v.Item1, "_", v.Item2, '_', v.Item3, "_".Unique(), ".xml");
                            var    fullFileName = Path.Combine(BT_InParsed, fileName);

                            using (var file = File.CreateText(fullFileName))
                            {
                                file.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                                file.WriteLine("<VFPData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\");");
                                file.WriteLine(xml);
                                file.WriteLine("</VFPData>");
                            }

                            Trace.WriteLine("Export file: ".concat(fileName, " rule: ", rule), "RETRY");
                            Program.LogSafe("Export file: ".concat(fullFileName, " rule: ", rule), EventLogEntryType.Information);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.Message, "RETRY");
                            Program.LogSafe(ex.ToString(), EventLogEntryType.Error);
                        }
                    }

                    thread.Yield();
                }
            }
        }