Exemplo n.º 1
0
        private async Task LoadAllAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            models.Clear();
            if (!serverConnection.IsAvailable)
            {
                log.Debug($"Using local storage.");

                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            if (dispatcher != null)
            {
                log.Debug("Using dispatcher to run the query. Skipping the query result as other brach will process it.");
                await dispatcher.QueryAsync(listAll);
            }
            else
            {
                log.Debug("Using next middleware to run the query.");
                models.AddRange((List <CategoryModel>) await next(listAll));

                log.Debug("Storing to local storage.");
                await localStorage.SaveAsync(models);
            }
        }
Exemplo n.º 2
0
        private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            log.Debug($"Ensure list, currently has '{models.Count}' models.");

            if (models.Count == 0)
            {
                if (listAllTask == null)
                {
                    log.Debug($"Fire network/storage query.");
                    listAllTask = LoadAllAsync(dispatcher, next, listAll);
                }

                log.Debug($"Awating task.");

                try
                {
                    await listAllTask;
                }
                finally
                {
                    listAllTask = null;
                }

                log.Debug($"Awaiting done.");
            }
        }
Exemplo n.º 3
0
        private async Task LoadAllAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCurrency listAll)
        {
            models.Clear();
            if (!serverConnection.IsAvailable)
            {
                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            if (dispatcher != null)
            {
                models.AddRange(await dispatcher.QueryAsync(listAll));
            }
            else
            {
                models.AddRange((List <CurrencyModel>) await next(listAll));
            }

            await localStorage.SaveAsync(models);
        }
Exemplo n.º 4
0
        private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCurrency listAll)
        {
            if (models.Count == 0)
            {
                if (listAllTask == null)
                {
                    listAllTask = LoadAllAsync(dispatcher, next, listAll);
                }

                await listAllTask;
                listAllTask = null;
            }
        }
Exemplo n.º 5
0
        private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
        {
            if (!network.IsOnline)
            {
                profile = await localStorage.LoadAsync();

                if (profile != null)
                {
                    return;
                }
            }

            profile = (ProfileModel) await next(query);

            await localStorage.SaveAsync(profile);
        }
Exemplo n.º 6
0
        private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
        {
            if (!serverConnection.IsAvailable)
            {
                profile = await localStorage.LoadAsync();

                if (profile != null)
                {
                    return;
                }
            }

            profile = (ProfileModel) await next(query);

            await localStorage.SaveAsync(profile);
        }
Exemplo n.º 7
0
        private async Task LoadAllAsync(ListAllCurrency listAll, HttpQueryDispatcher.Next next)
        {
            models.Clear();
            if (!network.IsOnline)
            {
                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            models.AddRange((List <CurrencyModel>) await next(listAll));
            await localStorage.SaveAsync(models);
        }
Exemplo n.º 8
0
        public async Task<object> ExecuteAsync(object query, HttpQueryDispatcher.Next next)
        {
            if (query is ListAllCategory listAll)
            {
                if (models.Count == 0)
                {
                    if (models.Count == 0)
                    {
                        if (listAllTask == null)
                            listAllTask = LoadAllAsync(listAll, next);

                        await listAllTask;
                        listAllTask = null;
                    }
                }

                return models.Select(c => c.Clone()).ToList();
            }
            else if (query is GetCategoryName categoryName)
            {
                CategoryModel model = Find(categoryName.CategoryKey);
                if (model != null)
                    return model.Name;
            }
            else if (query is GetCategoryIcon categoryIcon)
            {
                CategoryModel model = Find(categoryIcon.CategoryKey);
                if (model != null)
                    return model.Icon;
            }
            else if (query is GetCategoryColor categoryColor)
            {
                CategoryModel model = Find(categoryColor.CategoryKey);
                if (model != null)
                    return model.Color;
            }
            else if (query is GetCategoryNameDescription categoryNameDescription)
            {
                CategoryModel model = Find(categoryNameDescription.CategoryKey);
                if (model != null)
                    return new CategoryNameDescriptionModel(model.Name, model.Description);
            }

            return await next(query);
        }
Exemplo n.º 9
0
        private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListUserProperty listAll)
        {
            if (models.Count == 0)
            {
                if (listAllTask == null)
                {
                    listAllTask = LoadAllAsync(dispatcher, next, listAll);
                }

                try
                {
                    await listAllTask;
                }
                finally
                {
                    listAllTask = null;
                }
            }
        }
Exemplo n.º 10
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher.Next next)
        {
            if (query is ListAllCurrency listAll)
            {
                if (models.Count == 0)
                {
                    if (listAllTask == null)
                    {
                        listAllTask = LoadAllAsync(listAll, next);
                    }

                    await listAllTask;
                    listAllTask = null;
                }

                return(models.Select(c => c.Clone()).ToList());
            }
            else if (query is GetCurrencyDefault currencyDefault)
            {
                CurrencyModel model = models.FirstOrDefault(c => c.IsDefault);
                if (model != null)
                {
                    return(model.UniqueCode);
                }
            }
            else if (query is GetCurrencySymbol currencySymbol)
            {
                CurrencyModel model = Find(currencySymbol.UniqueCode);
                if (model != null)
                {
                    return(model.Symbol);
                }
            }

            return(await next(query));
        }
Exemplo n.º 11
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is ListAllCurrency listAll)
            {
                await EnsureListAsync(null, next, listAll);

                return(models.Select(c => c.Clone()).ToList());
            }
            else if (query is GetCurrencyDefault currencyDefault)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CurrencyModel model = models.FirstOrDefault(c => c.IsDefault);
                if (model != null)
                {
                    return(model.UniqueCode);
                }
            }
            else if (query is FindCurrencyDefault currencyDefaultNullable)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CurrencyModel model = models.FirstOrDefault(c => c.IsDefault);
                if (model != null)
                {
                    return(model.UniqueCode);
                }
            }
            else if (query is GetCurrencySymbol currencySymbol)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CurrencyModel model = Find(currencySymbol.UniqueCode);
                if (model != null)
                {
                    return(model.Symbol);
                }
            }

            return(await next(query));
        }
Exemplo n.º 12
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is GetProfile getProfile)
            {
                if (profile == null)
                {
                    if (getProfileTask == null)
                    {
                        getProfileTask = LoadProfileAsync(getProfile, next);
                    }

                    await getProfileTask;
                    getProfileTask = null;
                }

                return(profile);
            }

            return(await next(query));
        }
Exemplo n.º 13
0
 private async Task LoadAllAsync(ListAllCurrency listAll, HttpQueryDispatcher.Next next)
 {
     models.Clear();
     models.AddRange((List <CurrencyModel>) await next(listAll));
 }
Exemplo n.º 14
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is GetProfile getProfile)
            {
                if (profile == null)
                {
                    log.Debug("Profile is null.");

                    if (getProfileTask == null)
                    {
                        log.Debug("Profile task is null.");
                        getProfileTask = LoadProfileAsync(getProfile, next);
                    }

                    try
                    {
                        log.Debug("Awating profile task.");
                        await getProfileTask;
                    }
                    finally
                    {
                        log.Debug("Clearing profile task.");
                        getProfileTask = null;
                    }
                }

                log.Debug("Returning profile.");
                return(profile);
            }

            return(await next(query));
        }
Exemplo n.º 15
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is ListAllCategory listAll)
            {
                await EnsureListAsync(null, next, listAll);

                return(models.Select(c => c.Clone()).ToList());
            }
            else if (query is GetCategoryName categoryName)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CategoryModel model = Find(categoryName.CategoryKey);
                if (model != null)
                {
                    return(model.Name);
                }
            }
            else if (query is GetCategoryIcon categoryIcon)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CategoryModel model = Find(categoryIcon.CategoryKey);
                if (model != null)
                {
                    return(model.Icon);
                }
            }
            else if (query is GetCategoryColor categoryColor)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CategoryModel model = Find(categoryColor.CategoryKey);
                if (model == null)
                {
                    return(Color.FromArgb(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue));
                }

                return(model.Color);
            }
            else if (query is GetCategoryNameDescription categoryNameDescription)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                CategoryModel model = Find(categoryNameDescription.CategoryKey);
                if (model != null)
                {
                    return(new CategoryNameDescriptionModel(model.Name, model.Description));
                }
            }

            return(await next(query));
        }
Exemplo n.º 16
0
        Task <object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is GetPwaStatus)
            {
                return(Task.FromResult <object>(new PwaStatus(isInstallable, isUpdateable)));
            }

            return(next(query));
        }
Exemplo n.º 17
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is ListAllCategory listAll)
            {
                if (models.Count == 0)
                {
                    if (listAllTask == null)
                    {
                        listAllTask = LoadAllAsync(listAll, next).ContinueWith(t => listAllTask = null);
                    }

                    await listAllTask;
                }

                return(models.Select(c => c.Clone()).ToList());
            }
            else if (query is GetCategoryName categoryName)
            {
                CategoryModel model = Find(categoryName.CategoryKey);
                if (model != null)
                {
                    return(model.Name);
                }
            }
            else if (query is GetCategoryIcon categoryIcon)
            {
                CategoryModel model = Find(categoryIcon.CategoryKey);
                if (model != null)
                {
                    return(model.Icon);
                }
            }
            else if (query is GetCategoryColor categoryColor)
            {
                CategoryModel model = Find(categoryColor.CategoryKey);
                if (model == null)
                {
                    var models = await dispatcher.QueryAsync(new ListAllCategory());

                    model = models.FirstOrDefault(c => c.Key.Equals(categoryColor.CategoryKey));
                }

                model = Find(categoryColor.CategoryKey);
                if (model == null)
                {
                    return(Color.FromArgb(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue));
                }

                return(model.Color);
            }
            else if (query is GetCategoryNameDescription categoryNameDescription)
            {
                CategoryModel model = Find(categoryNameDescription.CategoryKey);
                if (model != null)
                {
                    return(new CategoryNameDescriptionModel(model.Name, model.Description));
                }
            }

            return(await next(query));
        }
Exemplo n.º 18
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is GetDateFormatProperty)
            {
                var value = await dispatcher.QueryAsync(new FindUserProperty("DateFormat")) ?? CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern;

                return(value);
            }
            else if (query is GetPriceDecimalDigitsProperty)
            {
                var value = IntPropertyValue(await dispatcher.QueryAsync(new FindUserProperty("PriceDecimalDigits")), 2);
                return(value);
            }

            return(await next(query));
        }
Exemplo n.º 19
0
        async Task <object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is ListBottomMenuItem)
            {
                var value = await dispatcher.QueryAsync(new FindUserProperty("MobileMenu"));

                Console.WriteLine($"MM: (1) '{value}', {value == null}, {value == String.Empty}");

                var selectedItems = value != null?value.Split(',') : Array.Empty <string>();

                return(storage.Where(m => selectedItems.Contains(m.Identifier)).ToList <IActionMenuItemModel>());
            }
            else if (query is ListAvailableMenuItem)
            {
                return(storage.ToList <IAvailableMenuItemModel>());
            }
            else if (query is FindUserProperty findProperty && findProperty.Key == "MobileMenu")
            {
                var value = (string) await next(findProperty);

                Console.WriteLine($"MM: (2) '{value}', {value == null}, {value == String.Empty}");

                if (value == null)
                {
                    return(DefaultValue);
                }

                return(value);
            }
Exemplo n.º 20
0
 private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
 {
     profile = (ProfileModel) await next(query);
 }
Exemplo n.º 21
0
        Task <object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is FindApiVersion)
            {
                return(Task.FromResult <object>(last));
            }

            return(next(query));
        }
Exemplo n.º 22
0
        public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
        {
            if (query is ListUserProperty listAll)
            {
                await EnsureListAsync(null, next, listAllQuery);

                return(models.Select(c => c.Clone()).ToList());
            }
            else if (query is FindUserProperty find)
            {
                await EnsureListAsync(dispatcher, null, listAllQuery);

                UserPropertyModel model = models.FirstOrDefault(m => m.Key == find.Key);
                if (model != null)
                {
                    return(model.Value);
                }
            }

            return(await next(query));
        }