/// <summary> /// Handles the <see cref="_process"/>.Exited event. /// If packaging succeeded (<see cref="_succeeded"/>), <see cref="_result"/> is set from the retreived data. /// </summary> /// <param name="sender">The exited <see cref="VirtualizedProcess"/>.</param> /// <param name="exitCode">The associated <see cref="NativeResultCode"/>.</param> private void Process_Exited(VirtualizedProcess sender, int exitCode) { if (sender != _process) { throw new ApplicationException("An unexpected exception occured in the application workflow." + " Process_Exited event is called from an unknown Process."); } _succeeded = exitCode == (int)NativeResultCode.Success; _result = !_succeeded ? null : new PackagedApplication(_startInfo.WorkingDirectory.FileName, _process.GetExecutables(), _startInfo.Files.RegistryDatabase.FileName); _waitHandle.Set(); sender.Dispose(); }
/// <summary> /// Starts a process from the <see cref="ApplicationData"/> loaded from the filename specified. /// </summary> /// <exception cref="FileNotFoundException"> /// A <see cref="FileNotFoundException"/> is thrown if the <paramref name="applicationDataFile"/> can not be found. /// </exception> /// <exception cref="HostException"> /// A <see cref="HostException"/> is thrown if the process can't be started. /// </exception> /// <param name="applicationDataFile"> /// The file to load the <see cref="ApplicationData"/> from, /// representing the application to start. /// </param> public static void StartProcess(string applicationDataFile) { if (!File.Exists(applicationDataFile)) { throw new FileNotFoundException("Unable to locate the virtual application's datafile.", applicationDataFile); } var data = ApplicationData.Load(applicationDataFile); if (data == null) { throw new HostException("\"" + applicationDataFile + "\"" + " could not be found or contains invalid data while trying" + " to start a new process based on this file."); } var workingDirectory = new ApplicationFile(Path.GetDirectoryName(applicationDataFile)); var startInfo = new VirtualProcessStartInfo(data, workingDirectory); _process = VirtualizedProcess.Start(startInfo); }
/// <summary> /// Handles the <see cref="_process"/>.Exited event. /// If packaging succeeded (<see cref="_succeeded"/>), <see cref="_result"/> is set from the retreived data. /// </summary> /// <param name="sender">The exited <see cref="VirtualizedProcess"/>.</param> /// <param name="exitCode">The associated <see cref="NativeResultCode"/>.</param> private void Process_Exited(VirtualizedProcess sender, int exitCode) { if (sender != _process) throw new ApplicationException("An unexpected exception occured in the application workflow." + " Process_Exited event is called from an unknown Process."); _succeeded = exitCode == (int)NativeResultCode.Success; _result = !_succeeded ? null : new PackagedApplication(_startInfo.WorkingDirectory.FileName, _process.GetExecutables(), _startInfo.Files.RegistryDatabase.FileName); _waitHandle.Set(); sender.Dispose(); }