コード例 #1
0
        /// <summary>
        /// Validate the table access policy
        /// </summary>
        /// <param name="policy">SharedAccessBlobPolicy object</param>
        /// <param name="policyIdentifier">The policy identifier which need to be checked.</param>
        internal static bool ValidateTableAccessPolicy(IStorageTableManagement channel,
                                                       string tableName, XTable.SharedAccessTablePolicy policy, string policyIdentifier)
        {
            if (string.IsNullOrEmpty(policyIdentifier))
            {
                return(true);
            }
            XTable.CloudTable          table      = channel.GetTableReference(tableName);
            XTable.TableRequestOptions options    = null;
            XTable.OperationContext    context    = null;
            XTable.TablePermissions    permission = channel.GetTablePermissions(table, options, context);

            XTable.SharedAccessTablePolicy sharedAccessPolicy =
                GetExistingPolicy <XTable.SharedAccessTablePolicy>(permission.SharedAccessPolicies, policyIdentifier);

            if (policy.Permissions != XTable.SharedAccessTablePermissions.None)
            {
                throw new ArgumentException(Resources.SignedPermissionsMustBeOmitted);
            }

            if (policy.SharedAccessExpiryTime.HasValue && sharedAccessPolicy.SharedAccessExpiryTime.HasValue)
            {
                throw new ArgumentException(Resources.SignedExpiryTimeMustBeOmitted);
            }

            return(!sharedAccessPolicy.SharedAccessExpiryTime.HasValue);
        }
コード例 #2
0
        /// <summary>
        /// Get Storage Table Operation Context for rest calls
        /// </summary>
        /// <param name="outputWriter">Output writer for writing logs for each rest call</param>
        /// <returns>Storage Table operation context</returns>
        public static XTable.OperationContext GetStorageTableOperationContext(Action <string> outputWriter)
        {
            if (!_inited)
            {
                Init();
            }

            var context = new XTable.OperationContext {
                ClientRequestID = ClientRequestId
            };

            context.SendingRequest += (s, e) =>
            {
                context.StartTime = DateTime.Now;

                Interlocked.Increment(ref _startedRemoteCallCounter);
                // TODO: Remove IfDef

                //https://github.com/Azure/azure-storage-net/issues/658
                var message = String.Format(Resources.StartRemoteCall,
                                            _startedRemoteCallCounter, String.Empty, e.Request.RequestUri.ToString());

                try
                {
                    outputWriter?.Invoke(message);
                }
                catch
                {
                    //catch the exception. If so, the storage client won't sleep and retry
                }
            };

            context.ResponseReceived += (s, e) =>
            {
                context.EndTime = DateTime.Now;
                Interlocked.Increment(ref _finishedRemoteCallCounter);

                var elapsedTime = (context.EndTime - context.StartTime).TotalMilliseconds;
                // TODO: Remove IfDef
                //https://github.com/Azure/azure-storage-net/issues/658
                var message = String.Format(Resources.FinishRemoteCall,
                                            e.Request.RequestUri.ToString(), String.Empty, String.Empty, e.RequestInformation.ServiceRequestID, elapsedTime);

                try
                {
                    outputWriter?.Invoke(message);
                }
                catch
                {
                    //catch the exception. If so, the storage client won't sleep and retry
                }
            };

            context.CustomUserAgent = ApiConstants.UserAgentHeaderValue;

            return(context);
        }
コード例 #3
0
 /// <summary>
 /// Delete the specified azure storage table
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 public void Delete(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     try
     {
         Task.Run(() => table.DeleteAsync(requestOptions, operationContext)).Wait();
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #4
0
        public override IDictionary <string, EntityProperty> WriteEntity(Microsoft.Azure.Cosmos.Table.OperationContext operationContext)
        {
            var entityProperties = base.WriteEntity(operationContext);

            var objectProperties = this.GetType().GetProperties();

            foreach (PropertyInfo property in objectProperties)
            {
                // see if the property has the attribute to not serialization, and if it does remove it from the entities to send to write
                object[] notSerializedAttributes = property.GetCustomAttributes(typeof(NotSerializedAttribute), false);
                if (notSerializedAttributes.Length > 0)
                {
                    entityProperties.Remove(property.Name);
                }
            }

            return(entityProperties);
        }
コード例 #5
0
        /// <summary>
        /// List azure storage tables
        /// </summary>
        /// <param name="prefix">Table name prefix</param>
        /// <param name="requestOptions">Table request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>An enumerable collection of tables that begin with the specified prefix</returns>
        public IEnumerable <CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
        {
            if (String.IsNullOrEmpty(prefix))
            {
                return(tableList);
            }
            else
            {
                List <CloudTable> prefixTables = new List <CloudTable>();

                foreach (CloudTable table in tableList)
                {
                    if (table.Name.ToLower().StartsWith(prefix.ToLower()))
                    {
                        prefixTables.Add(table);
                    }
                }

                return(prefixTables);
            }
        }
コード例 #6
0
 public void SetStorageTableServiceProperties(Azure.Cosmos.Table.ServiceProperties properties, XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 /// <summary>
 /// Return a task that asynchronously fetch table permissions
 /// </summary>
 /// <param name="table">target table</param>
 /// <param name="requestOptions">request options</param>
 /// <param name="operationContext">context</param>
 /// <returns></returns>
 public Task <TablePermissions> GetTablePermissionsAsync(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     return(Task.Factory.StartNew(() => this.GetTablePermissions(table,
                                                                 requestOptions, operationContext)));
 }
コード例 #8
0
 /// <summary>
 /// Set table permission
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="tablePermissions">table permissions</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns></returns>
 public void SetTablePermissions(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     this.tablePermissions = tablePermissions;
 }
コード例 #9
0
 public static IDictionary <string, EntityProperty> WriteUserObject(object entity, OperationContext operationContext)
 {
     CommonUtility.AssertNotNull("entity", entity);
     return(ReflectionWrite(entity, operationContext));
 }
コード例 #10
0
        /// <summary>
        /// List azure storage tables
        /// </summary>
        /// <param name="prefix">Table name prefix</param>
        /// <param name="requestOptions">Table request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>An enumerable collection of tables that begin with the specified prefix</returns>
        public IEnumerable <CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
        {
            //https://ahmet.im/blog/azure-listblobssegmentedasync-listcontainerssegmentedasync-how-to/
            TableContinuationToken continuationToken = null;
            var results = new List <CloudTable>();

            do
            {
                try
                {
                    var response = tableClient.ListTablesSegmentedAsync(prefix, null, continuationToken, requestOptions, operationContext).Result;
                    continuationToken = response.ContinuationToken;
                    results.AddRange(response.Results);
                }
                catch (AggregateException e) when(e.InnerException is XTable.StorageException)
                {
                    throw e.InnerException;
                }
            } while (continuationToken != null);
            return(results);
        }
コード例 #11
0
 public virtual void ReadEntity(IDictionary <string, EntityProperty> properties, OperationContext operationContext)
 {
     ReflectionRead(this, properties, operationContext);
 }
コード例 #12
0
 /// <summary>
 /// Set table permission
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="tablePermissions">table permissions</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns></returns>
 public void SetTablePermissions(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     try
     {
         Task.Run(() => table.SetPermissionsAsync(tablePermissions, requestOptions, operationContext)).Wait();
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #13
0
 /// <summary>
 /// Checks whether the table exists.
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>True if table exists; otherwise, false.</returns>
 public bool DoesTableExist(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     try
     {
         return(table.ExistsAsync(requestOptions, operationContext).Result);
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #14
0
 public static IDictionary <string, EntityProperty> Flatten(object entity, EntityPropertyConverterOptions entityPropertyConverterOptions, OperationContext operationContext)
 {
     CommonUtility.AssertNotNull("entity", entity);
     return(EntityPropertyConverter.Flatten(entity, entityPropertyConverterOptions, operationContext));
 }
コード例 #15
0
        private static void ReflectionRead(object entity, IDictionary <string, EntityProperty> properties, OperationContext operationContext)
        {
            foreach (PropertyInfo item in (IEnumerable <PropertyInfo>)entity.GetType().GetProperties())
            {
                if (!ShouldSkipProperty(item, operationContext))
                {
                    if (!properties.ContainsKey(item.Name))
                    {
                        Logger.LogInformational(operationContext, "Omitting property '{0}' from de-serialization because there is no corresponding entry in the dictionary provided.", item.Name);
                    }
                    else
                    {
                        EntityProperty entityProperty = properties[item.Name];
                        if (entityProperty.IsNull)
                        {
                            item.SetValue(entity, null, null);
                        }
                        else
                        {
                            switch (entityProperty.PropertyType)
                            {
                            case EdmType.String:
                                if (!(item.PropertyType != typeof(string)))
                                {
                                    item.SetValue(entity, entityProperty.StringValue, null);
                                }
                                break;

                            case EdmType.Binary:
                                if (!(item.PropertyType != typeof(byte[])))
                                {
                                    item.SetValue(entity, entityProperty.BinaryValue, null);
                                }
                                break;

                            case EdmType.Boolean:
                                if (!(item.PropertyType != typeof(bool)) || !(item.PropertyType != typeof(bool?)))
                                {
                                    item.SetValue(entity, entityProperty.BooleanValue, null);
                                }
                                break;

                            case EdmType.DateTime:
                                if (item.PropertyType == typeof(DateTime))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.Value.UtcDateTime, null);
                                }
                                else if (item.PropertyType == typeof(DateTime?))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.HasValue ? new DateTime?(entityProperty.DateTimeOffsetValue.Value.UtcDateTime) : null, null);
                                }
                                else if (item.PropertyType == typeof(DateTimeOffset))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue.Value, null);
                                }
                                else if (item.PropertyType == typeof(DateTimeOffset?))
                                {
                                    item.SetValue(entity, entityProperty.DateTimeOffsetValue, null);
                                }
                                break;

                            case EdmType.Double:
                                if (!(item.PropertyType != typeof(double)) || !(item.PropertyType != typeof(double?)))
                                {
                                    item.SetValue(entity, entityProperty.DoubleValue, null);
                                }
                                break;

                            case EdmType.Guid:
                                if (!(item.PropertyType != typeof(Guid)) || !(item.PropertyType != typeof(Guid?)))
                                {
                                    item.SetValue(entity, entityProperty.GuidValue, null);
                                }
                                break;

                            case EdmType.Int32:
                                if (!(item.PropertyType != typeof(int)) || !(item.PropertyType != typeof(int?)))
                                {
                                    item.SetValue(entity, entityProperty.Int32Value, null);
                                }
                                break;

                            case EdmType.Int64:
                                if (!(item.PropertyType != typeof(long)) || !(item.PropertyType != typeof(long?)))
                                {
                                    item.SetValue(entity, entityProperty.Int64Value, null);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
 public static TResult ConvertBack <TResult>(IDictionary <string, EntityProperty> properties, EntityPropertyConverterOptions entityPropertyConverterOptions, OperationContext operationContext)
 {
     return(EntityPropertyConverter.ConvertBack <TResult>(properties, entityPropertyConverterOptions, operationContext));
 }
コード例 #17
0
 public static void ReadUserObject(object entity, IDictionary <string, EntityProperty> properties, OperationContext operationContext)
 {
     CommonUtility.AssertNotNull("entity", entity);
     ReflectionRead(entity, properties, operationContext);
 }
コード例 #18
0
 /// <summary>
 /// Get table reference from azure server
 /// </summary>
 /// <param name="name">Table name</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>A CloudTable object if the specified table exists, otherwise null.</returns>
 public CloudTable GetTableReferenceFromServer(string name, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     foreach (CloudTable table in tableList)
     {
         if (table.Name == name)
         {
             return(table);
         }
     }
     return(null);
 }
コード例 #19
0
 /// <summary>
 /// Get the Table service properties
 /// </summary>
 /// <param name="account">Cloud storage account</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>The service properties of the specified service type</returns>
 public XTable.ServiceProperties GetStorageTableServiceProperties(XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     XTable.CloudStorageAccount account = StorageContext.TableStorageAccount;
     try
     {
         return(account.CreateCloudTableClient().GetServicePropertiesAsync(options, operationContext).Result);
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #20
0
 /// <summary>
 /// Return a task that asynchronously fetch table permissions
 /// </summary>
 /// <param name="table">target table</param>
 /// <param name="requestOptions">request options</param>
 /// <param name="operationContext">context</param>
 /// <returns></returns>
 public Task <TablePermissions> GetTablePermissionsAsync(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     return(Task.FromResult(this.GetTablePermissions(table, requestOptions, operationContext)));
 }
コード例 #21
0
        private static IDictionary <string, EntityProperty> ReflectionWrite(object entity, OperationContext operationContext)
        {
            Dictionary <string, EntityProperty> dictionary = new Dictionary <string, EntityProperty>();

            foreach (PropertyInfo item in (IEnumerable <PropertyInfo>)entity.GetType().GetProperties())
            {
                if (!ShouldSkipProperty(item, operationContext))
                {
                    EntityProperty entityProperty = EntityProperty.CreateEntityPropertyFromObject(item.GetValue(entity, null), item.PropertyType);
                    if (entityProperty != null)
                    {
                        dictionary.Add(item.Name, entityProperty);
                    }
                }
            }
            return(dictionary);
        }
コード例 #22
0
 /// <summary>
 /// Get table permission
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 public TablePermissions GetTablePermissions(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     try
     {
         return(table.GetPermissionsAsync(requestOptions, operationContext).Result);
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #23
0
        /// <summary>
        /// Cloud a azure storage table if not exists.
        /// </summary>
        /// <param name="table">Cloud table object</param>
        /// <param name="requestOptions">Table request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>True if table was created; otherwise, false.</returns>
        public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
        {
            CloudTable tableRef = GetTableReferenceFromServer(table.Name, requestOptions, operationContext);

            if (tableRef != null)
            {
                return(false);
            }
            else
            {
                tableRef = GetTableReference(table.Name);
                tableList.Add(tableRef);
                return(true);
            }
        }
コード例 #24
0
 /// <summary>
 /// Return a task that asynchronously set table permissions
 /// </summary>
 /// <param name="table">target table</param>
 /// <param name="tablePermissions">permissions to set</param>
 /// <param name="requestOptions">request options</param>
 /// <param name="operationContext">context</param>
 /// <returns></returns>
 public Task SetTablePermissionsAsync(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     return(table.SetPermissionsAsync(tablePermissions, requestOptions, operationContext));
 }
コード例 #25
0
 /// <summary>
 /// Delete the specified azure storage table
 /// </summary>
 /// <param name="table">Cloud table object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 public void Delete(CloudTable table, TableRequestOptions requestOptions = null, XTable.OperationContext operationContext = null)
 {
     foreach (CloudTable tableRef in tableList)
     {
         if (table.Name == tableRef.Name)
         {
             tableList.Remove(tableRef);
             return;
         }
     }
 }
コード例 #26
0
 /// <summary>
 /// Set Table service properties
 /// </summary>
 /// <param name="account">Cloud storage account</param>
 /// <param name="properties">Service properties</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation context</param>
 public void SetStorageTableServiceProperties(XTable.ServiceProperties properties, XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     XTable.CloudStorageAccount account = StorageContext.TableStorageAccount;
     try
     {
         Task.Run(() => account.CreateCloudTableClient().SetServicePropertiesAsync(properties, options, operationContext)).Wait();
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
コード例 #27
0
        /// <summary>
        /// Checks whether the table exists.
        /// </summary>
        /// <param name="table">Cloud table object</param>
        /// <param name="requestOptions">Table request options</param>
        /// <param name="operationContext">Operation context</param>
        /// <returns>True if table exists; otherwise, false.</returns>
        public bool DoesTableExist(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
        {
            foreach (CloudTable tableRef in tableList)
            {
                if (table.Name == tableRef.Name)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #28
0
 /// <summary>
 /// Get table permission
 /// </summary>
 /// <param name="table">CloudTable object</param>
 /// <param name="requestOptions">Table request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>Table permission</returns>
 public TablePermissions GetTablePermissions(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
 {
     return(this.tablePermissions);
 }
コード例 #29
0
 public virtual IDictionary <string, EntityProperty> WriteEntity(OperationContext operationContext)
 {
     return(ReflectionWrite(this, operationContext));
 }