예제 #1
0
        public void SumTest()
        {
            StorageRunnerContext.RunOnTable(storage,
                                            "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                            (cloudTable) =>
            {
                var entity = new DemoTableEntity
                {
                    PartitionKey = "PartitionKey",
                    RowKey       = "RowKey",
                    Name         = "Tomcat",
                    Count        = 3,
                };
                TableOperation insertOperation = TableOperation.Insert(entity);
                cloudTable.Execute(insertOperation);

                entity = new DemoTableEntity
                {
                    PartitionKey = "PartitionKey",
                    RowKey       = "RowKey2",
                    Name         = "jerry",
                    Count        = 100,
                };
                insertOperation = TableOperation.Insert(entity);
                cloudTable.Execute(insertOperation);

                var query = cloudTable.CreateQuery <DemoTableEntity>()
                            .Where(p => p.PartitionKey == "PartitionKey").AsEnumerable();

                Console.WriteLine("Total count:" + query.Sum(p => p.Count));
            });
        }
예제 #2
0
        public void InsertOrUpdate()
        {
            StorageRunnerContext.RunOnTable(storage,
                                            "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                            (cloudTable) =>
            {
                TableOperation retrieveOperation = TableOperation.Retrieve <DemoTableEntity>("PartitionKey", "Tomcat");
                TableResult retrieveResult       = cloudTable.Execute(retrieveOperation);
                DemoTableEntity result           = (DemoTableEntity)retrieveResult.Result;
                if (result != null)
                {
                    Console.WriteLine("name=" + result.Name);
                }
                else
                {
                    Console.WriteLine("It's null.");
                }

                result = new DemoTableEntity()
                {
                    PartitionKey = "PartitionKey", RowKey = "Tomcat", Rate = 1.55
                };
                TableOperation insertOrUpdateOp = TableOperation.InsertOrReplace(result);
                cloudTable.Execute(insertOrUpdateOp);

                result = (DemoTableEntity)cloudTable.Execute(retrieveOperation).Result;
                Console.WriteLine(result.Timestamp.ToString());

                TableOperation mergeOp = TableOperation.Merge(result);
                cloudTable.Execute(mergeOp);

                result = (DemoTableEntity)cloudTable.Execute(retrieveOperation).Result;
                Console.WriteLine(result.Timestamp.ToString());
            });
        }
예제 #3
0
        public void TableCaseQuery()
        {
            // The conclusion is that: `Equals()` using OrdinalIgnoreCase is that working at all.

            StorageRunnerContext.RunOnTable(storage,
                                            "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                            (cloudTable) =>
            {
                var entity = new DemoTableEntity
                {
                    PartitionKey     = "PartitionKey",
                    RowKey           = "RowKey",
                    Name             = "Tomcat",
                    CloudEnvironment = CloudEnvironment.AzureChina.ToString()
                };
                TableOperation insertOperation = TableOperation.Insert(entity);
                cloudTable.Execute(insertOperation);

                var query = cloudTable.CreateQuery <DemoTableEntity>()
                            .Where(p => p.PartitionKey == "PartitionKey" &&
                                   p.Name.Equals("Tomcat", StringComparison.OrdinalIgnoreCase)).ToArray();

                Console.WriteLine("name=" + query.FirstOrDefault()?.Name);
            });
        }
예제 #4
0
        public void ClientEncryption4Table()
        {
            StorageRunnerContext.RunOnTable(storage,
                                            "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                            (cloudTable) =>
            {
                RsaKey key = new RsaKey(Guid.NewGuid().ToString());
                TableEncryptionPolicy policy = new TableEncryptionPolicy(key, null);
                TableRequestOptions options  = new TableRequestOptions()
                {
                    EncryptionPolicy   = policy,
                    EncryptionResolver = (pk, rk, propName) =>
                    {
                        if (propName == "Name")
                        {
                            return(true);
                        }
                        return(false);
                    }
                };

                TableOperation retrieveOperation = TableOperation.Retrieve <DemoTableEntity>("PartitionKey", "Tomcat");
                TableResult retrieveResult       = cloudTable.Execute(retrieveOperation, options);
                DemoTableEntity result           = (DemoTableEntity)retrieveResult.Result;
                if (result != null)
                {
                    Console.WriteLine("name=" + result.Name);
                }
                else
                {
                    Console.WriteLine("It's null.");
                }

                result = new DemoTableEntity()
                {
                    PartitionKey = "PartitionKey", RowKey = "Tomcat", Rate = 1.55, Name = "originalname"
                };
                TableOperation insertOrUpdateOp = TableOperation.Insert(result);
                cloudTable.Execute(insertOrUpdateOp, options);

                result = (DemoTableEntity)cloudTable.Execute(retrieveOperation, options).Result;
                Console.WriteLine(result.Timestamp.ToString());

                // https://github.com/Azure/azure-storage-net/blob/c1966e1cd64d5eb8e40733ebd6b07b6b8e8fb136/Lib/ClassLibraryCommon/Table/Protocol/TableOperationHttpRequestFactory.cs
                // Merge or InsertOrMerge are not supported.
                result.Max = 1000;
                TableOperation mergeOps = TableOperation.Merge(result);
                result = (DemoTableEntity)cloudTable.Execute(mergeOps).Result;

                result = (DemoTableEntity)cloudTable.Execute(retrieveOperation, options).Result;
                Console.WriteLine(result.Timestamp.ToString());

                var segment = cloudTable.ExecuteQuerySegmented(cloudTable.CreateQuery <DemoTableEntity>(), null, options);
                var list    = segment.Results;
                Console.WriteLine(list.Count);
            });
        }
예제 #5
0
 public void EntityDoesntExistTest()
 {
     StorageRunnerContext.RunOnTable(storage,
                                     "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                     (cloudTable) =>
     {
         TableOperation retrieveOperation = TableOperation.Retrieve <DemoTableEntity>("PartitionKey", "Tomcat");
         TableResult retrieveResult       = cloudTable.Execute(retrieveOperation);
         DemoTableEntity result           = (DemoTableEntity)retrieveResult.Result;
         if (result != null)
         {
             Console.WriteLine("name=" + result.Name);
         }
         else
         {
             Console.WriteLine("It's null.");
         }
     });
 }
예제 #6
0
        public void IntricateQuery()
        {
            StorageRunnerContext.RunOnTable(storage,
                                            "jwtesttablea" + Guid.NewGuid().ToString().Substring(0, 8),
                                            (cloudTable) =>
            {
                var entity = new DemoTableEntity
                {
                    PartitionKey     = "PartitionKey",
                    RowKey           = "RowKey",
                    Name             = "Tomcat",
                    Count            = 0,
                    Max              = 0,
                    CloudEnvironment = CloudEnvironment.AzureChina.ToString()
                };
                TableOperation insertOperation = TableOperation.Insert(entity);
                cloudTable.Execute(insertOperation);

                var entity2 = new DemoTableEntity
                {
                    PartitionKey     = "PartitionKey",
                    RowKey           = "RowKey2",
                    Name             = "Tomcat2",
                    Count            = 10,
                    Max              = 5,
                    CloudEnvironment = CloudEnvironment.AzureChina.ToString()
                };
                TableOperation insertOperation2 = TableOperation.Insert(entity2);
                cloudTable.Execute(insertOperation2);

                // cannot compare columns in Azure table storage
                TableQuery <DemoTableEntity> query = new TableQuery <DemoTableEntity>().Where(AndMultipleFilters(
                                                                                                  TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "PartitionKey"),
                                                                                                  TableQuery.GenerateFilterConditionForInt("Max", QueryComparisons.NotEqual, 1)
                                                                                                  ));

                var entities = cloudTable.ExecuteQuery(query);

                Console.WriteLine("Count:" + entities.Count());
                Console.WriteLine("name=" + entities.FirstOrDefault()?.Name);
            });
        }