本文整理汇总了C#中IOperation.Request方法的典型用法代码示例。如果您正苦于以下问题:C# IOperation.Request方法的具体用法?C# IOperation.Request怎么用?C# IOperation.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOperation
的用法示例。
在下文中一共展示了IOperation.Request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteOperationInternal
private ODocument ExecuteOperationInternal(IOperation operation)
{
try
{
if (_networkStream == null)
Reconnect();
var req = new Request(this);
req.SetSessionId(SessionId);
Request request = operation.Request(req);
byte[] buffer;
foreach (RequestDataItem item in request.DataItems)
{
switch (item.Type)
{
case "byte":
case "short":
case "int":
case "long":
Send(item.Data);
break;
case "record":
buffer = new byte[2 + item.Data.Length];
Buffer.BlockCopy(BinarySerializer.ToArray(item.Data.Length), 0, buffer, 0, 2);
Buffer.BlockCopy(item.Data, 0, buffer, 2, item.Data.Length);
Send(buffer);
break;
case "bytes":
case "string":
case "strings":
Send(BinarySerializer.ToArray(item.Data.Length));
Send(item.Data);
break;
default:
break;
}
}
_networkStream.Flush();
if (request.OperationMode != OperationMode.Synchronous)
return null;
Response response = new Response(this);
response.Receive();
return ((IOperation)operation).Response(response);
}
catch (IOException)
{
Destroy();
throw;
}
}
示例2: ExecuteOperation
internal ODocument ExecuteOperation(IOperation operation)
{
Request request = operation.Request(SessionId);
byte[] buffer;
foreach (RequestDataItem item in request.DataItems)
{
switch (item.Type)
{
case "byte":
case "short":
case "int":
case "long":
Send(item.Data);
break;
case "record":
buffer = new byte[2 + item.Data.Length];
Buffer.BlockCopy(BinarySerializer.ToArray(item.Data.Length), 0, buffer, 0, 2);
Buffer.BlockCopy(item.Data, 0, buffer, 2, item.Data.Length);
Send(buffer);
break;
case "bytes":
case "string":
case "strings":
//buffer = new byte[4 + item.Data.Length];
//Buffer.BlockCopy(BinarySerializer.ToArray(item.Data.Length), 0, buffer, 0, 4);
//Buffer.BlockCopy(item.Data, 0, buffer, 4, item.Data.Length);
//Send(buffer);
Send(BinarySerializer.ToArray(item.Data.Length));
Send(item.Data);
break;
default:
break;
}
}
_networkStream.Flush();
if (request.OperationMode == OperationMode.Synchronous)
{
try
{
Response response = new Response(this);
response.Receive();
return ((IOperation)operation).Response(response);
}
catch (Exception )
{
//reset connection as the socket may contains unread data and is considered unstable
Reconnect();
throw;
}
}
else
{
return null;
}
}