diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-07-19 17:14:59 +0300 |
---|---|---|
committer | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-07-25 12:31:12 +0300 |
commit | ff0c97f9667cad70267617512c0702d7e30ae9d4 (patch) | |
tree | 5657d013f9c941ffaae9426db082c65e220a7632 /main/src/addins | |
parent | bff6d46b154e7f650608f6f18cec84c1f131af2e (diff) |
[DotNetCore] Remove execution logic from DotNetCoreExecutionCommand
And move it to the ExecutionHandler's, as before
Diffstat (limited to 'main/src/addins')
4 files changed, 61 insertions, 63 deletions
diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs index 439396d2b5..da240f9e9a 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs @@ -24,16 +24,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; -using System.Threading.Tasks; -using System.Net.Sockets; -using MonoDevelop.Core; -using MonoDevelop.Ide; using MonoDevelop.DotNetCore; namespace MonoDevelop.AspNetCore { - public class AspNetCoreExecutionCommand : DotNetCoreExecutionCommand + public class AspNetCoreExecutionCommand : DotNetCoreBaseExecutionCommand { public AspNetCoreExecutionCommand (string directory, string outputPath, string arguments) : base (directory, outputPath, arguments) @@ -44,54 +39,5 @@ namespace MonoDevelop.AspNetCore // so that it contains the raw value of AppUrl // which might provide more than one url i.e. https://localhost:5000;http://localhost:5001 public string ApplicationURLs { get; set; } - - public override async Task PostLaunchAsync (Task processTask) - { - await base.PostLaunchAsync (processTask).ConfigureAwait (false); - - var aspNetCoreTarget = Target as AspNetCoreExecutionTarget; - var launchUrl = LaunchURL ?? ""; - Uri launchUri; - //Check if lanuchUrl is valid absolute url and use it if it is... - if (!Uri.TryCreate (launchUrl, UriKind.Absolute, out launchUri)) { - //Otherwise check if appUrl is valid absolute and lanuchUrl is relative then concat them... - Uri appUri; - if (!Uri.TryCreate (ApplicationURL, UriKind.Absolute, out appUri)) { - LoggingService.LogWarning ("Failed to launch browser because invalid launch and app urls."); - return; - } - if (!Uri.TryCreate (launchUrl, UriKind.Relative, out launchUri)) { - LoggingService.LogWarning ("Failed to launch browser because invalid launch url."); - return; - } - launchUri = new Uri (appUri, launchUri); - } - - //Try to connect every 50ms while process is running - while (!processTask.IsCompleted) { - await Task.Delay (50).ConfigureAwait (false); - using (var tcpClient = new TcpClient ()) { - try { - await tcpClient.ConnectAsync (launchUri.Host, launchUri.Port).ConfigureAwait (false); - // pause briefly to allow the server process to initialize - await Task.Delay (TimeSpan.FromSeconds (1)).ConfigureAwait (false); - break; - } catch { - } - } - } - - if (processTask.IsCompleted) { - LoggingService.LogDebug ("Failed to launch browser because process exited before server started listening."); - return; - } - - // Process is still alive hence we succesfully connected inside loop to web server, launch browser - if (aspNetCoreTarget != null && !aspNetCoreTarget.DesktopApplication.IsDefault) { - aspNetCoreTarget.DesktopApplication.Launch (launchUri.AbsoluteUri); - } else { - IdeServices.DesktopService.ShowUrl (launchUri.AbsoluteUri); - } - } } } diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs index 63dd43a004..7cfe068f93 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs @@ -26,8 +26,11 @@ using System; using System.Linq; +using System.Threading.Tasks; +using System.Net.Sockets; using MonoDevelop.Core; using MonoDevelop.Core.Execution; +using MonoDevelop.Ide; namespace MonoDevelop.AspNetCore { @@ -54,9 +57,58 @@ namespace MonoDevelop.AspNetCore console, envVariables); - dotNetCoreCommand.PostLaunchAsync (process.Task).Ignore (); + if (dotNetCoreCommand.LaunchBrowser) { + LaunchBrowserAsync (dotNetCoreCommand.ApplicationURL, dotNetCoreCommand.LaunchURL, dotNetCoreCommand.Target, process.Task).Ignore (); + } return process; } + + public static async Task LaunchBrowserAsync (string appUrl, string launchUrl, ExecutionTarget target, Task processTask) + { + var aspNetCoreTarget = target as AspNetCoreExecutionTarget; + launchUrl = launchUrl ?? ""; + Uri launchUri; + //Check if lanuchUrl is valid absolute url and use it if it is... + if (!Uri.TryCreate (launchUrl, UriKind.Absolute, out launchUri)) { + //Otherwise check if appUrl is valid absolute and lanuchUrl is relative then concat them... + Uri appUri; + if (!Uri.TryCreate (appUrl, UriKind.Absolute, out appUri)) { + LoggingService.LogWarning ("Failed to launch browser because invalid launch and app urls."); + return; + } + if (!Uri.TryCreate (launchUrl, UriKind.Relative, out launchUri)) { + LoggingService.LogWarning ("Failed to launch browser because invalid launch url."); + return; + } + launchUri = new Uri (appUri, launchUri); + } + + //Try to connect every 50ms while process is running + while (!processTask.IsCompleted) { + await Task.Delay (50).ConfigureAwait (false); + using (var tcpClient = new TcpClient ()) { + try { + await tcpClient.ConnectAsync (launchUri.Host, launchUri.Port).ConfigureAwait (false); + // pause briefly to allow the server process to initialize + await Task.Delay (TimeSpan.FromSeconds (1)).ConfigureAwait (false); + break; + } catch { + } + } + } + + if (processTask.IsCompleted) { + LoggingService.LogDebug ("Failed to launch browser because process exited before server started listening."); + return; + } + + // Process is still alive hence we succesfully connected inside loop to web server, launch browser + if (aspNetCoreTarget != null && !aspNetCoreTarget.DesktopApplication.IsDefault) { + aspNetCoreTarget.DesktopApplication.Launch (launchUri.AbsoluteUri); + } else { + IdeServices.DesktopService.ShowUrl (launchUri.AbsoluteUri); + } + } } }
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs index db026228ca..de4542a37b 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs @@ -24,14 +24,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Threading.Tasks; using MonoDevelop.Core.Execution; namespace MonoDevelop.DotNetCore { - public class DotNetCoreExecutionCommand : ProcessExecutionCommand + public class DotNetCoreBaseExecutionCommand : ProcessExecutionCommand { - public DotNetCoreExecutionCommand (string directory, string outputPath, string arguments) + public DotNetCoreBaseExecutionCommand (string directory, string outputPath, string arguments) { WorkingDirectory = directory; OutputPath = outputPath; @@ -50,10 +49,13 @@ namespace MonoDevelop.DotNetCore public string LaunchURL { get; set; } public string ApplicationURL { get; set; } public PipeTransportSettings PipeTransport { get; set; } + } - public virtual Task PostLaunchAsync (Task processTask) + public class DotNetCoreExecutionCommand : DotNetCoreBaseExecutionCommand + { + public DotNetCoreExecutionCommand (string directory, string outputPath, string arguments) + : base (directory, outputPath, arguments) { - return Task.FromResult (0); } } }
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs index bc532c6547..272092479d 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs @@ -53,8 +53,6 @@ namespace MonoDevelop.DotNetCore console, envVariables); - dotNetCoreCommand.PostLaunchAsync (process.Task).Ignore (); - return process; } } |