public void OnStored(Type modelType, nStoreOperation storaeOperationType, int modelCount, Exception e) { if (!StoreOperations.ContainsKey(storaeOperationType)) { StoreOperations[storaeOperationType] = 0; } StoreOperations[storaeOperationType]++; }
public async Task StoreAsync <T>(nStoreOperation storageOperationType, IEnumerable <T> models) where T : new() { try { // Retrieve a reference to the table. CloudTable table = GetTableReference(GetTableName <T>()); // Create the batch operation. TableBatchOperation batchOperation = new TableBatchOperation(); // lookup the entitymapper var entityMapper = _entityMapperRegistry[typeof(T)]; // Add all items foreach (var model in models) { switch (storageOperationType) { case nStoreOperation.insertOperation: batchOperation.Insert(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.insertOrReplaceOperation: batchOperation.InsertOrReplace(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.mergeOperation: batchOperation.Merge(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.mergeOrInserOperation: batchOperation.InsertOrMerge(new DynamicTableEntity <T>(model, entityMapper)); break; } } // execute await table.ExecuteBatchAsync(batchOperation); } catch (StorageException ex) { // check the exception if (!_autoCreateTable || !ex.Message.StartsWith("0:The table specified does not exist", StringComparison.CurrentCulture)) { throw ex; } // try to create the table await CreateTableAsync <T>(); // retry await StoreAsync <T>(storageOperationType, models); } }
public async Task StoreAsync <T>(nStoreOperation storaeOperationType, IEnumerable <T> models) where T : new() { try { // notify delegate if (_delegate != null) { _delegate.OnStoring(typeof(T), storaeOperationType); } // Retrieve a reference to the table. CloudTable table = GetTableReference(GetTableName <T>()); // Create the batch operation. List <TableBatchOperation> batchOperations = new List <TableBatchOperation>(); // Create the first batch var currentBatch = new TableBatchOperation(); batchOperations.Add(currentBatch); // lookup the entitymapper var entityMapper = _entityMapperRegistry[typeof(T)]; // define the modelcounter int modelCounter = 0; // Add all items foreach (var model in models) { switch (storaeOperationType) { case nStoreOperation.insertOperation: currentBatch.Insert(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.insertOrReplaceOperation: currentBatch.InsertOrReplace(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.mergeOperation: currentBatch.Merge(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.mergeOrInserOperation: currentBatch.InsertOrMerge(new DynamicTableEntity <T>(model, entityMapper)); break; case nStoreOperation.delete: currentBatch.Delete(new DynamicTableEntity <T>(model, entityMapper)); break; } modelCounter++; if (modelCounter % 100 == 0) { currentBatch = new TableBatchOperation(); batchOperations.Add(currentBatch); } } // execute foreach (var createdBatch in batchOperations) { if (createdBatch.Count() > 0) { await table.ExecuteBatchAsync(createdBatch); // notify delegate if (_delegate != null) { _delegate.OnStored(typeof(T), storaeOperationType, createdBatch.Count(), null); } } } } catch (StorageException ex) { // check the exception if (_autoCreateTable && ex.Message.StartsWith("0:The table specified does not exist", StringComparison.CurrentCulture)) { // try to create the table await CreateTableAsync <T>(); // retry await StoreAsync <T>(storaeOperationType, models); } else { // notify delegate if (_delegate != null) { _delegate.OnStored(typeof(T), storaeOperationType, 0, ex); } throw ex; } } }
public void OnStoring(Type modelType, nStoreOperation storaeOperationType) { }
public PagedTableEntityWriter(StorageContext parentContext, nStoreOperation operation, int pageSize) { _pageSize = pageSize > 100 ? 100 : pageSize; _operation = operation; _parentContext = parentContext; }