本文整理汇总了C#中ICommand.OnCommandDataReceived方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.OnCommandDataReceived方法的具体用法?C# ICommand.OnCommandDataReceived怎么用?C# ICommand.OnCommandDataReceived使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommand
的用法示例。
在下文中一共展示了ICommand.OnCommandDataReceived方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
/// <summary>
/// Executes the specified command on this connection
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public CommandResult ExecuteCommand(ICommand cmd)
{
if (!IsConnected) return null;
ArrayList resultArray = new ArrayList();
PrepareCommand(cmd);
IMAPResponse response = IMAPResponse.IMAP_SUCCESS_RESPONSE;
byte[] data = GetStringBytes(cmd.CommandString);
Stopwatch sw = new Stopwatch();
try
{
WriteToStream(data, 0, data.Length);
long bytesReceived = 0;
long totalBytes = 0;
while (true)
{
string result = ReadLine();
if (result == null) break;
sw.Start();
resultArray.Add(result);
if (result.StartsWith(cmd.ResponseOK))
{
//Log(LogType.IMAP, result);
response = IMAPResponse.IMAP_SUCCESS_RESPONSE;
break;
}
if (result.StartsWith(cmd.ResponseNO) || result.StartsWith(cmd.ResponseBAD))
{
//Log(LogType.IMAP, result);
response = IMAPResponse.IMAP_FAILURE_RESPONSE;
break;
}
if (resultArray.Count == 1)
totalBytes = DetermineTotalSize(result);
else
{
//if (cmd is MessagePartCommand)
// bytesReceived += GetStringBytes(result, GetCurrentEncoding()).LongLength;
//else
bytesReceived += GetStringBytes(result).LongLength;
}
if (bytesReceived > totalBytes)
totalBytes = bytesReceived;
cmd.OnCommandDataReceived(bytesReceived, totalBytes);
if (cmd.GetType() != typeof(MessagePartCommand))
Log(LogType.IMAP, result);
}
sw.Stop();
//if (cmd is MessagePartCommand)
// System.Diagnostics.Debugger.Break();
}
catch (Exception e)
{
_logger.Log(LogType.IMAP, e.Message);
}
//Log(LogType.IMAP, "");
return new CommandResult(resultArray, response, sw.Elapsed);
}