public async Task <ShowAwaitableResult <TTarget> > ShowAndGetViewModelImmediately <TTarget>(TTarget targetViewModel = null, string viewMappingKey = null) where TTarget : class, IViewModel { var vm = targetViewModel ?? ServiceLocator.Instance.Resolve <TTarget>(viewMappingKey); var vmt = InternalTestShow(vm, viewMappingKey); return(await TaskExHelper.FromResult(new ShowAwaitableResult <TTarget>() { Closing = vm.WaitForClose(), ViewModel = vm })); }
public static StorageHub <TToken, TValue> CreateXmlDatacontractFileStorageHub( Func <TToken, string> fileNameFactory, string folder = null, Func <Task <TToken[]> > storageTokensSelector = null) { var hub = new XmlDataContractStreamStorageHub <TToken, TValue>( async(tp, tk) => { folder = folder ?? Environment.CurrentDirectory; var filepath = Path.Combine(folder, fileNameFactory(tk)); switch (tp) { case StreamOpenType.Read: return(await TaskExHelper.FromResult(new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))); case StreamOpenType.Write: return(await TaskExHelper.FromResult(new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))); default: return(null); } }, storageTokensSelector ); return(hub); }
private async Task <bool> FileExists(string fileAName) { await TaskExHelper.Yield(); var iso = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); return(iso.FileExists(fileAName)); }
protected override async Task OnBindedViewLoad(MVVMSidekick.Views.IView view) { await base.OnBindedViewLoad(view); if (IsInDesignMode) { HelloWorld = "Hello Mvvm world, Design mode sample"; } else { if (Id == null) { Id = Guid.NewGuid().ToString(); } GetValueContainer(x => x.CountDown).GetNullObservable() .Subscribe( _ => { HelloWorld = string.Format("Loading {0}", CountDown); } ); } // Loading count down. You may want to replace your own logic here. await ExecuteTask( async() => { try { for (Double i = CountDown; i > 0; i = i - 1) { CountDown = i; await TaskExHelper.Delay(500); } CountDown = 0; HelloWorld = "Hello Mvvm world!"; } catch (Exception) { throw; } finally { StateName = "Loaded"; } } ); Title = "Hello Mvvm world2!"; }
public async Task <ShowAwaitableResult <TTarget> > ShowAndGetViewModel <TTarget>(TTarget targetViewModel = null, string viewMappingKey = null) where TTarget : class, IViewModel { IView view = null; view = InternalLocateViewIfNotSet <TTarget>(targetViewModel, viewMappingKey, view); targetViewModel = targetViewModel ?? view.ViewModel as TTarget; InternalShowView(view, Target, _navigator.CurrentBindingView.ViewModel); return(await TaskExHelper.FromResult(new ShowAwaitableResult <TTarget> { Closing = targetViewModel.WaitForClose(), ViewModel = targetViewModel })); }
/// <summary> /// Informs the ThreadPool that there's work to be executed for this scheduler. /// </summary> private async void NotifyThreadPoolOfPendingWork() { #if NETFX_CORE await ThreadPool.RunAsync((_1) => #else await TaskExHelper.Yield(); ThreadPool.QueueUserWorkItem(_ => #endif { // Note that the current thread is now processing work items. // This is necessary to enable inlining of tasks into this thread. _currentThreadIsProcessingItems = true; try { // Process all available items in the queue. while (true) { Task item; lock (_tasks) { // When there are no more items to be processed, // note that we're done processing, and get out. if (_tasks.Count == 0) { --_delegatesQueuedOrRunning; break; } // Get the next item from the queue item = _tasks.First.Value; _tasks.RemoveFirst(); } // Execute the task we pulled out of the queue base.TryExecuteTask(item); } } // We're done processing items on the current thread finally { _currentThreadIsProcessingItems = false; } #if NETFX_CORE }); #else }, null);
private void PropScribe() { GetValueContainer(vm => vm.IsImageMode).GetNewValueObservable().Subscribe(e => { var isimagemode = e.EventArgs; AppSettings.Instance.IsEnableImageMode = isimagemode; }).DisposeWith(this); GetValueContainer(vm => vm.IsLightTheme).GetNewValueObservable().Subscribe(async e => { var islighttheme = e.EventArgs; AppSettings.Instance.CurrentTheme = islighttheme ? ElementTheme.Light : ElementTheme.Dark; App.SetShellDecoration(false); //StageManager.DefaultStage.Frame.RequestedTheme = AppSettings.Instance.CurrentTheme; await TaskExHelper.Yield(); // await StageManager.DefaultStage.Show(new SettingPage_Model()); // ((Page) this.StageManager.CurrentBindingView).RequestedTheme = AppSettings.Instance.CurrentTheme; }).DisposeWith(this); GetValueContainer(vm => vm.AccentColor).GetNewValueObservable().Subscribe(e => { var accentcolor = e.EventArgs; AppSettings.Instance.AccentColor = accentcolor; App.SetShellDecoration(true); // await StageManager.DefaultStage.Show(new SettingPage_Model()); }).DisposeWith(this); //CheckBox点击之后,马上更改设置,以实现实时更新 EventRouter.Instance.GetEventChannel <Object>() .Where(x => x.EventName == "NotyCheckedByEventRouter") .Subscribe( async e => { var item = e.EventData as PostType; if (item != null) { var query = ListPostTypes.Where(listPosttype => listPosttype.IsSelected); AppSettings.Instance.SelectChannelTypes = query.ToList(); } await TaskExHelper.Yield(); } ).DisposeWith(this); }
public async Task <TService> ResolveAsync <TService>(string name = null, object paremeter = null) { name = name ?? ""; var subdic = ServiceTypedCache <TService> .dic; ServiceLocatorEntryStruct <TService> entry = null; if (subdic.TryGetValue(name, out entry)) { return(await entry.GetServiceAsync()); } else { //#if SILVERLIGHT_5||WINDOWS_PHONE_7 // return await T.askEx.FromResult(default(TService)); //#else // return await T.ask.FromResult(default(TService)); //#endif return(await TaskExHelper.FromResult(default(TService))); } }
/// <summary> /// Show a view model and return the view model after leave view. /// </summary> /// <typeparam name="TTarget">view model type</typeparam> /// <param name="targetViewModel">view model instance</param> /// <param name="viewMappingKey">mapping key</param> /// <returns></returns> public async Task <ShowAwaitableResult <TTarget> > ShowAndGetViewModelImmediately <TTarget>(TTarget targetViewModel = null, string viewMappingKey = null) where TTarget : class, IViewModel { IView view = null; view = InternalLocateViewIfNotSet <TTarget>(targetViewModel, viewMappingKey, view); targetViewModel = targetViewModel ?? view.ViewModel as TTarget; if (view.ViewType == ViewType.Page) { var mvpg = view as MVVMPage; mvpg.Frame = Frame; } SetVMAfterLoad(targetViewModel, view); InternalShowView(view, Target, _navigator.CurrentBindingView.ViewModel); return(await TaskExHelper.FromResult(new ShowAwaitableResult <TTarget> { Closing = targetViewModel.WaitForClose(), ViewModel = targetViewModel })); }
private void SubscribeCommand() { EventRouter.Instance.GetEventChannel <Object>() .Where(x => x.EventName == "NavToPostDetailByEventRouter") .Subscribe( async e => { await TaskExHelper.Yield(); var item = e.EventData as PostDetail; if (item != null) { await StageManager.DefaultStage.Show(new PostDetailPage_Model(item)); //StageManager.DefaultStage.Frame.Navigate(typeof(PostDetailPage),item); } } ).DisposeWith(this); EventRouter.Instance.GetEventChannel <Object>() .Where(x => x.EventName == "NavToAuthorDetailByEventRouter") .Subscribe( async e => { await TaskExHelper.Yield(); var item = e.EventData as Author; if (item != null) { item.AuthorPostList = new IncrementalLoadingCollection <AuthorPostSource, PostDetail>(item.Id.ToString(), AppStrings.PageSize); await StageManager.DefaultStage.Show(new AuthorPage_Model(item)); //StageManager.DefaultStage.Frame.Navigate(typeof(PostDetailPage),item); } } ).DisposeWith(this); }
private async Task <bool> FileExists(string fileAName) { var p = Path.Combine(Environment.CurrentDirectory, fileAName); return(await TaskExHelper.FromResult(File.Exists(p))); }