internal SearchContext(IEnumerable <Service> services, ContextSettings settings) { Services = services; Settings = settings; _activeContext = new Lazy <IBrowsingContext>(() => BuildContext(settings)); #if DEBUG DebugEnforceMaximumResults = true; #endif }
internal SearchContext(IEnumerable <object> services, ContextSettings settings) { Services = services; Settings = settings; _browsing = new Lazy <IBrowsingContext>( () => BuildBrowsingContext(settings.Timeout, () => BuildHttpClient(settings.Timeout))); _fetching = new Lazy <IFetchingContext>( () => new FetchingContext(BuildHttpClient(settings.Timeout, new HttpClient()))); #if DEBUG EnforceMaximumResults = true; #endif }
static IBrowsingContext BuildContext(ContextSettings settings) { if (settings.Timeout.HasValue) { var client = new HttpClient(); client.Timeout = settings.Timeout.Value; var requester = new HttpClientRequester(); return(BrowsingContext.New( Configuration.Default .WithRequester(requester) .WithDefaultLoader())); } return(BrowsingContext.New(Configuration.Default.WithDefaultLoader())); }
/// <summary>Configures a search context with a <c>ContextSettings</c> instance. If <c>merge</c> /// is <c>true</c> the settings instance is merged to the actul one.</summary> public static SearchContext WithConfiguration(this SearchContext context, ContextSettings settings, bool merge = false) { Guard.AgainstNull(nameof(context), context); if (merge) { var merged = context.Settings; if (settings.MaximumResults != default(int?)) { merged.MaximumResults = settings.MaximumResults; } if (settings.Timeout != default(TimeSpan)) { merged.Timeout = settings.Timeout; } if (settings.EnableRaisingEvents != default(bool)) { merged.EnableRaisingEvents = settings.EnableRaisingEvents; } return(new SearchContext(context.Services, merged)); } return(new SearchContext(context.Services, settings)); }
public SearchContext(ContextSettings settings) : this(Enumerable.Empty <object>(), settings) { }
public SearchContext(ContextSettings settings) : this(Enumerable.Empty <Service>(), settings) { }
/// <summary> /// Configure a search context with a <see cref="ContextSettings"/> instance. /// </summary> /// <param name="context">The search context to alter.</param> /// <param name="settings">The settings to configure in the search context.</param> /// <returns>A <see cref="SearchContext"/> instance with new configuration settings.</returns> public static SearchContext WithConfiguration(this SearchContext context, ContextSettings settings) { return(new SearchContext(context.Services, settings)); }