如果我手动单击按钮,我有 Windows 文件导入方法和应用程序工作正常,但如果我使用 QTP(快速测试专业)等工具运行我的应用程序,相同的代码将失败
我用粗体突出了失败的行。 [ remoteStream.Write(buffer, 0, bytesRead);]
using (FileStream localStream = File.OpenRead(filePath))
{
RemoteFile remoteFile = this.serverComponent.GetUploadFileHandle(filePath);
if (remoteFile == null)
{
stopWatch.Stop();
}
using (RemoteFileStream remoteStream = new RemoteFileStream(remoteFile))
{
long localFileSize = localStream.Length;
long readSoFar = 0;
int bytesRead = 0;
byte[] buffer = new byte[bufferSize];
while ((bytesRead = localStream.Read(buffer, 0, bufferSize)) > 0)
{
remoteStream.Write(buffer, 0, bytesRead);
readSoFar += bytesRead;
progressListener.UpdateFileProgress(firmwareID, readSoFar, localFileSize);
}
}
uploadSuccess = this.server.UploadFileDone(remoteFile);
}
stopWatch.Stop();
progressListener.UpdateFileStatus(firmwareID, uploadSuccess ? FirmwareImportStatus.ImportSuccessful : FirmwareImportStatus.ImportFailed);
}
触发导入的 QTP 代码。 SwfWindow("Swfname:=ImportFWImagesWF").SwfButton("Swfname:=btnNext","text:=Import").Click
我正在覆盖Stream c# 类。我最终遇到了套接字异常 “System.Net.Sockets.SocketException:现有连接被远程主机强行关闭”
我正在覆盖 Stream c# 类。我的班级名称是RemoteFileStream
服务器代码
public override void Write(byte[] buffer, int offset, int count)
{
#region Check Args
if (buffer == null)
{
throw (new ArgumentNullException("The buffer is null"));
}
if (offset < 0 || count < 0)
{
throw (new ArgumentOutOfRangeException("The offset or count is negative."));
}
if (offset + count > buffer.Length)
{
throw (new ArgumentException("The sum of offset and count is larger than the buffer length."));
}
#endregion
_rf.Write(buffer, offset, count);//Exception comes from here
}
注意:只有当我从 QTP 工具访问我的应用程序时才会出现异常。如果我手动运行我的应用程序,则没有问题。是因为权限问题吗?请帮我。