Exemple #1
0
        private void PlaceOrderAction()
        {
            try
            {
                /*ThreadingHelpers.InvokeOnMainThread(async () =>
                 * {
                 *  AppInitialiserService.SetInitialiser<ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) =>
                 *  {
                 *      vm.UserDetails = UserDetails;
                 *      vm.ProductTypes = App.MasterData.ProductTypeMaster;
                 *  });
                 *
                 *  await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower());
                 * });*/


                ThreadingHelpers.InvokeOnMainThread(async() =>
                                                    await AppNavigationService.GoToAsync(nameof(SupplierCataloguePage).ToLower(),
                                                                                         (SupplierCataloguePageViewModel vm) =>
                {
                    vm.UserDetails  = UserDetails;
                    vm.ProductTypes = App.MasterData.ProductTypeMaster;
                })
                                                    );
            }
            catch (Exception ex)
            {
            }
        }
        private async Task DeleteProductAction(Product item)
        {
            var response = await AppPopupInputService.ShowMessageOkCancelAlertPopup("Remove Product", "Are you sure to remove product?", "OK", "CANCEL");

            if (!response.Equals("ok", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            ThreadingHelpers.InvokeOnMainThread(() =>
            {
                Orders.Remove(item);
                var orders = Orders.ToList();
                Orders.Clear();
                Orders = null;
                Orders = orders;

                if (IsOrderAvailable)
                {
                    OrderSubmitText = "SUBMIT ORDER";
                }
                else
                {
                    OrderSubmitText   = "PLACE ORDER";
                    OrdersHeadingText = "No order has been placed.";
                }
            }
                                                );
        }
Exemple #3
0
        public void HideLoading()
        {
            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                int retry = 0;

                if (_spinnerPageInstance == null)
                {
                    return;
                }

                while (!_isSpinning && retry <= 5)
                {
                    await Task.Delay(200);
                    retry++;
                }

                if (_spinnerPageInstance != null)
                {
                    await _navigationService.Navigation.RemovePopupPageAsync(_spinnerPageInstance, true);
                    //await _navigationService.Navigation.PopPopupAsyncSafe(_popupNavigation, true);
                }

                _spinnerPageInstance = null;
                _isSpinning          = false;
            });
        }
Exemple #4
0
 private void AddressSuggestions_Updated(object sender, AddressSuggestionsUpdatedEventArgs eventArgs)
 {
     try
     {
         ThreadingHelpers.BeginUpdate(MyComboBox);
         var text = ThreadingHelpers.GetText(MyComboBox);
         ThreadingHelpers.ClearItems(MyComboBox);
         foreach (var addressSuggestions in eventArgs.AddressSuggestions)
         {
             ThreadingHelpers.AddItem(MyComboBox, addressSuggestions);
         }
         ThreadingHelpers.SetDroppedDown(MyComboBox, true);
         ThreadingHelpers.ClearSelection(MyComboBox);
         ThreadingHelpers.SetText(MyComboBox, text);
         ThreadingHelpers.SetSelectionStart(MyComboBox, text.Length);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
     finally
     {
         ThreadingHelpers.EndUpdate(MyComboBox);
     }
 }
        private async Task SupplierTapped(LinCUser item)
        {
            try
            {
                AppSpinner.ShowLoading();

                var response = await _services.UserService.GetUserProducts(UserDetails.UserId,
                                                                           item.UserId, SelectedProductType.ProductTypeId);

                if (response.Data.Item1 != null && response.Data.Item1.Count > 0)
                {
                    ThreadingHelpers.InvokeOnMainThread(async() =>
                                                        await AppNavigationService.GoToAsync(nameof(ProductsPage).ToLower(),
                                                                                             (ProductsPageViewModel vm) =>
                    {
                        vm.UserDetails = App.UserDetails;
                        vm.Products    = response.Data.Item1;
                        vm.SupplierId  = item.UserId;
                    })
                                                        );
                }

                AppSpinner.HideLoading();
            }
            catch (Exception ex)
            {
            }
        }
        private void PlaceOrderAction()
        {
            if (IsOrderAvailable)
            {
                // Save to backend DB

                ThreadingHelpers.InvokeOnMainThread(async() =>
                                                    await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(),
                                                                                         (UserDashboardPageViewModel vm) =>
                {
                    vm.UserDetails = App.UserDetails;
                    vm.Products    = this.Products;
                    //vm.Orders = Orders.Where(o => o.IsSubmitted).ToList();
                })
                                                    );
            }
            else
            {
                ThreadingHelpers.InvokeOnMainThread(async() =>
                {
                    AppInitialiserService.SetInitialiser <ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) =>
                    {
                        vm.UserDetails  = UserDetails;
                        vm.ProductTypes = App.MasterData.ProductTypeMaster;
                        //vm.ProductList = Products;
                        //vm.Product = new Product();
                        //vm.ProductTypes = App.MasterData.ProductTypeMaster;
                    });

                    await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower());
                });
            }
        }
        private void SaveNewProductNameAction()
        {
            try
            {
                ThreadingHelpers.InvokeOnMainThread(() =>
                {
                    //LinCComonModel prdNameObj = new LinCComonModel() { Name = NewProductName, Value = NewProductName, ItemId = string.Empty };

                    //var controlValues = DefaultProductName.ControlValues.ToList();
                    //controlValues.Add(prdNameObj);

                    //DefaultProductName.ControlValues.Clear();
                    //DefaultProductName.ControlValues = null;

                    //DefaultProductName.ControlValues = controlValues;
                    //DefaultProductName.DefaultItem = prdNameObj;
                    //DefaultProductName.SelectedIndex = controlValues.Count - 1;

                    //Product.ProductNameId = string.Empty;
                    //Product.ProductName = prdNameObj.Name;
                    //Product.IsNewProductName = true;

                    NewProductName             = string.Empty;
                    ProductNameEntryVisibility = false;
                });
            }
            catch (Exception)
            {
            }
        }
        internal static async Task NavigatePopToRootAsync()
        {
            var modalCount = App.NavigationRoot.Navigation.ModalStack.Count;

            for (int currModal = 0; currModal < modalCount; currModal++)
            {
                ThreadingHelpers.InvokeOnMainThread(async() => await App.NavigationRoot.Navigation.PopModalAsync(false));
            }
        }
Exemple #9
0
 private void CallCustomerCare()
 {
     ThreadingHelpers.InvokeOnMainThread(async() =>
                                         await AppNavigationService.GoToAsync(nameof(ChatPage).ToLower(),
                                                                              (ChatPageViewModel vm) =>
     {
         vm.UserDetails = App.UserDetails;
     })
                                         );
 }
        public void ReferencePassingTest()
        {
            var data = new DataBag();

            ThreadingHelpers.ExecuteOnThread(
                () => data.X++,
                10);

            Assert.Equal(10, data.X);
        }
Exemple #11
0
 private void ProductCatAction()
 {
     ThreadingHelpers.InvokeOnMainThread(async() =>
                                         await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower(),
                                                                              (ProductCataloguePageViewModel vm) =>
     {
         vm.UserDetails = App.UserDetails;
     })
                                         );
 }
Exemple #12
0
 private void Register()
 {
     ThreadingHelpers.InvokeOnMainThread(async() =>
                                         await AppNavigationService.GoToAsync(nameof(RegistrationPage).ToLower(),
                                                                              (RegistrationPageViewModel vm) =>
     {
         //vm.UserDetails = new LinCUser();
     })
                                         );
 }
        private void DisplayNetworkError(ViewModelError error)
        {
            var alert = new ErrorAlert()
            {
                Description   = error.Description,
                Title         = _errorTitle,
                ViewModelType = this.GetType(),
                Severity      = ViewModelError.ErrorSeverity.Warning
            };

            ThreadingHelpers.InvokeOnMainThread(async() => await _popupInputService.ShowMessageOkAlertPopup(alert.Title, alert.Description, "OK"));
        }
Exemple #14
0
        private void IncreaseQuantityAction(Product item)
        {
            int qty = item.Quantity;

            qty += 1;

            ThreadingHelpers.InvokeOnMainThread(() =>
            {
                item.Quantity = qty;
                item.Price    = (item.UnitPrice == 0 ? 10:item.UnitPrice) * qty;
            });
        }
Exemple #15
0
    private void MyComboBox_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (char.IsControl(e.KeyChar))
        {
            return;
        }
        var searchString = ThreadingHelpers.GetText(MyComboBox);

        if (searchString.Length > 1)
        {
            Task.Run(() => GetAddressSuggestions(searchString));
        }
    }
Exemple #16
0
        public void ShowLoading(bool isCancellable = true)
        {
            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                if (_spinnerPageInstance == null)
                {
                    _spinnerPageInstance = new ProgressSpinnerPage(isCancellable);

                    await _navigationService.Navigation.PushPopupAsyncSafe(_spinnerPageInstance, _popupNavigation, true)
                    .ContinueWith((t) => _isSpinning = true);
                }
            });
        }
Exemple #17
0
        private async Task RegisterAction()
        {
            //AppSpinner.ShowLoading();
            //await GetMasterData();
            //AppSpinner.HideLoading();

            ThreadingHelpers.InvokeOnMainThread(async() =>
                                                await AppNavigationService.GoToAsync(nameof(RegistrationPage).ToLower(),
                                                                                     (RegistrationPageViewModel vm) =>
            {
                //vm.UserDetails = new LinCUser();
            })
                                                );
        }
Exemple #18
0
        static void Main(string[] args)
        {
            // Here you can play around with those method, prototype and easily debug

            Console.WriteLine($"Main thread is {Thread.CurrentThread.ManagedThreadId}");

            // Generate a token that's immediately cancelled
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.Cancel();
            CancellationToken cancelToken = cts.Token;

            // new CancellationTokenSource(200).Token

            /*
             * ThreadingHelpers.ExecuteOnThread(() =>
             * {
             *  var thread = Thread.CurrentThread;
             *  Console.WriteLine($"Hello from thread {thread.ManagedThreadId} from a pool: {thread.IsThreadPoolThread}");
             *  Thread.Sleep(1000);
             *  //throw new StackOverflowException();
             * }, 3, cancelToken,
             * (System.Exception exception) => { Console.WriteLine($"<{exception.Message}> occurred !"); });
             */

            /*
             * ThreadingHelpers.ExecuteOnThread(
             *  () => throw new NullReferenceException(),
             *  10,
             *  new CancellationTokenSource(1000).Token,
             *  errorAction: (System.Exception exception) => { Console.WriteLine($"<{exception.Message}> occurred !"); });
             */

            /*
             * ThreadingHelpers.ExecuteOnThreadPool(() =>
             * {
             *  var thread = Thread.CurrentThread;
             *  Console.WriteLine(
             *      $"Hello from thread {thread.ManagedThreadId} from a pool: {thread.IsThreadPoolThread}");
             * }, 3);
             */


            ThreadingHelpers.ExecuteOnThreadPool(
                () => Thread.Sleep(100),
                3,
                cancelToken,
                errorAction: (System.Exception exception) => { Console.WriteLine($"<{exception.Message}> occurred !"); }
                );
        }
Exemple #19
0
        private async Task SubmitProductsAction()
        {
            if (Products == null || Products.Count == 0)
            {
                await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "No product available to submit.", "OK");

                return;
            }

            var selectedPrdCount = Products.Count(p => p.IsSubmitted);

            if (selectedPrdCount == 0)
            {
                await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "Please select one product to submit.", "OK");

                return;
            }

            // save to db
            try
            {
                AppSpinner.ShowLoading();

                var response = await _services.UserService.SaveOrders(Products, UserDetails, SupplierId);

                AppSpinner.HideLoading();

                if (response.Data != null)
                {
                    ThreadingHelpers.InvokeOnMainThread(async() =>
                                                        await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(),
                                                                                             (UserDashboardPageViewModel vm) =>
                    {
                        vm.UserDetails = App.UserDetails;
                        vm.Products    = Products;
                        vm.Orders      = response.Data;
                    })
                                                        );
                }
                else
                {
                    await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "Unable to place order. Please try again.", "OK");
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void DecreaseQuantityAction(Product item)
        {
            int qty = item.Quantity;

            qty -= 1;

            if (qty < 1)
            {
                qty = 1;
            }
            ThreadingHelpers.InvokeOnMainThread(() =>
            {
                item.Quantity = qty;
                item.Price    = item.UnitPrice * qty;
            });
        }
        private void AddProductAction()
        {
            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                AppInitialiserService.SetInitialiser <AddProductPageViewModel>((AddProductPageViewModel vm) =>
                {
                    vm.UserDetails  = UserDetails;
                    vm.ProductList  = Products;
                    vm.Product      = new Product();
                    vm.ProductTypes = App.MasterData.ProductTypeMaster;
                    vm.IsAddProduct = true;
                });

                await AppNavigationService.GoToAsync(nameof(AddProductPage).ToLower());
            });
        }
Exemple #22
0
        public void TimeoutCancellationTest()
        {
            var errorActionMock = new Mock <Action <Exception> >();

            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(200);

            ThreadingHelpers.ExecuteOnThreadPool(
                () => Thread.Sleep(100),
                10,
                cts.Token,
                errorAction: errorActionMock.Object);

            errorActionMock.Verify(m => m(It.IsAny <OperationCanceledException>()), Times.Once);
        }
Exemple #23
0
        private void AddProductAction()
        {
            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                //    AppInitialiserService.SetInitialiser<AddProductPageViewModel>((AddProductPageViewModel vm) =>
                //    {
                //        vm.UserDetails = UserDetails;
                //        vm.ProductList = Products;
                //        vm.Product = new Product();
                //        vm.ProductTypes = App.MasterData.ProductTypeMaster;
                //        vm.IsAddProduct = true;
                //    });

                await AppNavigationService.GoBackAsync();
            });
        }
Exemple #24
0
 private async Task AddToCartAction()
 {
     try
     {
         ThreadingHelpers.InvokeOnMainThread(async() =>
                                             await AppNavigationService.GoToAsync(nameof(CartPage).ToLower(),
                                                                                  (CartPageViewModel vm) =>
         {
             vm.UserDetails = App.UserDetails;
             vm.Products    = this.Products;
             vm.Orders      = this.Products.Where(p => p.ShouldAddToCart).ToList();
         })
                                             );
     }
     catch (Exception ex)
     {
     }
 }
Exemple #25
0
        static void Main(string[] args)
        {
            // Here you can play around with those method, prototype and easily debug

            Console.WriteLine($"Main thread is {Thread.CurrentThread.ManagedThreadId}");

            ThreadingHelpers.ExecuteOnThread(() =>
            {
                var thread = Thread.CurrentThread;
                Console.WriteLine($"Hello from thread {thread.ManagedThreadId} from a pool: {thread.IsThreadPoolThread}");
            }, 3);

            ThreadingHelpers.ExecuteOnThreadPool(() =>
            {
                var thread = Thread.CurrentThread;
                Console.WriteLine(
                    $"Hello from thread {thread.ManagedThreadId} from a pool: {thread.IsThreadPoolThread}");
            }, 3);
        }
        public void RunningOnDifferentThreadTest()
        {
            var  mainThreadId         = Thread.CurrentThread.ManagedThreadId;
            var  testThreadId         = 0;
            bool?testThreadIsFromPool = null;

            ThreadingHelpers.ExecuteOnThread(
                () =>
            {
                Thread.Sleep(100);
                testThreadId         = Thread.CurrentThread.ManagedThreadId;
                testThreadIsFromPool = Thread.CurrentThread.IsThreadPoolThread;
            }, 1);

            Assert.NotEqual(0, testThreadId);
            Assert.NotEqual(mainThreadId, testThreadId);
            Assert.NotNull(testThreadIsFromPool);
            Assert.False(testThreadIsFromPool);
        }
Exemple #27
0
        public async Task DeleteProductAction(Product item)
        {
            var response = await AppPopupInputService.ShowMessageOkCancelAlertPopup("Remove Product", "Are you sure to remove product?", "OK", "CANCEL");

            if (!response.Equals("ok", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            ThreadingHelpers.InvokeOnMainThread(() =>
            {
                Products.Remove(item);
                var prds = Products.ToList();
                Products.Clear();
                Products = null;
                Products = prds;
            }
                                                );
        }
        private async Task EditProductAction(Product item)
        {
            AppSpinner.ShowLoading();
            await Task.Delay(10);

            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                AppInitialiserService.SetInitialiser <ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) =>
                {
                    vm.UserDetails = UserDetails;
                    vm.Products    = Products;
                });
                await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower());

                //await AppNavigationService.GoBackAsync();
            }
                                                );

            AppSpinner.HideLoading();
        }
Exemple #29
0
        public async Task EditProductAction(Product item)
        {
            AppSpinner.ShowLoading();
            await Task.Delay(10);

            ThreadingHelpers.InvokeOnMainThread(async() =>
            {
                //    AppInitialiserService.SetInitialiser<AddProductPageViewModel>((AddProductPageViewModel vm) =>
                //    {
                //        vm.UserDetails = UserDetails;
                //        vm.ProductList = Products;
                //        vm.Product = item;
                //        vm.IsAddProduct = false;
                //    });

                await AppNavigationService.GoBackAsync();
            }
                                                );

            AppSpinner.HideLoading();
        }
        private void AdjustQuantityAction(string item)
        {
            int qty = Product.Quantity;

            if (item.Equals("Minus"))
            {
                qty -= 1;
            }
            else
            {
                qty += 1;
            }

            if (qty <= 0)
            {
                qty = 1;
            }
            ThreadingHelpers.InvokeOnMainThread(() =>
            {
                Product.Quantity = qty;
            });
        }