private void Cleanup(TabCloseReason tabCloseReason, QueryDeveloperViewModel queryDeveloperViewModel, IDisposable watchSubscription)
 {
     watchSubscription.Dispose();
     if (tabCloseReason == TabCloseReason.TabClosed)
     {
         RemoveDocument(queryDeveloperViewModel);
     }
 }
        private void RemoveDocument(QueryDeveloperViewModel queryDeveloperViewModel)
        {
            var fileName = _queryFileService.GetFileName(queryDeveloperViewModel.FileId);

            if (!File.Exists(fileName))
            {
                return;
            }

            try
            {
                File.Delete(fileName);
            }
            catch { /* TODO uhm something */ }
        }
 private void PopulateDocument(QueryDeveloperViewModel queryDeveloperViewModel)
 {
     Task.Factory.StartNew(() =>
     {
         var fileName = _queryFileService.GetFileName(queryDeveloperViewModel.FileId);
         return(File.Exists(fileName) ? File.ReadAllText(fileName) : string.Empty);
     }).ContinueWith(t =>
     {
         if (t.Exception != null)
         {
             //TODO uhm something
         }
         else
         {
             if (string.IsNullOrEmpty(queryDeveloperViewModel.QueryRunnerViewModel.Document.Text))
             {
                 queryDeveloperViewModel.QueryRunnerViewModel.Document.Text = t.Result;
             }
         }
     }, TaskScheduler.FromCurrentSynchronizationContext());
 }
 private IDisposable Watch(QueryDeveloperViewModel queryDeveloperViewModel)
 {
     return(queryDeveloperViewModel.DocumentChangedObservable.Throttle(TimeSpan.FromSeconds(3))
            .ObserveOn(new EventLoopScheduler())
            .Subscribe(SaveDocument));
 }