Beispiel #1
0
        private async Task <TokenEntity> Update(TokenEntity orig, long pos, long neg)
        {
            var table   = _table();
            int backoff = 1;

            do
            {
                try
                {
                    var newtoken = orig.Increment(pos, neg);
                    await table.ExecuteAsync(TableOperation.InsertOrReplace(newtoken));

                    return(newtoken);
                }
                catch (StorageException ex)
                {
                    if (ex.RequestInformation.HttpStatusCode != (int)HttpStatusCode.PreconditionFailed &&
                        ex.RequestInformation.HttpStatusCode != (int)HttpStatusCode.Conflict)
                    {
                        throw;
                    }
                    await Task.Delay(backoff * 100);

                    backoff *= 2;
                    orig     = await GetToken(table, orig.Token);
                }
            } while (backoff < 256);
            throw new Exception("failed to update " + orig);
        }
Beispiel #2
0
        public TokenEntity Increment(long pos, long neg)
        {
            var merged = new TokenEntity(Classification, Token);

            merged.Postives  = Postives + pos;
            merged.Negatives = Negatives + neg;
            return(merged);
        }