private async System.Threading.Tasks.Task DownloadRDPFileAsync(TvmModel tvm, string localDownloadTargetPath = null) { string fileName = null; bool? result; if (string.IsNullOrEmpty(localDownloadTargetPath)) { // Configure save file dialog box Microsoft.Win32.SaveFileDialog saveFileDlg = new Microsoft.Win32.SaveFileDialog(); saveFileDlg.FileName = tvm.Name; // Default file name saveFileDlg.DefaultExt = ".rdp"; // Default file extension. saveFileDlg.Filter = "RDP File (.rdp)|*.rdp"; // Filter files by extension // Show save file dialog box result = saveFileDlg.ShowDialog(); if (result == true) { fileName = saveFileDlg.FileName; } } else { fileName = Path.Combine(localDownloadTargetPath, Path.GetFileName(tvm.Name) + ".rdp"); result = true; } if (result == true) { // Save document using (MemoryStream memoryStream = new MemoryStream()) { await tvm.DownloadRDPAsync(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); using (FileStream fileStream = new FileStream(fileName, FileMode.Create)) { await memoryStream.CopyToAsync(fileStream); } } // Launch // We don't ask for permission to launch here because the process seems // to do that for us. The connection is always "untrusted" and, // given security settings, it is likely to remain that way. Process.Start(fileName); } }
private void RegisterMessages() { Messenger.Default.Register <UpdateWaitSpinnerMessage>(this, ProcessUpdateWaitSpinnerMessage); Messenger.Default.Register <RefreshMessage>(this, (message) => { switch (message.ItemToRefresh) { case RefreshTarget.Pools: AsyncOperationTracker.Instance.AddTrackedInternalOperation(this.GetDataAsync(dataProvider, false, false, true)); break; case RefreshTarget.WorkItems: AsyncOperationTracker.Instance.AddTrackedInternalOperation(this.GetDataAsync(dataProvider, true, false, false)); break; } } ); Messenger.Default.Register <ModelNotFoundAfterRefresh>(this, (message) => { ModelBase modelBase = message.Model; WorkItemModel workItemModel = modelBase as WorkItemModel; if (workItemModel != null) { this.workItems.Remove(workItemModel); FirePropertyChangedEvent("WorkItemTabTitle"); SelectedWorkItem = null; } PoolModel poolModel = modelBase as PoolModel; if (poolModel != null) { this.pools.Remove(poolModel); FirePropertyChangedEvent("PoolTabTitle"); SelectedPool = null; SelectedTVM = null; } JobModel jobModel = modelBase as JobModel; if (jobModel != null) { jobModel.ParentWorkItem.Jobs.Remove(jobModel); FirePropertyChangedEvent("JobTabTitle"); } TaskModel taskModel = modelBase as TaskModel; if (taskModel != null) { taskModel.ParentJob.Tasks.Remove(taskModel); taskModel.ParentJob.UpdateTaskView(); FirePropertyChangedEvent("TasksTabTitle"); } TvmModel vmModel = modelBase as TvmModel; if (vmModel != null) { vmModel.ParentPool.Tvms.Remove(vmModel); vmModel.ParentPool.UpdateTvmView(); FirePropertyChangedEvent("VMsTabTitle"); selectedTVM = null; } }); }