Beispiel #1
0
        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);
        }
Beispiel #2
0
 static public IResultOrError <IBrowserConnection> ReuseOrOpenConnection(this IBrowserProcess process) =>
 process?.ReuseConnection() ?? process?.OpenConnection();