Ejemplo n.º 1
0
        private static async Task Main(string storageConnectionString = "", string storageTable = "",
                                       string csvFilePath             = "")
        {
            var table = await AzTableService.CreateTableAsync(storageTable, storageConnectionString).ConfigureAwait(false);

            using (var reader = new StreamReader(csvFilePath))
                using (var csv = new CsvReader(reader))
                {
                    var records = csv.GetRecords <CsvDto>();
                    foreach (var r in records)
                    {
                        var entity = new CsvEntity(r.Id.ToString(), r.Name);
                        await AzTableService.InsertOrMergeEntityAsync(table, entity).ConfigureAwait(false);
                    }
                }
        }
Ejemplo n.º 2
0
        public static async Task <CsvEntity> InsertOrMergeEntityAsync(CloudTable table, CsvEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            try
            {
                var insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

                var result = await table.ExecuteAsync(insertOrMergeOperation);

                var insertedCustomer = result.Result as CsvEntity;

                return(insertedCustomer);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }