public static async Task <PagedListResult <TOutput> > PaginateListResultAsync <TInput, TOutput>(
            this Microsoft.Azure.Cosmos.Table.CloudTable table,
            Microsoft.Azure.Cosmos.Table.TableQuery <TInput> query,
            int pageSize,
            Func <TInput, Task <TOutput> > conversion,
            CosmosTableBasedContinuationToken continuationToken,
            CancellationToken cancelationToken = default(CancellationToken))
            where TInput : Microsoft.Azure.Cosmos.Table.ITableEntity, new()
        {
            var items = new List <TOutput>();
            var token = continuationToken.IsContinuation ? continuationToken.TableCursor : null;
            var oc    = new Microsoft.Azure.Cosmos.Table.OperationContext();
            var ro    = new Microsoft.Azure.Cosmos.Table.TableRequestOptions();

            query = query.Take(pageSize);

            var seg = await table.ExecuteQuerySegmentedAsync(query, token, ro, oc, cancelationToken);

            continuationToken.TableCursor = seg.ContinuationToken;
            items.AddRange(
                (await Task.WhenAll(seg.Select(async x => await conversion(x))))
                .Where(x => x != null)
                );

            return(new PagedListResult <TOutput> {
                Items = items, ContinuationToken = continuationToken?.ToString()
            });
        }
示例#2
0
        public FeatureGateStore(
            IConfiguration configuration,
            ILogger <FeatureGateStore> logger,
            ServiceOption serviceOption,
            EventualCloudTableClient storage)
        {
            var slot       = configuration.GetDeploymentSlot().ToString().ToLower();
            var slotName   = slot.ToString().ToLower();
            var connection = configuration.GetValue <string>("SAFeatureGate");

            newGates_ = configuration.GetValue("NewFeatureGates", false);
            var storageAccount = CloudStorageAccount.Parse(connection);
            var tableClient    = TableStorageHelpers.CreateClient(storageAccount);

            Storage = storage.GetTableReference($"{slotName}Gates");
            Storage.CreateIfNotExists();
            logger_    = logger;
            rnd_       = new Random();
            GatesTable = new TableStorage(tableClient, $"{slotName}Gates", true);
            Service    = serviceOption.Service;
        }
示例#3
0
        private static async Task <string> UpdateFavoritePSStoreAsync(Microsoft.Azure.Cosmos.Table.CloudTable table, ShoppingFavorite favorite, ILogger log)
        {
            var    baseAddress = "https://web.np.playstation.com/api/graphql/v1/op?operationName=productRetrieveForCtasWithPrice&variables=%7B%22productId%22%3A%22{0}%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%228532da7eda369efdad054ca8f885394a2d0c22d03c5259a422ae2bb3b98c5c99%22%7D%7D";
            string offer       = null;

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("x-psn-store-locale-override", "it-IT");
                HttpResponseMessage response = await client.GetAsync(String.Format(baseAddress, favorite.RowKey));

                if (response.IsSuccessStatusCode)
                {
                    var jsonResponse = await response.Content.ReadAsStringAsync();

                    var game = JsonConvert.DeserializeObject <PsStoreGame>(jsonResponse);
                    if (game.data.productRetrieve != null)
                    {
                        if (favorite.DiscountedPrice != game.data.productRetrieve.webctas[0].price.discountedPrice)
                        {
                            offer = $"{favorite.Name} - Old Price: {favorite.DiscountedPrice} - New Price: {game.data.productRetrieve.webctas[0].price.discountedPrice} - Discount: {game.data.productRetrieve.webctas[0].price.discountText}";
                            log.LogInformation($"Discount {game.data.productRetrieve.webctas[0].price.discountText} for favorite {favorite.Name} - Old Price: {favorite.DiscountedPrice} - New Price: {game.data.productRetrieve.webctas[0].price.discountedPrice}");
                        }
                        favorite.Discount        = String.IsNullOrEmpty(game.data.productRetrieve.webctas[0].price.discountText) ? String.Empty : game.data.productRetrieve.webctas[0].price.discountText;
                        favorite.DiscountedPrice = game.data.productRetrieve.webctas[0].price.discountedPrice;
                        favorite.DiscountDate    = DateTime.Now;
                        favorite.Price           = game.data.productRetrieve.webctas[0].price.basePrice;
                        await ShoppingTrackerDAL.InsertOrMergeShoppingFavoriteAsync(table, favorite);
                    }
                    else
                    {
                        log.LogError($"Product is no more available in the store: {favorite.Name}");
                    }
                }
                else
                {
                    log.LogError($"Impossible to update favorite: {favorite.Name}");
                }
            }
            return(offer);
        }
示例#4
0
 public AddTodoItemFunction(ICloudTableFactory cloudTableFactory, IAuthService authService, ITodoListService todoItemService)
 {
     _authService     = authService;
     _todoListService = todoItemService;
     _cloudTable      = cloudTableFactory.CreateCloudTable(TableStorageConstants.TodoItemTable);
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserExternalLoginTableAccess"/> class.
 /// </summary>
 /// <param name="table">the cloud table to use.</param>
 /// <param name="logger">an optional logger.</param>
 public UserExternalLoginTableAccess(Microsoft.Azure.Cosmos.Table.CloudTable table, Microsoft.Extensions.Logging.ILogger <TableAccess <UserExternalLogin> > logger = null)
     : base(table, logger)
 {
 }