コード例 #1
0
 private static IObjectToTypeConverter<IStorageTable> CreateConverter(IStorageTableClient client, IBindableTablePath path)
 {
     return new CompositeObjectToTypeConverter<IStorageTable>(
         new OutputConverter<IStorageTable>(new IdentityConverter<IStorageTable>()),
         new OutputConverter<CloudTable>(new CloudTableToStorageTableConverter()),
         new OutputConverter<string>(new StringToStorageTableConverter(client, path)));
 }
コード例 #2
0
 private static IObjectToTypeConverter <IStorageTable> CreateConverter(IStorageTableClient client,
                                                                       IBindableTablePath path)
 {
     return(new CompositeObjectToTypeConverter <IStorageTable>(
                new OutputConverter <IStorageTable>(new IdentityConverter <IStorageTable>()),
                new OutputConverter <CloudTable>(new CloudTableToStorageTableConverter()),
                new OutputConverter <string>(new StringToStorageTableConverter(client, path))));
 }
コード例 #3
0
        public async Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            ParameterInfo  parameter      = context.Parameter;
            TableAttribute tableAttribute = parameter.GetCustomAttribute <TableAttribute>(inherit: false);

            if (tableAttribute == null)
            {
                return(null);
            }

            string          tableName = Resolve(tableAttribute.TableName);
            IStorageAccount account   = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken, _nameResolver);

            // requires storage account with table support
            account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);

            StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext
            {
                Parameter = context.Parameter
            };
            IStorageTableClient client = account.CreateTableClient(clientFactoryContext);

            bool     bindsToEntireTable = tableAttribute.RowKey == null;
            IBinding binding;

            if (bindsToEntireTable)
            {
                IBindableTablePath path = BindableTablePath.Create(tableName);
                path.ValidateContractCompatibility(context.BindingDataContract);

                IStorageTableArgumentBinding argumentBinding = _tableBindingProvider.TryCreate(parameter);

                if (argumentBinding == null)
                {
                    throw new InvalidOperationException("Can't bind Table to type '" + parameter.ParameterType + "'.");
                }

                binding = new TableBinding(parameter.Name, argumentBinding, client, path);
            }
            else
            {
                string partitionKey           = Resolve(tableAttribute.PartitionKey);
                string rowKey                 = Resolve(tableAttribute.RowKey);
                IBindableTableEntityPath path = BindableTableEntityPath.Create(tableName, partitionKey, rowKey);
                path.ValidateContractCompatibility(context.BindingDataContract);

                IArgumentBinding <TableEntityContext> argumentBinding = _entityBindingProvider.TryCreate(parameter);

                if (argumentBinding == null)
                {
                    throw new InvalidOperationException("Can't bind Table entity to type '" + parameter.ParameterType + "'.");
                }

                binding = new TableEntityBinding(parameter.Name, argumentBinding, client, path);
            }

            return(binding);
        }
コード例 #4
0
 public TableBinding(string parameterName, ITableArgumentBinding argumentBinding, IStorageTableClient client, IBindableTablePath path)
 {
     _parameterName = parameterName;
     _argumentBinding = argumentBinding;
     _client = client;
     _accountName = TableClient.GetAccountName(client);
     _path = path;
     _converter = CreateConverter(client, path);
 }
コード例 #5
0
 public TableBinding(string parameterName, IStorageTableArgumentBinding argumentBinding, IStorageTableClient client, IBindableTablePath path)
 {
     _parameterName   = parameterName;
     _argumentBinding = argumentBinding;
     _client          = client;
     _accountName     = TableClient.GetAccountName(client);
     _path            = path;
     _converter       = CreateConverter(client, path);
 }
コード例 #6
0
 public StringToStorageTableConverter(IStorageTableClient client, IBindableTablePath defaultPath)
 {
     _client      = client;
     _defaultPath = defaultPath;
 }