using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Services.Optimization.Billing.Interfaces; namespace HeuristicLab.Services.Optimization.Billing.Business { public class MockupBillingService : IOptimizationBilling { private static IList products; private static IDictionary> userToOrders; private static IList allOrders; private static IDictionary users; private static IDictionary> records; private static IDictionary> invoices; private static long maxId = 1; static MockupBillingService() { Model.Product oaas; products = new List(); products.Add(oaas = new Model.Product() { Name = "Optimization-as-a-Service - Experiment execution", Description = "Create and run your experiments within HeuristicLab Hive", ProductId = 1, Price = 10.0, ProductType = "Optimization Service" }); products.Add(new Model.Product() { Name = "Whatever-o-matic - Experiment execution", Description = "Another fine product", ProductId = 2, Price = 100.0, ProductType = "Product" }); userToOrders = new Dictionary>(); allOrders = new List(); users = new Dictionary(); records = new Dictionary>(); records["fschoeppl"] = new List() { 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 } }; invoices = new Dictionary>(); invoices["fschoeppl"] = new List() { new Model.Invoice() { Due = DateTime.Now.AddDays(-1), Status = Model.InvoiceStatus.Overdue, InvoiceId = 1, OrderId = 1, InvoiceLines = new List() { new Model.InvoiceLine() { Product = oaas, ProductId = oaas.ProductId, ProductPrice = oaas.Price, Quantity = 2, InvoiceLineId = 1, InvoiceId = 1 } }, UserId = 1, User = new Model.User() { UserId = 1, Name = "fschoeppl" } } }; } public IList GetProducts() { return products; } public void SaveOrder(Model.Order order) { IList orders; if (!userToOrders.TryGetValue(order.User.Name, out orders)) { userToOrders[order.User.Name] = orders = new List(); } var oldOrder = (from o in orders where o.OrderId == order.OrderId select o).FirstOrDefault(); if (oldOrder == null) { order.OrderId = maxId++; orders.Add(order); allOrders.Add(order); } else { oldOrder.Invoices = order.Invoices; oldOrder.OrderLines = order.OrderLines; oldOrder.State = order.State; oldOrder.ActiveSince = order.ActiveSince; oldOrder.ActiveUntil = order.ActiveUntil; oldOrder.BillingPeriod = order.BillingPeriod; oldOrder.BillingType = order.BillingType; } } public IList GetOrdersByState(Model.OrderState state) { return (from o in allOrders where o.State == state select o).ToList(); } public IList GetOrders(string userName) { return (from o in allOrders where o.User.Name == userName select o).ToList(); } public Model.User GetUser(string userName) { Model.User user; if (!users.TryGetValue(userName, out user)) return null; return user; } public void SaveUser(Model.User user) { users[user.Name] = user; } public IList GetUsageRecords(string userName) { IList foundRecords; if (records.TryGetValue(userName, out foundRecords)) { return foundRecords; } return null; } public IList GetInvoices(string userName) { IList foundInvoices; if (invoices.TryGetValue(userName, out foundInvoices)) { return foundInvoices; } return null; } #region IOptimizationBilling Members public IList GetProductByName(string productName) { throw new NotImplementedException(); } public void UpdateOrder(Model.Order order) { throw new NotImplementedException(); } public IList GetUsageRecords(string username, DateTime from, DateTime to) { throw new NotImplementedException(); } public void SaveInvoice(Model.Invoice invoice) { throw new NotImplementedException(); } #endregion } }