Ejemplo n.º 1
0
        public object OnRead(RedisValue value)
        {
            Guid guid;
            if (value.IsByteArray()) return new Guid((byte[])value);
            if (Guid.TryParse(value, out guid)) return guid;

            throw new ArgumentException("Value is not a Guid");
        }
Ejemplo n.º 2
0
        public object OnRead(RedisValue value)
        {
            Guid guid;

            if (value.IsByteArray())
            {
                return(new Guid((byte[])value));
            }
            if (Guid.TryParse(value, out guid))
            {
                return(guid);
            }

            throw new ArgumentException("Value is not a Guid");
        }
        /// <summary>
        /// Adds an entry into the Table Database
        /// key.Prefix = table
        /// GetPartitionKey = partition
        /// SHAhash = {c} rowkey (c is count, allowing for mulitple entries)
        /// value = value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public override async Task AddListItemAsync(RedisKeyObject key, RedisValue value, CancellationToken token = default(CancellationToken))
        {
            var hash = GetSHAHash(value);

            // First we need to look for the item
            var table = await GetCloudTableAsync(key.Prefix, token);

            var operation = TableOperation.Retrieve <DynamicTableEntity>(GetPartitionKey(key), hash);
            var result    = await table.ExecuteAsync(operation, token);

            // If result is not found
            if (result.Result == null)
            {
                var entry = new DynamicTableEntity
                {
                    PartitionKey = GetPartitionKey(key),
                    RowKey       = hash,
                };
                entry.Properties.Add("Count", new EntityProperty(1));

                if (value.IsByteArray())
                {
                    entry.Properties.Add("Value", new EntityProperty((byte[])value));
                    operation = TableOperation.Insert(entry);
                }
                else
                {
                    entry.Properties.Add("Value", new EntityProperty((string)value));
                    operation = TableOperation.Insert(entry);
                }
            }
            else
            {
                ((DynamicTableEntity)result.Result)["Count"].Int32Value++;
                operation = TableOperation.Replace(((DynamicTableEntity)result.Result));
            }

            await table.ExecuteAsync(operation, token);
        }