aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web/ExtensionMethods
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-02-24 00:57:14 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-02-24 00:57:14 +0200
commit0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b (patch)
treebb5e4055020aa4417e1f7703a611353ce44689d6 /Software/Visual_Studio/Tango.Web/ExtensionMethods
parent17612c08da93c75d4c941a643bc7602c18f351d8 (diff)
downloadTango-0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b.tar.gz
Tango-0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b.zip
Working on refresh tokens...
Diffstat (limited to 'Software/Visual_Studio/Tango.Web/ExtensionMethods')
-rw-r--r--Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs
new file mode 100644
index 000000000..43c4804d3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs
@@ -0,0 +1,69 @@
+using Microsoft.WindowsAzure.Storage.Table;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+public static class CloudTableExtensions
+{
+ /// <summary>
+ /// Demonstrate the most efficient storage query - the point query - where both partition key and row key are specified.
+ /// </summary>
+ /// <param name="table">Sample table name</param>
+ /// <param name="partitionKey">Partition key - i.e., last name</param>
+ /// <param name="rowKey">Row key - i.e., first name</param>
+ /// <returns>A Task object</returns>
+ public static async Task<T> GetEntityAsync<T>(this CloudTable table, string partitionKey, string rowKey) where T : class, ITableEntity
+ {
+ TableOperation retrieveOperation = TableOperation.Retrieve<T>(partitionKey, rowKey);
+ TableResult result = await table.ExecuteAsync(retrieveOperation);
+ T customer = result.Result as T;
+ return customer;
+ }
+
+ /// <summary>
+ /// The Table Service supports two main types of insert operations.
+ /// 1. Insert - insert a new entity. If an entity already exists with the same PK + RK an exception will be thrown.
+ /// 2. Replace - replace an existing entity. Replace an existing entity with a new entity.
+ /// 3. Insert or Replace - insert the entity if the entity does not exist, or if the entity exists, replace the existing one.
+ /// 4. Insert or Merge - insert the entity if the entity does not exist or, if the entity exists, merges the provided entity properties with the already existing ones.
+ /// </summary>
+ /// <param name="table">The sample table name</param>
+ /// <param name="entity">The entity to insert or merge</param>
+ /// <returns>A Task object</returns>
+ public static async Task<T> InsertOrUpdateEntityAsync<T>(this CloudTable table, T entity) where T : class, ITableEntity
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException("Specified entity is null.");
+ }
+
+ // Create the InsertOrReplace table operation
+ TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);
+
+ // Execute the operation.
+ TableResult result = await table.ExecuteAsync(insertOrMergeOperation);
+ T insertedCustomer = result.Result as T;
+
+ return insertedCustomer;
+ }
+
+ /// <summary>
+ /// Delete an entity
+ /// </summary>
+ /// <param name="table">Sample table name</param>
+ /// <param name="deleteEntity">Entity to delete</param>
+ /// <returns>A Task object</returns>
+ public static async Task DeleteEntityAsync<T>(this CloudTable table, T deleteEntity) where T : class, ITableEntity
+ {
+ if (deleteEntity == null)
+ {
+ throw new ArgumentNullException("Specified entity was null.");
+ }
+
+ TableOperation deleteOperation = TableOperation.Delete(deleteEntity);
+ await table.ExecuteAsync(deleteOperation);
+ }
+}