private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            LibraryCode lc  = new LibraryCode();
            string      msg = await lc.BadEttiquette().ConfigureAwait(continueOnCapturedContext: false);

            return(msg);
        }
Beispiel #2
0
        public async Task ReceivesDataContext()
        {
            await TestHost.SwitchToAppThread();

            var window = await WindowHelpers.CreateInvisibleWindowAsync <DialogWindow>();

            var vm     = new TheViewModel();
            var dialog = (CustomDialog)window.Resources["CustomDialog"];

            await window.ShowMetroDialogAsync(dialog);

            await TestHost.SwitchToAppThread(); // No idea why we have to do this again

            Assert.Equal(await window.GetCurrentDialogAsync <CustomDialog>(), dialog);
            Assert.NotNull(await window.GetCurrentDialogAsync <BaseMetroDialog>());
            Assert.Null(await window.GetCurrentDialogAsync <MessageDialog>());

            dialog.DataContext = vm;
            var textBlock = dialog.FindChild <TextBlock>("TheDialogBody");

            Assert.Equal(vm.Text, textBlock.Text);

            await window.HideMetroDialogAsync(dialog);

            await TestHost.SwitchToAppThread(); // No idea why we have to do this again

            Assert.Null(await window.GetCurrentDialogAsync <MessageDialog>());
        }
Beispiel #3
0
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var theViewModel = new TheViewModel();

        theViewModel.SiteId = int.Parse(request.Form.Get("SiteId"));
        //other your code here
    }
        public MainWindow()
        {
            InitializeComponent();
            TheViewModel vm = this.DataContext as TheViewModel;

            vm.DescriptionTextBox = this.txtProductDescription;
        }
        public async Task ReceivesDataContext()
        {
            await TestHost.SwitchToAppThread();

            var window = await WindowHelpers.CreateInvisibleWindowAsync<DialogWindow>();
            var vm = new TheViewModel();
            var dialog = (CustomDialog) window.Resources["CustomDialog"];

            await window.ShowMetroDialogAsync(dialog);

            await TestHost.SwitchToAppThread(); // No idea why we have to do this again

            Assert.Equal(await window.GetCurrentDialogAsync<CustomDialog>(), dialog);
            Assert.NotNull(await window.GetCurrentDialogAsync<BaseMetroDialog>());
            Assert.Null(await window.GetCurrentDialogAsync<MessageDialog>());

            dialog.DataContext = vm;
            var textBlock = dialog.FindChild<TextBlock>("TheDialogBody");

            Assert.Equal(vm.Text, textBlock.Text);

            await window.HideMetroDialogAsync(dialog);

            await TestHost.SwitchToAppThread(); // No idea why we have to do this again

            Assert.Null(await window.GetCurrentDialogAsync<MessageDialog>());
        }
Beispiel #6
0
        public Page2()
        {
            this.InitializeComponent();
            ViewModel   = new TheViewModel();
            DataContext = ViewModel;

            ViewModel.LoadData();
        }
        private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            await Task.Delay(10);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            await Task.Delay(1000);

            return($"You will never see this message.");
        }
        private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            await Task.Delay(10).ConfigureAwait(continueOnCapturedContext: false);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            await Task.Delay(1000);

            return("You will never see this message");
        }
Beispiel #9
0
        private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            await Task.Delay(10);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            await Task.Delay(1000);

            return($"Never switched contexts.");
        }
        private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            //quick delay just to (attempt) to switch threads
            await Task.Delay(1).ConfigureAwait(continueOnCapturedContext: false);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            await Task.Delay(1000).ConfigureAwait(continueOnCapturedContext: false);

            return($"No deadlock because blocking call is on different context.");
        }
Beispiel #11
0
        private async Task <string> CallSomethingAsync(TheViewModel vm)
        {
            //All this work is context UN-aware and will switch to a separate
            //context.
            await Task.Delay(10).ConfigureAwait(continueOnCapturedContext: false);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            await Task.Delay(1000).ConfigureAwait(continueOnCapturedContext: false);

            return($"Work is on default context but resumes on captured.");
        }
        /// <summary>
        /// Blows up because trying to access GUI from wrong context.
        /// </summary>
        /// <param name="parameter"></param>
        public async void Execute(object parameter)
        {
            TheViewModel vm = parameter as TheViewModel;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;

            //Switching to default context here.
            string msg = await CallSomethingAsync(vm).ConfigureAwait(continueOnCapturedContext: false);

            //Still on default context, no access to GUI thread. Boom.
            vm.UpdateDescription(msg);
        }
        /// <summary>
        /// Deadlocks
        /// </summary>
        /// <param name="parameter"></param>
        public void Execute(object parameter)
        {
            TheViewModel vm = parameter as TheViewModel;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;

            //Blocks while CallSomethingAsync runs.
            string msg = CallSomethingAsync(vm).Result;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            vm.UpdateDescription(msg);
        }
Beispiel #14
0
        public NewPage()
        {
            this.InitializeComponent();
            var viewTitleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;

            viewTitleBar.BackgroundColor       = Windows.UI.Colors.CornflowerBlue;
            viewTitleBar.ButtonBackgroundColor = Windows.UI.Colors.CornflowerBlue;
            ViewModel   = new TheViewModel();
            DataContext = ViewModel;

            ViewModel.LoadData();
        }
        /// <summary>
        /// Deadlocks
        /// </summary>
        /// <param name="parameter"></param>
        public void Execute(object parameter)
        {
            TheViewModel vm = parameter as TheViewModel;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;

            //Blocks while CallSomethingAsync runs. CallSomethingAsync
            //cannot resume on the context because .Result is blocking.
            var msg = CallSomethingAsync(vm);

            vm.UpdateDescription(msg.Result);
        }
Beispiel #16
0
        /// <summary>
        /// Works because we never switch contexts
        /// </summary>
        /// <param name="parameter"></param>
        public async void Execute(object parameter)
        {
            TheViewModel vm = parameter as TheViewModel;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;

            //Remains context aware
            string msg = await CallSomethingAsync(vm);

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
            vm.UpdateDescription(msg);
        }
Beispiel #17
0
        /// <summary>
        /// Work is done on default context but is resumed on the
        /// captured context.
        /// </summary>
        /// <param name="parameter"></param>
        public async void Execute(object parameter)
        {
            TheViewModel vm = parameter as TheViewModel;

            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;

            //No ConfigureAwait False here! The work in that method DOES
            //operate on a different conext but execution will resume
            //on the original context so we can access the GUI thread.
            string msg = await CallSomethingAsync(vm);

            vm.UpdateDescription(msg);
            vm.CurrentThreadID = Thread.CurrentThread.ManagedThreadId;
        }
        public CurrentSessionPage()
        {
            InitializeComponent();
            this.BackgroundColor = Color.FromHex("#36AFC5");
#if __IOS__
            Padding = new Thickness(0, 25, 0, 0);
#endif

            // Adds button interactions to different xaml objects
            var convertTemperatureTap = new TapGestureRecognizer();
            convertTemperatureTap.Tapped += (sender, e) => {
                TheViewModel.ToggleTemperatureConversion();
            };
            TemperatureConversionLabel.GestureRecognizers.Add(convertTemperatureTap);
        }
 public MainWindow(TheViewModel viewModel_)
 {
     InitializeComponent();
     //CurrentVM = new TheViewModel();
     CurrentVM                         = viewModel_;
     this.DataContext                  = CurrentVM;
     AppWindow                         = this;
     CurrentVM.FallBtnCom.MyEvent     += () => ShowFall();
     CurrentVM.RepBtnCom.MyEvent      += () => ShowRep();
     CurrentVM.AnalysisBtnCom.MyEvent += () => ShowGraph();
     CurrentVM.MapsBtnCom.MyEvent     += () => ShowMaps();
     this.welcomeTxt.Text             += " " + CurrentVM.TheUser.EmailUser;
     ////
     this.reportingBtn.IsEnabled = CurrentVM.TheUser.CellCenter;
     this.fallingBtn.IsEnabled   = CurrentVM.TheUser.Analyst;
     this.searchBtn.IsEnabled    = CurrentVM.TheUser.Analyst;
     this.analysBtn.IsEnabled    = CurrentVM.TheUser.Analyst;
     ////
 }
 private void Convert_Btn_Clicked(object sender, EventArgs e)
 {
     TheViewModel.ToggleTemperatureConversion();
 }
 private void Btn_Clicked(object sender, EventArgs e)
 {
     TheViewModel.StartOrStopCurrentSession();
 }
Beispiel #22
0
 public MapsCommand(TheViewModel vm)
 {
     CurrentVM = vm;
 }
Beispiel #23
0
 public Login()
 {
     InitializeComponent();
     CurrentVM        = new TheViewModel();
     this.DataContext = CurrentVM;
 }
Beispiel #24
0
 public BLClass()
 {
     ViewModel = new TheViewModel {
         Text = "This is cross platform text"
     };
 }