/// <summary> /// The <see cref="Task{TResult}"/> for <see cref="LaunchResult"/>. /// </summary> /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/>.</param> /// <param name="startupTimeout">The, optional, startup timeout in seconds.</param> /// <param name="reattached">If DreamDaemon was reattached.</param> /// <param name="apiValidate">If this is a DMAPI validation session.</param> /// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Session.LaunchResult"/> for the operation.</returns> async Task <LaunchResult> GetLaunchResult( IAssemblyInformationProvider assemblyInformationProvider, uint?startupTimeout, bool reattached, bool apiValidate) { var startTime = DateTimeOffset.UtcNow; var useBridgeRequestForLaunchResult = !reattached && (apiValidate || DMApiAvailable); var startupTask = useBridgeRequestForLaunchResult ? initialBridgeRequestTcs.Task : process.Startup; var toAwait = Task.WhenAny(startupTask, process.Lifetime); if (startupTimeout.HasValue) { toAwait = Task.WhenAny(toAwait, Task.Delay(TimeSpan.FromSeconds(startupTimeout.Value))); } logger.LogTrace( "Waiting for LaunchResult based on {0}{1}...", useBridgeRequestForLaunchResult ? "initial bridge request" : "process startup", startupTimeout.HasValue ? $" with a timeout of {startupTimeout.Value}s" : String.Empty); await toAwait.ConfigureAwait(false); var result = new LaunchResult { ExitCode = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null, StartupTime = startupTask.IsCompleted ? (TimeSpan?)(DateTimeOffset.UtcNow - startTime) : null }; logger.LogTrace("Launch result: {0}", result); if (!result.ExitCode.HasValue && reattached && !disposed) { var reattachResponse = await SendCommand( new TopicParameters( assemblyInformationProvider.Version, reattachInformation.RuntimeInformation.ServerPort), reattachTopicCts.Token) .ConfigureAwait(false); if (reattachResponse != null) { if (reattachResponse.InteropResponse?.CustomCommands != null) { chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands; } else if (reattachResponse.InteropResponse != null) { logger.LogWarning( "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.", CompileJob.DMApiVersion.Semver()); } } } return(result); }
/// <summary> /// The <see cref="Task{TResult}"/> for <see cref="LaunchResult"/>. /// </summary> /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/>.</param> /// <param name="startupTimeout">The, optional, startup timeout in seconds.</param> /// <param name="reattached">If DreamDaemon was reattached.</param> /// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Session.LaunchResult"/> for the operation.</returns> async Task <LaunchResult> GetLaunchResult( IAssemblyInformationProvider assemblyInformationProvider, uint?startupTimeout, bool reattached) { var startTime = DateTimeOffset.Now; Task toAwait = process.Startup; if (startupTimeout.HasValue) { toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime)); } await toAwait.ConfigureAwait(false); var result = new LaunchResult { ExitCode = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null, StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null }; logger.LogTrace("Launch result: {0}", result); if (!result.ExitCode.HasValue && reattached && !disposed) { var reattachResponse = await SendCommand( new TopicParameters( assemblyInformationProvider.Version, reattachInformation.RuntimeInformation.ServerPort), reattachTopicCts.Token) .ConfigureAwait(false); if (reattachResponse.InteropResponse?.CustomCommands != null) { chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands; } else if (reattachResponse.InteropResponse != null) { logger.LogWarning( "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.", Dmb.CompileJob.DMApiVersion.Semver()); } } return(result); }