Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo.moya@xamarin.com>2019-07-19 15:15:42 +0300
committerRodrigo Moya <rodrigo.moya@xamarin.com>2019-07-25 12:31:12 +0300
commitbff6d46b154e7f650608f6f18cec84c1f131af2e (patch)
tree2602fca1895001ba4675336ef9a8bb95bd802ae9 /main/src/addins
parent48103c130b838ec523fef7922b6418781a64edb4 (diff)
[DotNetCore] Allow *Command's to provide post launch operations
Instead of duplicating code, just make the ExecutionHandler's call the specific Command implementation of its PostLaunch logic.
Diffstat (limited to 'main/src/addins')
-rw-r--r--main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs74
-rw-r--r--main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs59
-rw-r--r--main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs6
-rw-r--r--main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs54
4 files changed, 70 insertions, 123 deletions
diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs
index f7077b2cde..439396d2b5 100644
--- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs
+++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionCommand.cs
@@ -24,36 +24,74 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using MonoDevelop.Core.Execution;
+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 : ProcessExecutionCommand
+ public class AspNetCoreExecutionCommand : DotNetCoreExecutionCommand
{
public AspNetCoreExecutionCommand (string directory, string outputPath, string arguments)
+ : base (directory, outputPath, arguments)
{
- WorkingDirectory = directory;
- OutputPath = outputPath;
- DotNetArguments = arguments;
-
- Command = DotNetCoreRuntime.FileName;
- Arguments = string.Format ("\"{0}\" {1}", outputPath, arguments);
}
- public string OutputPath { get; private set; }
- public string DotNetArguments { get; private set; }
-
- public bool PauseConsoleOutput { get; set; }
- public bool ExternalConsole { get; set; }
- public bool LaunchBrowser { get; set; }
- public string LaunchURL { get; set; }
- public string ApplicationURL { get; set; }
- public PipeTransportSettings PipeTransport { get; set; }
-
// Since we are now supporting more than one url, we added this property
// 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 ec1ae1642f..63dd43a004 100644
--- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs
+++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/AspNetCoreExecutionHandler.cs
@@ -24,14 +24,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using MonoDevelop.Core;
-using MonoDevelop.Core.Execution;
-using MonoDevelop.Ide;
using System;
using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Net.Sockets;
+using MonoDevelop.Core;
+using MonoDevelop.Core.Execution;
namespace MonoDevelop.AspNetCore
{
@@ -57,57 +53,10 @@ namespace MonoDevelop.AspNetCore
dotNetCoreCommand.WorkingDirectory,
console,
envVariables);
- if (dotNetCoreCommand.LaunchBrowser) {
- LaunchBrowser (dotNetCoreCommand.ApplicationURL, dotNetCoreCommand.LaunchURL, dotNetCoreCommand.Target, process.Task).Ignore ();
- }
- return process;
- }
-
- public static async Task LaunchBrowser (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);
- using (var tcpClient = new TcpClient ()) {
- try {
- tcpClient.Connect (launchUri.Host, launchUri.Port);
- // pause briefly to allow the server process to initialize
- await Task.Delay (TimeSpan.FromSeconds (1));
- break;
- } catch {
- }
- }
- }
+ dotNetCoreCommand.PostLaunchAsync (process.Task).Ignore ();
- 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);
- }
+ return process;
}
}
} \ 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 646fb372fc..db026228ca 100644
--- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs
+++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionCommand.cs
@@ -24,6 +24,7 @@
// 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
@@ -49,5 +50,10 @@ namespace MonoDevelop.DotNetCore
public string LaunchURL { get; set; }
public string ApplicationURL { get; set; }
public PipeTransportSettings PipeTransport { get; set; }
+
+ public virtual Task PostLaunchAsync (Task processTask)
+ {
+ 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 01f0858897..bc532c6547 100644
--- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs
+++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreExecutionHandler.cs
@@ -24,14 +24,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using MonoDevelop.Core;
-using MonoDevelop.Core.Execution;
-using MonoDevelop.Ide;
using System;
using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Net.Sockets;
+using MonoDevelop.Core;
+using MonoDevelop.Core.Execution;
namespace MonoDevelop.DotNetCore
{
@@ -56,52 +52,10 @@ namespace MonoDevelop.DotNetCore
dotNetCoreCommand.WorkingDirectory,
console,
envVariables);
- if (dotNetCoreCommand.LaunchBrowser) {
- LaunchBrowser (dotNetCoreCommand.ApplicationURL, dotNetCoreCommand.LaunchURL, process.Task).Ignore ();
- }
- return process;
- }
-
- public static async Task LaunchBrowser (string appUrl, string launchUrl, Task processTask)
- {
- 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);
- using (var tcpClient = new TcpClient ()) {
- try {
- tcpClient.Connect (launchUri.Host, launchUri.Port);
- // pause briefly to allow the server process to initialize
- await Task.Delay (TimeSpan.FromSeconds (1));
- break;
- } catch {
- }
- }
- }
+ dotNetCoreCommand.PostLaunchAsync (process.Task).Ignore ();
- 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
- IdeServices.DesktopService.ShowUrl (launchUri.AbsoluteUri);
+ return process;
}
}
} \ No newline at end of file