/// <summary> /// /// </summary> /// <returns></returns> public bool IsRemoteAccessible() { if (string.IsNullOrWhiteSpace(RemoteUrl)) { return(true); } if (RemoteUrl.StartsWith("http")) { var uri = new Uri(RemoteUrl); var host = uri.Host; var port = uri.Port; var cli = new TcpClient(); try{ var t = cli.ConnectAsync(host, port); return(t.Wait(500)); } catch { return(false); } } return(Directory.Exists(RemoteUrl)); }
private ConsoleApplicationHandler PrepareCall(string command, string args, int timeout) { if ((command == "fetch" || command == "push" || command == "clone") && !string.IsNullOrWhiteSpace(RemoteUrl) && RemoteUrl.StartsWith("http")) { if (!IsRemoteAccessible()) { if (null != OnNotConnected) { OnNotConnected.Invoke(); } if (!NoErrorOnNotConnected) { throw new Exception("Cannot perform " + command + " because remote url " + RemoteUrl + " is not accessible"); } return(ConsoleApplicationHandler.Null); } } return(new ConsoleApplicationHandler { ExePath = "git", WorkingDirectory = DirectoryName ?? Environment.CurrentDirectory, Arguments = command + " " + args, NoWindow = true, Timeout = timeout }); }