Пример #1
0
        /// <summary>
        /// Create and Get Json Blob
        /// </summary>
        /// <returns></returns>
        public static async Task CreateAndGetJsonBlob()
        {
            CloudStorageAccount storageAccount = GetCloudStorageAccount.CreateStorageAccount();
            string TestContainerName           = containerName + DateTime.Now.ToString("yyyyMMddhhmmss").ToString();

            blobStorage = new BlobStorage(storageAccount, TestContainerName, BlobContainerPublicAccessType.Blob);

            List <CustomerEntity> insertEntityList = InsertDataCount.CreateCustomerEntity();

            string serializeListEntity = JsonConvert.SerializeObject(insertEntityList);

            string currentBlobName = BlobName + DateTime.Now.ToString("yyyyMMddhhmmss").ToString();
            await blobStorage.CreateBlockBlobString(currentBlobName, "application/json", serializeListEntity);

            string getJsonObject = await blobStorage.GetBlockBlobDataString(currentBlobName);

            List <CustomerEntity> getListEntity = JsonConvert.DeserializeObject <List <CustomerEntity> >(getJsonObject).ToList();

            if (getListEntity.Count == insertEntityList.Count &&
                insertEntityList.Count == GetSameEntities(getListEntity, insertEntityList).Count())
            {
                Log.Info("Get blob Data success, Count:{0}", getListEntity.Count);
                //blobStorage.DeleteContainer();
            }
            else
            {
                Log.Error("Get blob Data Fail, Expect Count:{0}, Actual Count{1}, blob Container name:{2}",
                          insertEntityList.Count, getListEntity.Count, TestContainerName);
            }
        }
Пример #2
0
        /// <summary>
        /// Drop Table according to table prefix
        /// </summary>
        /// <param name="tablePrefix">tablePrefix</param>
        public static void DropTable(string tablePrefix)
        {
            CloudStorageAccount        storageAccount = GetCloudStorageAccount.CreateStorageAccount();
            TableStorage <TableEntity> tableStorage   = new TableStorage <TableEntity>(storageAccount);
            IEnumerable <CloudTable>   tableList      = tableStorage.ListAllContainer();

            foreach (var table in tableList)
            {
                if (table.Name.Contains(tablePrefix))
                {
                    tableStorage.DeleteTable(table);
                    Console.WriteLine("Delete the table success:{0}", table.Name);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Drop Blob Container according to blob container prefix
        /// </summary>
        /// <param name="blobContainerPrefix">blobContainerPrefix</param>
        public static void DropBlobContainer(string blobContainerPrefix)
        {
            CloudStorageAccount storageAccount             = GetCloudStorageAccount.CreateStorageAccount();
            BlobStorage         blobStorage                = new BlobStorage(storageAccount);
            IEnumerable <CloudBlobContainer> containerList = blobStorage.ListAllContainer();

            foreach (var container in containerList)
            {
                if (container.Name.Contains(blobContainerPrefix))
                {
                    blobStorage.DeleteContainer(container);
                    Console.WriteLine("Delete the container success:{0}", container.Name);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Create and Get Table
        /// </summary>
        /// <returns></returns>
        public static async Task CreateAndGetTable()
        {
            CloudStorageAccount storageAccount = GetCloudStorageAccount.CreateStorageAccount();
            string currentTableName            = TableName + DateTime.Now.ToString("yyyyMMddhhmmss").ToString();

            //string currentTableName = "testtable20151225090911";

            tableStorage = new TableStorage <CustomerEntity>(storageAccount, currentTableName);

            List <CustomerEntity> insertEntityList = InsertDataCount.CreateCustomerEntity();

            await tableStorage.CreateEntities(insertEntityList);

            List <CustomerEntity> getTableResult = new List <CustomerEntity>();

            getTableResult = tableStorage.GetEntitiesByPartitionKey("Jonathan").Result.ToList();

            if (getTableResult.Count == insertEntityList.Count &&
                insertEntityList.Count == GetSameEntities(getTableResult, insertEntityList).Count())
            {
                Log.Info("GetEntitiesByPartitionKey from Table Success, Count:{0}", getTableResult.Count);
            }
            else
            {
                Log.Error("GetEntitiesByPartitionKey from Table Fail, Expect Count:{0}, Actual Count{1}, table name:{2}",
                          insertEntityList.Count, getTableResult.Count, currentTableName);
            }

            getTableResult = new List <CustomerEntity>();

            getTableResult = tableStorage.GetEntitiesByRowKeyAsync(
                InsertDataCount.StartRowKey(),
                InsertDataCount.EndRowKey()).Result.ToList();

            if (getTableResult.Count == takeCount &&
                takeCount == GetSameEntities(getTableResult, insertEntityList).Count())
            {
                Log.Info("GetEntitiesByRowKey from Table Success, Count:{0}", getTableResult.Count);
                //tableStorage.DeleteTable();
            }
            else
            {
                Log.Error("GetEntitiesByRowKey from Table Fail, Expect Count:{0}, Actual Count:{1}, table name:{2}",
                          insertEntityList.Count, getTableResult.Count, currentTableName);
            }
        }