Exemple #1
0
 public override void Refresh(DetailLevel detailLevel = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null)
 {
     using (System.Threading.Tasks.Task asyncTask = RefreshAsync(detailLevel, additionalBehaviors))
     {
         asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors);
     }
 }
Exemple #2
0
 /// <summary>
 /// Downloads a file on this TVM
 /// </summary>
 /// <param name="filePath">The path of the file on the tVM</param>
 /// <param name="destinationStream">The target stream to place the file into</param>
 public async System.Threading.Tasks.Task DownloadFileAsync(string filePath, Stream destinationStream)
 {
     System.Threading.Tasks.Task asyncTask = this.DownloadVMFile(filePath, destinationStream);
     AsyncOperationTracker.Instance.AddTrackedOperation(new AsyncOperationModel(
                                                            asyncTask,
                                                            new VMOperation(VMOperation.GetVMFile, this.ParentPool.Name, this.VM.Name)));
     await asyncTask;
 }
Exemple #3
0
 /// <summary>
 /// Downloads an RDP file associated with this TVM
 /// </summary>
 /// <param name="destinationStream">The target stream to place the RDP file into</param>
 public async System.Threading.Tasks.Task DownloadRDPAsync(Stream destinationStream)
 {
     try
     {
         System.Threading.Tasks.Task asyncTask = this.VM.GetRDPFileAsync(destinationStream);
         AsyncOperationTracker.Instance.AddTrackedOperation(new AsyncOperationModel(
                                                                asyncTask,
                                                                new VMOperation(VMOperation.GetRdp, this.ParentPool.Name, this.VM.Name)));
         await asyncTask;
     }
     catch (Exception e)
     {
         Messenger.Default.Send(new GenericDialogMessage(e.ToString()));
     }
 }
Exemple #4
0
 /// <summary>
 /// Reimages the TVM
 /// </summary>
 public async System.Threading.Tasks.Task ReimageAsync()
 {
     try
     {
         System.Threading.Tasks.Task asyncTask = this.VM.ReimageAsync();
         AsyncOperationTracker.Instance.AddTrackedOperation(new AsyncOperationModel(
                                                                asyncTask,
                                                                new VMOperation(VMOperation.Reimage, this.ParentPool.Name, this.VM.Name)));
         await asyncTask;
         await this.RefreshAsync(ModelRefreshType.Basic, showTrackedOperation : false);
     }
     catch (Exception e)
     {
         Messenger.Default.Send(new GenericDialogMessage(e.ToString()));
     }
 }
		public void SpinIndexingWorkers()
		{
			if (backgroundWorkersSpun)
				throw new InvalidOperationException("The background workers has already been spun and cannot be spun again");

			backgroundWorkersSpun = true;

			workContext.StartIndexing();
			indexingBackgroundTask = System.Threading.Tasks.Task.Factory.StartNew(
				indexingExecuter.Execute,
				CancellationToken.None, TaskCreationOptions.LongRunning, backgroundTaskScheduler);
			reducingBackgroundTask = System.Threading.Tasks.Task.Factory.StartNew(
				new ReducingExecuter(workContext).Execute,
				CancellationToken.None, TaskCreationOptions.LongRunning, backgroundTaskScheduler);
		}
        private void SearchForDevices(List<string> ips, Action<List<SyncDevice>> actionDiscoveryEnded)
        {            
            int ipCount = 0;
            _cancellationTokenSource = new CancellationTokenSource();
            ParallelOptions parallelOptions = new ParallelOptions();
            parallelOptions.CancellationToken = _cancellationTokenSource.Token;

#if !WINDOWS_PHONE
            parallelOptions.MaxDegreeOfParallelism = 2; //System.Environment.ProcessorCount; // Not available on WP8
#endif
            _currentTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                var devices = new List<SyncDevice>();
                try
                {
                    Tracing.Log("SyncDiscoveryService - SearchForDevices - processorCount: {0}", System.Environment.ProcessorCount);
                    IsRunning = true;
                    Parallel.For(1, ips.Count, parallelOptions, (index) =>
                    {
                        try
                        {
                            Tracing.Log("SyncDiscoveryService - Pinging {0}...", ips[index]);
                            string url = string.Format("http://{0}:{1}/sessionsapp.version", ips[index], Port);

                            //string content = await _httpClient.GetStringAsync(url); // This seems to pile up tasks until they hit await...
                            var task = _httpClient.GetStringAsync(url);
                            string content = task.Result; // This is the good way to use tasks and async properly in Parallel.For

                            Tracing.Log("SyncDiscoveryService - Got version from {0}: {1}", ips[index], content);
                            var device = XmlSerialization.Deserialize<SyncDevice>(content);
                            if (device.SyncVersionId.ToUpper() == SyncListenerService.SyncVersionId.ToUpper())
                            {
                                device.Url = String.Format("http://{0}:{1}/", ips[index], Port);
                                devices.Add(device);

                                lock (_lock)
                                {
                                    _devices.Add(device);
                                }

                                Tracing.Log("SyncDiscoveryService - Raising OnDeviceFound event...");
                                if (OnDeviceFound != null)
                                    OnDeviceFound(device);
                                Tracing.Log("SyncDiscoveryService - The following host is available: {0}", ips[index]);
                            }
                        }
                        catch (Exception ex)
                        {
                            // Ignore IP address
                            //Tracing.Log("SyncDiscoveryService - SearchForDevices - Parallel.For - Exception: {0}", ex);
                        }
                        finally
                        {
                            ipCount++;
                            float percentageDone = ((float)ipCount / (float)ips.Count) * 100;
                            if (OnDiscoveryProgress != null)
                                OnDiscoveryProgress(percentageDone, String.Format("Finding devices on local network ({0:0}%)", percentageDone));
                        }
                    });

                    IsRunning = false;

                    Tracing.Log("SyncDiscoveryService - Discovery done!");
                    if (actionDiscoveryEnded != null)
                        actionDiscoveryEnded(devices);
                }
                catch (System.OperationCanceledException ex)
                {
                    Tracing.Log("SyncDiscoveryService - SearchForDevices - OperationCanceledException: {0}", ex);
                    IsRunning = false;

                    if (actionDiscoveryEnded != null)
                        actionDiscoveryEnded(new List<SyncDevice>());
                }
                catch (Exception ex)
                {
                    Tracing.Log("SyncDiscoveryService - SearchForDevices - Exception: {0}", ex);
                    IsRunning = false;
                }

                _devices = devices.ToList();
            });
        }
Exemple #7
0
        public override async Task RefreshAsync(ModelRefreshType refreshType, bool showTrackedOperation = true)
        {
            if (refreshType.HasFlag(ModelRefreshType.Basic))
            {
                try
                {
                    Messenger.Default.Send(new UpdateWaitSpinnerMessage(WaitSpinnerPanel.UpperRight, true));
                    System.Threading.Tasks.Task asyncTask = this.VM.RefreshAsync();
                    if (showTrackedOperation)
                    {
                        AsyncOperationTracker.Instance.AddTrackedOperation(new AsyncOperationModel(
                                                                               asyncTask,
                                                                               new VMOperation(VMOperation.Refresh, this.ParentPool.Name, this.VM.Name)));
                    }
                    else
                    {
                        AsyncOperationTracker.Instance.AddTrackedInternalOperation(asyncTask);
                    }

                    await asyncTask;
                    this.LastUpdatedTime = DateTime.UtcNow;

                    //
                    // Fire property change events for this models properties
                    //
                    this.FireChangesOnRefresh(ModelRefreshType.Basic);
                }
                catch (Exception e)
                {
                    this.HandleException(e);
                }
                finally
                {
                    Messenger.Default.Send(new UpdateWaitSpinnerMessage(WaitSpinnerPanel.UpperRight, false));
                }
            }

            if (refreshType.HasFlag(ModelRefreshType.Children))
            {
                try
                {
                    Messenger.Default.Send(new UpdateWaitSpinnerMessage(WaitSpinnerPanel.LowerRight, true));
                    //Set this before the children load so that on revisit we know we have loaded the children (or are in the process)
                    this.HasLoadedChildren = true;

                    try
                    {
                        System.Threading.Tasks.Task <List <ITaskFile> > asyncTask = this.ListFilesAsync();
                        AsyncOperationTracker.Instance.AddTrackedOperation(new AsyncOperationModel(
                                                                               asyncTask,
                                                                               new VMOperation(VMOperation.ListVMFiles, this.ParentPool.Name, this.VM.Name)));

                        this.Files = await asyncTask;
                    }
                    catch (Exception)
                    {
                        this.HasLoadedChildren = false; //On exception, we failed to load children so try again next time
                        //Swallow the exception to stop popups from occuring for every bad VM
                    }

                    this.FireChangesOnRefresh(ModelRefreshType.Children);
                }
                catch (Exception e)
                {
                    this.HasLoadedChildren = false; //On exception, we failed to load children so try again next time
                    this.HandleException(e);
                }
                finally
                {
                    Messenger.Default.Send(new UpdateWaitSpinnerMessage(WaitSpinnerPanel.LowerRight, false));
                }
            }
        }