本文整理汇总了C#中TableBatchOperation.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# TableBatchOperation.Insert方法的具体用法?C# TableBatchOperation.Insert怎么用?C# TableBatchOperation.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableBatchOperation
的用法示例。
在下文中一共展示了TableBatchOperation.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TableBatchAddNullShouldThrow
public void TableBatchAddNullShouldThrow()
{
TableBatchOperation batch = new TableBatchOperation();
try
{
batch.Add(null);
Assert.Fail();
}
catch (ArgumentNullException)
{
// no op
}
catch (Exception)
{
Assert.Fail();
}
try
{
batch.Insert(0, null);
Assert.Fail();
}
catch (ArgumentNullException)
{
// no op
}
catch (Exception)
{
Assert.Fail();
}
}
示例2: Add
public async void Add(IList<ITableEntity> notes)
{
var batchOperation = new TableBatchOperation();
notes.ToList().ForEach(n => batchOperation.Insert(n));
await _table.ExecuteBatchAsync(batchOperation);
}
示例3: DoInsert
async Task<CommandResult> DoInsert(CloudTable table, long n, Func<long, EntityNk[]> entityFactory)
{
var batchOperation = new TableBatchOperation();
foreach (var e in entityFactory(n))
{
batchOperation.Insert(e);
}
var cresult = new CommandResult { Start = DateTime.UtcNow.Ticks };
var cbt = 0L;
var context = GetOperationContext((t) => cbt = t);
try
{
var results = await table.ExecuteBatchAsync(batchOperation, operationContext: context);
cresult.Elapsed = cbt;
}
catch (Exception ex)
{
cresult.Elapsed = -1;
Console.Error.WriteLine("Error DoInsert {0} {1}", n, ex.ToString());
}
return cresult;
}
示例4: Append
protected override void Append(LoggingEvent[] loggingEvents)
{
try
{
TableBatchOperation batchOperation = new TableBatchOperation();
base.Append(loggingEvents);
foreach (var e in loggingEvents)
{
var logitem = new LogItem
{
Exception = e.GetExceptionString(),
Level = e.Level.Name,
LoggerName = e.LoggerName,
Message = e.RenderedMessage,
RoleInstance = RoleInfo
};
batchOperation.Insert(logitem);
}
_log4NetTable.ExecuteBatch(batchOperation);
}
catch (Exception ex)
{
Trace.TraceError("AzureTableAppender Append " + ex.Message);
}
}
示例5: ComposeBatch
private TableBatchOperation ComposeBatch(IEnumerable<LogEvent> events)
{
var batch = new TableBatchOperation();
foreach (LogEvent e in events)
{
var row = new ElasticTableEntity
{
PartitionKey = e.EventTime.ToString("yy-MM-dd"),
RowKey = e.EventTime.ToString("HH-mm-ss-fff")
};
row.Add("source", e.SourceName);
row.Add("severity", e.Severity);
row.Add("message", e.FormattedMessage);
row.Add("error", e.ErrorException == null ? string.Empty : e.ErrorException.ToString());
if (e.Properties != null)
{
foreach (var p in e.Properties)
{
if (p.Key == LogEvent.ErrorPropertyName) continue;
row.Add(p.Key, p.Value);
}
}
batch.Insert(row);
}
return batch.Count > 0 ? batch : null;
}
示例6: InsertBets
private void InsertBets()
{
if (this.Bets.Count == 0)
{
return;
}
var tableBets = this.CreateTableClient("Bet");
tableBets.CreateIfNotExists();
var batchOperation = new TableBatchOperation();
foreach (var kvp in this.Bets)
{
var bet = new BetEntity();
bet.TicketNumber = kvp.Key;
bet.BetNumber = kvp.Value;
bet.RaffleId = this.RaffleId;
batchOperation.Insert(bet);
}
tableBets.ExecuteBatch(batchOperation);
}
示例7: SaveToStorageInBatch
public void SaveToStorageInBatch(List<Log> list)
{
var batchOperation = new TableBatchOperation();
foreach (var log in list)
{
var entity = GetLogTableEntity(log);
batchOperation.Insert(entity);
}
var result = _table.ExecuteBatch(batchOperation);
}
示例8: About
public ActionResult About()
{
var storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
var client = storageAccount.CreateCloudTableClient();
var stebraTable = client.GetTableReference("StebraList");
if (!stebraTable.Exists())
{
stebraTable.Create();
}
TableOperation retrieveOperation = TableOperation.Retrieve<StebraEntity>("WeAreStebra", "ListItem3");
// Execute the operation.
TableResult retrievedResult = stebraTable.Execute(retrieveOperation);
StebraEntity result = (StebraEntity)retrievedResult.Result;
if (result != null)
{
result.ImageUrl = "http://cdn.buzznet.com/assets/users16/crizz/default/funny-pictures-thriller-kitten-impresses--large-msg-121404159787.jpg";
//var awesomeStebra = new StebraEntity("WeAreStebra", "ListItem2");
//awesomeStebra.ImageUrl = "http://rubmint.com/wp-content/plugins/wp-o-matic/cache/6cb1b_funny-pictures-colur-blind-kitteh-finded-yew-a-pumikin.jpg";
//var coolStebra = new StebraEntity("WeAreStebra", "ListItem2");
//coolStebra.ImageUrl = "http://rubmint.com/wp-content/plugins/wp-o-matic/cache/6cb1b_funny-pictures-colur-blind-kitteh-finded-yew-a-pumikin.jpg";
//var batchOperation = new TableBatchOperation();
TableOperation batchOperation = TableOperation.InsertOrReplace(result);
//batchOperation.Insert(awesomeStebra);
//batchOperation.Insert(coolStebra);
//stebraTable.ExecuteBatch(batchOperation);
stebraTable.Execute(batchOperation);
}
else
{
var awesomeStebra = new StebraEntity("WeAreStebra", "ListItem3");
awesomeStebra.ImageUrl = "http://rubmint.com/wp-content/plugins/wp-o-matic/cache/6cb1b_funny-pictures-colur-blind-kitteh-finded-yew-a-pumikin.jpg";
var batchOperation = new TableBatchOperation();
batchOperation.Insert(awesomeStebra);
stebraTable.ExecuteBatch(batchOperation);
}
return View();
}
示例9: Main
static void Main(string[] args)
{
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
var storageAccount = CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("employee1");
table.CreateIfNotExists();
var employeeEntity1 = new EmployeeEntity("Kasagoni", "Person1")
{
Email = "[email protected]",
PhoneNumber = "123-456-7890"
};
var employeeEntity2 = new EmployeeEntity("Kasagoni", "Person2")
{
Email = "[email protected]",
PhoneNumber = "123-456-7890"
};
var employeeEntity3 = new EmployeeEntity("Kasagoni", "Person3")
{
Email = "[email protected]",
PhoneNumber = "123-456-7890"
};
var batchOpertaion = new TableBatchOperation();
batchOpertaion.Insert(employeeEntity1);
batchOpertaion.Insert(employeeEntity2);
batchOpertaion.Insert(employeeEntity3);
table.ExecuteBatch(batchOpertaion);
Console.WriteLine("Table Storage Operations Complete, Press Any Key to Exit!");
Console.ReadKey();
}
示例10: BackupPostCollection
private static async Task BackupPostCollection(DocumentCollection dc, DocumentClient client)
{
Trace.TraceInformation("Collection '{0}' start. Time: '{1}'", dc.Id,
DateTime.Now.ToString(CultureInfo.CurrentCulture));
try
{
var ds =
from d in client.CreateDocumentQuery<PostMessage>(dc.DocumentsLink)
where d.Type == "Post"
select d;
TableBatchOperation batchOperation = new TableBatchOperation();
List<dynamic> docList = new List<dynamic>();
foreach (var d in ds)
{
TablePost c = ModelService.TablePostData(d);
batchOperation.Insert(c);
docList.Add(d);
if (batchOperation.Count == 100)
{
var operation = batchOperation;
var res = await _retryPolicy.ExecuteAsync(
() => _table.ExecuteBatchAsync(operation));
batchOperation = new TableBatchOperation();
if (res.Count == operation.Count)
{
await _iDbService.DocumentDb.BatchDelete(dc, docList);
docList = new List<dynamic>();
Trace.TraceInformation("inserted");
}
}
}
if (batchOperation.Count > 0)
{
var operation = batchOperation;
var res = await _retryPolicy.ExecuteAsync(
() => _table.ExecuteBatchAsync(operation));
if (res.Count == operation.Count)
{
await _iDbService.DocumentDb.BatchDelete(dc, docList);
Trace.TraceInformation("inserted");
}
}
}
catch (Exception e)
{
Trace.TraceError("Error in BackupCollection " + e.Message);
}
}
示例11: AddUser
public void AddUser(int dddEventId, int eventbriteOrderNo, string firstName, string lastName, string userToken, string clientToken)
{
var mapping = new EventBriteUserTokenMapping
{
PartitionKey = dddEventId.ToString(),
RowKey = eventbriteOrderNo.ToString(),
UserToken = userToken,
ClientToken = clientToken
};
var user = new User
{
PartitionKey = dddEventId.ToString(),
RowKey = userToken,
FirstName = firstName,
LastName = lastName
};
TableBatchOperation batch = new TableBatchOperation();
batch.Insert(mapping);
batch.Insert(user);
usersTable.ExecuteBatch(batch);
}
示例12: SendBuffer
protected override void SendBuffer(LoggingEvent[] events)
{
var grouped = events.GroupBy(evt => evt.LoggerName);
foreach (var group in grouped)
{
foreach (var batch in group.Batch(100))
{
var batchOperation = new TableBatchOperation();
foreach (var azureLoggingEvent in batch.Select(GetLogEntity))
{
batchOperation.Insert(azureLoggingEvent);
}
_table.ExecuteBatch(batchOperation);
}
}
}
示例13: Post
public async Task<IEnumerable<string>> Post()
{
var watch = new Stopwatch();
var result = new List<string>();
var table = _client.GetTableReference(TableName);
await table.CreateIfNotExistsAsync();
for (int i = 1; i < 11; i++)
{
watch.Restart();
var batch = new TableBatchOperation();
batch.Insert(new Customer { RowKey = "1000" + i, PartitionKey = "None", Forename = "Bernd", Surname = "Mayer" });
await table.ExecuteBatchAsync(batch);
watch.Stop();
result.Add($"Azure Table Save {i} try: {watch.ElapsedMilliseconds}");
}
return result;
}
示例14: Save
public void Save(MessageLogEntity entity)
{
TableBatchOperation batchOperation = new TableBatchOperation();
this.retryPolicy.ExecuteAction(() =>
{
var context = this.tableClient.GetTableReference(this.tableName);
batchOperation.Insert(entity);
try
{
context.ExecuteBatch(batchOperation);
}
catch
{
}
});
}
示例15: SaveNews
//save news to azure table from inparameter listItems
public static void SaveNews(ListItemCollection listItems)
{
var batchOperation = new TableBatchOperation(); //make only one call to Azure Table, use Batch.
foreach (ListItem item in listItems)
{
//Convert ListItems to Table-entries(Entity)
var entity = new StebraEntity(
"News", //string Stebratype
item["Title"].ToString(), //string newsEntry
"Descriptive text", //string NewsDescription
item["Article"].ToString(), //string NewsArticle
item["Datum"].ToString(), //string NewsDate
item["Body"].ToString() //string NewsBody
);
batchOperation.Insert(entity); //Batch this
}
NewsTable.ExecuteBatch(batchOperation); //Execute Batch
}