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