Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using System.Collections.Generic;
11 : using Cqrs.Azure.BlobStorage.DataStores;
12 : using Cqrs.DataStores;
13 : using Cqrs.Entities;
14 :
15 : namespace Cqrs.Azure.BlobStorage
16 : {
17 : /// <summary>
18 : /// Extension methods for Azure Blob storage.
19 : /// </summary>
20 : public static class BlobStorageStoreExtensions
21 1 : {
22 : /// <summary>
23 : /// Get <typeparamref name="TData"/> by its name.
24 : /// </summary>
25 1 : public static TData GetByName<TData>(this IDataStore<TData> datastore, string name)
26 : {
27 : var rawDatastore = (BlobStorageStore<TData>)datastore;
28 : return rawDatastore.GetByName(name);
29 : }
30 :
31 : /// <summary>
32 : /// Get <typeparamref name="TData"/> by its name.
33 : /// </summary>
34 1 : public static TData GetByName<TData>(this IDataStore<TData> datastore, Guid id)
35 : where TData : Entity, new()
36 : {
37 : var rawDatastore = (BlobStorageStore<TData>)datastore;
38 : return rawDatastore.GetByName(string.Format("{0}.json", rawDatastore.GenerateFileName(new TData { Rsn = id })));
39 : }
40 :
41 : /// <summary>
42 : /// Get all <typeparamref name="TData"/> items in the folder.
43 : /// </summary>
44 1 : public static IEnumerable<TData> GetByFolder<TData>(this IDataStore<TData> datastore, string folderName)
45 : {
46 : var rawDatastore = (BlobStorageStore<TData>)datastore;
47 : return rawDatastore.GetByFolder(folderName);
48 : }
49 :
50 : /// <summary>
51 : /// Get all <typeparamref name="TData"/> items in the folder.
52 : /// </summary>
53 1 : public static IEnumerable<TData> GetByFolder<TData>(this IDataStore<TData> datastore)
54 : where TData : Entity
55 : {
56 : var rawDatastore = (BlobStorageDataStore<TData>)datastore;
57 : return rawDatastore.GetByFolder();
58 : }
59 : }
60 : }
|