コード例 #1
0
        /// <summary>
        /// Saves the request log to database.
        /// </summary>
        /// <param name="vmConfig">The VM configuration.</param>
        private static async Task SaveRequestLogToDB(VMConfig vmConfig, string exceptionMessage = "NA")
        {
            VMRequestLogEntity vmRequestLogEntity = new VMRequestLogEntity(vmConfig.VMName, vmConfig.VMSize)
            {
                VMName       = vmConfig.VMName,
                VMSize       = vmConfig.VMSize,
                ErrorMessage = exceptionMessage
            };

            await CosmosDBStorageHelper.InsertOrMergeEntityAsync(table, vmRequestLogEntity);
        }
コード例 #2
0
        /// <summary>
        /// Inserts the or merge entity asynchronous.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="entity">The entity.</param>
        /// <returns>The entity</returns>
        public static async Task <VMRequestLogEntity> InsertOrMergeEntityAsync(CloudTable table, VMRequestLogEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            try
            {
                await table.CreateIfNotExistsAsync();

                // Create the InsertOrMerge table operation
                var insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

                // Execute the operation.
                var result = await table.ExecuteAsync(insertOrMergeOperation);

                var insertedVMRequestLogEntity = result.Result as VMRequestLogEntity;

                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge);
                }

                return(insertedVMRequestLogEntity);
            }
            catch (StorageException)
            {
                throw;
            }
        }