示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageTableLoader{TIn, TOut}"/> class.
        /// </summary>
        /// <param name="tableName">The name of the table to load.</param>
        /// <param name="mapEntityFunc">The map entity function, this maps the TIn to TOut</param>
        /// <param name="allPartitionKeys">All partition keys to load</param>
        /// <param name="connectionString">The connectionstring to the storage account.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <remarks>The table will start to load as soon as this type is constructed.</remarks>
        /// <remarks>The table will start to load as soon as this type is constructed.</remarks>
        public AzureStorageTableLoader(string connectionString
                                       , string tableName
                                       , Func <TIn, TOut> mapEntityFunc
                                       , IEnumerable <string> allPartitionKeys)
        {
            if (mapEntityFunc == null)
            {
                throw new ArgumentNullException(nameof(mapEntityFunc));
            }

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(connectionString));
            }

            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(tableName));
            }

            _mapEntityFunc = mapEntityFunc;
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            _tablePool = new CloudTablePool(tableName, storageAccount.CreateCloudTableClient());

            _readAllEntitiesTask = Task.Run(async() =>
            {
                _allEntities = await ReadAllEntitiesFromTableStorage(allPartitionKeys);
            });
        }
        public static bool RowExistsForRowKey(this ITablePool <CloudTable> tablePool, string rowKey)
        {
            var        queryFilter = TableQuery.GenerateFilterCondition(RowKeyField, OpEquals, rowKey);
            TableQuery query       = new TableQuery();

            query.SelectColumns = QuerySelectColumnsPartitionKeyRowKeyOnly;
            query.FilterString  = queryFilter;

            return(tablePool.Execute(table =>
            {
                var result = table.ExecuteQuery(query);
                return result.Any();
            }));
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageTableLoader{TIn, TOut}"/> class.
        /// </summary>
        /// <param name="table">The table to load entities from.</param>
        /// <param name="mapEntityFunc">The map entity function, this maps the TIn to TOut</param>
        /// <param name="allPartitionKeys">All partition keys to load</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <remarks>The table will start to load as soon as this type is constructed.</remarks>
        public AzureStorageTableLoader(CloudTable table
                                       , Func <TIn, TOut> mapEntityFunc
                                       , IEnumerable <string> allPartitionKeys)
        {
            if (mapEntityFunc == null)
            {
                throw new ArgumentNullException(nameof(mapEntityFunc));
            }

            _mapEntityFunc = mapEntityFunc;

            _tablePool = new CloudTablePool(table.Name, table.ServiceClient);

            _readAllEntitiesTask = Task.Run(async() =>
            {
                _allEntities = await ReadAllEntitiesFromTableStorage(allPartitionKeys);
            });
        }