本文整理汇总了C#中Npgsql.NpgsqlConnector.CancelRequest方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnector.CancelRequest方法的具体用法?C# NpgsqlConnector.CancelRequest怎么用?C# NpgsqlConnector.CancelRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlConnector
的用法示例。
在下文中一共展示了NpgsqlConnector.CancelRequest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Process commandTimeout behavior.
if ((context.Mediator.CommandTimeout > 0) &&
(!context.Socket.Poll(1000000*context.Mediator.CommandTimeout, SelectMode.SelectRead)))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState || context.CancelRequestCalled)))
{
try
{
context.CancelRequest();
foreach (IServerResponseObject obj in ProcessBackendResponsesEnum(context))
{
if (obj is IDisposable)
{
(obj as IDisposable).Dispose();
}
}
}
catch(Exception ex)
{
}
//We should have gotten an error from CancelRequest(). Whether we did or not, what we
//really have is a timeout exception, and that will be less confusing to the user than
//"operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
switch (context.BackendProtocolVersion)
{
case ProtocolVersion.Version2:
return ProcessBackendResponses_Ver_2(context);
case ProtocolVersion.Version3:
return ProcessBackendResponses_Ver_3(context);
default:
throw new NpgsqlException(resman.GetString("Exception_UnknownProtocol"));
}
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}
示例2: ProcessExistingBackendResponses
internal IEnumerable<IServerResponseObject> ProcessExistingBackendResponses(NpgsqlConnector context)
{
try
{
return ProcessBackendResponses_Ver_3(context);
}
catch (ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch { }
throw;
}
}
示例3: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Flush buffers to the wire.
context.Stream.Flush();
// Process commandTimeout behavior.
if ((context.Mediator.BackendCommandTimeout > 0) &&
(!CheckForContextSocketAvailability(context, SelectMode.SelectRead)))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as
// CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState)))
{
try
{
context.CancelRequest();
ProcessAndDiscardBackendResponses(context);
}
catch(Exception)
{
}
// We should have gotten an error from CancelRequest(). Whether we did or not, what we
// really have is a timeout exception, and that will be less confusing to the user than
// "operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command
// as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
return ProcessBackendResponses(context);
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}
示例4: ProcessBackendResponses
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal virtual void ProcessBackendResponses( NpgsqlConnector context )
{
try
{
// Process commandTimeout behavior.
if ((context.Mediator.CommandTimeout > 0) && (!context.Socket.Poll(1000000 * context.Mediator.CommandTimeout, SelectMode.SelectRead)))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as CancelRequest will also try to stablish a connection and sends commands.
if ((this is NpgsqlStartupState || this is NpgsqlConnectedState))
throw new NpgsqlException(resman.GetString("Exception_ConnectionTimeout"));
else
context.CancelRequest();
}
switch (context.BackendProtocolVersion)
{
case ProtocolVersion.Version2 :
ProcessBackendResponses_Ver_2(context);
break;
case ProtocolVersion.Version3 :
ProcessBackendResponses_Ver_3(context);
break;
}
}
finally
{
// reset expectations right after getting new responses
context.Mediator.ResetExpectations();
}
}
示例5: ProcessBackendResponsesEnum
///<summary>
/// This method is responsible to handle all protocol messages sent from the backend.
/// It holds all the logic to do it.
/// To exchange data, it uses a Mediator object from which it reads/writes information
/// to handle backend requests.
/// </summary>
///
internal IEnumerable<IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context)
{
try
{
// Flush buffers to the wire.
context.Stream.Flush();
// Process commandTimeout behavior.
// We will give an extra 5 seconds to context.Mediator.CommandTimeout
// because we'd prefer to receive a timeout error from PG
// than to be forced to start a new connection and send a cancel request.
// The result is that a timeout could take 5 seconds too long to occur, but if everything
// is healthy, that shouldn't happen.
if ((context.Mediator.BackendCommandTimeout > 0) && (!context.Stream.WaitAvailable(TimeSpan.FromSeconds(context.Mediator.BackendCommandTimeout + 5))))
{
// If timeout occurs when establishing the session with server then
// throw an exception instead of trying to cancel query. This helps to prevent loop as
// CancelRequest will also try to stablish a connection and sends commands.
if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState)))
{
try
{
context.CancelRequest();
ProcessAndDiscardBackendResponses(context);
}
catch(Exception)
{
}
// We should have gotten an error from CancelRequest(). Whether we did or not, what we
// really have is a timeout exception, and that will be less confusing to the user than
// "operation cancelled by user" or similar, so whatever the case, that is what we'll throw.
// Changed message again to report about the two possible timeouts: connection or command
// as the establishment timeout only was confusing users when the timeout was a command timeout.
}
throw new NpgsqlException(resman.GetString("Exception_ConnectionOrCommandTimeout"));
}
switch (context.BackendProtocolVersion)
{
case ProtocolVersion.Version2:
return ProcessBackendResponses_Ver_2(context);
case ProtocolVersion.Version3:
return ProcessBackendResponses_Ver_3(context);
default:
throw new NpgsqlException(resman.GetString("Exception_UnknownProtocol"));
}
}
catch(ThreadAbortException)
{
try
{
context.CancelRequest();
context.Close();
}
catch {}
throw;
}
}