示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="tableName">The table name</param>
        /// <param name="storageConnectionString">The connection string</param>
        /// <param name="options">Table storage options</param>
        protected TableStoreBase(string tableName, string storageConnectionString, TableStorageOptions options)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("Table name cannot be null or empty", nameof(tableName));
            }

            if (string.IsNullOrWhiteSpace(storageConnectionString))
            {
                throw new ArgumentException("Table connection string cannot be null or empty", nameof(storageConnectionString));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "Table storage options cannot be null");
            }

            var validator = new TableStorageOptionsValidator();

            validator.ValidateAndThrow(options);

            OptimisePerformance(storageConnectionString, options);
            var cloudTableClient = CreateTableClient(storageConnectionString, options.Retries, options.RetryWaitTimeInSeconds);

            CloudTable = cloudTableClient.GetTableReference(tableName);

            if (options.EnsureTableExists)
            {
                if (!TableExists())
                {
                    CreateTable();
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="tableName">The table name</param>
        /// <param name="storageConnectionString">The connection string</param>
        /// <param name="options">Table storage options</param>
        public TableStore(string tableName, string storageConnectionString, TableStorageOptions options)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("Table name cannot be null or empty", nameof(tableName));
            }

            if (string.IsNullOrWhiteSpace(storageConnectionString))
            {
                throw new ArgumentException("Table connection string cannot be null or empty", nameof(storageConnectionString));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "Table storage options cannot be null");
            }

            var validator = new TableStorageOptionsValidator();

            validator.ValidateAndThrow(options);

            OptimisePerformance(storageConnectionString, options);
            var cloudTableClient = CreateTableClient(storageConnectionString, options.Retries, options.RetryWaitTimeInSeconds);

            _cloudTable = cloudTableClient.GetTableReference(tableName);

            if (options.EnsureTableExists)
            {
#if NETCOREAPP2_0 || NETCOREAPP2_1
                CreateTableAsync().Wait();
#else
                CreateTable();
#endif
            }
        }
示例#3
0
        /// <summary>
        /// Settings to improve performance
        /// </summary>
        private static void OptimisePerformance(string storageConnectionString, TableStorageOptions options)
        {
            var account           = CloudStorageAccount.Parse(storageConnectionString);
            var tableServicePoint = ServicePointManager.FindServicePoint(account.TableEndpoint);

            tableServicePoint.UseNagleAlgorithm = options.UseNagleAlgorithm;
            tableServicePoint.Expect100Continue = options.Expect100Continue;
            tableServicePoint.ConnectionLimit   = options.ConnectionLimit;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="tableName">The table name</param>
 /// <param name="storageConnectionString">The connection string</param>
 /// <param name="options">Table storage options</param>
 public TableStore(string tableName, string storageConnectionString, TableStorageOptions options)
     : base(tableName, storageConnectionString, options)
 {
 }