コード例 #1
0
        /// <summary>
        /// Add sensor data
        /// </summary>
        /// <param name="deviceId">Device Id</param>
        /// <param name="temperature">Temperature</param>
        /// <param name="humidity">Humidity</param>
        /// <param name="localTime">Local time</param>
        /// <returns></returns>
        public bool AddSensorHatData(string deviceId, int temperature, int humidity, DateTime localTime)
        {
            long ticks     = DateTime.UtcNow.Ticks;
            var  latestEnt = new SensorHatEntity(deviceId, temperature, humidity, localTime, true, ticks);
            var  oldestEnt = new SensorHatEntity(deviceId, temperature, humidity, localTime, false, ticks);

            // EntityGroupTransaction
            TableBatchOperation batch = new TableBatchOperation();

            batch.InsertOrMerge(latestEnt);
            batch.InsertOrMerge(oldestEnt);

            try
            {
                _table.ExecuteBatch(batch);

                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);

                return(false);
            }
        }
コード例 #2
0
ファイル: UsersController.cs プロジェクト: arcs001/casa
        public IEnumerable<Usuarios> GetCreataTableStorage()
        {
            CloudTable table = getTable();
            table.CreateIfNotExists();

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(new Usuarios("usuarios", "759990") { Nome = "Christiano Donke", Email = "*****@*****.**" });
            batch.InsertOrMerge(new Usuarios("usuarios", "677040") { Nome = "Alexandre Campos", Email = "*****@*****.**" });

            table.ExecuteBatch(batch);

            return this.queryAzureStorage();
        }
コード例 #3
0
        public void InsertOrMerge(string partitionKey, string rowKey, string propertyName, object propertyValue)
        {
            Require.NotEmpty(partitionKey, "partitionKey");
            Require.NotEmpty(rowKey, "rowKey");
            Require.NotEmpty(propertyName, "propertyName");

            AssertBatchSizeIsNotExceeded();

            var entity = m_tableEntityConverter.CreateDynamicTableEntityFromProperties(propertyName, propertyValue);

            entity.PartitionKey = partitionKey;
            entity.RowKey       = rowKey;

            m_batch.InsertOrMerge(entity);
        }
コード例 #4
0
        private async Task <IEnumerable <T> > ExecuteQuery <T>() where T : BaseEntity, new()
        {
            var tableReference = _client.GetTableReference(typeof(T).Name);
            await tableReference.CreateIfNotExistsAsync();

            var result = await tableReference.ExecuteQueryAsync(new TableQuery <DateTimeAwareTableEntityAdapter <T> >());

            var adaptersWithInconsistentPartitionKey =
                new ConcurrentList <DateTimeAwareTableEntityAdapter <T> >(result.Where(x => x.InconsistentPartitionKey));

            foreach (var batch in SplitToBatches(adaptersWithInconsistentPartitionKey))
            {
                var deleteOp = new TableBatchOperation();
                var insertOp = new TableBatchOperation();
                foreach (var item in batch)
                {
                    deleteOp.Delete(item);
                    insertOp.InsertOrMerge(new DateTimeAwareTableEntityAdapter <T>(item.OriginalEntity));
                }

                await tableReference.ExecuteBatchAsync(insertOp);

                await tableReference.ExecuteBatchAsync(deleteOp);
            }

            return(result.Select(v => v.OriginalEntity).ToList());
        }
コード例 #5
0
        private bool InsertOrReplace <T>(T[] entries, CloudTable table)
            where T : ITableEntity
        {
            try
            {
                TableBatchOperation batch = new TableBatchOperation();

                for (int i = 0; i < entries.Length; i++)
                {
                    // Create the Delete TableOperation
                    batch.InsertOrMerge(entries[i]);

                    if (batch.Count >= 100)
                    {
                        table.ExecuteBatch(batch);
                        batch = new TableBatchOperation();
                    }
                }

                if (batch.Count > 0)
                {
                    table.ExecuteBatch(batch);
                }

                return(true);
            }
            catch (Exception ex)
            {
                //LogHelper.GetLogger().Error(ex.ToString(), ex);
                return(false);
            }
        }
コード例 #6
0
ファイル: InstanceTable.cs プロジェクト: RemSoftDev/Wouter
        public void SaveInstanceInfo(InstanceInfo instanceInfo)
        {
            var batchOp = new TableBatchOperation();

            batchOp.InsertOrMerge(instanceInfo);
            var result = table.ExecuteBatch(batchOp);
        }
コード例 #7
0
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable           TransferH      = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!TransferH.ContainsKey(Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey       = Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0');
                        Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();

                        properties.Add("BankAccount", new EntityProperty(Program._DATA_TABLE.Rows[i]["BankAccountID"].ToString().Trim()));
                        properties.Add("TransferMoney", new EntityProperty(double.Parse(Program._DATA_TABLE.Rows[i]["TransferMoney"].ToString().ToLower().Trim())));
                        try
                        {
                            properties.Add("ReceiveDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceiveDate"].ToString())));
                        }
                        catch { }

                        //BankTransferHeaderEntity data = new BankTransferHeaderEntity("88888888", Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0'));
                        //data.BankAccount = Program._DATA_TABLE.Rows[i]["BankAccountID"].ToString().Trim();
                        //data.TransferMoney = double.Parse(Program._DATA_TABLE.Rows[i]["TransferMoney"].ToString().ToLower().Trim());
                        //try { data.ReceiveDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceiveDate"].ToString()); }
                        //catch { }
                        batchOperation.InsertOrMerge(data);
                        recTransferH++;
                        TransferH[Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }
            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #8
0
ファイル: ShopBarcode.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable barcode = new Hashtable();
            StringBuilder sb = new StringBuilder();
            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!barcode.ContainsKey(Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim()))
                {
                    try
                    {
                        sb.Append(Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim() + "|");
                        ShopBarcodeEntity data = new ShopBarcodeEntity(Program._DATA_TABLE.Rows[i]["Shop"].ToString().Trim(), Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim());
                        data.OrderNo = Program._DATA_TABLE.Rows[i]["BillNumber"].ToString().Trim();
                        data.Product = Program._DATA_TABLE.Rows[i]["Product"].ToString().Trim().PadLeft(8, '0');
                        data.Cost = double.Parse(Program._DATA_TABLE.Rows[i]["SellPrice"].ToString().Trim());
                        data.SellFinished = false;
                        batchOperation.InsertOrMerge(data);
                        barcode[Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                Program._RECORD++;
                Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD*100);
                Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + sb.ToString() + "\n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #9
0
        public void InsertFrequencies(string partition, Dictionary <string, int> countsByKey)
        {
            TableBatchOperation batchOperation = new TableBatchOperation();

            int count = 0;

            foreach (KeyValuePair <string, int> item in countsByKey)
            {
                FrequencyEntity frequencyEntity = new FrequencyEntity
                {
                    PartitionKey = partition,
                    RowKey       = StringTokenizer.SanitizeTableKey(item.Key, ""),
                    Count        = item.Value
                };

                batchOperation.InsertOrMerge(frequencyEntity);
                count++;
                if (count == 100)
                {
                    tokenAllocationTable.ExecuteBatch(batchOperation);
                    batchOperation = new TableBatchOperation();
                    count          = 0;
                }
            }

            if (count > 0)
            {
                tokenAllocationTable.ExecuteBatch(batchOperation);
            }
        }
コード例 #10
0
            private static void AddOperationToBatch(ref TableBatchOperation tableBatchOperation, TAzureTableEntity entity, string batchMethodName)
            {
                switch (batchMethodName)
                {
                case CtConstants.TableOpInsert:
                    tableBatchOperation.Insert(entity);
                    break;

                case CtConstants.TableOpInsertOrMerge:
                    tableBatchOperation.InsertOrMerge(entity);
                    break;

                case CtConstants.TableOpInsertOrReplace:
                    tableBatchOperation.InsertOrReplace(entity);
                    break;

                case CtConstants.TableOpMerge:
                    tableBatchOperation.Merge(entity);
                    break;

                case CtConstants.TableOpDelete:
                    entity.ETag = "*";
                    tableBatchOperation.Delete(entity);
                    break;

                case CtConstants.TableOpReplace:
                    tableBatchOperation.Replace(entity);
                    break;
                }
            }
コード例 #11
0
        /// <summary>
        /// Demonstrate inserting of a large batch of entities. Some considerations for batch operations:
        ///  1. You can perform updates, deletes, and inserts in the same single batch operation.
        ///  2. A single batch operation can include up to 100 entities.
        ///  3. All entities in a single batch operation must have the same partition key.
        ///  4. While it is possible to perform a query as a batch operation, it must be the only operation in the batch.
        ///  5. Batch size must be less than or equal to 4 MB
        /// </summary>
        /// <param name="table">Sample table name</param>
        /// <returns>A Task object</returns>
        private static async Task BatchInsertOfCustomerEntitiesAsync(CloudTable table)
        {
            try
            {
                // Create the batch operation.
                TableBatchOperation batchOperation = new TableBatchOperation();

                // The following code  generates test data for use during the query samples.
                for (int i = 0; i < 100; i++)
                {
                    batchOperation.InsertOrMerge(new CustomerEntity("Smith", string.Format("{0}", i.ToString("D4")))
                    {
                        Email       = string.Format("{0}@contoso.com", i.ToString("D4")),
                        PhoneNumber = string.Format("425-555-{0}", i.ToString("D4"))
                    });
                }

                // Execute the batch operation.
                IList <TableResult> results = await table.ExecuteBatchAsync(batchOperation);

                foreach (var res in results)
                {
                    var customerInserted = res.Result as CustomerEntity;
                    Console.WriteLine("Inserted entity with\t Etag = {0} and PartitionKey = {1}, RowKey = {2}", customerInserted.ETag, customerInserted.PartitionKey, customerInserted.RowKey);
                }
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
コード例 #12
0
ファイル: WorkerRole.cs プロジェクト: sungakim816/netscrap
        /// <summary>
        /// Batch Insert Operation for optimization purposes,
        /// </summary>
        /// <param name="tName">Name of the table</param>
        /// <param name="list">List of Object</param>
        /// <returns></returns>
        private async Task BatchInsertViaTableName(string tName, List <WebsitePage> list)
        {
            CloudTable table = tableClient.GetTableReference(tName);
            await table.CreateIfNotExistsAsync();                                        // create if not exist

            var pages         = list.Where(page => page.Domain.Equals(tName));           // get all websitepage objects with similar tablename (domain)
            var partitionkeys = pages.Select(page => page.PartitionKey).Distinct();      // get all distinct partitionkeys, from the list (keywords) distinct
            TableBatchOperation batchInsertOperation = new TableBatchOperation();        // create a table batch operation object

            foreach (string key in partitionkeys)                                        // iterate partitionkeys
            {
                Dictionary <string, string> rowkeys = new Dictionary <string, string>(); // iterate through websitepage object lists with similar partition keys
                foreach (WebsitePage page in pages.Where(p => p.PartitionKey.Equals(key)))
                {
                    if (!rowkeys.ContainsKey(page.RowKey)) // check duplicate items,
                    {
                        batchInsertOperation.InsertOrMerge(page);
                        rowkeys.Add(page.RowKey, page.RowKey);
                    }
                }
                await table.ExecuteBatchAsync(batchInsertOperation);

                batchInsertOperation.Clear();
            }
        }
コード例 #13
0
        public async Task PersistAsync(ICollection <string> entities)
        {
            var batch = new TableBatchOperation();

            foreach (var url in entities)
            {
                var rowKey = GetRowKey(url);
                var row    = await _table.ExecuteAsync(TableOperation.Retrieve(PartitionKey, rowKey, new List <string>()));

                if (row.Result == null)
                {
                    var persistedEntity = new PersistedEntity
                    {
                        PartitionKey = PartitionKey,
                        RowKey       = rowKey,
                        Url          = url,
                        Notified     = false
                    };
                    batch.InsertOrMerge(persistedEntity);
                }
            }

            if (batch.Any())
            {
                await _table.ExecuteBatchAsync(batch);
            }
        }
コード例 #14
0
        public async Task InsertOrMergeAsync(IEnumerable <Player> players)
        {
            var batchOperations = new List <TableBatchOperation>();
            var grouped         = players.GroupBy(p => p.ClubInformation.ExternalId);

            foreach (var group in grouped)
            {
                var currentOperationIndex = 0;
                var batchOperation        = new TableBatchOperation();

                foreach (var player in group)
                {
                    batchOperation.InsertOrMerge(player.ToPersisted());
                    currentOperationIndex++;

                    if (currentOperationIndex >= TableServiceBatchMaximumOperations)
                    {
                        currentOperationIndex = 0;
                        batchOperations.Add(batchOperation);
                        batchOperation = new TableBatchOperation();
                    }
                }

                batchOperations.Add(batchOperation);
            }

            var dataSource = await _dataSource;
            await dataSource.ExecuteBatchAsync(batchOperations);
        }
コード例 #15
0
            private void AddOperationToBatch(ref TableBatchOperation tableBatchOperation, TAzureTableEntity entity, SaveType batchMethodName)
            {
                switch (batchMethodName)
                {
                case SaveType.Insert:
                    tableBatchOperation.Insert(entity);
                    break;

                case SaveType.InsertOrMerge:
                    tableBatchOperation.InsertOrMerge(entity);
                    break;

                case SaveType.InsertOrReplace:
                    tableBatchOperation.InsertOrReplace(entity);
                    break;

                case SaveType.Merge:
                    tableBatchOperation.Merge(entity);
                    break;

                case SaveType.Delete:
                    tableBatchOperation.Delete(entity);
                    break;

                case SaveType.Replace:
                    tableBatchOperation.Replace(entity);
                    break;
                }
            }
コード例 #16
0
        public void Write(string key, string value)
        {
            var batch  = new TableBatchOperation();
            var record = new AzureTableRecord
            {
                PartitionKey = _appName,
                RowKey       = key,
                ETag         = "*"
            };

            if (value != null)
            {
                record.Value = value;
                batch.InsertOrMerge(record);
            }
            else
            {
                batch.Delete(record);
            }

            try
            {
                _table.ExecuteBatch(batch);
            }
            catch (StorageException)
            {
                //not ideal check. If value is null (Delete operation) and record doesn't exist
                //I ignore the exception as it simply says that entity doesn't exist which is fine.
                //I don't know how to check for the specific error code.
                if (value != null)
                {
                    throw;
                }
            }
        }
コード例 #17
0
ファイル: AzureTable.cs プロジェクト: BOONRewardsInc/rewards
        /// <summary>
        ///     Batch Insert
        ///     Make sure that all the entities have the same partition id
        /// </summary>
        /// <param name="entities">
        ///     The entities.
        /// </param>
        /// <param name="failureCount">
        ///     The count of failures.
        /// </param>
        /// <typeparam name="T">
        ///     The ITableEntity
        /// </typeparam>
        /// <returns>
        ///     true is all batch entities inserted
        /// </returns>
        public bool BatchInsertOrMergeEntities <T>(IList <T> entities, out int failureCount) where T : ITableEntity
        {
            failureCount = 0;
            if (entities == null)
            {
                throw new ArgumentNullException("entities", "The TableEntities cannot be null");
            }

            var batchOperation = new TableBatchOperation();

            foreach (T entity in entities)
            {
                batchOperation.InsertOrMerge(entity);
            }

            IList <TableResult> result = this.CloudTable.ExecuteBatch(batchOperation);
            bool succuess = true;

            foreach (TableResult tableResult in result)
            {
                if (tableResult.HttpStatusCode != (int)HttpStatusCode.Created &&
                    tableResult.HttpStatusCode != (int)HttpStatusCode.NoContent)
                {
                    succuess = false;
                    failureCount++;
                }
            }

            return(succuess);
        }
コード例 #18
0
ファイル: Demo.aspx.cs プロジェクト: enesgezici/AzureOrnekler
        //Table Batch Operation in a transaction.
        protected async void Button4_Click(object sender, EventArgs e)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference("Urunler");
            TableBatchOperation batchOperation = new TableBatchOperation();

            //All entities in a given batch must have the same partition key.
            for (int i = 0; i < 100; i++)
            {
                batchOperation.InsertOrMerge(new Urun()
                {
                    PartitionKey = "Musteri1",
                    RowKey       = i.ToString(),
                    Adi          = "Deneme" + i.ToString(),
                    Aciklama     = "Açıklama"
                });
            }
            IList <TableResult> results = await table.ExecuteBatchAsync(batchOperation);

            foreach (var res in results)
            {
                var eklenenUrun = res.Result as Urun;
            }
        }
コード例 #19
0
        /// <summary>
        /// Insert entities async.
        /// </summary>
        /// <param name="entities">The array of entities.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The array of inserted entities.</returns>
        public async Task <T[]> InsertAsync(T[] entities, CancellationToken cancellationToken)
        {
            List <T> items = new List <T>();

            // Create the batch operation.
            TableBatchOperation batchOperation = new TableBatchOperation();

            // For each entity.
            for (int i = 0; i < entities.Length; i++)
            {
                // Insert the entity.
                batchOperation.InsertOrMerge(entities[i]);
            }

            // Execute the batch operation.
            IList <TableResult> results = await _cloudTable.ExecuteBatchAsync(batchOperation, cancellationToken);

            // For each item.
            foreach (var item in results)
            {
                T inserted = item.Result as T;
                items.Add(inserted);
            }

            // Return the array
            return(items.ToArray());
        }
コード例 #20
0
        /// <summary>
        /// Insert Batch
        /// </summary>
        /// <param name="entities">Entities</param>
        public virtual async Task <IEnumerable <TableResult> > Insert(IEnumerable <IDictionary <string, object> > entities)
        {
            var result = new List <TableResult>();

            foreach (var batch in this.Batch(entities))
            {
                var batchOperation = new TableBatchOperation();

                foreach (var entity in batch)
                {
                    var properties = new Dictionary <string, EntityProperty>();
                    entity.Keys.Where(k => k != PartitionKey && k != RowKey && k != ETag).ToList().ForEach(key => properties.Add(key, EntityProperty.CreateEntityPropertyFromObject(entity[key])));

                    var partitionKey = entity.Keys.Contains(PartitionKey) ? entity[PartitionKey].ToString() : string.Empty;
                    var rowKey       = entity.Keys.Contains(RowKey) ? entity[RowKey].ToString() : string.Empty;
                    var etag         = entity.Keys.Contains(ETag) ? entity[ETag].ToString() : null;

                    batchOperation.InsertOrMerge(new DynamicTableEntity(partitionKey, rowKey, etag, properties));
                }

                var r = await this.reference.ExecuteBatchAsync(batchOperation);

                result.AddRange(r);
            }

            return(result);
        }
コード例 #21
0
ファイル: SeedData.cs プロジェクト: Lulubul/Netflix
        public async Task AddMoviesEntitesAsync()
        {
            var partionKey = Guid.NewGuid().ToString();
            var tvSeries   = new List <MovieEntity> {
                new MovieEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "Inside the real narcos",
                    Description  = "",
                    Genres       = "0b452f44-ffae-41d0-b125-dfee76a2d54a",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v5/rendition/8235889aa78c638456a837ba52c96294bfd5070d/AAAABVMta4Fjh88G4OFYOKqY7dQjOKq2Aj4MGtFihhQaQKpfTCJ6BaLPH35JrZr_7pNHJVyKO1BjJLBqJzSBwBu7JtlqewoLhG2RHmMmnwq5x8Lx2HAE6mW0sqB6OMC9HX8oT8ziRrqs-KsOAZCqGTm446MVprFK5a241WggIGUf80_l4rDJSpPZ-cD-eHJqP6bSqNM3lGVtCQEGj_oVrpR42TG80nkyO0dTFnfg8nnQirC9Np7gOg-FwuZLKzM23bz1LtnWmX5s83YJzYf9bQ.webp"
                },
                new MovieEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "Mowgli the legend of jungle",
                    Description  = "",
                    Genres       = "0b452f44-ffae-41d0-b125-dfee76a2d54a",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v5/rendition/8235889aa78c638456a837ba52c96294bfd5070d/AAAABXXMR156Hg0LTwBZbdYEpfFzV9DsS14wgrQFCZDa8ohmTWNBg9hk2TBUW8BAkRTOG8BWC_bPaRyMSt1lpYSp0XxdTqPB0X5PK6yZwSpBVYJZZ37oNrNCYhXm2hENCf5gIQ0FYUGkvjOELOqVjs-clHMyay1xvlrmDPt_mYCK7Z0JigMNavAuuHBQ10fZZoVud2zooCchN85_Q-QbHVcslnOwYaE8j66dRtln89TD8G-f41UPHSnvgl6JAiH2jEc5lI3kRSuwNgcoTYc21g.webp"
                },
                new MovieEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "Murder Mointain",
                    Description  = "",
                    Genres       = "0b452f44-ffae-41d0-b125-dfee76a2d54a",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v5/rendition/8235889aa78c638456a837ba52c96294bfd5070d/AAAABVMta4Fjh88G4OFYOKqY7dQjOKq2Aj4MGtFihhQaQKpfTCJ6BaLPH35JrZr_7pNHJVyKO1BjJLBqJzSBwBu7JtlqewoLhG2RHmMmnwq5x8Lx2HAE6mW0sqB6OMC9HX8oT8ziRrqs-KsOAZCqGTm446MVprFK5a241WggIGUf80_l4rDJSpPZ-cD-eHJqP6bSqNM3lGVtCQEGj_oVrpR42TG80nkyO0dTFnfg8nnQirC9Np7gOg-FwuZLKzM23bz1LtnWmX5s83YJzYf9bQ.webp"
                },
                new MovieEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "Bird Box",
                    Description  = "",
                    Genres       = "0b452f44-ffae-41d0-b125-dfee76a2d54a",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v5/rendition/8235889aa78c638456a837ba52c96294bfd5070d/AAAABYuRQJDvbcfKyM3lCUKoZb3CnTKIlRktbf9J_87XB9jxtmywOkQYBpPS8dvjtfLPrhGz2vGKmtkhX1_z4UtTDqmt0hey5bRyEV1C7SOZHxz3Qd_VdtqAcchELHedbkRYR2xmDsu3l4gYpU2FjisPtTCuKmvqhuE7Uykf50AmSmXpDkdDXhuKtNrcyDoKjFbkBguqucmFlEBCNXaCDkN3By1dYaSOaCDMUj-e-HxbY0s6lSim4mJxh6v6ASKKna0H8YVT21BKPLGHtkabfw.webp"
                },
                new MovieEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = Guid.NewGuid().ToString(),
                    Name         = "Watership down",
                    Description  = "",
                    Genres       = "0b452f44-ffae-41d0-b125-dfee76a2d54a",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v5/rendition/8235889aa78c638456a837ba52c96294bfd5070d/AAAABSaM9rO_DsASwj8LVbgd1WmAZNq-joiIVeDjdaDRY2qQyeRnE7LHsLfVhETAVZz1196lZUuxBf_1AMqqC5TC2Pa1eqJHIEX6zuCMriswa6MQ2AYbULrLVHfeZjLPZA37XDOHC8t1V-3B2A7tWhhbpcL2eZnEkUhjV52XSVagUU87TVv9SOItyf0trLHciooW1js-2jMzRlSRz4XLqTk9O04vRg9q2T4_nnnfjIVscj0x4Xd8aK2zPVvMAyD-n3FqUqg20wDsYVwpo7-mgw.webp"
                }
            };

            var table = GetTable("movies", _storageConnectionString);
            TableBatchOperation batchOperation = new TableBatchOperation();

            foreach (var entity in tvSeries)
            {
                batchOperation.InsertOrMerge(entity);
            }
            await table.ExecuteBatchAsync(batchOperation);
        }
コード例 #22
0
        /// <summary>
        /// Insere uma coleção de entidades na tabela no Azure Table Storage.
        /// </summary>
        public async Task <TableBatchResult> BatchInsertOrMergeEntityAsync(CloudTable table, IList <T> entities)
        {
            try
            {
                if (entities != null)
                {
                    TableBatchOperation tableBatchOperation = new TableBatchOperation();

                    foreach (var item in entities)
                    {
                        tableBatchOperation.InsertOrMerge(item);
                    }

                    TableBatchResult tableBachResult = await table.ExecuteBatchAsync(tableBatchOperation);

                    return(tableBachResult);
                }
                else
                {
                    throw new ArgumentNullException("entities");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #23
0
        public void InsertOrMerge(E entity)
        {
            CheckNotSaved();

            _context.InsertOrMerge(ConvertToFatEntity(entity));
            _isDirty = true;
        }
コード例 #24
0
        /// <summary>Create the table batch operation for the scheduled entity for the set of virtual machines.</summary>
        /// <param name="filteredVmSet">Set of virtual machines.</param>
        /// <param name="schedulerFrequency">Schedule frequency, it will be reading from the config</param>
        /// <param name="virtualMachineGroup"></param>
        /// <returns></returns>
        public static TableBatchOperation CreateScheduleEntity(IList <VirtualMachineCrawlerResponse> filteredVmSet,
                                                               int schedulerFrequency, List <string> azureFiOperationList, VirtualMachineGroup virtualMachineGroup)
        {
            TableBatchOperation tableBatchOperation = new TableBatchOperation();
            Random   random = new Random();
            DateTime randomExecutionDateTime = DateTime.UtcNow.AddMinutes(random.Next(1, schedulerFrequency));
            var      sessionId = Guid.NewGuid().ToString();

            foreach (var item in filteredVmSet)
            {
                if (item == null)
                {
                    continue;
                }

                string fiOperation = string.Empty;
                var    actionType  = GetActionType(item.RowKey, azureFiOperationList, item.State, out fiOperation);
                var    entityEntry = RuleEngineHelper.ConvertToScheduledRuleEntity(item, sessionId, actionType,
                                                                                   fiOperation, randomExecutionDateTime, virtualMachineGroup);
                if (entityEntry != null)
                {
                    tableBatchOperation.InsertOrMerge(entityEntry);
                }
            }

            return(tableBatchOperation);
        }
コード例 #25
0
ファイル: Bank.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable bank = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!bank.ContainsKey(Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey = Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();

                        properties.Add("Bank", new EntityProperty(Program._DATA_TABLE.Rows[i]["Bank"].ToString().Trim()));
                        properties.Add("BranchName", new EntityProperty(Program._DATA_TABLE.Rows[i]["BranchName"].ToString().ToLower().Trim()));
                        properties.Add("AccountNumber", new EntityProperty(Program._DATA_TABLE.Rows[i]["AccountNumber"].ToString().Trim()));
                        properties.Add("AccountName", new EntityProperty(Program._DATA_TABLE.Rows[i]["AccountName"].ToString().Trim()));
                        properties.Add("AccountType", new EntityProperty(int.Parse(Program._DATA_TABLE.Rows[i]["AccountType"].ToString().Trim())));

                        //BankEntity data = new BankEntity("88888888", Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0'));
                        //data.Bank = Program._DATA_TABLE.Rows[i]["Bank"].ToString().Trim();
                        //data.BranchName = Program._DATA_TABLE.Rows[i]["BranchName"].ToString().ToLower().Trim();
                        //data.AccountNumber = Program._DATA_TABLE.Rows[i]["AccountNumber"].ToString().Trim();
                        //data.AccountName = Program._DATA_TABLE.Rows[i]["AccountName"].ToString().Trim();
                        //data.AccountType = int.Parse(Program._DATA_TABLE.Rows[i]["AccountType"].ToString().Trim());
                        batchOperation.InsertOrMerge(data);
                        recBank++;
                        bank[Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #26
0
        /// <summary>
        /// Insert or merge a batch of entities in Azure table storage.
        /// A batch can contain up to 100 entities.
        /// </summary>
        /// <param name="entities">Entities to be inserted or merged in Azure table storage.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        public async Task BatchInsertOrMergeAsync(IEnumerable <T> entities)
        {
            try
            {
                var array = entities.ToArray();
                for (var i = 0; i <= array.Length / 100; i++)
                {
                    var lowerBound = i * 100;
                    var upperBound = Math.Min(lowerBound + 99, array.Length - 1);
                    if (lowerBound > upperBound)
                    {
                        break;
                    }

                    var batchOperation = new TableBatchOperation();
                    for (var j = lowerBound; j <= upperBound; j++)
                    {
                        batchOperation.InsertOrMerge(array[j]);
                    }

                    await this.Table.ExecuteBatchAsync(batchOperation);
                }
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, ex.Message);
                throw;
            }
        }
コード例 #27
0
        protected void InsertOrMerge(TableEntity entity, string tableName)
        {
            // Create the table client.
            CloudTableClient tableClient = StorageAccount.CreateCloudTableClient();

            // Retrieve a reference to the table.
            CloudTable table = tableClient.GetTableReference(tableName);

            // Create the batch operation.
            TableBatchOperation batchOperation = new TableBatchOperation();

            // Add the entity to the batch
            batchOperation.InsertOrMerge(entity);

            // Merge
            try
            {
                table.ExecuteBatch(batchOperation);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404)
                {
                    // Create the table if it doesn't exist.
                    table.CreateIfNotExists();

                    // do the insert again
                    table.ExecuteBatch(batchOperation);
                }
            }
        }
コード例 #28
0
        public async Task AddOrMerge(IList <TModel> model)
        {
            TableBatchOperation insertOperation = new TableBatchOperation();

            model.ToList().ForEach(x => insertOperation.InsertOrMerge(x));
            await this.PrepareTable().ExecuteBatchAsync(insertOperation);
        }
コード例 #29
0
        private static async Task BatchExecuteExample()
        {
            Console.WriteLine("Executing batch operation example");
            Console.WriteLine("=================================");

            tableName = $"demoBatch{Guid.NewGuid().ToString().Substring(0, 5)}";

            table = await CreateTableAsync(tableName);

            var batchOperation = new TableBatchOperation();

            for (var i = 1; i <= 100; i++)
            {
                batchOperation.InsertOrMerge(new EmployeeEntity($"FirstName-{i}", $"LastName-{i}"));
            }

            var results = await table.ExecuteBatchAsync(batchOperation);

            foreach (var res in results)
            {
                var entity = res.Result as EmployeeEntity;

                Console.WriteLine($"Inserted entity with ETag = {entity.ETag} and RowKey = {entity.RowKey}");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("=================================");
            Console.WriteLine(Environment.NewLine);
        }
コード例 #30
0
        public async Task InsertOrMerge(IEnumerable <T> entities)
        {
            var count          = 0;
            var batchOperation = new TableBatchOperation();

            foreach (var entity in entities)
            {
                batchOperation.InsertOrMerge(entity);
                count++;

                if (count == batchSize)
                {
                    await table.ExecuteBatchAsync(batchOperation).ConfigureAwait(false);

                    count          = 0;
                    batchOperation = new TableBatchOperation();
                }
            }

            // Last batch
            if (count > 0)
            {
                await table.ExecuteBatchAsync(batchOperation).ConfigureAwait(false);
            }
        }
コード例 #31
0
ファイル: Bank.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable           bank           = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!bank.ContainsKey(Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey       = Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0');
                        Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty>();

                        properties.Add("Bank", new EntityProperty(Program._DATA_TABLE.Rows[i]["Bank"].ToString().Trim()));
                        properties.Add("BranchName", new EntityProperty(Program._DATA_TABLE.Rows[i]["BranchName"].ToString().ToLower().Trim()));
                        properties.Add("AccountNumber", new EntityProperty(Program._DATA_TABLE.Rows[i]["AccountNumber"].ToString().Trim()));
                        properties.Add("AccountName", new EntityProperty(Program._DATA_TABLE.Rows[i]["AccountName"].ToString().Trim()));
                        properties.Add("AccountType", new EntityProperty(int.Parse(Program._DATA_TABLE.Rows[i]["AccountType"].ToString().Trim())));

                        //BankEntity data = new BankEntity("88888888", Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0'));
                        //data.Bank = Program._DATA_TABLE.Rows[i]["Bank"].ToString().Trim();
                        //data.BranchName = Program._DATA_TABLE.Rows[i]["BranchName"].ToString().ToLower().Trim();
                        //data.AccountNumber = Program._DATA_TABLE.Rows[i]["AccountNumber"].ToString().Trim();
                        //data.AccountName = Program._DATA_TABLE.Rows[i]["AccountName"].ToString().Trim();
                        //data.AccountType = int.Parse(Program._DATA_TABLE.Rows[i]["AccountType"].ToString().Trim());
                        batchOperation.InsertOrMerge(data);
                        recBank++;
                        bank[Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }
            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #32
0
ファイル: SeedData.cs プロジェクト: Lulubul/Netflix
        public async Task AddTvSeriesEntitesAsync()
        {
            var partionKey = Guid.NewGuid().ToString();
            var tvSeries   = new List <TvSeriesEntity> {
                new TvSeriesEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = "11c260fe-c2d3-42a2-b5de-edac53f9314b",
                    Name         = "One Strange Rock",
                    Description  = "",
                    Genres       = "822f4ae9-393e-4927-b69d-174c266b5308",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v6/0DW6CdE4gYtYx8iy3aj8gs9WtXE/AAAABRbsXRKRIXU95XgpmgqZzdMVpx1YsqF9Gq0zXsw2bU3HhgFarz98hY6rofzJ2S6CIq12QiDIvnVc-WgiJSmEGbSSdMJ5_ByE.webp?r=939"
                },
                new TvSeriesEntity {
                    PartitionKey = partionKey,
                    RowKey       = "5ac12709-0025-4023-95d2-2c4e690acc22",
                    Name         = "Flash",
                    Description  = "",
                    Genres       = "822f4ae9-393e-4927-b69d-174c266b5308",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v6/0DW6CdE4gYtYx8iy3aj8gs9WtXE/AAAABV2Ug2r4TUikHQJypNB8RDj0bSIDgqVO5ZORnchk-54OEWE6G8TuIAcGqqER1Wle5zrRdLs5y8TCD_eQ5Vyv2xqGvveZAEOmjVf8d1kldMLcoHZAd-Ef8bPnsjmhEQFQgA.webp?r=39c"
                },
                new TvSeriesEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = "d05fd9c1-0d2a-43e3-9c7d-fcbde028691c",
                    Name         = "Super Girl",
                    Description  = "",
                    Genres       = "822f4ae9-393e-4927-b69d-174c266b5308",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v6/0DW6CdE4gYtYx8iy3aj8gs9WtXE/AAAABXpsefLDl4eR3TIh5VHh5iT4GXHjVHVpjy-Ev8Ag-SNht1ufo4BaHWdxfZS2m6ZxTIUv1BhQLfpUczeUYLV3j58_GcfJBwW_2P06XHDASUysVSYPjLs6iNipPURLwott6A.webp?r=d51",
                },
                new TvSeriesEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = "b1e63fda-4f1a-4dd9-a7b1-8fb4757b79c9",
                    Name         = "Peaky Blinders",
                    Description  = "Thomas schemes to get closer to Billy Kimber at the Cheltenham races, and considers an offer from IRA sympathizers to buy his stolen guns.",
                    Genres       = "822f4ae9-393e-4927-b69d-174c266b5308",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v6/0DW6CdE4gYtYx8iy3aj8gs9WtXE/AAAABcXm0tleWsBfN7vL3kOivse8Js183I_MOTU8q3BgSz3bXvvWzFENgDT1LXDUqRtM46fogUSZAqaJugupPcc265hnZk1hfTJm.webp?r=780",
                },
                new TvSeriesEntity
                {
                    PartitionKey = partionKey,
                    RowKey       = "4cf3731a-29c2-4af7-b86c-71ef5a934e0d",
                    Name         = "Marco Polo",
                    Description  = "",
                    Genres       = "822f4ae9-393e-4927-b69d-174c266b5308",
                    Image        = "https://occ-0-3032-768.1.nflxso.net/dnm/api/v6/0DW6CdE4gYtYx8iy3aj8gs9WtXE/AAAABROUedyDkrdJSH6-uneDRNX2yi_DZAjNXK2-ffA-sJC-nKEtmApyiGzV8Wh6KubaAS47kYAZ1ZVfS-4ctJWSwLaQE7BBtqmM.jpg?r=afb"
                }
            };

            var table = GetTable("tvSeries", _storageConnectionString);
            TableBatchOperation batchOperation = new TableBatchOperation();

            foreach (var entity in tvSeries)
            {
                batchOperation.InsertOrMerge(entity);
            }
            await table.ExecuteBatchAsync(batchOperation);
        }
コード例 #33
0
        public async Task BatchInsertRecordFeaturesAsync()
        {
            try
            {
                string tableName = "testorg" + DateTime.Now.ToString("yyyyMMddhhmm");

                // Create or reference an existing table
                CloudTable table = await Common.CreateTableAsync(tableName);

                var entities    = new string[] { "Account", "Contact", "Lead", "Opportunity", "Case" };
                var recordCount = 5000;
                var batchSize   = 100;

                foreach (var entity in entities)
                {
                    _logger.LogInformation($"Start processing entity {entity}");

                    var curRecordNum = 0;
                    while (curRecordNum < recordCount)
                    {
                        using (var perfScope = _perfCounterCollector.BeginPerfScope("FeatureGeneration/BatchInsert"))
                        {
                            var recordsToInsert = Math.Min(batchSize, recordCount - curRecordNum);
                            await InsertOneBatchAsync(table, entity, curRecordNum, recordsToInsert);

                            curRecordNum += recordsToInsert;
                        }
                    }

                    _logger.LogInformation($"Complete processing entity {entity}");
                }
            }
            catch (StorageException e)
            {
                _logger.LogError($"Failed to insert features, {e}");
                throw;
            }

            async Task InsertOneBatchAsync(CloudTable destTable, string entityType, int baseId, int batchSize)
            {
                // Create the batch operation.
                TableBatchOperation batchOperation = new TableBatchOperation();

                // The following code  generates test data for use during the query samples.
                var id = baseId;

                for (int i = 0; i < batchSize; i++, id++)
                {
                    batchOperation.InsertOrMerge(new RecordFeatures(entityType, string.Format("{0}", id.ToString("D4")))
                    {
                    });
                }

                // Execute the batch operation.
                IList <TableResult> results = await destTable.ExecuteBatchAsync(batchOperation);
            }
        }
コード例 #34
0
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable TransferD = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                string Rowkey = (Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim() + "-" + Program._DATA_TABLE.Rows[i]["SellNumber"].ToString().Trim());
                if (!TransferD.ContainsKey(Rowkey))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey = Rowkey;
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();

                        properties.Add("SellNumber", new EntityProperty(Program._DATA_TABLE.Rows[i]["SellNumber"].ToString().Trim().PadLeft(8, '0')));
                        properties.Add("ReceiveMoney", new EntityProperty(double.Parse(Program._DATA_TABLE.Rows[i]["ReceiveMoney"].ToString().ToLower().Trim())));

                        //BankTransferDetailEntity data = new BankTransferDetailEntity("88888888", Rowkey);
                        //data.SellNumber = Program._DATA_TABLE.Rows[i]["SellNumber"].ToString().Trim().PadLeft(8, '0');
                        //data.ReceiveMoney = double.Parse(Program._DATA_TABLE.Rows[i]["ReceiveMoney"].ToString().ToLower().Trim());
                        batchOperation.InsertOrMerge(data);
                        recTransferD++;
                        TransferD[Rowkey] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #35
0
ファイル: UcConfig.cs プロジェクト: PowerDD/PowerPOS-Online
        private void bwUpdateConfig_DoWork(object sender, DoWorkEventArgs e)
        {
            dynamic d = new DynamicEntity(Param.ShopId, "Config");
            d.Value = JsonConvert.SerializeObject(Param.SystemConfig);
            var azureTable = Param.AzureTableClient.GetTableReference("Shop");
            TableBatchOperation batchOperation = new TableBatchOperation();
            batchOperation.InsertOrMerge(d);
            azureTable.ExecuteBatch(batchOperation);

            d = new DynamicEntity(Param.ShopId, Param.LicenseKey);
            d.DevicePrinter = Param.DevicePrinter;
            azureTable = Param.AzureTableClient.GetTableReference("ShopApplication");
            batchOperation = new TableBatchOperation();
            batchOperation.InsertOrMerge(d);
            azureTable.ExecuteBatch(batchOperation);

            Properties.Settings.Default.DevicePrinter = Param.DevicePrinter;
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Upgrade();
        }
コード例 #36
0
ファイル: Batch.cs プロジェクト: adhurwit/AzureStorageTools
        public void Load()
        {
            TableBatchManager.LogInfo("Load batch called");
            try
            {
            TableBatchOperation op = new TableBatchOperation();
            foreach (var e in Entities)
            {
                if (Merge)
                    op.InsertOrMerge(e);
                else
                    op.InsertOrReplace(e);
            }
            Table.ExecuteBatch(op);
            TableBatchManager.LogInfo("exec batch");
            }
            catch(Exception ex)
            {
                TableBatchManager.LogError("Error: " + ex);

            }
        }
コード例 #37
0
        public void TableBatchOperationsWithEmptyKeys()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            // Insert Entity
            DynamicTableEntity ent = new DynamicTableEntity() { PartitionKey = "", RowKey = "" };
            ent.Properties.Add("foo2", new EntityProperty("bar2"));
            ent.Properties.Add("foo", new EntityProperty("bar"));
            TableBatchOperation batch = new TableBatchOperation();
            batch.Insert(ent);
            currentTable.ExecuteBatch(batch);

            // Retrieve Entity
            TableBatchOperation retrieveBatch = new TableBatchOperation();
            retrieveBatch.Retrieve(ent.PartitionKey, ent.RowKey);
            TableResult result = currentTable.ExecuteBatch(retrieveBatch).First();

            DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
            Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
            Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(ent.Properties["foo"].StringValue, retrievedEntity.Properties["foo"].StringValue);
            Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
            Assert.AreEqual(ent.Properties["foo2"].StringValue, retrievedEntity.Properties["foo2"].StringValue);
            Assert.AreEqual(ent.Properties["foo2"], retrievedEntity.Properties["foo2"]);

            // InsertOrMerge
            DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value"));
            batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            currentTable.ExecuteBatch(batch);

            result = currentTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]);

            // InsertOrReplace
            DynamicTableEntity insertOrReplaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue"));
            batch = new TableBatchOperation();
            batch.InsertOrReplace(insertOrReplaceEntity);
            currentTable.ExecuteBatch(batch);

            result = currentTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(1, retrievedEntity.Properties.Count);
            Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);

            // Merge
            DynamicTableEntity mergeEntity = new DynamicTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag };
            mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged"));
            batch = new TableBatchOperation();
            batch.Merge(mergeEntity);
            currentTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            result = currentTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]);

            // Replace
            DynamicTableEntity replaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag };
            replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace"));
            batch = new TableBatchOperation();
            batch.Replace(replaceEntity);
            currentTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            result = currentTable.ExecuteBatch(retrieveBatch).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(replaceEntity.Properties["replaceProp"], retrievedEntity.Properties["replaceProp"]);

            // Delete Entity
            batch = new TableBatchOperation();
            batch.Delete(retrievedEntity);
            currentTable.ExecuteBatch(batch);

            // Retrieve Entity
            result = currentTable.ExecuteBatch(retrieveBatch).First();
            Assert.IsNull(result.Result);
        }
コード例 #38
0
        public void TableBatchAllSupportedOperationsSync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            TableBatchOperation batch = new TableBatchOperation();
            string pk = Guid.NewGuid().ToString();

            // insert
            batch.Insert(GenerateRandomEnitity(pk));

            // delete
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Delete(entity);
            }

            // replace
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Replace(entity);
            }

            // insert or replace
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrReplace(entity);
            }

            // merge
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Merge(entity);
            }

            // insert or merge
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrMerge(entity);
            }

            IList<TableResult> results = currentTable.ExecuteBatch(batch);

            Assert.AreEqual(results.Count, 6);

            IEnumerator<TableResult> enumerator = results.GetEnumerator();
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
        }
コード例 #39
0
        public void TableBatchAllSupportedOperationsAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            TableBatchOperation batch = new TableBatchOperation();
            string pk = Guid.NewGuid().ToString();

            // insert
            batch.Insert(GenerateRandomEnitity(pk));

            // delete
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Delete(entity);
            }

            // replace
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Replace(entity);
            }

            // insert or replace
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrReplace(entity);
            }

            // merge
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.Merge(entity);
            }

            // insert or merge
            {
                DynamicTableEntity entity = GenerateRandomEnitity(pk);
                currentTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrMerge(entity);
            }

            IList<TableResult> results = null;
            using (ManualResetEvent evt = new ManualResetEvent(false))
            {
                IAsyncResult asyncRes = null;
                currentTable.BeginExecuteBatch(batch, (res) =>
                {
                    asyncRes = res;
                    evt.Set();
                }, null);
                evt.WaitOne();

                results = currentTable.EndExecuteBatch(asyncRes);
            }

            Assert.AreEqual(results.Count, 6);

            IEnumerator<TableResult> enumerator = results.GetEnumerator();
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
        }
コード例 #40
0
ファイル: Product.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable product = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!product.ContainsKey(Program._DATA_TABLE.Rows[i]["PN"].ToString().Trim()) || Program._UPDATE == true)
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey = Program._DATA_TABLE.Rows[i]["PN"].ToString().Trim().PadLeft(8, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
                        properties.Add("SKU", new EntityProperty(Program._DATA_TABLE.Rows[i]["ProductCode"].ToString().Trim()));
                        properties.Add("BuyerCode", new EntityProperty(Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim()));
                        properties.Add("Name", new EntityProperty(Program._DATA_TABLE.Rows[i]["Name"].ToString().Trim()));
                        properties.Add("Price", new EntityProperty(Program._DATA_TABLE.Rows[i]["MinPrice"].ToString().Trim()));
                        properties.Add("Price1", new EntityProperty(Program._DATA_TABLE.Rows[i]["price1"].ToString().Trim()));
                        properties.Add("Price2", new EntityProperty(Program._DATA_TABLE.Rows[i]["price2"].ToString().Trim()));
                        properties.Add("Price3", new EntityProperty(Program._DATA_TABLE.Rows[i]["price3"].ToString().Trim()));
                        properties.Add("Price4", new EntityProperty(Program._DATA_TABLE.Rows[i]["price4"].ToString().Trim()));
                        properties.Add("Price5", new EntityProperty(Program._DATA_TABLE.Rows[i]["price5"].ToString().Trim()));
                        properties.Add("Price6", new EntityProperty(Program._DATA_TABLE.Rows[i]["Price6"].ToString().Trim()));
                        properties.Add("Price7", new EntityProperty("0"));
                        properties.Add("Price8", new EntityProperty("0"));
                        properties.Add("Stock", new EntityProperty(Convert.ToInt32(Program._DATA_TABLE.Rows[i]["stock"].ToString().Trim())));
                        properties.Add("Cost", new EntityProperty(Convert.ToDouble(Program._DATA_TABLE.Rows[i]["cost"].ToString().Trim())));
                        properties.Add("CoverImage", new EntityProperty(Program._DATA_TABLE.Rows[i]["CoverImage"].ToString().Trim()));
                        properties.Add("Image1", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image1"].ToString().Trim()));
                        properties.Add("Image2", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image2"].ToString().Trim()));
                        properties.Add("Image3", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image3"].ToString().Trim()));
                        properties.Add("Image4", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image4"].ToString().Trim()));
                        properties.Add("Image5", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image5"].ToString().Trim()));
                        properties.Add("Image6", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image6"].ToString().Trim()));
                        properties.Add("Image7", new EntityProperty(Program._DATA_TABLE.Rows[i]["Image7"].ToString().Trim()));
                        properties.Add("Image8", new EntityProperty(""));
                        properties.Add("Image9", new EntityProperty(""));
                        properties.Add("Image10", new EntityProperty(""));
                        properties.Add("Image11", new EntityProperty(""));
                        properties.Add("Image12", new EntityProperty(""));
                        properties.Add("Width", new EntityProperty(Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Width"].ToString().Trim())));
                        properties.Add("Length", new EntityProperty(Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Length"].ToString().Trim())));
                        properties.Add("Height", new EntityProperty(Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Height"].ToString().Trim())));
                        properties.Add("GrossWeight", new EntityProperty(Convert.ToDouble(Program._DATA_TABLE.Rows[i]["GrossWeight"].ToString().Trim())));
                        properties.Add("Rating", new EntityProperty("0"));
                        properties.Add("ReviewCount", new EntityProperty("0"));
                        properties.Add("Category", new EntityProperty(Program._DATA_TABLE.Rows[i]["GroupId"].ToString().Trim().PadLeft(5, '0')));
                        properties.Add("Brand", new EntityProperty(Program._DATA_TABLE.Rows[i]["BrandId"].ToString().Trim().PadLeft(5, '0')));
                        properties.Add("Warranty", new EntityProperty(Convert.ToInt32(Program._DATA_TABLE.Rows[i]["Warranty"].ToString().Trim())));
                        properties.Add("Location", new EntityProperty(Program._DATA_TABLE.Rows[i]["Location"].ToString().Trim()));
                        if (!Program._UPDATE) { properties.Add("View", new EntityProperty("0")); }
                        string ac = Program._DATA_TABLE.Rows[i]["active"].ToString().Trim();
                        if (ac == "1") {properties.Add("Active", new EntityProperty(true)); } else { properties.Add("Active", new EntityProperty(false)); }
                        properties.Add("Visible", new EntityProperty(Convert.ToBoolean(Program._DATA_TABLE.Rows[i]["visible"].ToString().Trim())));
                        try { properties.Add("AddDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["AddDate"].ToString()))); }
                        catch { }
                        properties.Add("OnCart", new EntityProperty(Convert.ToInt32(Program._DATA_TABLE.Rows[i]["onCart"].ToString().Trim())));
                        properties.Add("OnOrder", new EntityProperty(Convert.ToInt32(Program._DATA_TABLE.Rows[i]["onOrder"].ToString().Trim())));

                        data.Properties = properties;
                        //ProductEntity data = new ProductEntity("88888888", Program._DATA_TABLE.Rows[i]["PN"].ToString().Trim().PadLeft(8, '0'));
                        //data.SKU = Program._DATA_TABLE.Rows[i]["ProductCode"].ToString().Trim();
                        //data.BuyerCode = Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim();
                        //data.Name = Program._DATA_TABLE.Rows[i]["Name"].ToString().Trim();
                        //data.Price = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["MinPrice"].ToString().Trim());
                        //data.Price1 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price1"].ToString().Trim());
                        //data.Price2 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price2"].ToString().Trim());
                        //data.Price3 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price3"].ToString().Trim());
                        //data.Price4 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price4"].ToString().Trim());
                        //data.Price5 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price5"].ToString().Trim());
                        //data.Price6 = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["price6"].ToString().Trim());
                        //data.Price7 = 0;
                        //data.Price8 = 0;
                        //data.Stock = Convert.ToInt32(Program._DATA_TABLE.Rows[i]["stock"].ToString().Trim());
                        //data.Cost = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["cost"].ToString().Trim());
                        //data.CoverImage = Program._DATA_TABLE.Rows[i]["CoverImage"].ToString().Trim();
                        //data.Image1 = Program._DATA_TABLE.Rows[i]["Image1"].ToString().Trim();
                        //data.Image2 = Program._DATA_TABLE.Rows[i]["Image2"].ToString().Trim();
                        //data.Image3 = Program._DATA_TABLE.Rows[i]["Image3"].ToString().Trim();
                        //data.Image4 = Program._DATA_TABLE.Rows[i]["Image4"].ToString().Trim();
                        //data.Image5 = Program._DATA_TABLE.Rows[i]["Image5"].ToString().Trim();
                        //data.Image6 = Program._DATA_TABLE.Rows[i]["Image6"].ToString().Trim();
                        //data.Image7 = Program._DATA_TABLE.Rows[i]["Image7"].ToString().Trim();
                        //data.Image8 = "";
                        //data.Image9 = "";
                        //data.Image10 = "";
                        //data.Image11 = "";
                        //data.Image12 = "";
                        //data.Width = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Width"].ToString().Trim());
                        //data.Length = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Length"].ToString().Trim());
                        //data.Height = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Height"].ToString().Trim());
                        //data.Weight = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["Weight"].ToString().Trim());
                        //data.GrossWeight = Convert.ToDouble(Program._DATA_TABLE.Rows[i]["GrossWeight"].ToString().Trim());
                        //data.Rating = 0;
                        //data.ReviewCount = 0;
                        //data.Category = Program._DATA_TABLE.Rows[i]["GroupId"].ToString().Trim().PadLeft(5, '0');
                        //data.Brand = Program._DATA_TABLE.Rows[i]["BrandId"].ToString().Trim().PadLeft(5, '0');
                        //data.Warranty = Convert.ToInt32(Program._DATA_TABLE.Rows[i]["Warranty"].ToString().Trim());
                        //data.Location = Program._DATA_TABLE.Rows[i]["Location"].ToString().Trim();
                        //if (Program._UPDATE == false) { data.View = 0; }
                        //string ac = Program._DATA_TABLE.Rows[i]["active"].ToString().Trim();
                        //if (ac == "1") { data.Active = true; } else { data.Active = false; }
                        //data.Visible = Convert.ToBoolean(Program._DATA_TABLE.Rows[i]["visible"].ToString().Trim());
                        //try { data.AddDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["AddDate"].ToString()); }
                        //catch { }
                        //data.OnCart = Convert.ToInt32(Program._DATA_TABLE.Rows[i]["onCart"].ToString().Trim());
                        //data.OnOrder = Convert.ToInt32(Program._DATA_TABLE.Rows[i]["onOrder"].ToString().Trim());
                        batchOperation.InsertOrMerge(data);
                        recProduct++;
                        product[Program._DATA_TABLE.Rows[i]["PN"].ToString().Trim()] = true;
                    }
                    catch
                    {
                        Console.WriteLine(Program._DATA_TABLE.Rows[i]["PN"].ToString().Trim());
                    }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }

            //DynamicTableEntity data = new DynamicTableEntity();
            ////{
            ////    PartitionKey = "88888888",
            ////    RowKey = "1234",
            ////    ETag = "*",
            ////};

            //Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
            //properties.Add(key, new EntityProperty(int.Parse(value.ToString())));
            //data.Properties = properties;

            //var azureTable = Param.AzureTableClient.GetTableReference(table);
            //TableOperation updateOperation = TableOperation.Merge(data);
            //azureTable.Execute(updateOperation);
        }
コード例 #41
0
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable TransferH = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!TransferH.ContainsKey(Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey = Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();

                        properties.Add("BankAccount", new EntityProperty(Program._DATA_TABLE.Rows[i]["BankAccountID"].ToString().Trim()));
                        properties.Add("TransferMoney", new EntityProperty(double.Parse(Program._DATA_TABLE.Rows[i]["TransferMoney"].ToString().ToLower().Trim())));
                        try
                        {
                            properties.Add("ReceiveDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceiveDate"].ToString())));
                        }
                        catch { }

                        //BankTransferHeaderEntity data = new BankTransferHeaderEntity("88888888", Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim().PadLeft(6, '0'));
                        //data.BankAccount = Program._DATA_TABLE.Rows[i]["BankAccountID"].ToString().Trim();
                        //data.TransferMoney = double.Parse(Program._DATA_TABLE.Rows[i]["TransferMoney"].ToString().ToLower().Trim());
                        //try { data.ReceiveDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceiveDate"].ToString()); }
                        //catch { }
                        batchOperation.InsertOrMerge(data);
                        recTransferH++;
                        TransferH[Program._DATA_TABLE.Rows[i]["ID"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #42
0
ファイル: Category.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable category = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!category.ContainsKey(Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = "88888888";
                        data.RowKey = Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim().PadLeft(5, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
                        properties.Add("Name", new EntityProperty(Program._DATA_TABLE.Rows[i]["Name"].ToString()));
                        properties.Add("Url", new EntityProperty(Program._DATA_TABLE.Rows[i]["Name"].ToString().ToLower().Replace("/", "-").Replace(" ", "_").Replace("_-_", "-")));
                        properties.Add("Active", new EntityProperty(true));
                        properties.Add("Priority", new EntityProperty(99));

                        if (Program._DATA_TABLE.Rows[i]["cnt"] == null)
                        {
                            properties.Add("ProductCount", new EntityProperty(0));
                        }
                        else
                        {
                            properties.Add("ProductCount", new EntityProperty(int.Parse(Program._DATA_TABLE.Rows[i]["cnt"].ToString())));
                        }

                        //CategoryEntity data = new CategoryEntity("88888888", Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim().PadLeft(5, '0'));
                        //data.Name = Program._DATA_TABLE.Rows[i]["Name"].ToString();
                        //data.Url = Program._DATA_TABLE.Rows[i]["Name"].ToString().ToLower().Replace("/", "-").Replace(" ", "_").Replace("_-_", "-");
                        //data.Active = true;
                        //data.Priority = 99;
                        //if (Program._DATA_TABLE.Rows[i]["cnt"] == null)
                        //{
                        //    data.ProductCount = 0;
                        //}
                        //else
                        //{
                        //    data.ProductCount = int.Parse(Program._DATA_TABLE.Rows[i]["cnt"].ToString());
                        //}
                        batchOperation.InsertOrMerge(data);
                        recCategory++;
                        category[Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #43
0
        public void TableBatchInsertOrMergeSync()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            // Insert Or Merge with no pre-existing entity
            DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity("insertOrMerge entity", "foo");
            insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            currentTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            TableResult result = currentTable.Execute(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count);

            DynamicTableEntity mergeEntity = new DynamicTableEntity(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey);
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch2 = new TableBatchOperation();
            batch2.InsertOrMerge(mergeEntity);
            currentTable.ExecuteBatch(batch2);

            // Retrieve Entity & Verify Contents
            result = currentTable.Execute(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count);

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
コード例 #44
0
        private async Task DoTableBatchOperationsWithEmptyKeysAsync(TablePayloadFormat format)
        {
            tableClient.DefaultRequestOptions.PayloadFormat = format;

            // Insert Entity
            DynamicTableEntity ent = new DynamicTableEntity() { PartitionKey = "", RowKey = "" };
            ent.Properties.Add("foo2", new EntityProperty("bar2"));
            ent.Properties.Add("foo", new EntityProperty("bar"));
            TableBatchOperation batch = new TableBatchOperation();
            batch.Insert(ent);
            await currentTable.ExecuteBatchAsync(batch);

            // Retrieve Entity
            TableBatchOperation retrieveBatch = new TableBatchOperation();
            retrieveBatch.Retrieve(ent.PartitionKey, ent.RowKey);
            TableResult result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();

            DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey);
            Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey);
            Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(ent.Properties["foo"].StringValue, retrievedEntity.Properties["foo"].StringValue);
            Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]);
            Assert.AreEqual(ent.Properties["foo2"].StringValue, retrievedEntity.Properties["foo2"].StringValue);
            Assert.AreEqual(ent.Properties["foo2"], retrievedEntity.Properties["foo2"]);

            // InsertOrMerge
            DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrMergeEntity.Properties.Add("foo3", new EntityProperty("value"));
            batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            await currentTable.ExecuteBatchAsync(batch);

            result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["foo3"], retrievedEntity.Properties["foo3"]);

            // InsertOrReplace
            DynamicTableEntity insertOrReplaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey);
            insertOrReplaceEntity.Properties.Add("prop2", new EntityProperty("otherValue"));
            batch = new TableBatchOperation();
            batch.InsertOrReplace(insertOrReplaceEntity);
            await currentTable.ExecuteBatchAsync(batch);

            result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(1, retrievedEntity.Properties.Count);
            Assert.AreEqual(insertOrReplaceEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);

            // Merge
            DynamicTableEntity mergeEntity = new DynamicTableEntity(retrievedEntity.PartitionKey, retrievedEntity.RowKey) { ETag = retrievedEntity.ETag };
            mergeEntity.Properties.Add("mergeProp", new EntityProperty("merged"));
            batch = new TableBatchOperation();
            batch.Merge(mergeEntity);
            await currentTable.ExecuteBatchAsync(batch);

            // Retrieve Entity & Verify Contents
            result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
            retrievedEntity = result.Result as DynamicTableEntity;

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(mergeEntity.Properties["mergeProp"], retrievedEntity.Properties["mergeProp"]);

            // Replace
            DynamicTableEntity replaceEntity = new DynamicTableEntity(ent.PartitionKey, ent.RowKey) { ETag = retrievedEntity.ETag };
            replaceEntity.Properties.Add("replaceProp", new EntityProperty("replace"));
            batch = new TableBatchOperation();
            batch.Replace(replaceEntity);
            await currentTable.ExecuteBatchAsync(batch);

            // Retrieve Entity & Verify Contents
            result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(replaceEntity.Properties.Count, retrievedEntity.Properties.Count);
            Assert.AreEqual(replaceEntity.Properties["replaceProp"], retrievedEntity.Properties["replaceProp"]);

            // Delete Entity
            batch = new TableBatchOperation();
            batch.Delete(retrievedEntity);
            await currentTable.ExecuteBatchAsync(batch);

            // Retrieve Entity
            result = (await currentTable.ExecuteBatchAsync(retrieveBatch)).First();
            Assert.IsNull(result.Result);
        }
コード例 #45
0
        internal override void InitializeHooks()
        {
            OnTableClientState(TableClientState.PREFER_NEW, async () => {
                TableBatchOperation batch = new TableBatchOperation();
                batch.InsertOrMerge(TestUtils.CreateTestEntity2("0", false));
                await RunBatchAsync(batch);

                await RunQueryStreamedAsync(new TableQuery<DynamicTableEntity>
                {
                    FilterString = TableQuery.GenerateFilterConditionForBool("isHappy", QueryComparisons.Equal, true)
                });
            });
        }
コード例 #46
0
ファイル: Customer.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable customer = new Hashtable();

            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if (!customer.ContainsKey(Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim()))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = Program._DATA_TABLE.Rows[i]["shop"].ToString().Trim();
                        data.RowKey = Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim().PadLeft(6, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();

                        properties.Add("Member", new EntityProperty(Program._DATA_TABLE.Rows[i]["Member"].ToString().Trim()));
                        properties.Add("Name", new EntityProperty(Program._DATA_TABLE.Rows[i]["Name"].ToString().Trim()));
                        properties.Add("ShopName", new EntityProperty(Program._DATA_TABLE.Rows[i]["ShopName"].ToString().Trim()));
                        properties.Add("ContactName", new EntityProperty(Program._DATA_TABLE.Rows[i]["ContactName"].ToString().Trim()));
                        properties.Add("Email", new EntityProperty(Program._DATA_TABLE.Rows[i]["Email"].ToString().Trim()));
                        properties.Add("Address", new EntityProperty(Program._DATA_TABLE.Rows[i]["Address"].ToString().Trim()));
                        properties.Add("Address2", new EntityProperty(Program._DATA_TABLE.Rows[i]["Address2"].ToString().Trim()));
                        properties.Add("District", new EntityProperty(Program._DATA_TABLE.Rows[i]["District"].ToString().Trim()));
                        properties.Add("Province", new EntityProperty(Program._DATA_TABLE.Rows[i]["Province"].ToString().Trim()));
                        properties.Add("ZipCode", new EntityProperty(Program._DATA_TABLE.Rows[i]["ZipCode"].ToString().Trim()));
                        properties.Add("Tel", new EntityProperty(Program._DATA_TABLE.Rows[i]["Tel"].ToString().Trim()));
                        properties.Add("Mobile", new EntityProperty(Program._DATA_TABLE.Rows[i]["Mobile"].ToString().Trim()));
                        properties.Add("Fax", new EntityProperty(Program._DATA_TABLE.Rows[i]["Fax"].ToString().Trim()));
                        properties.Add("TaxCode", new EntityProperty(Program._DATA_TABLE.Rows[i]["TaxCode"].ToString().Trim()));
                        properties.Add("Credit", new EntityProperty(int.Parse(Program._DATA_TABLE.Rows[i]["Credit"].ToString().Trim())));
                        properties.Add("DiscountPercent", new EntityProperty((int)double.Parse(Program._DATA_TABLE.Rows[i]["DiscountPercent"].ToString().Trim())));
                        properties.Add("SellPrice", new EntityProperty(int.Parse(Program._DATA_TABLE.Rows[i]["SellPrice"].ToString().Trim())));
                        properties.Add("Comment", new EntityProperty(Program._DATA_TABLE.Rows[i]["Comment"].ToString().Trim()));
                        try { properties.Add("AddDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["AddDate"].ToString()))); }
                        catch { }
                        string ac = Program._DATA_TABLE.Rows[i]["Active"].ToString().Trim();
                        if (ac == "1") { properties.Add("Active", new EntityProperty(true)); } else { properties.Add("Active", new EntityProperty(false)); }

                        ////CustomerEntity data = new CustomerEntity(Program._DATA_TABLE.Rows[i]["shop"].ToString().Trim(), Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim().PadLeft(6, '0'));
                        //data.Member = Program._DATA_TABLE.Rows[i]["Member"].ToString().Trim();
                        //data.Name = Program._DATA_TABLE.Rows[i]["Name"].ToString().Trim();
                        //data.ShopName = Program._DATA_TABLE.Rows[i]["ShopName"].ToString().Trim();
                        //data.ContactName = Program._DATA_TABLE.Rows[i]["ContactName"].ToString().Trim();
                        //data.Email = Program._DATA_TABLE.Rows[i]["Email"].ToString().Trim();
                        //data.Address = Program._DATA_TABLE.Rows[i]["Address"].ToString().Trim();
                        //data.Address2 = Program._DATA_TABLE.Rows[i]["Address2"].ToString().Trim();
                        //data.District = Program._DATA_TABLE.Rows[i]["District"].ToString().Trim();
                        //data.Province = Program._DATA_TABLE.Rows[i]["Province"].ToString().Trim();
                        //data.ZipCode = Program._DATA_TABLE.Rows[i]["Zipcode"].ToString().Trim();
                        //data.Tel = Program._DATA_TABLE.Rows[i]["Tel"].ToString().Trim();
                        //data.Mobile = Program._DATA_TABLE.Rows[i]["Mobile"].ToString().Trim();
                        //data.Fax = Program._DATA_TABLE.Rows[i]["Fax"].ToString().Trim();
                        //data.TaxCode = Program._DATA_TABLE.Rows[i]["TaxCode"].ToString().Trim();
                        //data.Credit = int.Parse(Program._DATA_TABLE.Rows[i]["Credit"].ToString().Trim());
                        //data.DiscountPercent = (int)double.Parse(Program._DATA_TABLE.Rows[i]["DiscountPercent"].ToString().Trim());
                        //data.SellPrice = int.Parse(Program._DATA_TABLE.Rows[i]["SellPrice"].ToString().Trim());
                        //data.Comment = Program._DATA_TABLE.Rows[i]["Comment"].ToString().Trim();
                        //try { data.AddDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["AddDate"].ToString()); }
                        //catch { }
                        //string ac = Program._DATA_TABLE.Rows[i]["Active"].ToString().Trim();
                        //if (ac == "1") { data.Active = true; } else { data.Active = false; }
                        batchOperation.InsertOrMerge(data);
                        recCustomer++;
                        customer[Program._DATA_TABLE.Rows[i]["RowKey"].ToString().Trim()] = true;
                    }
                    catch { }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }
            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #47
0
        public void CloudTableClientNullPartitionKeyRowKeyCheck()
        {
            CloudTableClient client = GenerateCloudTableClient();
            var table = client.GetTableReference("newtable");
            table.CreateIfNotExists();
            try
            {
                TableBatchOperation batch = new TableBatchOperation();
                TableEntity entity = new TableEntity(null, "foo");
                batch.InsertOrMerge(entity);
                table.ExecuteBatch(batch);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
            }

            try
            {
                TableBatchOperation batch = new TableBatchOperation();
                TableEntity entity = new TableEntity("foo", null);
                batch.InsertOrMerge(entity);
                table.ExecuteBatch(batch);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
            }
        }
コード例 #48
0
        async Task DoRandomAtomicCalls()
        {
            for (int callNum = 0; callNum < MigrationModel.NUM_CALLS_PER_MACHINE; callNum++)
            {
                SortedDictionary<PrimaryKey, DynamicTableEntity> dump = await peekProxy.DumpReferenceTableAsync();

                if (PSharpRuntime.Nondeterministic())
                {
                    // Query
                    var query = new TableQuery<DynamicTableEntity>();
                    query.FilterString = ChainTableUtils.CombineFilters(
                        TableQuery.GenerateFilterCondition(
                            TableConstants.PartitionKey, QueryComparisons.Equal, MigrationModel.SINGLE_PARTITION_KEY),
                        TableOperators.And,
                        NondeterministicUserPropertyFilterString());
                    await RunQueryAtomicAsync(query);
                }
                else
                {
                    // Batch write
                    int batchSize = PSharpRuntime.Nondeterministic() ? 2 : 1;
                    var batch = new TableBatchOperation();
                    var rowKeyChoices = new List<string> { "0", "1", "2", "3", "4", "5" };

                    for (int opNum = 0; opNum < batchSize; opNum++)
                    {
                        int opTypeNum = PSharpNondeterminism.Choice(7);
                        int rowKeyI = PSharpNondeterminism.Choice(rowKeyChoices.Count);
                        string rowKey = rowKeyChoices[rowKeyI];
                        rowKeyChoices.RemoveAt(rowKeyI);  // Avoid duplicate in same batch
                        var primaryKey = new PrimaryKey(MigrationModel.SINGLE_PARTITION_KEY, rowKey);
                        string eTag = null;
                        if (opTypeNum >= 1 && opTypeNum <= 3)
                        {
                            DynamicTableEntity existingEntity;
                            int etagTypeNum = PSharpNondeterminism.Choice(
                                dump.TryGetValue(primaryKey, out existingEntity) ? 3 : 2);
                            switch (etagTypeNum)
                            {
                                case 0: eTag = ChainTable2Constants.ETAG_ANY; break;
                                case 1: eTag = "wrong"; break;
                                case 2: eTag = existingEntity.ETag; break;
                            }
                        }
                        DynamicTableEntity entity = new DynamicTableEntity
                        {
                            PartitionKey = MigrationModel.SINGLE_PARTITION_KEY,
                            RowKey = rowKey,
                            ETag = eTag,
                            Properties = new Dictionary<string, EntityProperty> {
                                // Give us something to see on merge.  Might help with tracing too!
                                { string.Format("{0}_c{1}_o{2}", machineId.ToString(), callNum, opNum),
                                    new EntityProperty(true) },
                                // Property with 50%/50% distribution for use in filters.
                                { "isHappy", new EntityProperty(PSharpRuntime.Nondeterministic()) }
                            }
                        };
                        switch (opTypeNum)
                        {
                            case 0: batch.Insert(entity); break;
                            case 1: batch.Replace(entity); break;
                            case 2: batch.Merge(entity); break;
                            case 3: batch.Delete(entity); break;
                            case 4: batch.InsertOrReplace(entity); break;
                            case 5: batch.InsertOrMerge(entity); break;
                            case 6:
                                entity.ETag = ChainTable2Constants.ETAG_DELETE_IF_EXISTS;
                                batch.Delete(entity); break;
                        }
                    }

                    await RunBatchAsync(batch);
                }
            }
        }
コード例 #49
0
        public void TableBatchInsertOrMergeAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            // Insert Or Merge with no pre-existing entity
            DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity("insertOrMerge entity", "foo");
            insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);

            using (ManualResetEvent evt = new ManualResetEvent(false))
            {
                IAsyncResult asyncRes = null;
                currentTable.BeginExecuteBatch(batch, (res) =>
                {
                    asyncRes = res;
                    evt.Set();
                }, null);
                evt.WaitOne();

                currentTable.EndExecuteBatch(asyncRes);
            }

            // Retrieve Entity & Verify Contents
            TableResult result = currentTable.Execute(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count);

            DynamicTableEntity mergeEntity = new DynamicTableEntity(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey);
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch2 = new TableBatchOperation();
            batch2.InsertOrMerge(mergeEntity);
            using (ManualResetEvent evt = new ManualResetEvent(false))
            {
                IAsyncResult asyncRes = null;
                currentTable.BeginExecuteBatch(batch2, (res) =>
                {
                    asyncRes = res;
                    evt.Set();
                }, null);
                evt.WaitOne();

                currentTable.EndExecuteBatch(asyncRes);
            }

            // Retrieve Entity & Verify Contents
            result = currentTable.Execute(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count);

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
コード例 #50
0
        private async Task InsertOrMergeBatchWithNEntities(int n, TablePayloadFormat format)
        {
            tableClient.DefaultRequestOptions.PayloadFormat = format;

            string pk = Guid.NewGuid().ToString();

            TableBatchOperation insertBatch = new TableBatchOperation();
            TableBatchOperation mergeBatch = new TableBatchOperation();
            TableBatchOperation delBatch = new TableBatchOperation();

            for (int m = 0; m < n; m++)
            {
                insertBatch.InsertOrMerge(GenerateRandomEntity(pk));
            }

            IList<TableResult> results = await currentTable.ExecuteBatchAsync(insertBatch);
            foreach (TableResult res in results)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);

                // update entity and add to merge batch
                DynamicTableEntity ent = res.Result as DynamicTableEntity;
                ent.Properties.Add("foo2", new EntityProperty("bar2"));
                mergeBatch.InsertOrMerge(ent);

            }

            // execute insertOrMerge batch, this time entities exist
            IList<TableResult> mergeResults = await currentTable.ExecuteBatchAsync(mergeBatch);

            foreach (TableResult res in mergeResults)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);

                // Add to delete batch
                delBatch.Delete((ITableEntity)res.Result);
            }

            IList<TableResult> delResults = await currentTable.ExecuteBatchAsync(delBatch);
            foreach (TableResult res in delResults)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);
            }
        }
コード例 #51
0
        private async Task DoTableBatchInsertOrMergeAsync(TablePayloadFormat format)
        {
            tableClient.DefaultRequestOptions.PayloadFormat = format;

            // Insert Or Merge with no pre-existing entity
            DynamicTableEntity insertOrMergeEntity = new DynamicTableEntity("insertOrMerge entity", "foo" + format.ToString());
            insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            await currentTable.ExecuteBatchAsync(batch);

            // Retrieve Entity & Verify Contents
            TableResult result = await currentTable.ExecuteAsync(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            DynamicTableEntity retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count);

            DynamicTableEntity mergeEntity = new DynamicTableEntity(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey);
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch2 = new TableBatchOperation();
            batch2.InsertOrMerge(mergeEntity);
            await currentTable.ExecuteBatchAsync(batch2);

            // Retrieve Entity & Verify Contents
            result = await currentTable.ExecuteAsync(TableOperation.Retrieve(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            retrievedEntity = result.Result as DynamicTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count);

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
コード例 #52
0
ファイル: Barcode.cs プロジェクト: PowerDD/DataSync
        public void Insert()
        {
            TableBatchOperation batchOperation = new TableBatchOperation();
            Hashtable barcode = new Hashtable();
            for (int i = id; i < id + 100 && i < Program._DATA_TABLE.Rows.Count; i++)
            {
                if ((!barcode.ContainsKey(Program._DATA_TABLE.Rows[i]["Shop"].ToString().Trim()) && !barcode.ContainsKey(Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim())) || (Program._UPDATE == true))
                {
                    try
                    {
                        DynamicTableEntity data = new DynamicTableEntity();
                        data.PartitionKey = Program._DATA_TABLE.Rows[i]["Shop"].ToString().Trim();
                        data.RowKey = Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim().PadLeft(8, '0');
                        Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>();
                        //BarcodeEntity data = new BarcodeEntity(Program._DATA_TABLE.Rows[i]["Shop"].ToString().Trim(), Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim().PadLeft(8, '0'));
                        properties.Add("Product", new EntityProperty(Program._DATA_TABLE.Rows[i]["ProductID"].ToString().Trim().PadLeft(8, '0')));
                        properties.Add("DocNo", new EntityProperty(Program._DATA_TABLE.Rows[i]["DocNumber"].ToString().Trim().PadLeft(8, '0')));
                        properties.Add("SellNo", new EntityProperty(Program._DATA_TABLE.Rows[i]["SellNumber"].ToString().Trim().PadLeft(8, '0')));
                        properties.Add("OrderNo", new EntityProperty(Program._DATA_TABLE.Rows[i]["BillNumber"].ToString().Trim()));
                        try
                        {
                            properties.Add("ReceivedDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceivedDate"].ToString())));
                        }
                        catch { }
                        try
                        {
                            properties.Add("SellDate", new EntityProperty(Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["SellDate"].ToString())));
                        }
                        catch { }
                        properties.Add("Customer", new EntityProperty(Program._DATA_TABLE.Rows[i]["CustomerNumber"].ToString().Trim().PadLeft(6, '0')));
                        properties.Add("SellPrice", new EntityProperty(double.Parse(Program._DATA_TABLE.Rows[i]["SellPrice"].ToString().Trim())));
                        properties.Add("Cost", new EntityProperty(0));
                        properties.Add("OperationCost", new EntityProperty(0));
                        properties.Add("SellFinished", new EntityProperty(true));

                        //data.Product = Program._DATA_TABLE.Rows[i]["ProductID"].ToString().Trim().PadLeft(8, '0');
                        //data.DocNo = Program._DATA_TABLE.Rows[i]["DocNumber"].ToString().Trim().PadLeft(8, '0');
                        //data.SellNo = Program._DATA_TABLE.Rows[i]["SellNumber"].ToString().Trim().PadLeft(8, '0');
                        //data.OrderNo = Program._DATA_TABLE.Rows[i]["BillNumber"].ToString().Trim();
                        //try { data.ReceivedDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["ReceivedDate"].ToString()); }
                        //catch { }
                        //try { data.SellDate = Convert.ToDateTime(Program._DATA_TABLE.Rows[i]["SellDate"].ToString()); }
                        //catch { }
                        //data.Customer = Program._DATA_TABLE.Rows[i]["CustomerNumber"].ToString().Trim().PadLeft(6, '0');
                        //data.SellPrice = double.Parse(Program._DATA_TABLE.Rows[i]["SellPrice"].ToString().Trim());
                        //data.Cost = 0;
                        //data.OperationCost = 0;
                        //data.SellFinished = true;
                        recBarcode++;
                        batchOperation.InsertOrMerge(data);
                        barcode[Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim()] = true;
                    }
                    catch
                    {
                        Console.WriteLine(Program._DATA_TABLE.Rows[i]["Barcode"].ToString().Trim());
                    }
                }
            }

            try
            {
                if (Program._DATA_TABLE.Rows.Count > 0)
                {
                    if (Program._UPDATE)
                    {
                        Program._RECORD++;
                        Console.WriteLine("Update Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                        //Program._COUNT_BARCODE--;
                    }
                    else
                    {
                        Program._RECORD++;
                        Console.WriteLine("Insert Record {0}-{1}\t\tTotal {2} Records", id + 1, id + 100, Program._RECORD * 100);
                        Program._CLOUD_TABLE.ExecuteBatch(batchOperation);
                    }
                }

            }
            catch (Exception e)
            {
                Program.WriteErrorLog("Record " + (id + 1) + "-" + (id + 100) + " Error \n" + e.Message + "\n" + e.StackTrace);
            }
        }
コード例 #53
0
        public async Task TableBatchOnSecondaryAsync()
        {
            AssertSecondaryEndpoint();

            CloudTable table = GenerateCloudTableClient().GetTableReference(GenerateRandomTableName());

            TableRequestOptions options = new TableRequestOptions()
            {
                LocationMode = LocationMode.SecondaryOnly,
                RetryPolicy = new NoRetry(),
            };

            TableBatchOperation batch = new TableBatchOperation();
            batch.Retrieve("PartitionKey", "RowKey");

            OperationContext context = new OperationContext();
            await table.ExecuteBatchAsync(batch, options, context);
            Assert.AreEqual(StorageLocation.Secondary, context.LastResult.TargetLocation);

            batch = new TableBatchOperation();
            batch.Insert(new DynamicTableEntity("PartitionKey", "RowKey"));

            StorageException e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);

            batch = new TableBatchOperation();
            batch.InsertOrMerge(new DynamicTableEntity("PartitionKey", "RowKey"));

            e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);

            batch = new TableBatchOperation();
            batch.InsertOrReplace(new DynamicTableEntity("PartitionKey", "RowKey"));

            e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);

            batch = new TableBatchOperation();
            batch.Merge(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });

            e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);

            batch = new TableBatchOperation();
            batch.Replace(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });

            e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);

            batch = new TableBatchOperation();
            batch.Delete(new DynamicTableEntity("PartitionKey", "RowKey") { ETag = "*" });

            e = await TestHelper.ExpectedExceptionAsync<StorageException>(
                async () => await table.ExecuteBatchAsync(batch, options, null),
                "Batch operations other than retrieve should not be sent to secondary");
            Assert.AreEqual(SR.PrimaryOnlyCommand, e.Message);
        }
コード例 #54
0
        public void TableIngressEgressBatch()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            TableBatchOperation batch = new TableBatchOperation();

            for (int m = 0; m < 100; m++)
            {
                // Insert Entity
                DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", m.ToString());
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[30 * 1024]));
                batch.InsertOrMerge(insertEntity);
            }

            // APM
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains("$batch"), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.EndExecuteBatch(currentTable.BeginExecuteBatch(batch, new TableRequestOptions() { RetryPolicy = new RetryPolicies.NoRetry() }, opContext, null, null));
                return opContext.LastResult;
            });

            // SYNC
            TestHelper.ValidateIngressEgress(Selectors.IfUrlContains("$batch"), () =>
            {
                OperationContext opContext = new OperationContext();
                currentTable.ExecuteBatch(batch, new TableRequestOptions() { RetryPolicy = new RetryPolicies.NoRetry() }, opContext);
                return opContext.LastResult;
            });
        }
コード例 #55
0
        private async Task DoTableBatchAllSupportedOperationsAsync(TablePayloadFormat format)
        {
            tableClient.DefaultRequestOptions.PayloadFormat = format;

            TableBatchOperation batch = new TableBatchOperation();
            string pk = Guid.NewGuid().ToString();

            // insert
            batch.Insert(GenerateRandomEntity(pk));

            // delete
            {
                DynamicTableEntity entity = GenerateRandomEntity(pk);
                await currentTable.ExecuteAsync(TableOperation.Insert(entity));
                batch.Delete(entity);
            }

            // replace
            {
                DynamicTableEntity entity = GenerateRandomEntity(pk);
                await currentTable.ExecuteAsync(TableOperation.Insert(entity));
                batch.Replace(entity);
            }

            // insert or replace
            {
                DynamicTableEntity entity = GenerateRandomEntity(pk);
                await currentTable.ExecuteAsync(TableOperation.Insert(entity));
                batch.InsertOrReplace(entity);
            }

            // merge
            {
                DynamicTableEntity entity = GenerateRandomEntity(pk);
                await currentTable.ExecuteAsync(TableOperation.Insert(entity));
                batch.Merge(entity);
            }

            // insert or merge
            {
                DynamicTableEntity entity = GenerateRandomEntity(pk);
                await currentTable.ExecuteAsync(TableOperation.Insert(entity));
                batch.InsertOrMerge(entity);
            }

            IList<TableResult> results = await currentTable.ExecuteBatchAsync(batch);

            Assert.AreEqual(results.Count, 6);

            IEnumerator<TableResult> enumerator = results.GetEnumerator();
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.Created);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current.HttpStatusCode, (int)HttpStatusCode.NoContent);
        }
コード例 #56
0
        private void InsertOrMergeBatchWithNEntities(int n)
        {
            string pk = Guid.NewGuid().ToString();

            TableBatchOperation insertBatch = new TableBatchOperation();
            TableBatchOperation mergeBatch = new TableBatchOperation();
            TableBatchOperation delBatch = new TableBatchOperation();

            for (int m = 0; m < n; m++)
            {
                insertBatch.InsertOrMerge(GenerateRandomEnitity(pk));
            }

            IList<TableResult> results = this.repTable.ExecuteBatch(insertBatch);
            foreach (TableResult res in results)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);

                // update entity and add to merge batch
                DynamicReplicatedTableEntity ent = res.Result as DynamicReplicatedTableEntity;
                ent.Properties.Add("foo2", new EntityProperty("bar2"));
                mergeBatch.InsertOrMerge(ent);

            }

            // execute insertOrMerge batch, this time entities exist
            IList<TableResult> mergeResults = this.repTable.ExecuteBatch(mergeBatch);

            foreach (TableResult res in mergeResults)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);

                // Add to delete batch
                delBatch.Delete((ITableEntity)res.Result);
            }

            IList<TableResult> delResults = this.repTable.ExecuteBatch(delBatch);
            foreach (TableResult res in delResults)
            {
                Assert.AreEqual(res.HttpStatusCode, (int)HttpStatusCode.NoContent);
            }
        }
コード例 #57
0
ファイル: Program.cs プロジェクト: Siriuszyq/Test1
        /// <summary>
        /// Demonstrate inserting of a large batch of entities. Some considerations for batch operations:
        ///  1. You can perform updates, deletes, and inserts in the same single batch operation.
        ///  2. A single batch operation can include up to 100 entities.
        ///  3. All entities in a single batch operation must have the same partition key.
        ///  4. While it is possible to perform a query as a batch operation, it must be the only operation in the batch.
        ///  5. Batch size must be <= 4MB
        /// </summary>
        /// <param name="table">Sample table name</param>
        private static async Task BatchInsertOfCustomerEntitiesAsync(CloudTable table)
        {
            // Create the batch operation. 
            TableBatchOperation batchOperation = new TableBatchOperation();

            // The following code  generates test data for use during the query samples.  
            for (int i = 0; i < 100; i++)
            {
                batchOperation.InsertOrMerge(new CustomerEntity("Smith", string.Format("{0}", i.ToString("D4")))
                {
                    Email = string.Format("{0}@contoso.com", i.ToString("D4")),
                    PhoneNumber = string.Format("425-555-{0}", i.ToString("D4"))
                });
            }

            // Execute the batch operation.
            IList<TableResult> results = await table.ExecuteBatchAsync(batchOperation);

            foreach (var res in results)
            {
                var customerInserted = res.Result as CustomerEntity;
                Console.WriteLine("Inserted entity with\t Etag = {0} and PartitionKey = {1}, RowKey = {2}", customerInserted.ETag, customerInserted.PartitionKey, customerInserted.RowKey);
            }

        }
コード例 #58
0
        public void TableBatchAllSupportedOperationsSync()
        {
            TableBatchOperation batch = new TableBatchOperation();
            string pk = Guid.NewGuid().ToString();

            // insert
            batch.Insert(GenerateRandomEnitity(pk));

            // delete
            {
                DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
                this.repTable.Execute(TableOperation.Insert(entity));
                batch.Delete(entity);
            }

            // replace
            {
                DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
                this.repTable.Execute(TableOperation.Insert(entity));
                batch.Replace(entity);
            }

            // insert or replace
            {
                DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
                this.repTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrReplace(entity);
            }

            // merge
            {
                DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
                this.repTable.Execute(TableOperation.Insert(entity));
                batch.Merge(entity);
            }

            // insert or merge
            {
                DynamicReplicatedTableEntity entity = GenerateRandomEnitity(pk);
                this.repTable.Execute(TableOperation.Insert(entity));
                batch.InsertOrMerge(entity);
            }

            IList<TableResult> results = this.repTable.ExecuteBatch(batch);

            Assert.AreEqual(results.Count, 6);
            IEnumerator<TableResult> enumerator = results.GetEnumerator();
            for (int i = 0; i < results.Count; i++)
            {
                enumerator.MoveNext();
                Assert.AreEqual((int)HttpStatusCode.NoContent, enumerator.Current.HttpStatusCode, "HttpStatusCode mismatch i={0}", i);
            }
        }
コード例 #59
0
        public void TableBatchInsertOrMergeSync()
        {
            // Insert Or Merge with no pre-existing entity
            DynamicReplicatedTableEntity insertOrMergeEntity = new DynamicReplicatedTableEntity("batchInsertOrMerge entity", "foo");
            insertOrMergeEntity.Properties.Add("prop1", new EntityProperty("value1"));

            TableBatchOperation batch = new TableBatchOperation();
            batch.InsertOrMerge(insertOrMergeEntity);
            IList<TableResult> batchResultList = this.repTable.ExecuteBatch(batch);

            // Retrieve Entity & Verify Contents
            TableResult result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            DynamicReplicatedTableEntity retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties.Count, retrievedEntity.Properties.Count);

            DynamicReplicatedTableEntity mergeEntity = new DynamicReplicatedTableEntity(insertOrMergeEntity.PartitionKey,
                                                                      insertOrMergeEntity.RowKey,
                                                                      batchResultList[0].Etag,
                                                                      retrievedEntity.Properties);
            mergeEntity.Properties.Add("prop2", new EntityProperty("value2"));

            TableBatchOperation batch2 = new TableBatchOperation();
            batch2.InsertOrMerge(mergeEntity);
            this.repTable.ExecuteBatch(batch2);

            // Retrieve Entity & Verify Contents
            result = this.repTable.Execute(TableOperation.Retrieve<DynamicReplicatedTableEntity>(insertOrMergeEntity.PartitionKey, insertOrMergeEntity.RowKey));
            retrievedEntity = result.Result as DynamicReplicatedTableEntity;
            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(2, retrievedEntity.Properties.Count, "retrievedEntity.Properties.Count={0}. (Expecting 2)", retrievedEntity.Properties.Count);

            Assert.IsNotNull(retrievedEntity);
            Assert.AreEqual(insertOrMergeEntity.Properties["prop1"], retrievedEntity.Properties["prop1"]);
            Assert.AreEqual(mergeEntity.Properties["prop2"], retrievedEntity.Properties["prop2"]);
        }
コード例 #60
0
ファイル: Startup.Data.cs プロジェクト: ichivers/TwilioWho
        public void SeedAzureStorage()
        {
            Character character = null;
            TableBatchOperation tableBatchOperation = new TableBatchOperation();
            CloudBlockBlob blockBlob = null;
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("characters");
            container.CreateIfNotExists();
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("characters");
            table.CreateIfNotExists();

            blockBlob = container.GetBlockBlobReference("sam");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\sam.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Sam",
                Bald = true,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = true,
                HairColour = "White",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("joe");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\joe.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Joe",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = true,
                HairColour = "Blonde",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("paul");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\paul.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Paul",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = true,
                HairColour = "White",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("george");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\george.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "George",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "White",
                Moustache = false ,
                Hat = true
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("philip");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\philip.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Philip",
                Bald = false,
                Beard = true,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Black",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("claire");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\claire.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Claire",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.female,
                EyeColour = "Brown",
                Glasses = true,
                HairColour = "Ginger",
                Moustache = false,
                Hat = true
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("anita");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\anita.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Anita",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.female,
                EyeColour = "Blue",
                Glasses = false,
                HairColour = "Blonde",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("alfred");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\alfred.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Alfred",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Blue",
                Glasses = false,
                HairColour = "Ginger",
                Moustache = true,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("susan");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\susan.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Susan",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.female,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "White",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("richard");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\richard.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Richard",
                Bald = true,
                Beard = true,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Brown",
                Moustache = true,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("frans");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\frans.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Frans",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Ginger",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("max");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\max.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Max",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Brown",
                Moustache = true,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("herman");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\herman.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Herman",
                Bald = true,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Ginger",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("david");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\david.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "David",
                Bald = false,
                Beard = true,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Blonde",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("bernard");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\bernard.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Bernard",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Brown",
                Moustache = false,
                Hat = true
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("alex");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\alex.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Alex",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Black",
                Moustache = true,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("tom");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\tom.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Tom",
                Bald = true,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Blue",
                Glasses = true,
                HairColour = "Black",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("robert");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\robert.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Robert",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Blue",
                Glasses = false,
                HairColour = "Brown",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("peter");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\peter.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Peter",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Blue",
                Glasses = false,
                HairColour = "White",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("maria");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\maria.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Maria",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.female,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Brown",
                Moustache = false,
                Hat = true
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("bill");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\bill.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Bill",
                Bald = true,
                Beard = true,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Ginger",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("eric");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\eric.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Eric",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Blonde",
                Moustache = false,
                Hat = true
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("charles");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\charles.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character(){
                PartitionKey = "Default",
                RowKey =  "Charles",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.male,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Blonde",
                Moustache = true,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            blockBlob = container.GetBlockBlobReference("anne");
            blockBlob.Properties.ContentType = "image/png";
            using (var fileStream = System.IO.File.OpenRead(HostingEnvironment.MapPath(@"~\Content\Images\anne.png")))
            {
                blockBlob.UploadFromStream(fileStream);
            }
            character = new Character()
            {
                PartitionKey = "Default",
                RowKey = "Anne",
                Bald = false,
                Beard = false,
                Gender = (int)Gender.female,
                EyeColour = "Brown",
                Glasses = false,
                HairColour = "Black",
                Moustache = false,
                Hat = false
            };
            tableBatchOperation.InsertOrMerge(character);

            table.ExecuteBatch(tableBatchOperation);
        }