示例#1
0
        /// <summary>
        /// Inserts the record into the table storage table, asynchronously.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <returns>Task.</returns>
        /// <exception cref="ArgumentNullException">record</exception>
        public Task InsertAsync(T record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            var entity = CreateEntity(record);

            return(_tableStore.InsertAsync(entity));
        }
        /// <inheritdoc />
        public Task IndexAsync(T data, string index)
        {
            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentException(nameof(index));
            }

            if (index.Length > 255)
            {
                throw new ArgumentException(nameof(index));
            }

            if (index.Length > _options.MaximumIndexLength && _options.ThrowOnMaximumIndexLengthExceeded)
            {
                throw new ArgumentException(nameof(index));
            }

            if (!_options.IsCaseSensitive)
            {
                index = index.ToLowerInvariant();
            }

            if (index.Length < _options.MinimumIndexLength)
            {
                if (_options.ThrowOnMinimumIndexLengthNotMet)
                {
                    throw new ArgumentException(nameof(index));
                }

                return(Task.FromResult(0));
            }

            var rowKeyValue = GetRowKeyValue(data).ToString();

            var terms = CreateIndexTerms(index);

            return(terms.ParallelForEachAsync(async term =>
            {
                try
                {
                    var entry = new TrieEntry <T> {
                        Data = data, Index = term, Key = GetRowKeyValue(data).ToString()
                    };

                    await _tableStore.InsertAsync(entry.ToTableEntity(term, rowKeyValue, x => x.Index, x => x.Key))
                    .ConfigureAwait(false);
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    if (_options.ThrowOnConflict)
                    {
                        throw;
                    }
                }
            }));
        }