Exemplo n.º 1
0
        public static async Task <bool> put(CloudTable redirectTable, RedirectEntity entity)
        {
            await redirectTable.CreateIfNotExistsAsync();

            try {
                TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);
                await redirectTable.ExecuteAsync(insertOrMergeOperation);
            }
            catch {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static async Task <bool> delete(CloudTable redirectTable, RedirectEntity entity)
        {
            await redirectTable.CreateIfNotExistsAsync();

            try {
                TableOperation deleteOperation = TableOperation.Delete(entity);
                await redirectTable.ExecuteAsync(deleteOperation);
            }
            catch {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public static async Task <bool> put(CloudTable redirectTable, string collection, string key, string redirectTo, int clickCount, IDictionary <string, int> geoCount, DateTime created, bool recycled)
        {
            await redirectTable.CreateIfNotExistsAsync();

            try {
                RedirectEntity newEntity             = new RedirectEntity(collection, key, redirectTo, clickCount, geoCount, created, recycled);
                TableOperation insertEntityOperation = TableOperation.InsertOrMerge(newEntity);
                await redirectTable.ExecuteAsync(insertEntityOperation);
            }
            catch {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public static async Task <RedirectEntity> get(CloudTable redirectTable, string?collection, string key)
        {
            await redirectTable.CreateIfNotExistsAsync();

            TableQuery <RedirectEntity> rangeQuery = new TableQuery <RedirectEntity>().Where(
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                                                       $"{collection ??= string.Empty}"),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal,
                                                       $"{key}")));

            var sessionRedirectFound = await redirectTable.ExecuteQuerySegmentedAsync(rangeQuery, null);

            if (sessionRedirectFound.Results.Count > 0)
            {
                RedirectEntity entity = sessionRedirectFound.Results.ToArray()[0];
                return(entity);
            }
            else
            {
                return(null);
            }
        }