static bool CanReuseProcess( this IBrowserProcess process, Interface.BrowserProcessConfig browserProcessConfig = null) { try { if (null == process) { return(false); } if (null != browserProcessConfig) { if (process?.Config?.ConfigMatchForReuse(browserProcessConfig) ?? false) { return(false); } } { var Connection = process?.ReuseConnection()?.Result; if (null != Connection) { return(true); } } var SetBrowserId = process?.GetBrowsersIds(); if (SetBrowserId.Failed()) { return(false); } foreach (var BrowserId in (SetBrowserId?.Result).EmptyIfNull()) { if (!(BrowserId?.ConnectionOffered ?? false)) { continue; } using (var Connection = process?.OpenConnection(BrowserId)?.Result) { if (Connection?.IsOpen ?? false) { return(true); } } } } catch { } return(false); }
static public IResultOrError <IBrowserConnection> OpenConnection(this IBrowserProcess process) { var SetBrowserId = process?.GetBrowsersIds(); if (null == SetBrowserId?.Result) { return(SetBrowserId.MapResult(_ => (IBrowserConnection)null)); } var SetBrowserIdSuitable = SetBrowserId?.Result?.Where(BrowserIdSuitable)?.ToArray(); var BrowserId = SetBrowserIdSuitable?.FirstOrDefault(c => c?.ConnectionOffered ?? false); return(process?.OpenConnection(BrowserId)); }
static public IResultOrError <IBrowserConnection> ReuseConnection(this IBrowserProcess process) { foreach (var Connection in (process?.Connections).EmptyIfNull()) { if (null == Connection) { continue; } if (null == Connection.Ping()) { return(Connection.AsResultSuccess()); } } return(null); }
public BrowserProcessCreation( IApp browserServiceInterface, BrowserProcessConfig browserProcessConfig, string url = null) { try { if (null == browserServiceInterface) { throw new NullReferenceException("Browser service interface not available."); } BrowserProcessOrError = browserServiceInterface.ReuseOrCreateProcess(browserProcessConfig); Thread.Sleep(1444); BrowserProcessErrorMessage = BrowserProcessOrError?.Error?.Message; BrowserProcess = BrowserProcessOrError?.Result; BrowserConnectionOrError = BrowserProcess?.ReuseOrOpenConnection(); BrowserConnectionErrorMessage = BrowserConnectionOrError?.Error?.Message; BrowserConnection = BrowserConnectionOrError?.Result; if (null != BrowserConnection && 0 < url?.Length) { Thread.Sleep(444); BrowserConnection.Document.Result.locationHref = url; } BrowserAddressTcp = BrowserConnection?.BrowserAddressTcp; } catch (Exception Exception) { this.Exception = Exception; } }
static public IResultOrError <IBrowserConnection> ReuseOrOpenConnection(this IBrowserProcess process) => process?.ReuseConnection() ?? process?.OpenConnection();