本文整理汇总了C#中Future.SendRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Future.SendRequest方法的具体用法?C# Future.SendRequest怎么用?C# Future.SendRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future.SendRequest方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cancel
public void Cancel ()
{
Future future = new Future (Service.FreeStmt, GetId (), (int) CLI.FreeStmtOption.SQL_CLOSE);
try
{
connection.futures.Add (future);
future.SendRequest (connection.Session);
future.GetResult (connection.Session, connection.futures);
}
finally
{
connection.futures.Remove (future);
}
}
示例2: Open
public override void Open (ConnectionOptions options)
{
Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
bool useRoundRobin = options.RoundRobin;
int hostIndex = 0;
int startIndex = 0;
charset_utf8 = (options.Charset != null && options.Charset.ToUpper() == "UTF-8");
ArrayList ds_list = options.DataSourceList;
if (ds_list != null)
{
if (ds_list.Count <= 1)
useRoundRobin = false;
if (ds_list.Count > 1 && useRoundRobin)
startIndex = hostIndex = rnd.Next(ds_list.Count);
while(true)
{
try {
if (ds_list.Count == 0)
{
socket.Connect (GetEndPoint (null));
}
else
{
socket.Connect (GetEndPoint ((string)ds_list[hostIndex]));
}
break;
} catch (SocketException e) {
hostIndex++;
if (useRoundRobin)
{
if (ds_list.Count == hostIndex)
hostIndex = 0;
if (hostIndex == startIndex)
throw e;
}
else if (ds_list.Count == hostIndex) // Failover mode last rec
{
throw e;
}
}
}
}
try
{
session = new TcpSession (this, socket);
socket.NoDelay = true;
#if MONO
Future future = new Future (Service.CallerId, new object[] { null });
#else
Future future = new Future (Service.CallerId, (object) null); // not object[]
#endif
future.SendRequest (session, options.ConnectionTimeout);
object[] results = (object[]) future.GetResultSerial (session);
peer = (string) results[1];
object[] idOpts = null;
if (results.Length > 2)
idOpts = (object[]) results[2];
int pwdClearCode = GetConnectionOption (idOpts, "SQL_ENCRYPTION_ON_PASSWORD", -1);
Debug.WriteLineIf (Switch.Enabled, "pwdClearCode: " + pwdClearCode);
string user = options.UserId;
string password = null;
if (pwdClearCode == 1)
password = options.Password;
else if (pwdClearCode == 2)
password = MagicEncrypt (user, options.Password);
else
password = Digest (user, options.Password, peer);
object[] info = new object[6];
info[0] = ".NET Application";
info[1] = 0;
info[2] = Environment.MachineName;
info[3] = ".NET";
info[4] = options.Charset != null ? options.Charset.ToUpper () : "";
info[5] = 0;
future = new Future (Service.Connect, user, password, Values.VERSION, info);
future.SendRequest (session, options.ConnectionTimeout);
results = future.GetResultSerial (session) as object[];
if (results == null)
throw new SystemException ("Login failed.");
switch ((AnswerTag) results[0])
{
case AnswerTag.QA_LOGIN:
SetConnectionOptions (results);
break;
case AnswerTag.QA_ERROR:
throw new SystemException (results[1].ToString () + " " + results[2].ToString ());
default:
throw new SystemException ("Bad login response.");
}
//.........这里部分代码省略.........
示例3: SendRequest
private void SendRequest (Future future)
{
Debug.Assert (pendingFuture == null);
pendingFuture = future;
try
{
connection.futures.Add (future);
future.SendRequest (connection.Session, timeout);
}
catch
{
connection.futures.Remove (future);
pendingFuture = null;
throw;
}
}
示例4: Dispose
private void Dispose (bool disposing)
{
// TODO: Review command disposing
/*
if (disposing)
{
CloseCursor ();
}
*/
Future future = new Future (Service.FreeStmt, GetId (), (int) CLI.FreeStmtOption.SQL_DROP);
try
{
connection.futures.Add (future);
future.SendRequest (connection.Session);
future.GetResult (connection.Session, connection.futures);
}
finally
{
connection.futures.Remove (future);
}
}
示例5: GetData
private long GetData (ColumnData column, BlobHandle blob, int length, object buffer, int bufferOffset)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "ManagedCommand.GetData()");
Future future = new Future (Service.GetData,
blob.current_page,
length,
blob.current_position,
blob.keyId,
blob.fragNo,
blob.dirPage,
blob.pages,
blob.tag == BoxTag.DV_BLOB_WIDE_HANDLE ? 1 : 0,
blob.timeStamp);
object result = null;
try
{
connection.futures.Add (future);
future.SendRequest (connection.Session, timeout);
result = future.GetResult (connection.Session, connection.futures);
}
finally
{
connection.futures.Remove (future);
}
if (!(result is object[]))
return 0;
object[] results = (object[]) result;
if (results[0] is int && (AnswerTag) results[0] == AnswerTag.QA_ERROR)
{
errors.AddServerError ((string) results[1], null, (string) results[2]);
Diagnostics.HandleResult (CLI.ReturnCode.SQL_ERROR, this, connection.OuterConnection);
}
int startOffset = column.lobOffset;
for (int i = 0; i < results.Length; i++)
{
if (results[i] is int[])
{
int[] array = (int[]) results[i];
blob.current_page = array[1];
blob.current_position = array[2];
continue;
}
else if (results[i] is string)
{
string s = (string) results[i];
if (buffer is char[])
{
char[] chars = s.ToCharArray ();
char[] charBuffer = (char[]) buffer;
Debug.WriteLineIf (Switch.Enabled, "do chars");
Debug.WriteLineIf (Switch.Enabled, "buffer length: " +
(charBuffer == null ? "no" : charBuffer.Length.ToString ()));
Debug.WriteLineIf (Switch.Enabled, "buffer offset: " + bufferOffset);
Debug.WriteLineIf (Switch.Enabled, "data length: " + chars.Length);
Debug.WriteLineIf (Switch.Enabled, "length: " + length);
if (charBuffer != null)
{
int copyLength = length < chars.Length ? length : chars.Length;
Array.Copy (chars, 0, charBuffer, bufferOffset, copyLength);
}
column.lobOffset += chars.Length;
bufferOffset += chars.Length;
length -= chars.Length;
}
else
{
byte[] bytes = Encoding.GetEncoding ("iso-8859-1").GetBytes (s);
byte[] byteBuffer = (byte[]) buffer;
Debug.WriteLineIf (Switch.Enabled, "do bytes");
Debug.WriteLineIf (Switch.Enabled, "buffer length: " +
(byteBuffer == null ? "no" : byteBuffer.Length.ToString ()));
Debug.WriteLineIf (Switch.Enabled, "buffer offset: " + bufferOffset);
Debug.WriteLineIf (Switch.Enabled, "data length: " + bytes.Length);
Debug.WriteLineIf (Switch.Enabled, "length: " + length);
if (byteBuffer != null)
{
int copyLength = length < bytes.Length ? length : bytes.Length;
Array.Copy (bytes, 0, byteBuffer, bufferOffset, copyLength);
}
column.lobOffset += bytes.Length;
bufferOffset += bytes.Length;
length -= bytes.Length;
}
}
}
return column.lobOffset - startOffset;
}
示例6: Fetch
public bool Fetch ()
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "ManagedCommand.Fetch ()");
for (;;)
{
Debug.WriteLineIf (Switch.Enabled, "isLastRow: " + isLastRow);
if (isLastRow)
{
currentRow = null;
return false;
}
if (prefetchRow != null)
{
prefetchedRows++;
currentRow = prefetchRow;
prefetchRow = null;
return true;
}
Debug.WriteLineIf (Switch.Enabled, "prefetchedRows: " + prefetchedRows + " / " + prefetchSize);
Debug.WriteLineIf (Switch.Enabled, "isLastInBatch: " + isLastInBatch);
if ((prefetchedRows == prefetchSize || isLastInBatch)
&& queryType == QueryType.QT_SELECT)
{
Future future = new Future (Service.Fetch, id, pendingFuture.RequestNo);
future.SendRequest (connection.Session, timeout);
prefetchedRows = 0;
}
CLI.ReturnCode rc = ProcessResult (true);
if (rc != CLI.ReturnCode.SQL_SUCCESS)
{
if (rc == CLI.ReturnCode.SQL_NO_DATA)
return false;
Diagnostics.HandleResult (rc, this, connection.OuterConnection);
}
}
}
示例7: Enlist
public override void Enlist (object distributedTransaction)
{
ITransaction transaction = (ITransaction) distributedTransaction;
if (transaction == null)
{
Future future = new Future (Service.TransactionEnlist, (int) DtpFlags.SQL_TP_UNENLIST, null);
object result = null;
try
{
futures.Add (future);
future.SendRequest (Session);
result = future.GetNextResult (Session, futures);
}
finally
{
futures.Remove (future);
}
if (result != null && result is object[])
{
object[] results = (object[]) result;
errors.AddServerError ((string) results[1], null, (string) results[2]);
Diagnostics.HandleErrors (CLI.ReturnCode.SQL_ERROR, this);
}
}
else
{
byte[] whereabouts = GetServerDtcWhereabouts ();
DTC.ITransactionExport export = DTC.GetTransactionExport (transaction, whereabouts);
byte[] cookie = DTC.GetTransactionCookie (transaction, export);
string cookie_encoded = Encode (cookie);
ManagedCommand cmd = new ManagedCommand (this);
cmd.SetParameters (null);
try
{
cmd.Execute ("select mts_enlist_transaction('" + cookie_encoded + "')");
if (cmd.Fetch ())
{
autocommit = false;
}
}
finally
{
cmd.CloseCursor (true);
cmd.Dispose ();
}
}
}
示例8: EndTransaction
public override void EndTransaction (bool commit)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
"ManagedConnection.EndTransaction ({0})", commit));
CLI.CompletionType completion = commit ?
CLI.CompletionType.SQL_COMMIT :
CLI.CompletionType.SQL_ROLLBACK;
Future future = new Future (
Service.Transaction, (int) completion, null);
object result = null;
try
{
futures.Add (future);
future.SendRequest (Session);
result = future.GetNextResult (Session, futures);
Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
"ManagedConnection.EndTransaction ({0}) success", commit));
}
finally
{
futures.Remove (future);
}
if (result is object[])
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
"ManagedConnection.EndTransaction ({0}) error", commit));
object[] results = (object[]) result;
errors.AddServerError ((string) results[1], null, (string) results[2]);
Diagnostics.HandleErrors (CLI.ReturnCode.SQL_ERROR, this);
}
autocommit = true;
isolation = CLI.IsolationLevel.SQL_TXN_READ_COMMITED;
Debug.WriteLineIf (CLI.FnTrace.Enabled, String.Format (
"ManagedConnection.EndTransaction ({0}) done", commit));
}
示例9: GetResult
internal object GetResult (ISession session, FutureList futures, bool remove)
{
Debug.WriteLineIf (CLI.FnTrace.Enabled, "Future.GetResult ()");
bool locked = false;
bool check_timeout = false;
try
{
for (;;)
{
if (!locked)
{
Monitor.Enter (this);
locked = true;
}
if (results != null && results.Count > 0)
{
object result = results[0];
if (remove)
results.RemoveAt (0);
return result;
}
if (error != null)
{
if (error is bool && (bool) error)
throw new SystemException ("Timeout expired.");
throw new SystemException (error.ToString ());
}
if (isComplete)
return null;
if (endOfTime != 0)
{
if (check_timeout)
{
long now = DateTime.Now.Ticks;
if (endOfTime > now)
{
timeout = (int) ((endOfTime - now) / Values.TicksPerSec);
}
else
{
Debug.WriteLineIf (Switch.Enabled, "future timed out: " + requestNo);
error = true;
Future cancel = new Future (Service.Cancel);
cancel.SendRequest (session);
throw new SystemException ("Timeout expired.");
}
}
else
{
check_timeout = true;
}
}
if (futures.ReadLock ())
{
try
{
bool read = session.PollRead (timeout);
if (read)
{
object[] answer = ReadAnswer (session, false);
if (answer != null)
{
int id = (int) answer[RpcMessageLayout.RRC_COND_NUMBER];
Debug.WriteLineIf (Switch.Enabled, "RRC_COND_NUMBER: " + id);
Future future = (Future) futures[id];
if (future != null)
future.HandleAnswer (answer);
}
}
}
finally
{
futures.ReadUnlock ();
}
}
else
{
// Unlock so that HandleAnswer for this future
// can be called from another thread.
Monitor.Exit (this);
locked = false;
futures.ReadWait (timeout);
}
}
}
finally
{
if (locked)
{
Monitor.Exit (this);
}
}
}