当前位置: 首页>>代码示例>>C#>>正文


C# TableBatchOperation.Add方法代码示例

本文整理汇总了C#中TableBatchOperation.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TableBatchOperation.Add方法的具体用法?C# TableBatchOperation.Add怎么用?C# TableBatchOperation.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TableBatchOperation的用法示例。


在下文中一共展示了TableBatchOperation.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessEventsAsync

        public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
        {
            var batch = new TableBatchOperation();

            foreach(var msg in messages)
            {
                var snap = JsonConvert.DeserializeObject<BusSnapshotInfo>(Encoding.UTF8.GetString(msg.GetBytes()));

                var entity = new DynamicTableEntity(snap.RouteShortName, snap.VehicleId.ToString());

                entity.Properties.Add("RouteShortName", EntityProperty.GeneratePropertyForString(snap.RouteShortName));
                entity.Properties.Add("VehicleId", EntityProperty.GeneratePropertyForInt(snap.VehicleId));
                entity.Properties.Add("TripId", EntityProperty.GeneratePropertyForInt(snap.TripId));
                entity.Properties.Add("Latitude", EntityProperty.GeneratePropertyForDouble(snap.Latitude));
                entity.Properties.Add("Longitude", EntityProperty.GeneratePropertyForDouble(snap.Longitude));
                entity.Properties.Add("DirectionOfTravel", EntityProperty.GeneratePropertyForString(snap.DirectionOfTravel.ToString()));
                entity.Properties.Add("NextStopId", EntityProperty.GeneratePropertyForInt(snap.NextStopId));
                entity.Properties.Add("Timeliness", EntityProperty.GeneratePropertyForString(snap.Timeliness.ToString()));
                entity.Properties.Add("TimelinessOffset", EntityProperty.GeneratePropertyForInt(snap.TimelinessOffset));
                entity.Properties.Add("Timestamp", EntityProperty.GeneratePropertyForDateTimeOffset(snap.Timestamp));

                batch.Add(TableOperation.InsertOrReplace(entity));
            }

            var tableClient = _account.CreateCloudTableClient();

            var table = tableClient.GetTableReference("snapshots");

            await table.CreateIfNotExistsAsync();

            await table.ExecuteBatchAsync(batch);

            await context.CheckpointAsync();
        }
开发者ID:jplane,项目名称:TheMartaBus.AzureServiceFabric,代码行数:34,代码来源:StorageProcessor.cs

示例2: PopulateTableData

        private static void PopulateTableData(CloudTable cloudTable)
        {
            // if the table does not exist then create it and populate it wih some data
            if (!cloudTable.Exists())
            {
                cloudTable.CreateIfNotExists();

                var tableBatchOperation = new TableBatchOperation();
                for (int i = 0; i < 100; i++)
                {
                    tableBatchOperation.Add(
                        TableOperation.Insert(new Person(i.ToString(), string.Format("Person {0}", i))));
                }

                cloudTable.ExecuteBatch(tableBatchOperation);
            }
        }
开发者ID:linal,项目名称:AzureStorageTableDemo,代码行数:17,代码来源:Program.cs

示例3: CreateCustomerMetadata

        static void CreateCustomerMetadata(CloudTableClient tableClient)
        {
            Console.WriteLine("Creating customers metadata...");

            CloudTable customersMetadataTable = tableClient.GetTableReference("customersmetadata");
            customersMetadataTable.CreateIfNotExists();

            var msftAddress1 = new DictionaryTableEntity();
            msftAddress1.PartitionKey = "MSFT";
            msftAddress1.RowKey = "ADDRESS-" + Guid.NewGuid().ToString("N").ToUpper();
            msftAddress1.Add("city", "Seattle");
            msftAddress1.Add("street", "111 South Jackson");

            var msftWebsite1 = new DictionaryTableEntity();
            msftWebsite1.PartitionKey = "MSFT";
            msftWebsite1.RowKey = "WEBSITE-" + Guid.NewGuid().ToString("N").ToUpper();
            msftWebsite1.Add("url", "http://www.microsoft.com");

            var msftWebsite2 = new DictionaryTableEntity();
            msftWebsite2.PartitionKey = "MSFT";
            msftWebsite2.RowKey = "WEBSITE-" + Guid.NewGuid().ToString("N").ToUpper();
            msftWebsite2.Add("url", "http://www.windowsazure.com");

            var batch = new TableBatchOperation();
            batch.Add(TableOperation.Insert(msftAddress1));
            batch.Add(TableOperation.Insert(msftWebsite1));
            batch.Add(TableOperation.Insert(msftWebsite2));
            customersMetadataTable.ExecuteBatch(batch);

            Console.WriteLine("Done. Press ENTER to read the customer metadata.");
            Console.ReadLine();
        }
开发者ID:sandrinodimattia,项目名称:WindowsAzure-DictionaryTableEntity,代码行数:32,代码来源:Program.cs

示例4: AddEntryToTable

 public void AddEntryToTable(string tableName)
 {
     CloudTable table = cloudTableClient.GetTableReference(tableName);
     table.CreateIfNotExists();
     TableBatchOperation batch = new TableBatchOperation();
     batch.Add(TableOperation.Insert(new TableEntity { RowKey = "Abhishek", PartitionKey = "Kolkata" }));
     batch.Add(TableOperation.Insert(new TableEntity { RowKey = "Abhijit", PartitionKey = "Kolkata" }));
     table.ExecuteBatch(batch);
 }
开发者ID:solondon,项目名称:VisualStudio2013andNETCookbookCode,代码行数:9,代码来源:TableExample.cs

示例5: ClearTable

        void ClearTable(CloudTable table)
        {
            var deviceIds = _deviceService.GetDeviceIds();

            foreach (var partitionKey in deviceIds)
            {
                TableBatchOperation batchDelete = new TableBatchOperation();

                // gets all the entities in the table for this partition key
                string partitionCondition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey);
                List<DynamicTableEntity> entities = table.ExecuteQuery(new TableQuery().Where(partitionCondition)).ToList();

                entities.ForEach(e =>
                {
                    batchDelete.Add(TableOperation.Delete(e));

                    // Azure has a limit on batch operations
                    if (batchDelete.Count == 100)
                    {
                        table.ExecuteBatch(batchDelete);
                        batchDelete = new TableBatchOperation();
                    }
                });

                // flush out whatever is left
                if (batchDelete.Count > 0)
                {
                    table.ExecuteBatch(batchDelete);
                }
            }
        }
开发者ID:magoroku15,项目名称:azure-iot-predictive-maintenance,代码行数:31,代码来源:SimulationService.cs

示例6: 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();
            }
        }
开发者ID:farukc,项目名称:rtable,代码行数:31,代码来源:RTableBatchOperationTests.cs

示例7: GetReplyNotif

        public List<Reply> GetReplyNotif(string userid)
        {
            TableQuery<ReplyNotificationEntifity> query = new TableQuery<ReplyNotificationEntifity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, userid));

            List<Reply> replies = new List<Reply>();
            TableBatchOperation batchOperation = new TableBatchOperation();
            int count = 0;

            // Print the fields for each customer.
            foreach (ReplyNotificationEntifity entity in _replyNotification.ExecuteQuery(query))
            {
                replies.Add(JsonConvert.DeserializeObject<Reply>(entity.Content));

                batchOperation.Add(TableOperation.Delete(entity));
                count++;

                if((count % 100) == 0){
                    _replyNotification.ExecuteBatch(batchOperation);
                    batchOperation = new TableBatchOperation();
                    count = 0;
                }
            }

            if (count > 0)
            {
                _replyNotification.ExecuteBatch(batchOperation);
            }

            return replies;
        }
开发者ID:ptolemy,项目名称:MSGorilla,代码行数:30,代码来源:ReplyManager.cs

示例8: Persist

        public async Task Persist(ProjectionMetaData metadata)
        {
            Trace.TraceInformation("Preparing batch for projection {0}.", metadata.ProjectionType);

            var batch = new TableBatchOperation();

           
                var entity = new DictionaryTableEntity
                {
                    PartitionKey = metadata.ProjectionType,
                    RowKey = Handler.Current()
                };

                entity.Add("ProjectionHash", metadata.ProjectionHash);
                batch.Add(TableOperation.InsertOrReplace(entity));


                Trace.TraceInformation("Executing batch for projection {0}.", metadata.ProjectionType);
                await _table.ExecuteBatchAsync(batch).ContinueWith(r =>
                {
                    Trace.TraceInformation("Batch for projection {0} complete {1} exceptions.", metadata.ProjectionType, r.Exception != null ? "with" : "without");
                    if (r.Exception != null)
                    {
                        r.Exception.Handle(exception =>
                        {
                            Trace.TraceError(exception.ToString());
                            return true;
                        });
                    }
                });
        }
开发者ID:MessageHandler,项目名称:MessageHandler.SDK.EventSource,代码行数:31,代码来源:AzureTableStorageProjectionMetaDataRepository.cs

示例9: EmitBatch

        /// <summary>
        /// Emit a batch of log events, running to completion synchronously.
        /// </summary>
        /// <param name="events">The events to emit.</param>
        /// <remarks>Override either <see cref="PeriodicBatchingSink.EmitBatch"/> or <see cref="PeriodicBatchingSink.EmitBatchAsync"/>,
        /// not both.</remarks>
        protected override void EmitBatch(IEnumerable<LogEvent> events)
        {
            var operation = new TableBatchOperation();
            
            var first = true;
            
            foreach (var logEvent in events)
            {
                if (first)
                {
                    //check to make sure the partition key is not the same as the previous batch
                    if (partitionKey != logEvent.Timestamp.Ticks)
                    {
                        batchRowId = 0; //the partitionkey has been reset
                        partitionKey = logEvent.Timestamp.Ticks; //store the new partition key
                    }
                    first = false;
                }

                var logEventEntity = new LogEventEntity(logEvent, _formatProvider, partitionKey);
                logEventEntity.RowKey += "|" + batchRowId;
                operation.Add(TableOperation.Insert(logEventEntity));

                batchRowId++;
            }
            _table.ExecuteBatch(operation);
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:33,代码来源:AzureBatchingTableStorageSink.cs

示例10: Delete

 public void Delete()
 {
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
     CloudTable table = tableClient.GetTableReference(tableName);
     var entries = table.CreateQuery<EventTableEntity>().Where(e => e.PartitionKey == Id).ToArray();
     var delete = new TableBatchOperation();
     foreach (var eventTableEntity in entries)
     {
         delete.Add(TableOperation.Delete(eventTableEntity));
     }
     table.ExecuteBatch(delete);
 }
开发者ID:mcintyre321,项目名称:Sourcery,代码行数:13,代码来源:AzureTableStorageEventStore.cs

示例11: Save

        public async Task Save(Page[] pages)
        {
            var table = await GetTable();

            var batchInsertOperation = new TableBatchOperation();

            foreach (var page in pages)
            {
                batchInsertOperation.Add(TableOperation.Insert(ToPageTableEntity(page)));
            }

            await table.ExecuteBatchAsync(batchInsertOperation);
        }
开发者ID:qjuanp,项目名称:azure-table-storage-examples,代码行数:13,代码来源:PagePersistence.cs

示例12: AddVotes

        public void AddVotes(IEnumerable<Vote> votes)
        {
            CreateTableStorageIfDoesntExist();

            var tableClient = GetTableClient();
            var table = tableClient.GetTableReference(_tableName);

            var batch = new TableBatchOperation();
            foreach (var vote in votes)
            {
                batch.Add(TableOperation.InsertOrReplace(vote));
            }

            table.ExecuteBatch(batch);
        }
开发者ID:OpenDDD,项目名称:dddmelbourne,代码行数:15,代码来源:VoteService.cs

示例13: BatchPostAsync

        public async Task<IEnumerable<Response<JsonObject>>> BatchPostAsync(IEnumerable<JsonObject> jsonObjects)
        {
            if (jsonObjects == null)
                throw new ArgumentNullException("jsonObjects");

            var table = await DefineTableAsync(CreateCloudTable).ConfigureAwait(false);
            var batch = new TableBatchOperation();

            foreach (var entity in jsonObjects.Select(json => json.ToDynamicEntity()))
                batch.Add(TableOperation.Insert(entity));

            var results = await table.ExecuteBatchAsync(batch).ConfigureAwait(false);

            return results
                .Select(result => result.Result as DynamicTableEntity)
                .Select(entity => entity.ToJsonObject())
                .Select(jsonObj => new Response<JsonObject>(HttpStatusCode.Created, jsonObj));
        }
开发者ID:proactima,项目名称:DynamicFluentAzure,代码行数:18,代码来源:FluentAzure.cs

示例14: Persist

        public async Task Persist(string streamtype, string id, IEnumerable<ISourcedEvent> pendingEvents)
        {
            Trace.TraceInformation("Preparing batch for stream {0}.", streamtype);

            var batch = new TableBatchOperation();

            foreach (var @event in pendingEvents)
            {
                var entity = new DictionaryTableEntity
                {
                    PartitionKey = streamtype,
                    RowKey = id + "_" + @event.Version.ToString(VersionKeyFormat)
                };

                var compressed = false;
                var body = Json.Encode(@event);
                if (body.Length > 32*1024)
                {
                    body = new GzipCompression().Compress(body);
                    compressed = true;
                }
                
                entity.Add("EventType", @event.GetType().FullName);
                entity.Add("SourceId", @event.SourceId);
                entity.Add("Version", @event.Version);
                entity.Add("Body", body);
                entity.Add("Compressed", compressed);
                batch.Add(TableOperation.Insert(entity));
            }

            Trace.TraceInformation("Executing batch on stream {0}.", streamtype);
            await _table.ExecuteBatchAsync(batch).ContinueWith(r =>
            {
                Trace.TraceInformation("Batch on stream {0} complete {1} exceptions.", streamtype, r.Exception != null ? "with" : "without");
                if (r.Exception != null)
                {
                    r.Exception.Handle(exception =>
                    {
                        Trace.TraceError(exception.ToString());
                        return true;
                    });
                }
            });
        }
开发者ID:MessageHandler,项目名称:MessageHandler.SDK.EventSource,代码行数:44,代码来源:AzureTableStorageEventSource.cs

示例15: SaveChanges

 public void SaveChanges()
 {
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
     CloudTable table = tableClient.GetTableReference(tableName);
     var entries = newEvents.Select(e => new EventTableEntity()
     {
         PartitionKey = id,
         RowKey = e.Value.Index.ToString().PadLeft(8, '0'),
         Content = e.Value.Content
     });
     var insert = new TableBatchOperation();
     foreach (var eventTableEntity in entries)
     {
         insert.Add(TableOperation.InsertOrReplace(eventTableEntity));
     }
     table.ExecuteBatch(insert);
     newEvents.Clear();
 }
开发者ID:mcintyre321,项目名称:Sourcery,代码行数:19,代码来源:AzureTableStorageEventStoreSession.cs


注:本文中的TableBatchOperation.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。