Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10013 for branches


Ignore:
Timestamp:
10/01/13 13:18:19 (11 years ago)
Author:
spimming
Message:

#1888:

  • enabled transactions
  • enabled tracing output
  • set correct invoice data
  • saving invoices
Location:
branches/OaaS
Files:
5 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab 3.3 Services.sln

    r9579 r10013  
    197197    {F685556B-F6EB-4143-8E7E-662D00FDD299}.Release|x86.Build.0 = Release|x86
    198198    {034C2EE4-E303-4E45-98AB-F0074EC83B81}.Debug|Any CPU.ActiveCfg = Debug
    199     {034C2EE4-E303-4E45-98AB-F0074EC83B81}.Debug|Any CPU.Build.0 = Debug
    200199    {034C2EE4-E303-4E45-98AB-F0074EC83B81}.Debug|Mixed Platforms.ActiveCfg = Debug
    201200    {034C2EE4-E303-4E45-98AB-F0074EC83B81}.Debug|Mixed Platforms.Build.0 = Debug
  • branches/OaaS/HeuristicLab.Services.Hive.DataAccess/3.3/Settings.Designer.cs

    r8326 r10013  
    22// <auto-generated>
    33//     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.269
     4//     Runtime Version:4.0.30319.18047
    55//
    66//     Changes to this file may cause incorrect behavior and will be lost if
     
    2727        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    2828        [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
    29         [global::System.Configuration.DefaultSettingValueAttribute("Data Source=pok6rtjc5c.database.windows.net;Initial Catalog=HeuristicLab.Hive-3.3" +
     29        [global::System.Configuration.DefaultSettingValueAttribute("Data Source=y1hi1qbs9d.database.windows.net;Initial Catalog=HeuristicLab.Hive-3.3" +
    3030            ";User ID=cloudia;Password=d1fFntitafvX;Enlist=False")]
    3131        public string HeuristicLab_Hive_LinqConnectionString {
  • branches/OaaS/HeuristicLab.Services.Hive.Scaler/HeuristicLab.Services.Optimization.Scaler.csproj

    r9588 r10013  
    8989      <SubType>Designer</SubType>
    9090    </None>
    91     <None Include="packages.config" />
     91    <None Include="packages.config">
     92      <SubType>Designer</SubType>
     93    </None>
    9294  </ItemGroup>
    9395  <ItemGroup>
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/App.config

    r9619 r10013  
    1 <?xml version="1.0" encoding="utf-8"?>
     1<?xml version="1.0"?>
    22<configuration>
    33  <configSections>
    44    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    5     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
     5    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    66  </configSections>
    77  <appSettings>
    8     <add key="BillingEngineInterval" value ="00:01:00"/>
     8    <add key="BillingEngineInterval" value="00:01:00"/>
     9    <add key="LongRunningDbCommandTimeout" value="00:05:00"/>
     10    <add key="StorageConnectionString" value="ADJUST_ME"/>
    911  </appSettings>
    1012  <connectionStrings>
    11     <add name="BillingContext" connectionString="ADJUST_ME" providerName="System.Data.SqlClient" />
     13    <add name="BillingContext" connectionString="ADJUST_ME" providerName="System.Data.SqlClient"/>
    1214  </connectionStrings>
    1315  <entityFramework>
    14     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
     16    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    1517  </entityFramework>
    16 </configuration>
     18<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/DDLScript.sql

    r9641 r10013  
    1818    [Due] [datetime] not null,
    1919    [StatusValue] [int] not null,
     20    [SubTotal] [float] not null,
    2021    [Total] [float] not null,
    2122    [Tax] [float] not null,
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/HeuristicLab.Services.Optimization.Billing.Test.csproj

    r9602 r10013  
    1212    <AssemblyName>HeuristicLab.Services.Optimization.Billing.Test</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile>Client</TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617  </PropertyGroup>
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/Program.cs

    r9619 r10013  
    99namespace HeuristicLab.Services.Optimization.Billing.Test {
    1010  class Program {
    11     private static BillingEngine.BillingEngine billingEngine;
     11    private static HeuristicLab.Services.Optimization.Billing.BillingEngine.BillingEngine billingEngine;
    1212    private static Thread billingEngineThread;
    1313
     
    1515      string ddlScript;
    1616      using (var context = new BillingContext()) {
    17         System.Data.Entity.Database.SetInitializer(new HeuristicLab.Services.Optimization.Billing.DataAccess.BillingContext.BillingContextInitiliazer());
    1817        ddlScript = (((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript());
    1918      }
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/BillingEngine.cs

    r9653 r10013  
    66using System.Linq;
    77using System.Threading;
     8using System.Transactions;
    89using HeuristicLab.Services.Optimization.Billing.Business;
    910using HeuristicLab.Services.Optimization.Billing.Interfaces;
     
    5152    public void Run() {
    5253      while (!stop) {
     54        TransactionOptions options = new TransactionOptions();
     55        options.IsolationLevel = IsolationLevel.ReadUncommitted;
     56        TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, options);
    5357        try {
    5458          Trace.WriteLine("[BillingEngine] Start billing cycle");
     
    5862          Trace.WriteLine(string.Format("[BillingEngine] Processing {0} active orders.", activeOrders.Count));
    5963          foreach (Order order in activeOrders) {
     64            Trace.WriteLine(string.Format("[BillingEngine] Processing order with id: {0}", order.OrderId));
     65
    6066            if (!order.NextBillableDay.HasValue) {
    6167              // An invoice has never been generated from this order
     
    6470            }
    6571
    66             if (order.NextBillableDay >= currentDate) {
    67               // TODO: Embed everything in a transaction
    68 
     72            if (order.NextBillableDay <= currentDate) {
    6973              // Collect Usage Data
     74              Trace.WriteLine("[BillingEngine] Collecting usage data");
    7075              //IList<UsageRecord> usageRecrods = BillingService.GetUsageRecords(order.User.Name, order.LastBillableDay.Value, currentDate);
    7176
    7277              // Collect Invoice Data
     78              Trace.WriteLine("[BillingEngine] Collecting invoice data");
    7379              Invoice invoice = new Invoice();
    7480              invoice.Order = order;
     
    96102              // Bill Post Processing: Apply Discounts or Promotions
    97103              // 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;
    99113
    100               // Invoice Formatting Engine: Generate Invoice
     114              // Invoice Formatting Engine: Generate Invoice
     115              Trace.WriteLine("[BillingEngine] Generating invoice document");
    101116              invoice.InvoiceDocument = InvoiceFormattingEngine.Generate(invoice);
    102117
     
    104119              billingService.UpdateOrder(order);
    105120              billingService.SaveInvoice(invoice);
     121
     122              transaction.Complete();
    106123            }
    107124          }
     
    112129          Trace.WriteLine(string.Format("[BillingEngine] The following exception occured: {0}", e.ToString()));
    113130        }
     131        finally {
     132          transaction.Dispose();
     133        }
     134
    114135        waitHandle.WaitOne(interval);
    115136      }
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/PlainTextInvoiceFormattingEngine.cs

    r9653 r10013  
    33using System.IO;
    44using System.Linq;
     5using System.Text.RegularExpressions;
    56using System.Windows.Forms;
    67using HeuristicLab.Services.Optimization.Billing.Interfaces;
     
    2021    private PlainTextInvoiceFormat invoiceFormat;
    2122    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    }
    2233
    2334    public PlainTextInvoiceFormattingEngine()
     
    8293      invoiceText = invoiceText.Replace("{INVOICE_TOTAL}", invoice.Total.ToString("C2").PadLeft(14));
    8394
     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
    8499      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);
    86101
    87102        RichTextBox richTextBox = new RichTextBox();
     
    90105        richTextBox.SelectionFont = new Font("Consolas", 10, FontStyle.Regular);
    91106
    92         File.WriteAllText(invoiceOutputPath, richTextBox.Rtf);
     107        //File.WriteAllText(invoiceOutputPath, richTextBox.Rtf);
     108        InvoiceDao.SaveDocument(invoiceOutputPath, richTextBox.Rtf);
    93109      } 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);
    95111
    96         File.WriteAllText(invoiceOutputPath, invoiceText);
     112        //File.WriteAllText(invoiceOutputPath, invoiceText);
     113        InvoiceDao.SaveDocument(invoiceOutputPath, invoiceText);
    97114      } else if (invoiceFormat == PlainTextInvoiceFormat.PDF) {
    98115        throw new Exception("PDF invoice format is currently not supported");
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs

    r9645 r10013  
    1919    }
    2020
     21    private ITransactionManager transaction;
     22    private ITransactionManager Transaction {
     23      get {
     24        if (transaction == null) transaction = new TransactionManager();
     25        return transaction;
     26      }
     27    }
     28
    2129    #endregion
    2230
     
    2533    public IList<Product> GetProducts() {
    2634      //TODO: Authentication
    27       //TODO: Enable Transaction
    28       return BillingDao.FindAllProducts().ToList();
     35      return Transaction.UseTransaction(() => {
     36        return BillingDao.FindAllProducts().ToList();
     37      });
    2938    }
    3039
    3140    public IList<Product> GetProductByName(string productName) {
    3241      //TODO: Authentication
    33       //TODO: Enable Transaction
    34       return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
     42      return Transaction.UseTransaction(() => {
     43        return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
     44      });
    3545    }
    3646
     
    4151    public void SaveOrder(Order order) {
    4252      //TODO: Authentication
    43       //TODO: Enable Transaction
    44       BillingDao.InsertOrUpdateOrder(order);
     53      Transaction.UseTransaction(() => {
     54        BillingDao.InsertOrUpdateOrder(order);
     55      });
    4556    }
    4657
    4758    public IList<Order> GetOrdersByState(OrderState state) {
    4859      //TODO: Authentication
    49       //TODO: Enable Transaction
    50       return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
     60      return Transaction.UseTransaction(() => {
     61        return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
     62      });
    5163    }
    5264
    5365    public IList<Order> GetOrders(string userName) {
    5466      //TODO: Authentication
    55       //TODO: Enable Transaction
    56       User user = GetUser(userName);
    57       return BillingDao.FindOrderBy(order => order.User == user).ToList();
     67      return Transaction.UseTransaction(() => {
     68        User user = GetUser(userName);
     69        return BillingDao.FindOrderBy(order => order.User == user).ToList();
     70      });
    5871    }
    5972
    6073    public void UpdateOrder(Order order) {
    6174      //TODO: Authentication
    62       //TODO: Enable Transaction
    63       BillingDao.InsertOrUpdateOrder(order);
     75      Transaction.UseTransaction(() => {
     76        BillingDao.InsertOrUpdateOrder(order);
     77      });
    6478    }
    6579
     
    7084    public User GetUser(string userName) {
    7185      //TODO: Authentication
    72       //TODO: Enable Transaction
    73       return BillingDao.FindUserBy(u => u.Name == userName).First();
     86      return Transaction.UseTransaction(() => {
     87        return BillingDao.FindUserBy(u => u.Name == userName).First();
     88      });
    7489    }
    7590
    7691    public void SaveUser(User user) {
    7792      //TODO: Authentication
    78       //TODO: Enable Transaction
    79       BillingDao.InsertOrUpdateUser(user);
     93      Transaction.UseTransaction(() => {
     94        BillingDao.InsertOrUpdateUser(user);
     95      });
    8096    }
    8197
     
    86102    public IList<UsageRecord> GetUsageRecords(string userName) {
    87103      //TODO: Authentication
    88       //TODO: Enable Transaction
    89       User user = GetUser(userName);
    90       return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
     104      return Transaction.UseTransaction(() => {
     105        User user = GetUser(userName);
     106        return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
     107      });
    91108    }
    92109
     
    101118    public IList<Invoice> GetInvoices(string userName) {
    102119      //TODO: Authentication
    103       //TODO: Enable Transaction
    104       User user = GetUser(userName);
    105       return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
     120      return Transaction.UseTransaction(() => {
     121        User user = GetUser(userName);
     122        return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
     123      });
    106124    }
    107125
    108126    public void SaveInvoice(Invoice invoice) {
    109127      //TODO: Authentication
    110       //TODO: Enable Transaction
    111       BillingDao.InsertOrUpdateInvoice(invoice);
     128      Transaction.UseTransaction(() => {
     129        BillingDao.InsertOrUpdateInvoice(invoice);
     130      });
    112131    }
    113132
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing/HeuristicLab.Services.Optimization.Billing.csproj

    r9645 r10013  
    3535      <HintPath>..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll</HintPath>
    3636    </Reference>
     37    <Reference Include="Microsoft.WindowsAzure.StorageClient, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    3738    <Reference Include="System" />
    3839    <Reference Include="System.ComponentModel.DataAnnotations" />
     
    4243    <Reference Include="System.Drawing" />
    4344    <Reference Include="System.ServiceModel" />
     45    <Reference Include="System.Transactions" />
    4446    <Reference Include="System.Windows.Forms" />
    4547    <Reference Include="System.Xml.Linq" />
     
    5052  </ItemGroup>
    5153  <ItemGroup>
     54    <Compile Include="BillingEngine\AzureInvoiceDao.cs" />
    5255    <Compile Include="BillingEngine\BillingEngine.cs" />
     56    <Compile Include="BillingEngine\FileSystemInvoiceDao.cs" />
    5357    <Compile Include="BillingEngine\PlainTextInvoiceFormattingEngine.cs" />
    5458    <Compile Include="Business\BillingService.cs" />
    5559    <Compile Include="Business\BillingServiceProvider.cs" />
     60    <Compile Include="Business\TransactionManager.cs" />
    5661    <Compile Include="DataAccess\BillingContext.cs" />
    5762    <Compile Include="DataAccess\BillingDao.cs" />
    5863    <Compile Include="Interfaces\IEntity.cs" />
    5964    <Compile Include="Interfaces\IGenericDao.cs" />
     65    <Compile Include="Interfaces\IInvoiceDao.cs" />
    6066    <Compile Include="Interfaces\IInvoiceFormattingEngine.cs" />
    6167    <Compile Include="Interfaces\IObjectWithState.cs" />
    6268    <Compile Include="Interfaces\IOptimizationBilling.cs" />
    6369    <Compile Include="Business\MockupBillingService.cs" />
     70    <Compile Include="Interfaces\ITransactionManager.cs" />
    6471    <Compile Include="Model\Model.cs" />
    6572    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/OaaS/HeuristicLab.Services.Optimization.Billing/Model/Model.cs

    r9645 r10013  
    151151    public DateTime Due { get; set; }
    152152    public int StatusValue { get; set; }
     153    public double SubTotal { get; set; }
    153154    public double Total { get; set; }
    154155    public double Tax { get; set; }
Note: See TracChangeset for help on using the changeset viewer.