- Timestamp:
- 10/01/13 13:18:19 (11 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/BillingEngine.cs
r9653 r10013 6 6 using System.Linq; 7 7 using System.Threading; 8 using System.Transactions; 8 9 using HeuristicLab.Services.Optimization.Billing.Business; 9 10 using HeuristicLab.Services.Optimization.Billing.Interfaces; … … 51 52 public void Run() { 52 53 while (!stop) { 54 TransactionOptions options = new TransactionOptions(); 55 options.IsolationLevel = IsolationLevel.ReadUncommitted; 56 TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, options); 53 57 try { 54 58 Trace.WriteLine("[BillingEngine] Start billing cycle"); … … 58 62 Trace.WriteLine(string.Format("[BillingEngine] Processing {0} active orders.", activeOrders.Count)); 59 63 foreach (Order order in activeOrders) { 64 Trace.WriteLine(string.Format("[BillingEngine] Processing order with id: {0}", order.OrderId)); 65 60 66 if (!order.NextBillableDay.HasValue) { 61 67 // An invoice has never been generated from this order … … 64 70 } 65 71 66 if (order.NextBillableDay >= currentDate) { 67 // TODO: Embed everything in a transaction 68 72 if (order.NextBillableDay <= currentDate) { 69 73 // Collect Usage Data 74 Trace.WriteLine("[BillingEngine] Collecting usage data"); 70 75 //IList<UsageRecord> usageRecrods = BillingService.GetUsageRecords(order.User.Name, order.LastBillableDay.Value, currentDate); 71 76 72 77 // Collect Invoice Data 78 Trace.WriteLine("[BillingEngine] Collecting invoice data"); 73 79 Invoice invoice = new Invoice(); 74 80 invoice.Order = order; … … 96 102 // Bill Post Processing: Apply Discounts or Promotions 97 103 // add discounts, sum up items to sub-total, calc. tax -> total current charges 98 // maybe use windows workflow foundation for this task 104 // maybe use rule execution feature from the windows workflow foundation for this task 105 Trace.WriteLine("[BillingEngine] Bill post preccessing"); 106 double subTotal = 0.0; 107 foreach (InvoiceLine invoiceLine in invoice.InvoiceLines) { 108 subTotal += invoiceLine.ProductPrice; 109 } 110 invoice.SubTotal = subTotal; 111 invoice.Tax = invoice.SubTotal * 0.2; 112 invoice.Total = invoice.SubTotal + invoice.Tax; 99 113 100 // Invoice Formatting Engine: Generate Invoice 114 // Invoice Formatting Engine: Generate Invoice 115 Trace.WriteLine("[BillingEngine] Generating invoice document"); 101 116 invoice.InvoiceDocument = InvoiceFormattingEngine.Generate(invoice); 102 117 … … 104 119 billingService.UpdateOrder(order); 105 120 billingService.SaveInvoice(invoice); 121 122 transaction.Complete(); 106 123 } 107 124 } … … 112 129 Trace.WriteLine(string.Format("[BillingEngine] The following exception occured: {0}", e.ToString())); 113 130 } 131 finally { 132 transaction.Dispose(); 133 } 134 114 135 waitHandle.WaitOne(interval); 115 136 } -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/PlainTextInvoiceFormattingEngine.cs
r9653 r10013 3 3 using System.IO; 4 4 using System.Linq; 5 using System.Text.RegularExpressions; 5 6 using System.Windows.Forms; 6 7 using HeuristicLab.Services.Optimization.Billing.Interfaces; … … 20 21 private PlainTextInvoiceFormat invoiceFormat; 21 22 private string invoiceOutputPath; 23 private IInvoiceDao invoiceDao; 24 25 private IInvoiceDao InvoiceDao { 26 get { 27 if (invoiceDao == null) { 28 invoiceDao = new FileSystemInvoiceDao(); 29 } 30 return invoiceDao; 31 } 32 } 22 33 23 34 public PlainTextInvoiceFormattingEngine() … … 82 93 invoiceText = invoiceText.Replace("{INVOICE_TOTAL}", invoice.Total.ToString("C2").PadLeft(14)); 83 94 95 // remove all escape sequences and replace directory separator with a hyphen 96 string customerName = Regex.Replace(invoice.User.ContactInformation.OrganizationName, "\\r\\n|\\[bnrt]", ""); 97 customerName = customerName.Replace("/", "-"); 98 84 99 if (invoiceFormat == PlainTextInvoiceFormat.RTF) { 85 invoiceOutputPath = string.Format("{0}_{1}_{2}.rtf", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), "{CUSTOMER}");100 invoiceOutputPath = string.Format("{0}_{1}_{2}.rtf", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), customerName); 86 101 87 102 RichTextBox richTextBox = new RichTextBox(); … … 90 105 richTextBox.SelectionFont = new Font("Consolas", 10, FontStyle.Regular); 91 106 92 File.WriteAllText(invoiceOutputPath, richTextBox.Rtf); 107 //File.WriteAllText(invoiceOutputPath, richTextBox.Rtf); 108 InvoiceDao.SaveDocument(invoiceOutputPath, richTextBox.Rtf); 93 109 } else if (invoiceFormat == PlainTextInvoiceFormat.TXT) { 94 invoiceOutputPath = string.Format("{0}_{1}_{2}.txt", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), "{CUSTOMER}");110 invoiceOutputPath = string.Format("{0}_{1}_{2}.txt", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), customerName); 95 111 96 File.WriteAllText(invoiceOutputPath, invoiceText); 112 //File.WriteAllText(invoiceOutputPath, invoiceText); 113 InvoiceDao.SaveDocument(invoiceOutputPath, invoiceText); 97 114 } else if (invoiceFormat == PlainTextInvoiceFormat.PDF) { 98 115 throw new Exception("PDF invoice format is currently not supported");
Note: See TracChangeset
for help on using the changeset viewer.