[9602] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
[9577] | 3 | using System.Linq;
|
---|
| 4 | using HeuristicLab.Services.Optimization.Billing.Interfaces;
|
---|
| 5 |
|
---|
| 6 | namespace HeuristicLab.Services.Optimization.Billing.Business {
|
---|
| 7 | public class MockupBillingService : IOptimizationBilling {
|
---|
| 8 |
|
---|
| 9 | private static IList<Model.Product> products;
|
---|
| 10 | private static IDictionary<string, IList<Model.Order>> userToOrders;
|
---|
| 11 | private static IList<Model.Order> allOrders;
|
---|
[9582] | 12 | private static IDictionary<string, Model.User> users;
|
---|
[9586] | 13 | private static IDictionary<string, IList<Model.UsageRecord>> records;
|
---|
| 14 | private static IDictionary<string, IList<Model.Invoice>> invoices;
|
---|
[9582] | 15 | private static long maxId = 1;
|
---|
[9577] | 16 |
|
---|
| 17 | static MockupBillingService() {
|
---|
[9586] | 18 | Model.Product oaas;
|
---|
[9577] | 19 | products = new List<Model.Product>();
|
---|
[9586] | 20 |
|
---|
| 21 | products.Add(oaas = new Model.Product() {
|
---|
[9577] | 22 | Name = "Optimization-as-a-Service - Experiment execution",
|
---|
| 23 | Description = "Create and run your experiments within HeuristicLab Hive",
|
---|
| 24 | ProductId = 1,
|
---|
| 25 | Price = 10.0,
|
---|
| 26 | ProductType = "Optimization Service"
|
---|
| 27 | });
|
---|
| 28 | products.Add(new Model.Product() {
|
---|
| 29 | Name = "Whatever-o-matic - Experiment execution",
|
---|
| 30 | Description = "Another fine product",
|
---|
| 31 | ProductId = 2,
|
---|
| 32 | Price = 100.0,
|
---|
| 33 | ProductType = "Product"
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | userToOrders = new Dictionary<string, IList<Model.Order>>();
|
---|
| 37 | allOrders = new List<Model.Order>();
|
---|
[9582] | 38 | users = new Dictionary<string, Model.User>();
|
---|
[9586] | 39 | records = new Dictionary<string, IList<Model.UsageRecord>>();
|
---|
| 40 | records["fschoeppl"] = new List<Model.UsageRecord>() {
|
---|
| 41 | new Model.UsageRecord() { ProductId = 1, Product = oaas, UsageRecordId = 1, User = new Model.User() { Name = "fschoeppl", UserId = 1 }, Begin = DateTime.Now, End = DateTime.Now.AddHours(2), UserId = 1, ResourceIdentifier = 0, ServiceIdentifier = 1 }
|
---|
| 42 | };
|
---|
| 43 | invoices = new Dictionary<string, IList<Model.Invoice>>();
|
---|
| 44 | invoices["fschoeppl"] = new List<Model.Invoice>() {
|
---|
| 45 | new Model.Invoice() {
|
---|
| 46 | Due = DateTime.Now.AddDays(-1),
|
---|
| 47 | Status = Model.InvoiceStatus.Overdue,
|
---|
| 48 | InvoiceId = 1, OrderId = 1,
|
---|
| 49 | InvoiceLines = new List<Model.InvoiceLine>() {
|
---|
| 50 | new Model.InvoiceLine() { Product = oaas, ProductId = oaas.ProductId, ProductPrice = oaas.Price, Quantity = 2, InvoiceLineId = 1, InvoiceId = 1 }
|
---|
| 51 | },
|
---|
| 52 | UserId = 1, User = new Model.User() { UserId = 1, Name = "fschoeppl" }
|
---|
| 53 | }
|
---|
| 54 | };
|
---|
[9577] | 55 | }
|
---|
| 56 |
|
---|
| 57 | public IList<Model.Product> GetProducts() {
|
---|
| 58 | return products;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public void SaveOrder(Model.Order order) {
|
---|
| 62 | IList<Model.Order> orders;
|
---|
| 63 | if (!userToOrders.TryGetValue(order.User.Name, out orders)) {
|
---|
[9586] | 64 | userToOrders[order.User.Name] = orders = new List<Model.Order>();
|
---|
[9577] | 65 | }
|
---|
[9582] | 66 | var oldOrder = (from o in orders where o.OrderId == order.OrderId select o).FirstOrDefault();
|
---|
| 67 | if (oldOrder == null) {
|
---|
| 68 | order.OrderId = maxId++;
|
---|
| 69 | orders.Add(order);
|
---|
| 70 | allOrders.Add(order);
|
---|
[9602] | 71 | } else {
|
---|
[9582] | 72 | oldOrder.Invoices = order.Invoices;
|
---|
| 73 | oldOrder.OrderLines = order.OrderLines;
|
---|
| 74 | oldOrder.State = order.State;
|
---|
| 75 | oldOrder.ActiveSince = order.ActiveSince;
|
---|
| 76 | oldOrder.ActiveUntil = order.ActiveUntil;
|
---|
| 77 | oldOrder.BillingPeriod = order.BillingPeriod;
|
---|
| 78 | oldOrder.BillingType = order.BillingType;
|
---|
| 79 | }
|
---|
[9577] | 80 | }
|
---|
| 81 |
|
---|
| 82 | public IList<Model.Order> GetOrdersByState(Model.OrderState state) {
|
---|
| 83 | return (from o in allOrders where o.State == state select o).ToList();
|
---|
| 84 | }
|
---|
[9582] | 85 |
|
---|
| 86 |
|
---|
| 87 | public IList<Model.Order> GetOrders(string userName) {
|
---|
| 88 | return (from o in allOrders where o.User.Name == userName select o).ToList();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | public Model.User GetUser(string userName) {
|
---|
| 93 | Model.User user;
|
---|
| 94 | if (!users.TryGetValue(userName, out user))
|
---|
| 95 | return null;
|
---|
| 96 | return user;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public void SaveUser(Model.User user) {
|
---|
| 100 | users[user.Name] = user;
|
---|
| 101 | }
|
---|
[9586] | 102 |
|
---|
| 103 |
|
---|
| 104 | public IList<Model.UsageRecord> GetUsageRecords(string userName) {
|
---|
| 105 | IList<Model.UsageRecord> foundRecords;
|
---|
| 106 | if (records.TryGetValue(userName, out foundRecords)) {
|
---|
| 107 | return foundRecords;
|
---|
| 108 | }
|
---|
| 109 | return null;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | public IList<Model.Invoice> GetInvoices(string userName) {
|
---|
| 114 | IList<Model.Invoice> foundInvoices;
|
---|
| 115 | if (invoices.TryGetValue(userName, out foundInvoices)) {
|
---|
| 116 | return foundInvoices;
|
---|
| 117 | }
|
---|
| 118 | return null;
|
---|
| 119 | }
|
---|
[9619] | 120 |
|
---|
| 121 | #region IOptimizationBilling Members
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | public IList<Model.Product> GetProductByName(string productName) {
|
---|
| 125 | throw new NotImplementedException();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public void UpdateOrder(Model.Order order) {
|
---|
| 129 | throw new NotImplementedException();
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | public IList<Model.UsageRecord> GetUsageRecords(string username, DateTime from, DateTime to) {
|
---|
| 133 | throw new NotImplementedException();
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[9645] | 136 | public void SaveInvoice(Model.Invoice invoice) {
|
---|
| 137 | throw new NotImplementedException();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[9619] | 140 | #endregion
|
---|
[9577] | 141 | }
|
---|
| 142 | }
|
---|