本文整理汇总了C#中Smb2FunctionalClient.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Smb2FunctionalClient.Read方法的具体用法?C# Smb2FunctionalClient.Read怎么用?C# Smb2FunctionalClient.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smb2FunctionalClient
的用法示例。
在下文中一共展示了Smb2FunctionalClient.Read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateByteLockRangeFromAnotherClient
/// <summary>
/// Read and write file within byte lock range when the file is locked or unlocked
/// </summary>
/// <param name="isLocked">Set true to indicate that byte lock range is taken on the file</param>
/// <param name="serverName">Name of file server to access</param>
/// <param name="targetFileName">Target file name to read and write</param>
private void ValidateByteLockRangeFromAnotherClient(bool isLocked, string serverName, string targetFileName)
{
uint status = 0;
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, serverName, currentAccessIp);
status = client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
serverName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId;
status = client.Create(
treeId,
targetFileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts);
string data;
Random random = new Random();
uint offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
uint length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));
status = client.Read(treeId, fileId, offset, length, out data);
status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
if (isLocked)
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content to locked range of file from different client is not expected to success");
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_FILE_LOCK_CONFLICT,
status,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
}
else
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content in file should succeed, actual status is {0}", Smb2Status.GetStatusCode(status));
}
}
示例2: ReadContentAfterFailover
/// <summary>
/// Read content after failover
/// </summary>
/// <param name="server">File server name.</param>
/// <param name="serverAccessIp">File server access IP.</param>
/// <param name="uncSharePath">The share path to read the file.</param>
/// <param name="file">The file name for reading content.</param>
/// <param name="content">The content to read.</param>
/// <param name="clientGuid">Smb2 client Guid.</param>
/// <param name="createGuid">The Guid for smb2 create request.</param>
/// <returns></returns>
protected bool ReadContentAfterFailover(string server,
IPAddress serverAccessIp,
string uncSharePath,
string file,
string content,
Guid clientGuid,
Guid createGuid)
{
uint status;
BaseTestSite.Assert.AreNotEqual(
null,
serverAccessIp,
"Access IP to the file server should not be empty");
BaseTestSite.Log.Add(
LogEntryKind.Debug,
"Got IP {0} to access the file server", serverAccessIp.ToString());
Smb2FunctionalClient afterFailover = new Smb2FunctionalClient(TestConfig.FailoverTimeout, TestConfig, BaseTestSite);
DoUntilSucceed(() => afterFailover.ConnectToServer(TestConfig.UnderlyingTransport, server, serverAccessIp), TestConfig.FailoverTimeout,
"Retry to connect to server until succeed within timeout span");
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends NEGOTIATE request with the same clientguid of previous client.");
status = afterFailover.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
clientGuid: clientGuid);
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "Negotiate failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends SESSION_SETUP request with the same SESSION_ID of previous client.");
status = afterFailover.ReconnectSessionSetup(
beforeFailover,
TestConfig.DefaultSecurityPackage,
server,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "ReconnectSessionSetup failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
// Retry TreeConnect because network path may not be available immediately
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client retries TREE_CONNECT to {0} until succeed or timeout in {1} because network path may not be available immediately.", uncSharePath, TestConfig.FailoverTimeout);
uint treeId = 0;
status = afterFailover.TreeConnect(uncSharePath, out treeId, (header, response) => { });
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "TreeConnect failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
// Retry Create because file may not be available immediately
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client retries to send CREATE request with SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 context with PERSISTENT flag set until succeed or timeout in {0}.", TestConfig.FailoverTimeout);
FILEID fileId = new FILEID();
Smb2CreateContextResponse[] serverCreateContexts;
status = DoUntilSucceed(
() => afterFailover.Create(
treeId,
file,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
new Smb2CreateContextRequest[] {
new Smb2CreateDurableHandleReconnectV2
{
FileId = new FILEID { Persistent = fileId.Persistent },
CreateGuid = createGuid,
Flags = CREATE_DURABLE_HANDLE_RECONNECT_V2_Flags.DHANDLE_FLAG_PERSISTENT
},
},
checker: (header, response) => { }),
TestConfig.FailoverTimeout,
"Retry Create until succeed within timeout span");
if (status != Smb2Status.STATUS_SUCCESS)
{
BaseTestSite.Log.Add(LogEntryKind.Warning, "Create failed with {0}.", Smb2Status.GetStatusCode(status));
return false;
}
string readContent;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends READ request to read content.");
status = afterFailover.Read(treeId, fileId, 0, (uint)content.Length, out readContent);
//.........这里部分代码省略.........
示例3: BVT_SMB2Basic_LockAndUnLock
//.........这里部分代码省略.........
BaseTestSite.Log.Add(
LogEntryKind.Comment,
"From client2 to read and take shared lock on the locking range of the same file after lock");
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Start client2 to create a file with sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT; CREATE.");
client2 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client2.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
status = client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
status = client2.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId2;
status = client2.TreeConnect(uncSharePath, out treeId2);
FILEID fileId2;
status = client2.Create(
treeId2,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId2,
out serverCreateContexts);
string data;
Random random = new Random();
uint offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
uint length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client2 sends READ request to read a random area in the locking range of file \"{0}\" with offset: {1}, length: {2}",
fileName, offset, length);
status = client2.Read(treeId2, fileId2, offset, length, out data);
//Construct LOCK_ELEMENT
LOCK_ELEMENT[] locksFromOtherOpen = new LOCK_ELEMENT[1];
locksFromOtherOpen[0].Offset = offset;
locksFromOtherOpen[0].Length = (ulong)length;
locksFromOtherOpen[0].Flags = LOCK_ELEMENT_Flags_Values.LOCKFLAG_SHARED_LOCK;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client2 attempts to take a shared lock on random range of file \"{0}\" with parameters offset:{1}, length:{2}, flags: {3})",
fileName, locksFromOtherOpen[0].Offset, locksFromOtherOpen[0].Length, locksFromOtherOpen[0].Flags.ToString());
status = client2.Lock(treeId2, lockSequence++, fileId2, locksFromOtherOpen);
locksFromOtherOpen[0].Flags = LOCK_ELEMENT_Flags_Values.LOCKFLAG_UNLOCK;
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client2 attempts to unlock the range");
status = client2.Lock(treeId2, lockSequence++, fileId2, locksFromOtherOpen);
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client2 sends WRITE request to write a random area in the locking range of file \"{0}\" after lock", fileName);
status = client2.Write(
treeId2,
fileId2,
content,
offset,
checker: (header, response) =>
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
示例4: BVT_MultiCredit_OneRequestWithMultiCredit
public void BVT_MultiCredit_OneRequestWithMultiCredit()
{
TestConfig.CheckDialect(DialectRevision.Smb21);
TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_LARGE_MTU);
Guid clientGuid = Guid.NewGuid();
string fileName = "MultiCredit_" + clientGuid.ToString() + ".txt";
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT");
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServerOverTCP(TestConfig.SutIPAddress);
Capabilities_Values clientCapabilities = Capabilities_Values.GLOBAL_CAP_LARGE_MTU;
client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: clientCapabilities);
client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId;
client.TreeConnect(uncSharePath, out treeId);
int bufferSize = (int)client.MaxBufferSize;
FILEID fileId;
Smb2CreateContextResponse[] serverCreateContexts;
ushort grantedCredit = 0;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with {0} credits", client.Credits);
client.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts,
checker: (header, response) =>
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"{0} should succeed, actually server returns {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
BaseTestSite.Log.Add(LogEntryKind.Debug,
"The MaxBufferSize of the server is {0}.",
client.MaxBufferSize);
BaseTestSite.Log.Add(LogEntryKind.Debug,
"Server has granted {0} credits to the client.",
client.Credits);
// Make sure client hold enough credits for test
ushort maxBufferSizeInCredit = (ushort)((client.MaxBufferSize -1)/ 65536 + 1);
if (client.Credits < maxBufferSizeInCredit)
{
if (client.Credits < 2)
{
BaseTestSite.Assert.Inconclusive(
"This test case is not applicable when the server only grants {0} credits",
client.Credits);
}
// Test max buffer according to granted credits.
bufferSize = (client.Credits - 1) * 65536;
}
grantedCredit = header.CreditRequestResponse;
});
contentWrite = Smb2Utility.CreateRandomStringInByte(bufferSize);
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client attempts to write {0} bytes content to file when server grants {1} credits",
client.MaxBufferSize, client.Credits);
client.Write(
treeId,
fileId,
contentWrite,
checker: (header, response) =>
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
header.Status,
"{0} should succeed, actually server returns {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
grantedCredit = header.CreditRequestResponse;
});
BaseTestSite.Log.Add(
LogEntryKind.TestStep,
"Client attempts to read {0} bytes content from file when server grants {1} credit",
bufferSize, client.Credits);
client.Read(treeId, fileId, 0, (uint)contentWrite.Length, out contentRead);
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF; 4. DISCONNECT");
client.Close(treeId, fileId);
client.TreeDisconnect(treeId);
client.LogOff();
client.Disconnect();
}
示例5: TestAsymmetricShare
private void TestAsymmetricShare(DialectRevision requestMaxDialect, string serverName, bool isAsymmetricShare)
{
int ret = 0;
uint callId = 0;
Guid clientGuid = Guid.NewGuid();
WITNESS_INTERFACE_INFO registerInterface;
string shareName = isAsymmetricShare ? TestConfig.AsymmetricShare : TestConfig.BasicFileShare;
#region Get the file server to access it through SMB2
IPAddress currentAccessIp = SWNTestUtility.GetCurrentAccessIP(serverName);
BaseTestSite.Assert.IsNotNull(currentAccessIp, "IP address of the file server should NOT be empty");
BaseTestSite.Log.Add(LogEntryKind.Debug, "Got the IP {0} to access the file server", currentAccessIp.ToString());
#endregion
#region Connect to the asymmetric share
uncSharePath = Smb2Utility.GetUncPath(serverName, shareName);
string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb);
testDirectory = CreateTestDirectory(uncSharePath);
string file = Path.Combine(testDirectory, Guid.NewGuid().ToString());
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP");
smb2Client = new Smb2FunctionalClient(TestConfig.FailoverTimeout, TestConfig, BaseTestSite);
smb2Client.ConnectToServerOverTCP(currentAccessIp);
smb2Client.Negotiate(
Smb2Utility.GetDialects(requestMaxDialect),
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
clientGuid: clientGuid,
checker: (Packet_Header header, NEGOTIATE_Response response) =>
{
BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "Negotiate should succeed.");
BaseTestSite.Assert.AreEqual(
requestMaxDialect,
response.DialectRevision,
"The server is expected to use dialect {0}. Actual dialect is {1}",
requestMaxDialect,
response.DialectRevision);
});
smb2Client.SessionSetup(
TestConfig.DefaultSecurityPackage,
serverName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId = 0;
Share_Capabilities_Values shareCapabilities = Share_Capabilities_Values.NONE;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends TREE_CONNECT request to the {0} on the {1}", shareName, serverName);
DoUntilSucceed(
() => smb2Client.TreeConnect(uncSharePath, out treeId, (header, response) => { shareCapabilities = response.Capabilities; }),
TestConfig.FailoverTimeout,
"Retry TreeConnect until succeed within timeout span");
if (requestMaxDialect == DialectRevision.Smb302 && isAsymmetricShare)
{
BaseTestSite.Assert.IsTrue(shareCapabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_ASYMMETRIC),
"The capabilities of the share should contain SHARE_CAP_ASYMMETRIC. The actual capabilities is {0}.", shareCapabilities);
}
else
{
BaseTestSite.Assert.IsFalse(shareCapabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_ASYMMETRIC),
"The capabilities of the share should not contain SHARE_CAP_ASYMMETRIC. The actual capabilities is {0}.", shareCapabilities);
#region Disconnect current SMB2 connection
smb2Client.TreeDisconnect(treeId);
smb2Client.LogOff();
smb2Client.Disconnect();
#endregion
return;
}
FILEID fileId;
Smb2CreateContextResponse[] serverCreateContexts;
Guid createGuid = Guid.NewGuid();
Guid leaseKey = Guid.NewGuid();
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client writes to the file.");
smb2Client.Create(
treeId,
file,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
out fileId,
out serverCreateContexts,
RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE);
smb2Client.Write(treeId, fileId, content);
string readContent;
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client reads from the file.");
smb2Client.Read(treeId, fileId, 0, (uint)content.Length, out readContent);
BaseTestSite.Assert.IsTrue(
content.Equals(readContent),
"Content read should be identical to that written.");
#endregion
#region Get register interface
DoUntilSucceed(() => SWNTestUtility.BindServer(swnClientForInterface, currentAccessIp,
TestConfig.DomainName, TestConfig.UserName, TestConfig.UserPassword, TestConfig.DefaultSecurityPackage,
TestConfig.DefaultRpceAuthenticationLevel, TestConfig.Timeout, serverName), TestConfig.FailoverTimeout,
"Retry BindServer until succeed within timeout span");
WITNESS_INTERFACE_LIST interfaceList = new WITNESS_INTERFACE_LIST();
BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client calls WitnessrGetInterfaceList.");
//.........这里部分代码省略.........
示例6: ValidateByteLockRangeFromAnotherClient
/// <summary>
/// Read and write the file within the locking byte range when lock or unlock is taken
/// </summary>
/// <param name="isLocked">Set true to indicate that access the file when lock operation is taken</param>
private void ValidateByteLockRangeFromAnotherClient(bool isLocked)
{
Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
status = client.Negotiate(
TestConfig.RequestDialects,
TestConfig.IsSMB1NegotiateEnabled,
capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES);
status = client.SessionSetup(
TestConfig.DefaultSecurityPackage,
TestConfig.SutComputerName,
TestConfig.AccountCredential,
TestConfig.UseServerGssToken);
uint treeId;
status = client.TreeConnect(uncSharePath, out treeId);
Smb2CreateContextResponse[] serverCreateContexts;
FILEID fileId;
status = client.Create(
treeId,
fileName,
CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
out fileId,
out serverCreateContexts);
string data;
Random random = new Random();
uint offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
uint length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));
status = client.Read(treeId, fileId, offset, length, out data);
status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
if (isLocked)
{
BaseTestSite.Assert.AreNotEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content to locked range of file from different client is not expected to success");
BaseTestSite.CaptureRequirementIfAreEqual(
Smb2Status.STATUS_FILE_LOCK_CONFLICT,
status,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
}
else
{
BaseTestSite.Assert.AreEqual(
Smb2Status.STATUS_SUCCESS,
status,
"Write content in file failed with error code=" + Smb2Status.GetStatusCode(status));
}
}