public static SMBConnection CreateSMBConnection(ISMBClientFactory smbClientFactory, IPAddress address, SMBTransportType transport, ISMBCredential credential, uint maxBufferSize) { var threadId = Thread.CurrentThread.ManagedThreadId; if (credential == null) { throw new ArgumentNullException(nameof(credential)); } lock (_connectionLock) { if (!instances.ContainsKey(threadId)) { instances.Add(threadId, new Dictionary <IPAddress, SMBConnection>()); } if (instances[threadId].ContainsKey(address)) { var instance = instances[threadId][address]; instance._referenceCount += 1; return(instance); } else { var instance = new SMBConnection(smbClientFactory, address, transport, credential, threadId, maxBufferSize); instance.Connect(); instances[threadId].Add(address, instance); return(instance); } } }
public static SMBConnection CreateSMBConnectionForStream(ISMBClientFactory smbClientFactory, IPAddress address, SMBTransportType transport, ISMBCredential credential, uint maxBufferSize) { if (credential == null) { throw new ArgumentNullException(nameof(credential)); } // Create new connection var instance = new SMBConnection(smbClientFactory, address, transport, credential, -1, maxBufferSize); instance.Connect(); return(instance); }