当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionConfiguration.SetConnectionStatusHandler方法代码示例

本文整理汇总了C#中ConnectionConfiguration.SetConnectionStatusHandler方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionConfiguration.SetConnectionStatusHandler方法的具体用法?C# ConnectionConfiguration.SetConnectionStatusHandler怎么用?C# ConnectionConfiguration.SetConnectionStatusHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConnectionConfiguration的用法示例。


在下文中一共展示了ConnectionConfiguration.SetConnectionStatusHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProfiledElasticsearchClient

        /// <summary>
        /// Provides base <see cref="ElasticsearchClient"/> with profiling features to current <see cref="MiniProfiler"/> session.
        /// </summary>
        /// <param name="configuration">Instance of <see cref="ConnectionConfiguration"/>. Its responses will be handled and pushed to <see cref="MiniProfiler"/></param>
		public ProfiledElasticsearchClient(ConnectionConfiguration configuration) 
			: base(configuration)
		{
			ProfilerUtils.ExcludeElasticsearchAssemblies();
			ProfilerUtils.ApplyConfigurationSettings(configuration);
			configuration.SetConnectionStatusHandler(response => MiniProfilerElasticsearch.HandleResponse(response, _profiler));
		}
开发者ID:bigerock,项目名称:MiniProfiler.Elasticsearch,代码行数:11,代码来源:ProfiledElasticsearchClient.cs

示例2: AvailableOptions

		/**
		 * The following is a list of available connection configuration options:
		 */

		public void AvailableOptions()
		{
			//hide
			var client = new ElasticsearchClient();
			//endhide

			var config = new ConnectionConfiguration()

				.DisableAutomaticProxyDetection()
				/** Disable automatic proxy detection.  Defaults to true. */

				.EnableHttpCompression()
				/**
				 * Enable compressed request and reesponses from Elasticsearch (Note that nodes need to be configured 
				 * to allow this.  See the [http module settings](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html) for more info).
				*/

				.DisableDirectStreaming()
				/**
				 * By default responses are deserialized off stream to the object you tell it to.
				 * For debugging purposes it can be very useful to keep a copy of the raw response on the result object. 
				 */;

			var result = client.Search<SearchResponse<object>>(new { size = 12 });
			var raw = result.ResponseBodyInBytes;
			/** This will only have a value if the client configuration has ExposeRawResponse set */

			/** 
			 * Please note that this only make sense if you need a mapped response and the raw response at the same time. 
			 * If you need a `string` or `byte[]` response simply call:
			 */
			var stringResult = client.Search<string>(new { });

			//hide
			config = config
				//endhide
				.SetConnectionStatusHandler(s => { })
				/** 
				* Allows you to pass a `Action&lt;IElasticsearchResponse&gt;` that can eaves drop every time a response (good or bad) is created. If you have complex logging needs 
				* this is a good place to add that in.
				*/

				.SetGlobalQueryStringParameters(new NameValueCollection())
				/**
				* Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request.
				*/

				.SetProxy(new Uri("http://myproxy"), "username", "pass")
				/** Sets proxy information on the connection. */

				.RequestTimeout(TimeSpan.FromSeconds(4))
				/**
				* Sets the global maximum time a connection may take.
				 * Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts 
				 * (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx).
				*/

				.ThrowExceptions()
				/**
				* As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to throw 
				* exceptions. 
				*
				* There are three category of exceptions thay may be thrown:
				*  
				* 1) ElasticsearchClientException: These are known exceptions, either an exception that occurred in the request pipeline
				* (such as max retries or timeout reached, bad authentication, etc...) or Elasticsearch itself returned an error (could 
				* not parse the request, bad query, missing field, etc...). If it is an Elasticsearch error, the `ServerError` property 
				* on the response will contain the the actual error that was returned.  The inner exception will always contain the 
				* root causing exception.
				*                                  
				* 2) UnexpectedElasticsearchClientException:  These are unknown exceptions, for instance a response from Elasticsearch not
				* properly deserialized.  These are usually bugs and should be reported.  This excpetion also inherits from ElasticsearchClientException
				* so an additional catch block isn't necessary, but can be helpful in distinguishing between the two.
				*
				* 3) Development time exceptions: These are CLR exceptions like ArgumentException, NullArgumentException etc... that are thrown
				* when an API in the client is misused.  These should not be handled as you want to know about them during development.
				*
				*/

				.PrettyJson()
				/**
				* Forces all serialization to be indedented and appends `pretty=true` to all the requests so that the responses are indented as well
				*/

				.SetBasicAuthentication("username", "password")
				/** Sets the HTTP basic authentication credentials to specify with all requests. */;

			/**
			* **Note:** This can alternatively be specified on the node URI directly:
			 */

			var uri = new Uri("http://username:[email protected]:9200");
			var settings = new ConnectionConfiguration(uri);

			/**
			*  ...but may become tedious when using connection pooling with multiple nodes.
//.........这里部分代码省略.........
开发者ID:ljchene,项目名称:elasticsearch-net,代码行数:101,代码来源:Connecting.doc.cs

示例3: AvailableOptions

		/**
		 * The following is a list of available connection configuration options:
		 */

		public void AvailableOptions()
		{
			//hide
			var client = new ElasticsearchClient();
			//endhide

			var config = new ConnectionConfiguration()

				.DisableAutomaticProxyDetection()
				/** Disable automatic proxy detection.  Defaults to true. */

				.EnableHttpCompression()
				/**
				 * Enable compressed request and reesponses from Elasticsearch (Note that nodes need to be configured 
				 * to allow this.  See the [http module settings](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html) for more info).
				*/

				.EnableMetrics()
				/** Enable more meta data to be returned per API call about requests (ping, sniff, failover, and general stats). */

				.EnableTrace()
				/**
				* Will cause `Elasticsearch.Net` to write connection debug information on the TRACE output of your application.
				*/

				.DisableDirectStreaming()
				/**
				 * By default responses are deserialized off stream to the object you tell it to.
				 * For debugging purposes it can be very useful to keep a copy of the raw response on the result object. 
				 */;

			var result = client.Search<SearchResponse<object>>(new { size = 12 });
			var raw = result.ResponseBodyInBytes;
			/** This will only have a value if the client configuration has ExposeRawResponse set */

			/** 
			 * Please note that this only make sense if you need a mapped response and the raw response at the same time. 
			 * If you need a `string` or `byte[]` response simply call:
			 */
			var stringResult = client.Search<string>(new { });

			//hide
			config = config
				//endhide
				.SetConnectionStatusHandler(s => { })
				/** 
				* Allows you to pass a `Action&lt;IElasticsearchResponse&gt;` that can eaves drop every time a response (good or bad) is created. If you have complex logging needs 
				* this is a good place to add that in.
				*/

				.SetGlobalQueryStringParameters(new NameValueCollection())
				/**
				* Allows you to set querystring parameters that have to be added to every request. For instance, if you use a hosted elasticserch provider, and you need need to pass an `apiKey` parameter onto every request.
				*/

				.SetProxy(new Uri("http://myproxy"), "username", "pass")
				/** Sets proxy information on the connection. */

				.RequestTimeout(TimeSpan.FromSeconds(4))
				/**
				* Sets the global maximum time a connection may take.
				 * Please note that this is the request timeout, the builtin .NET `WebRequest` has no way to set connection timeouts 
				 * (see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx).
				*/

				//TODO document this properly once we figure out exceptions
				.ThrowExceptions()
				/**
				* As an alternative to the C/go like error checking on `response.IsValid`, you can instead tell the client to always throw 
				 * an `ElasticsearchServerException` when a call resulted in an exception on the Elasticsearch server. Reasons for 
				 * such exceptions could be search parser errors and index missing exceptions.
				*/

				.PrettyJson()
				/**
				* Forces all serialization to be indedented and appends `pretty=true` to all the requests so that the responses are indented as well
				*/

				.SetBasicAuthentication("username", "password")
				/** Sets the HTTP basic authentication credentials to specify with all requests. */;

			/**
			* **Note:** This can alternatively be specified on the node URI directly:
			 */

			var uri = new Uri("http://username:[email protected]:9200");
			var settings = new ConnectionConfiguration(uri);

			/**
			*  ...but may become tedious when using connection pooling with multiple nodes.
			*/
		}
开发者ID:michaelbudnik,项目名称:elasticsearch-net,代码行数:96,代码来源:Connecting.doc.cs


注:本文中的ConnectionConfiguration.SetConnectionStatusHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。