Exemplo n.º 1
0
        private void createTenantReport(string tenantName) {
            BookingSummary summary;
            try {
                using (BookingServicePortTypeClient client = getBookingWSClient()) {
                    summary = client.getBookingSummaryByTenant(tenantName, 25);
                } 
            } catch (Exception e) {
                log.Error("cannot create booking report for " + tenantName, e);
                return;
            }
            if (summary == null || summary.NBookings == 0) {
                log.Info("no bookings found: " + tenantName);
            } else {
                using (PaymentEntities context = new PaymentEntities()) {
                    Dictionary<string, int> departures = new Dictionary<string,int>();
                    Dictionary<string, int> destinations = new Dictionary<string, int>();
                    for (int i = 0; i < summary.departures.Length; i++) {
                        departures.Add(summary.departures[i].name, (int)summary.departureCounts[i]);
                    }
                    for (int i = 0; i < summary.destinations.Length; i++) {
                        destinations.Add(summary.destinations[i].name, (int)summary.destinationCounts[i]);
                    }

                    DateTime date = DateTime.Now;
                    PaymentReportData prd = new PaymentReportData(date, summary.NBookings, decimal.Round((decimal)summary.totalSales, 2), destinations, departures);
                    string prdXml = prd.ToXMLString();
                    if (log.IsDebugEnabled) {
                        log.Debug("report as xml : " + prdXml);
                    }
                    AppData.Report report = AppData.Report.CreateReport(tenantName, date);
                    report.xmlData = prdXml;
                    context.AddToReport(report);
                    int changes = context.SaveChanges();
                    if (log.IsDebugEnabled) {
                        log.Debug("saved report: " + report + " changes: " + changes);
                    }
                }
            }

        }
Exemplo n.º 2
0
        public void TestXmlSerializableDictionary() {
            DateTime now = DateTime.Now;
            int totalBookings = 123;
            decimal totalSales = 450000.50M;
            Dictionary<string, int> destinations = new Dictionary<string, int>();
            destinations.Add("Destination1", 1);
            destinations.Add("Destination2", 2);
            destinations.Add("Destination3", 3);
            destinations.Add("Destination4", 4);
            destinations.Add("Destination5", 5);
            Dictionary<string, int> departures = new Dictionary<string, int>();
            departures.Add("Departure1", 1);
            departures.Add("Departure2", 2);
            departures.Add("Departure3", 3);
            departures.Add("Departure4", 4);
            departures.Add("Departure5", 5);

            PaymentReportData prd = new PaymentReportData(now, totalBookings, totalSales, destinations, departures);

            string xml = prd.ToXMLString();

            PaymentReportData prd2 = PaymentReportData.FromXML(xml);

            Assert.AreEqual(now, prd2.Date);
            Assert.AreEqual(totalBookings, prd2.TotalBookings);
            Assert.AreEqual(totalSales, prd2.TotalSales);
            Assert.AreEqual(destinations.Count, prd2.Destinations.Count);
            Assert.AreEqual(destinations["Destination1"], prd2.Destinations["Destination1"]);
            Assert.AreEqual(destinations["Destination2"], prd2.Destinations["Destination2"]);
            Assert.AreEqual(destinations["Destination3"], prd2.Destinations["Destination3"]);
            Assert.AreEqual(destinations["Destination4"], prd2.Destinations["Destination4"]);
            Assert.AreEqual(destinations["Destination5"], prd2.Destinations["Destination5"]);
            Assert.AreEqual(departures.Count, prd2.Departures.Count);
            Assert.AreEqual(departures["Departure1"], prd2.Departures["Departure1"]);
            Assert.AreEqual(departures["Departure2"], prd2.Departures["Departure2"]);
            Assert.AreEqual(departures["Departure3"], prd2.Departures["Departure3"]);
            Assert.AreEqual(departures["Departure4"], prd2.Departures["Departure4"]);
            Assert.AreEqual(departures["Departure5"], prd2.Departures["Departure5"]);
        }