public void ShowChooseEquation(VmEquations vmEquations)
 {
     try
     {
         //Navigation.PushAsync(new VwBrowseEquation(new VmBrowseEquation1(vmEquations)));
         Navigation.PushAsync(new VwBrowseEquation2(new VmBrowseEquation2(vmEquations)));
     }
     catch (Exception ex)
     {
         Logging.LogException(ex);
         throw;
     }
 }
        public TestPage(VmEquations vmEquations)
        {
            try
            {
                InitializeComponent();

                InitData();

                _vmEquations = vmEquations;

                this.BindingContext = this;
                //this.BindingContext = vmEquations;
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }
Exemple #3
0
        public VwEquationsPage2(VmEquations vmEquations)
        {
            try
            {
                // ----------------
                _vmEquations = vmEquations;

                this.BindingContext = vmEquations;

                vmEquations.MaxVarLengthChanged += OnMaxVarLengthChanged;
                vmEquations.CalculationFinished += OnCalculationFinished;

                // ----------------
                SetColWidths();

                // ----------------
                InitializeComponent();

                // ----------------
                // If we are using XAML compilation, then DisplayBinding must be set in code due to a bug. See: https://www.syncfusion.com/forums/130637/cannot-set-displaybinding-on-column-from-xaml
                calcGrid.Columns[1].DisplayBinding = new Binding()
                {
                    Path = "Value", Converter = new NumericConverter()
                };

                // ----------------
                if (Device.OS == TargetPlatform.Windows)
                {
                    calcGrid.Columns[2].Width = 200;        // Auto-sizing doen't seem to work for uwp
                }
                else
                {
                    calcGrid.Columns[2].ColumnSizer = ColumnSizer.Auto;
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }
        public static async Task <bool> StartEquations(INavigation navigationIn = null)
        {
            Utils.IncrementAppIsBusy();

            INavigation navigation2 = navigationIn;

            EquationsUiService equationsUiService = new EquationsUiService(navigation2);
            VmEquations        vmEquations        = new VmEquations(equationsUiService);

            Result <EquationsSystemProblems> r_equationsSystemProblems = null;

            r_equationsSystemProblems = await InitEquationSystem(vmEquations,
                                                                 async (x) =>
            {
                return(await ShowVwEquationsPage(navigation2, vmEquations, x));
            });

            equationsUiService.Navigation = navigation2;

            Utils.DecrementAppIsBusy();

            return(true);
        }
        // +++++++++++++++++++++++++++++++++++++++

        private static async Task <bool> ShowVwEquationsPage(INavigation navigation2, VmEquations vmEquations, Result <EquationsSystemProblems> r_equationsSystemProblems)
        {
            VwEquationsPage2 vwEquationsPage = null;

            vwEquationsPage = new AnyEquation.Equations.Views.VwEquationsPage2(vmEquations);

            if (navigation2 == null)
            {
                navigation2 = vwEquationsPage.Navigation;
            }
            else
            {
                await navigation2.PushAsync(vwEquationsPage, true);
            }

            // TODO: Report conflicts and/or allow the user to choose which to use?
            if ((r_equationsSystemProblems != null) && (r_equationsSystemProblems.Value != null))
            {
                EquationsSystemProblems equationsSystemProblems = r_equationsSystemProblems.Value;
                if (equationsSystemProblems.NumParamTypeInconsistencies > 0 || equationsSystemProblems.NumUOMInconsistencies > 0 ||
                    equationsSystemProblems.NumEqLibInconsistencies > 0)
                {
                    await vwEquationsPage.DisplayAlert("Data Loading Errors",
                                                       $"{equationsSystemProblems.NumParamTypeInconsistencies + equationsSystemProblems.NumUOMInconsistencies + equationsSystemProblems.NumEqLibInconsistencies} inconsistencies were found while reading data from the databases.", "Ok");
                }
            }

            return(true);
        }
        private static async Task <Result <EquationsSystemProblems> > InitEquationSystem(VmEquations vmEquations,
                                                                                         Func <Result <EquationsSystemProblems>, Task <bool> > finishedAction)
        {
            // Note: This cannot be called on a separate thread because it would refresh Observable collections,
            //       and thus cause a thread marshall error due to updates on a non-UI thread.
            //       Instead, it now creates a thread for the main content loading. This error only manifested itself in UWP
            //       A possible alternative is presented in: https://www.codeproject.com/Articles/64936/Multithreaded-ObservableImmutableCollection

            try
            {
                Result <EquationsSystemProblems> r_equationsSystemProblems = Result <EquationsSystemProblems> .Good(null);

                if (!_isInitialised)
                {
                    r_equationsSystemProblems = await Task.Run(async() => await ContentManager.LoadContent());
                }
                else
                {
                    await Task.Run(async() => await Task.Delay(100));       // TODO: By trial and error I found that this was necessary, otherwise the calculation grid doesn't show the second time the equation page is shown
                }

                vmEquations.SetContentManager(ContentManager.gContentManager);

                await finishedAction(r_equationsSystemProblems);

                _isInitialised = true;
                return(r_equationsSystemProblems);
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                return(Result <EquationsSystemProblems> .Bad(ex));
            }
        }