コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NapRequest" /> class.
        /// </summary>
        /// <param name="plugins">The set of plugins to apply during execution of this request.</param>
        /// <param name="initialConfiguration">The initial configuration for the request.</param>
        /// <param name="url">The URL to perform the request against.  Can be a full URL or a partial.</param>
        /// <param name="method">The method to use in the request.</param>
        internal NapRequest(IReadOnlyCollection <IPlugin> plugins, INapConfig initialConfiguration, string url, HttpMethod method)
        {
            // Set up initial configuration parameters.
            _plugins = plugins;
            _config  = initialConfiguration;
            _events  = new Dictionary <EventCode, List <Event> >();
            foreach (var header in _config.Headers)
            {
                _headers.Add(header.Key, header.Value);
            }
            foreach (var queryParameter in _config.QueryParameters)
            {
                _queryParameters.Add(queryParameter.Key, queryParameter.Value);
            }
            if (_config.Advanced.Proxy.Address != null)
            {
                Advanced.UseProxy(_config.Advanced.Proxy.Address);
            }
            if (!string.IsNullOrEmpty(_config.Advanced.Authentication.Username) && !string.IsNullOrEmpty(_config.Advanced.Authentication.Password))
            {
                Advanced.Authentication.Basic(_config.Advanced.Authentication.Username, _config.Advanced.Authentication.Password);
            }
            ClientCreator = _config.Advanced.ClientCreator;

            _url    = url;
            _method = method;
        }
コード例 #2
0
 /// <summary>
 /// Apply all plugins to the configuration.
 /// </summary>
 /// <param name="config">The configuration to permute using plugins.</param>
 /// <returns>A new, updated configuration as found by applying the plugins in order.</returns>
 private INapConfig Configure(INapConfig config)
 {
     if (_setup != null && _setup.Plugins != null)
     {
         return(_setup.Plugins.Aggregate(config, (c, p) => p.Configure(c)));
     }
     return(config);
 }
コード例 #3
0
 /// <summary>
 /// Helper method to run all plugin methods that need to be executed on <see cref="INapRequest"/> creation.
 /// </summary>
 private INapRequest CreateNapRequest(INapConfig config, string url, HttpMethod method)
 {
     try
     {
         var plugins = _setup?.Plugins.ToArray() ?? new IPlugin[] { }; // Enumerate plugins to make sure no other threads are going to add/remove plugins halfway through
         var request = new NapRequest(plugins, config, url, method);
         return(request);
     }
     catch (Exception e)
     {
         throw new Exception("Nap request creation aborted.  See inner exception for details.", e); // TODO: Specific exception
     }
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NapClient" /> class.
 /// </summary>
 /// <param name="config">The initial configuration to utilize on creation.</param>
 /// <param name="setup">The setup to utilize during creation of any requests, or operation of the Nap library.</param>
 public NapClient(INapConfig config, NapSetup setup) : this(config.BaseUrl)
 {
     _setup  = setup;
     _config = Configure(config);
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NapClient" /> class.
 /// </summary>
 /// <param name="config">The initial configuration to utilize on creation.</param>
 public NapClient(INapConfig config) : this(config.BaseUrl)
 {
     _config = config;
 }
コード例 #6
0
ファイル: NapConfigurationPlugin.cs プロジェクト: forki/Nap
 /// <summary>
 /// Setup a <see cref="NapClient"/> for initial use using a *.config file.
 /// Overwrites the <paramref name="config"/>, so this should be first in plugin order.
 /// </summary>
 /// <param name="config">Disposed, ignored configuration.</param>
 /// <returns>A new configuration that has been loaded using the *.config file.</returns>
 public override INapConfig Configure(INapConfig config)
 {
     return(NapConfig.GetCurrent());
 }
コード例 #7
0
 /// <summary>
 /// Setup a <see cref="NapClient"/> for initial use with a configuration.
 /// </summary>
 /// <param name="configuration">The configuration to permute and setup.</param>
 /// <returns>A new or modified client for generation of requests.</returns>
 public virtual INapConfig Configure(INapConfig configuration) => configuration;