他のタスクの中でも、「クラウド」に移行すると、アプリケーションテンプレートの構造化ストレージの問題が発生しました。 Windows Azureは、Windows Azureストレージサービス用にいくつかのストレージオプションを提供します。
- Windows Azure Blob-大きなデータアイテム用のストレージを提供します。
- Windows Azureテーブル-サービス状態の構造化ストレージを提供します。
- Windows Azureキュー-非同期ジョブのスケジューリングを提供して、サービス間のデータ交換を実装します。
一見、Tableは完璧にフィットしますが、一見しただけです。 プリミティブクエリを実行し、興味のある行のみを取得できます。Guidレコードのプロパティに別のレコードを配置することで、オブジェクトの階層を整理できます。 この分野の知識を深めると、各レコードは255フィールドを超えることはできません(これは私たちにとっては重要ではありません)最後に、各プロパティのサイズは64 kBを超えることはできませんが、この段階では既に最大300 kBのサイズのテキストを保存する必要があるため、これに我慢できません。
そして、Blobはどうですか? Blob-sを使用すると、現在のタスクのサイズが200 GBの面白い制限でレコードを保存でき、異なるコンテナーに配置して仮想フォルダーを使用してデータを構造化できるため、各Blobには合計サイズ8 kBのメタデータを付随させることができます。 間違いなくBlobのように見えるでしょうか? 再びいいえ! ブロブを選択することはできません。リクエストに応じて検索を実行するメカニズムはありません(いずれの場合も見つかりませんでした)。 あなたは尋ねます:「メタデータはどうですか? 結局、そこに構造に関する情報を配置できます!」そして、ほぼ正しいでしょう。Blobコンテンツなしでメタデータを取得し、選択するLINQクエリを作成することもできますが、コンテナー内のすべてのBlobのすべてのメタデータを受け取った後にこれを行う必要があります。 また、多数の要素があると、コストのかかる操作になります。
それでは、Windows Azureを使用しても問題を解決できませんか? もちろんできます! そして、私たちは方法を見つけました。多分それは完璧ではありませんが、私たちは完全に満足しています。 データ自体をBlobに保存し、データ構造に関する情報をテーブルに保存することが決定されました。 したがって、これらの2つの技術を組み合わせて、欠点を補い、活用します。
そして最後に、上に書かれたすべてを説明する少しのコード。 まず、テーブルストレージへのアクセスを容易にするラッパークラスを作成します。
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
public class DynamicTableServiceContext<T> : TableServiceContext where T : TableServiceEntity { private CloudStorageAccount storageAccount; private string tableName; public DynamicTableServiceContext(CloudStorageAccount storageAccount, string tableName) : base (storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials) { this .storageAccount = storageAccount; this .tableName = tableName; var tableStorage = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials); tableStorage.CreateTableIfNotExist(tableName); } public void Add(T entityToAdd) { AddObject(tableName, entityToAdd); SaveChanges(); } public void Update(T entityToUpdate) { UpdateObject(entityToUpdate); SaveChanges(); } public void Delete(T entityToDelete) { DeleteObject(entityToDelete); SaveChanges(); } public IQueryable<T> Load() { return CreateQuery<T>(tableName); } } * This source code was highlighted with Source Code Highlighter .
次に、レコードのエンティティを作成します。
*このソースコードは、 ソースコードハイライターで強調表示されました。
- パブリック 列挙型 ElementType
- {
- Obj = 1
- ObjCategory = 2
- }
- パブリック クラス BaseObjTableEntity:TableServiceEntity
- {
- public virtual int Type { get ; セット ; }
- パブリック ストリング Name { get ; セット ; }
- }
- パブリック クラス ObjTableEntity:BaseObjTableEntity
- {
- パブリック ストリング説明{ get ; セット ; }
- パブリック ストリング CategoryId { get ; セット ; }
- パブリック オーバーライド int型
- {
- get { return ( int )ElementType.Obj; }
- {}を設定
- }
- }
- パブリック クラス ObjCategoryTableEntity:BaseObjTableEntity
- {
- パブリック オーバーライド int型
- {
- get { return ( int )ElementType.ObjCategory; }
- {}を設定
- }
- }
このタスクでは、各ユーザーのオブジェクトをカテゴリ別に保存する必要があるため、オブジェクトとオブジェクトのカテゴリを1つのテーブルに保存することが決定されました(これがAzure Table Storageが提供するものです)。 テーブル内のレコードを区別するために、オブジェクトにはオブジェクトのタイプに関する情報を格納するフィールドがあります。 便宜上、これは列挙型ElementTypeの形式で行われます。 エントリの基本クラスはBaseObjTableEntityで、カテゴリとオブジェクトのクラスはそれぞれObjCategoryTableEntityとObjTableEntityです。
抽象TableServiceEntityクラスには、PartitionKey、RowKey、およびTimestampの3つのプロパティが含まれています。 最初の2つは複合キーとして使用され、同じPartitionKeyを持つレコードは常に同じサーバー内にあるため、ユーザーIDをこのプロパティに転送することにしました。 カテゴリのRowKeyはカテゴリのGuidであり、オブジェクトのRowKeyはBlobの名前であるGuidです。 したがって、オブジェクト自体はBlob-sに格納されます。それらを操作するために、単純なクラスを作成します。
*このソースコードは、 ソースコードハイライターで強調表示されました。
- パブリック クラス ObjBlob
- {
- パブリック ストリングコンテンツ{ get ; セット ; }
- パブリック ストリング Name { get ; セット ; }
- }
そして最後に、これらすべてを処理するクラス:
*このソースコードは、 ソースコードハイライターで強調表示されました。
- パブリック クラス ObjAzureRepository
- {
- private const string ObjContainerName = "objlibrary";
- private const string ObjTableName = "ObjLibrary";
- private const string DefaultPartitionKey = "Default";
- プライベート 読み取り専用 ストリング userID;
- public ObjAzureRepository( string userId)
- {
- this .userID = userId;
- }
- プライベート 文字列 azureStorageConnectionString;
- 保護された 文字列 AzureStorageConnectionString
- {
- 得る
- {
- if ( string .IsNullOrWhiteSpace(azureStorageConnectionString))
- {
- azureStorageConnectionString = WebConfigurationManager.ConnectionStrings ["AzureStorageConnectionString"]。ConnectionString;
- }
- return azureStorageConnectionString;
- }
- }
- プライベート CloudStorageAccount azureStorageAccount;
- 保護された CloudStorageAccount AzureStorageAccount
- {
- 得る
- {
- azureStorageAccountを返しますか? (azureStorageAccount = CloudStorageAccount.Parse(AzureStorageConnectionString));
- }
- }
- private DynamicTableServiceContext <ObjCategoryTableEntity> categoryContext;
- private DynamicTableServiceContext <ObjCategoryTableEntity> CategoryContext
- {
- 得る
- {
- if (categoryContext == null )
- {
- categoryContext = new DynamicTableServiceContext <ObjCategoryTableEntity>(AzureStorageAccount、ObjTableName);
- }
- return categoryContext;
- }
- }
- private DynamicTableServiceContext <ObjTableEntity> ObjContext;
- private DynamicTableServiceContext <ObjTableEntity> ObjContext
- {
- 得る
- {
- if (ObjContext == null )
- {
- ObjContext = new DynamicTableServiceContext <ObjTableEntity>(AzureStorageAccount、ObjTableName);
- }
- ObjContextを返します。
- }
- }
- public List <ObjCategoryTableEntity> GetObjCategories()
- {
- Return CategoryContext.Load()。Where <ObjCategoryTableEntity>(e => e.PartitionKey == userID && e.Type ==( int )ElementType.ObjCategory).ToList();
- }
- public List <ObjTableEntity> GetObjsByCategory(ObjCategoryTableEntityカテゴリー)
- {
- return ObjContext.Load()。Where(s => s.PartitionKey == userID && s.CategoryId == category.RowKey && s.Type ==( int )ElementType.Obj).ToList();
- }
- パブリック ObjBlob GetObjById( 文字列 ID)
- {
- CloudBlobClientクライアント= AzureStorageAccount.CreateCloudBlobClient();
- CloudBlobContainer container = client.GetContainerReference(ObjContainerName);
- container.CreateIfNotExist();
- CloudBlob Obj = container.GetBlobReference(id);
- return new ObjBlob(){Name = id、Content = Obj.DownloadText()};
- }
- public void AddCategory(ObjCategoryTableEntityカテゴリー)
- {
- CategoryContext.Add(カテゴリ);
- }
- public void ChangeCategory(ObjCategoryTableEntityカテゴリー)
- {
- CategoryContext.Update(カテゴリ);
- }
- public void RemoveCategory(ObjCategoryTableEntityカテゴリー)
- {
- CategoryContext.Delete(カテゴリ);
- }
- public void AddObj(ObjTableEntity Obj、 ストリング ObjContent)
- {
- ObjContext.Add(Obj);
- CloudBlobClientクライアント= AzureStorageAccount.CreateCloudBlobClient();
- CloudBlobContainer container = client.GetContainerReference(ObjContainerName);
- container.CreateIfNotExist();
- CloudBlob ObjBlob = container.GetBlobReference(Obj.RowKey);
- ObjBlob.UploadText(ObjContent);
- }
- public void ChangeObj(ObjTableEntity Obj)
- {
- ObjContext.Update(Obj);
- }
- public void RemoveObj(ObjTableEntity Obj)
- {
- ObjContext.Delete(Obj);
- }
- }
カテゴリの操作は非常に簡単です。AddObjオブジェクトを追加する方法だけが特別な注意に値します。テーブルへのエントリの追加に加えて、オブジェクトのコンテンツとともにBlobも追加され、IDでコンテンツを取得できます。
したがって、テーブル(クラウド側でレコードを選択する機能)とBlob-s(実質的に無制限のボリュームの要素のストレージ)の両方の利点を使用しながら、それらの欠点を回避します。
基本的に私が共有したかったのはこれだけです。おそらくそれは誰かにとって明白であり、彼はすでにそれを100回やったことがありますが、誰かにとってはそれは良い興味深い素材であり、「クラウド」への移行を支持する別のポイントになります。