UpdateEntity() 공개 메소드

public UpdateEntity ( string tablename, string partkey, string rowkey, object>.Dictionary entity ) : TableStorageListDictResponse
tablename string
partkey string
rowkey string
entity object>.Dictionary
리턴 TableStorageListDictResponse
예제 #1
0
 // scan the cacheurls table, compare uris with counts > 0 to uris in cache, if match then evict uri and decrement count
 public static void MaybePurgeCache(ICache cache)
 {
     try
     {
         var purgeable_entities = FetchPurgeableCacheDicts();
         GenUtils.LogMsg("status", String.Format("MaybePurgeCache: {0} purgeable entities", purgeable_entities.Count), null);
         foreach (var purgeable_entity in purgeable_entities)
         {
             var purgeable_cache_url = (string)purgeable_entity["cached_uri"];
             if (cache[purgeable_cache_url] != null)
             {
                 GenUtils.LogMsg("status", "MaybePurgeCache", purgeable_cache_url);
                 cache.Remove(purgeable_cache_url);
                 var obj   = HttpUtils.FetchUrl(new Uri(purgeable_cache_url));                       // rewarm the cache
                 var count = (int)purgeable_entity["count"];
                 count -= 1;
                 if (count < 0)
                 {
                     count = 0;
                     GenUtils.LogMsg("warning", "CacheUtils.MaybePurgeCache", "count went subzero, reset to zero");
                 }
                 purgeable_entity["count"] = count;
                 var rowkey = TableStorage.MakeSafeRowkeyFromUrl(purgeable_cache_url);
                 ts.UpdateEntity(cache_control_tablename, cache_control_partkey, rowkey, purgeable_entity);
             }
         }
     }
     catch (Exception e)
     {
         GenUtils.PriorityLogMsg("exception", "MaybePurgeCache", e.Message + e.StackTrace);
     }
 }
예제 #2
0
        public void UpdateEntityIsSuccessful()
        {
            if (ts.ExistsEntity(test_table, test_query) == false)
            {
                CreateEntityIsSuccessful();
            }
            var entity = new Dictionary <string, object>();

            entity.Add("PartitionKey", test_partition);
            entity.Add("RowKey", test_row);
            entity.Add("name", "entity_name");
            entity.Add("dt", test_dt);
            entity.Add("count", count + 1);
            Assert.AreEqual(HttpStatusCode.NoContent, ts.UpdateEntity(test_table, test_partition, test_row, entity).http_response.status);
            var q = string.Format("$filter=(count eq {0}) and (dt eq datetime'{1}')",
                                  count + 1, test_dt.ToString(TableStorage.ISO_FORMAT_UTC));
            var ts_response = ts.QueryEntities(test_table, q);
            var dicts       = ts_response.list_dict_obj;

            Assert.That(dicts.Count == 1);
            Assert.That((int)dicts[0]["count"] == count + 1);
        }
예제 #3
0
        // try to insert a dict<str,obj> into table store
        // if conflict, try to merge or update
        public static TableStorageListDictResponse DictObjToTableStore(Operation operation, Dictionary <string, object> dict, string table, string partkey, string rowkey)
        {
            TableStorage ts     = MakeDefaultTableStorage();
            var          entity = new Dictionary <string, object>();

            entity.Add("PartitionKey", partkey);
            entity.Add("RowKey", rowkey);
            foreach (var key in dict.Keys)
            {
                if (key != "PartitionKey" && key != "RowKey")
                {
                    entity.Add(key, dict[key]);
                }
            }
            var response = ts.InsertEntity(table, entity);

            if (response.http_response.status != HttpStatusCode.Created)
            {
                switch (operation)
                {
                case Operation.update:
                    response = ts.UpdateEntity(table, partkey, rowkey, entity);
                    break;

                case Operation.merge:
                    response = ts.MergeEntity(table, partkey, rowkey, entity);
                    break;

                default:
                    GenUtils.LogMsg("warning", "DictToTableStore unexpected operation", operation.ToString());
                    break;
                }
                if (response.http_response.status != HttpStatusCode.NoContent)
                {
                    GenUtils.PriorityLogMsg("error", "DictToTableStore: " + operation, response.http_response.status.ToString() + ", " + response.http_response.message);
                }
            }
            return(response);
        }