Example #1
0
        public ITableArgumentBinding TryCreate(Type parameterType)
        {
            if (!parameterType.IsGenericType ||
                (parameterType.GetGenericTypeDefinition() != typeof(IAsyncCollector <>)))
            {
                return(null);
            }

            Type entityType = GetCollectorItemType(parameterType);

            if (!TableClient.ImplementsOrEqualsITableEntity(entityType))
            {
                TableClient.VerifyContainsProperty(entityType, "RowKey");
                TableClient.VerifyContainsProperty(entityType, "PartitionKey");
            }

            return(CreateBinding(entityType));
        }
Example #2
0
        public IStorageTableArgumentBinding TryCreate(ParameterInfo parameter)
        {
            if (!parameter.ParameterType.IsGenericType || parameter.ParameterType.GetGenericTypeDefinition() != typeof(IQueryable <>))
            {
                return(null);
            }

            Type entityType = GetQueryableItemType(parameter.ParameterType);

            if (!TableClient.ImplementsITableEntity(entityType))
            {
                throw new InvalidOperationException("IQueryable is only supported on types that implement ITableEntity.");
            }

            TableClient.VerifyDefaultConstructor(entityType);

            return(CreateBinding(entityType));
        }
Example #3
0
        public static IBindableTableEntityPath Create(string tableNamePattern, string partitionKeyPattern,
                                                      string rowKeyPattern)
        {
            BindingTemplate tableNameTemplate    = BindingTemplate.FromString(tableNamePattern);
            BindingTemplate partitionKeyTemplate = BindingTemplate.FromString(partitionKeyPattern);
            BindingTemplate rowKeyTemplate       = BindingTemplate.FromString(rowKeyPattern);

            if (tableNameTemplate.HasParameters ||
                partitionKeyTemplate.HasParameters ||
                rowKeyTemplate.HasParameters)
            {
                return(new ParameterizedTableEntityPath(tableNameTemplate, partitionKeyTemplate, rowKeyTemplate));
            }

            TableClient.ValidateAzureTableName(tableNamePattern);
            TableClient.ValidateAzureTableKeyValue(partitionKeyPattern);
            TableClient.ValidateAzureTableKeyValue(rowKeyPattern);
            TableEntityPath innerPath = new TableEntityPath(tableNamePattern, partitionKeyPattern, rowKeyPattern);

            return(new BoundTableEntityPath(innerPath));
        }
Example #4
0
        public static bool TryParseAndValidate(string value, out TableEntityPath path)
        {
            if (value == null)
            {
                path = null;
                return(false);
            }

            string[] components = value.Split(new char[] { '/' });
            if (components.Length != 3)
            {
                path = null;
                return(false);
            }

            string tableName    = components[0];
            string partitionKey = components[1];
            string rowKey       = components[2];

            if (!TableClient.IsValidAzureTableName(tableName))
            {
                path = null;
                return(false);
            }

            if (!TableClient.IsValidAzureTableKeyValue(partitionKey))
            {
                path = null;
                return(false);
            }

            if (!TableClient.IsValidAzureTableKeyValue(rowKey))
            {
                path = null;
                return(false);
            }

            path = new TableEntityPath(tableName, partitionKey, rowKey);
            return(true);
        }
Example #5
0
        public async Task AddAsync(T item, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Careful:
            // 1. even with upsert, all rowkeys within a batch must be unique. If they aren't, the previous items
            // will be flushed.
            // 2. Capture at time of Add, in case item is mutated after add.
            // 3. Validate rowkey on the client so we get a nice error instead of the cryptic 400 from auzre.

            string partitionKey = item.PartitionKey;
            string rowKey       = item.RowKey;

            TableClient.ValidateAzureTableKeyValue(partitionKey);
            TableClient.ValidateAzureTableKeyValue(rowKey);

            Dictionary <string, IStorageTableOperation> partition;

            if (!_map.TryGetValue(partitionKey, out partition))
            {
                if (_map.Count >= MaxPartitionWidth)
                {
                    // Offline cache is too large. Clear some room
                    await FlushAsync(cancellationToken);
                }

                partition          = new Dictionary <string, IStorageTableOperation>();
                _map[partitionKey] = partition;
            }

            var itemCopy = Copy(item);

            if (partition.ContainsKey(rowKey))
            {
                // Replacing item forces a flush to ensure correct eTag behaviour.
                await FlushPartitionAsync(partition, cancellationToken);

                // Reinitialize partition
                partition          = new Dictionary <string, IStorageTableOperation>();
                _map[partitionKey] = partition;
            }

            _log.EntitiesWritten++;

            if (String.IsNullOrEmpty(itemCopy.ETag))
            {
                partition.Add(rowKey, _table.CreateInsertOperation(itemCopy));
            }
            else if (itemCopy.ETag.Equals("*"))
            {
                partition.Add(rowKey, _table.CreateInsertOrReplaceOperation(itemCopy));
            }
            else
            {
                partition.Add(rowKey, _table.CreateReplaceOperation(itemCopy));
            }

            if (partition.Count >= MaxBatchSize)
            {
                await FlushPartitionAsync(partition, cancellationToken);

                _map.Remove(partitionKey);
            }
        }
Example #6
0
 public static string Validate(string value)
 {
     TableClient.ValidateAzureTableName(value);
     return(value);
 }