Ejemplo n.º 1
0
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;

            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;

            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);

            tabContent.OnShow(showCtx);
            bool asyncShow       = false;
            var  asyncTabContent = tabContent as IAsyncFileTabContent;

            if (asyncTabContent != null)
            {
                if (asyncTabContent.CanStartAsyncWorker(showCtx))
                {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => {
                        AppCulture.InitializeCulture();
                        asyncTabContent.AsyncWorker(showCtx, ctx.CancellationTokenSource);
                    }, ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                  cachedUIContext.FileTab == this &&
                                                  UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                        {
                            asyncWorkerContext = null;
                        }
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, showCtx, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult());
                }
            }
            if (!asyncShow)
            {
                OnShown(serializedUI, onShownHandler, showCtx, true);
            }
            fileTabManager.OnNewTabContentShown(this);
        }
Ejemplo n.º 2
0
 void CancelAsyncWorker()
 {
     if (asyncWorkerContext == null)
     {
         return;
     }
     asyncWorkerContext.Cancel();
     asyncWorkerContext = null;
 }
Ejemplo n.º 3
0
 void CancelAsyncWorker()
 {
     if (asyncWorkerContext == null)
     {
         return;
     }
     asyncWorkerContext.CancellationTokenSource.Cancel();
     asyncWorkerContext = null;
 }
Ejemplo n.º 4
0
        void ShowInternal(DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            UIContext = tabContent.CreateUIContext(documentTabUIContextLocator);
            var cachedUIContext = UIContext;

            Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this);
            cachedUIContext.DocumentTab = this;
            Debug.Assert(cachedUIContext.DocumentTab == this);
            Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this);
            tabContent.DocumentTab = this;
            Debug.Assert(tabContent.DocumentTab == this);

            UpdateTitleAndToolTip();
            DnSpyEventSource.Log.ShowDocumentTabContentStart();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);

            tabContent.OnShow(showCtx);
            bool asyncShow = false;

            if (tabContent is AsyncDocumentTabContent asyncTabContent)
            {
                if (asyncTabContent.NeedAsyncWork(showCtx))
                {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    var asyncShowCtx = new AsyncShowContext(showCtx, ctx);
                    Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                  cachedUIContext.DocumentTab == this &&
                                                  UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                        {
                            asyncWorkerContext = null;
                        }
                        ctx.Dispose();
                        asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult());
                }
            }
            if (!asyncShow)
            {
                OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent);
            }
            documentTabService.OnNewTabContentShown(this);
        }
Ejemplo n.º 5
0
        public void AsyncExec(Action <CancellationTokenSource> preExec, Action asyncAction, Action <IAsyncShowResult> postExec)
        {
            CancelAsyncWorker();

            var ctx = new AsyncWorkerContext();

            asyncWorkerContext = ctx;
            preExec(ctx.CancellationTokenSource);
            Task.Factory.StartNew(() => asyncAction(), ctx.CancellationToken)
            .ContinueWith(t => {
                if (asyncWorkerContext == ctx)
                {
                    asyncWorkerContext = null;
                }
                ctx.Dispose();
                postExec(new AsyncShowResult(t, false));
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 6
0
 public AsyncShowContext(IShowContext showContext, AsyncWorkerContext asyncWorkerContext)
 {
     this.showContext        = showContext;
     this.asyncWorkerContext = asyncWorkerContext;
 }
Ejemplo n.º 7
0
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action<ShowTabContentEventArgs> onShownHandler)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;
            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;
            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var userData = tabContent.OnShow(cachedUIContext);
            bool asyncShow = false;
            var asyncTabContent = tabContent as IAsyncFileTabContent;
            if (asyncTabContent != null) {
                if (asyncTabContent.CanStartAsyncWorker(cachedUIContext, userData)) {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => {
                        AppCulture.InitializeCulture();
                        asyncTabContent.AsyncWorker(cachedUIContext, userData, ctx.CancellationTokenSource);
                    }, ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                cachedUIContext.FileTab == this &&
                                                UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                            asyncWorkerContext = null;
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(cachedUIContext, userData, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                    asyncTabContent.EndAsyncShow(cachedUIContext, userData, new AsyncShowResult());
            }
            if (!asyncShow)
                OnShown(serializedUI, onShownHandler, true);
            fileTabManager.OnNewTabContentShown(this);
        }
Ejemplo n.º 8
0
 void CancelAsyncWorker()
 {
     if (asyncWorkerContext == null)
         return;
     asyncWorkerContext.CancellationTokenSource.Cancel();
     asyncWorkerContext = null;
 }
Ejemplo n.º 9
0
        public void AsyncExec(Action<CancellationTokenSource> preExec, Action asyncAction, Action<IAsyncShowResult> postExec)
        {
            CancelAsyncWorker();

            var ctx = new AsyncWorkerContext();
            asyncWorkerContext = ctx;
            preExec(ctx.CancellationTokenSource);
            Task.Factory.StartNew(() => {
                AppCulture.InitializeCulture();
                asyncAction();
            }, ctx.CancellationTokenSource.Token)
            .ContinueWith(t => {
                if (asyncWorkerContext == ctx)
                    asyncWorkerContext = null;
                ctx.Dispose();
                postExec(new AsyncShowResult(t, false));
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 10
0
		void CancelAsyncWorker() {
			if (asyncWorkerContext == null)
				return;
			asyncWorkerContext.Cancel();
			asyncWorkerContext = null;
		}
Ejemplo n.º 11
0
		void ShowInternal(DocumentTabContent tabContent, object uiState, Action<ShowTabContentEventArgs> onShownHandler, bool isRefresh) {
			Debug.Assert(asyncWorkerContext == null);
			UIContext = tabContent.CreateUIContext(documentTabUIContextLocator);
			var cachedUIContext = UIContext;
			Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this);
			cachedUIContext.DocumentTab = this;
			Debug.Assert(cachedUIContext.DocumentTab == this);
			Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this);
			tabContent.DocumentTab = this;
			Debug.Assert(tabContent.DocumentTab == this);

			UpdateTitleAndToolTip();
			var showCtx = new ShowContext(cachedUIContext, isRefresh);
			tabContent.OnShow(showCtx);
			bool asyncShow = false;
			var asyncTabContent = tabContent as AsyncDocumentTabContent;
			if (asyncTabContent != null) {
				if (asyncTabContent.NeedAsyncWork(showCtx)) {
					asyncShow = true;
					var ctx = new AsyncWorkerContext();
					asyncWorkerContext = ctx;
					var asyncShowCtx = new AsyncShowContext(showCtx, ctx);
					Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken)
					.ContinueWith(t => {
						bool canShowAsyncOutput = ctx == asyncWorkerContext &&
												cachedUIContext.DocumentTab == this &&
												UIContext == cachedUIContext;
						if (asyncWorkerContext == ctx)
							asyncWorkerContext = null;
						ctx.Dispose();
						asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
						bool success = !t.IsFaulted && !t.IsCanceled;
						OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed);
					}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
				}
				else
					asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult());
			}
			if (!asyncShow)
				OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent);
			documentTabService.OnNewTabContentShown(this);
		}
Ejemplo n.º 12
0
			public AsyncShowContext(IShowContext showContext, AsyncWorkerContext asyncWorkerContext) {
				this.showContext = showContext;
				this.asyncWorkerContext = asyncWorkerContext;
			}