Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/AzureInvoiceDao.cs @ 13777

Last change on this file since 13777 was 10013, checked in by spimming, 11 years ago

#1888:

  • enabled transactions
  • enabled tracing output
  • set correct invoice data
  • saving invoices
File size: 2.1 KB
Line 
1using System.Configuration;
2using System.IO;
3using HeuristicLab.Services.Optimization.Billing.Interfaces;
4using Microsoft.WindowsAzure;
5using Microsoft.WindowsAzure.StorageClient;
6
7namespace HeuristicLab.Services.Optimization.Billing.BillingEngine {
8  public class AzureInvoiceDao : IInvoiceDao {
9    private CloudStorageAccount storageAccount;
10    private CloudStorageAccount StorageAccount {
11      get {
12        if (storageAccount == null) {
13          storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[AzureConstants.CLOUD_STORAGE_SETTINGS_STRING]);
14        }
15        return storageAccount;
16      }
17    }
18
19    private CloudBlobClient blobClient;
20    private CloudBlobClient BlobClient {
21      get {
22        if (blobClient == null) {
23          blobClient = StorageAccount.CreateCloudBlobClient();
24        }
25        return blobClient;
26      }
27    }
28
29    public AzureInvoiceDao() {
30
31    }
32
33    public bool SaveDocument(string documentName, string contents) {
34      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.INVOICE_BLOB_CONTAINER);
35      container.CreateIfNotExist();
36      var blob = container.GetBlobReference(documentName);
37      blob.UploadText(contents);
38      return true;
39    }
40
41    public string LoadDocument(string documentName) {
42      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.INVOICE_BLOB_CONTAINER);
43      container.CreateIfNotExist();
44      var blob = container.GetBlobReference(documentName);
45      return blob.DownloadText();
46    }
47
48    public void LoadDocument(string documentName, Stream target) {
49      CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.INVOICE_BLOB_CONTAINER);
50      container.CreateIfNotExist();
51      var blob = container.GetBlobReference(documentName);
52      blob.DownloadToStream(target);
53    }
54
55
56    private static class AzureConstants {
57      public static readonly string INVOICE_BLOB_CONTAINER = "invoices";
58      public static readonly string CLOUD_STORAGE_SETTINGS_STRING = "StorageConnectionString";
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.