Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 public SMBDirectory(ISMBClientFactory smbclientFactory, ISMBCredentialProvider credentialProvider,
                     IFileSystem fileSystem, uint maxBufferSize) : base(new FileSystem())
 {
     _smbClientFactory   = smbclientFactory;
     _credentialProvider = credentialProvider;
     _fileSystem         = fileSystem;
     _maxBufferSize      = maxBufferSize;
     transport           = SMBTransportType.DirectTCPTransport;
 }
 public SMBDirectoryInfoFactory(IFileSystem fileSystem, ISMBCredentialProvider credentialProvider,
                                ISMBClientFactory smbClientFactory, uint maxBufferSize)
 {
     _fileSystem         = fileSystem;
     _credentialProvider = credentialProvider;
     _smbClientFactory   = smbClientFactory;
     _maxBufferSize      = maxBufferSize;
     transport           = SMBTransportType.DirectTCPTransport;
 }
Ejemplo n.º 4
0
 public SMBFileSystem(ISMBClientFactory ismbClientfactory, ISMBCredentialProvider credentialProvider, uint maxBufferSize = 65536)
 {
     File          = new SMBFile(ismbClientfactory, credentialProvider, this, maxBufferSize);
     Directory     = new SMBDirectory(ismbClientfactory, credentialProvider, this, maxBufferSize);
     DirectoryInfo = new SMBDirectoryInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize);
     FileInfo      = new SMBFileInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize);
     FileStream    = new SMBFileStreamFactory(this);
     Path          = new SMBPath(this);
     DriveInfo     = new SMBDriveInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize);
 }
Ejemplo n.º 5
0
 private SMBConnection(ISMBClientFactory smbClientFactory, IPAddress address, SMBTransportType transport,
                       ISMBCredential credential, int threadId, uint maxBufferSize)
 {
     SMBClient       = smbClientFactory.CreateClient(maxBufferSize);
     _address        = address;
     _transport      = transport;
     _credential     = credential;
     _referenceCount = 1;
     _threadId       = threadId;
 }
Ejemplo n.º 6
0
 public SMBDirectoryInfoFactory(IFileSystem fileSystem, ISMBCredentialProvider credentialProvider,
                                ISMBClientFactory smbClientFactory, uint maxBufferSize, ILoggerFactory loggerFactory = null)
 {
     _logger             = loggerFactory?.CreateLogger <SMBDirectoryInfoFactory>();
     _fileSystem         = fileSystem;
     _credentialProvider = credentialProvider;
     _smbClientFactory   = smbClientFactory;
     _maxBufferSize      = maxBufferSize;
     transport           = SMBTransportType.DirectTCPTransport;
 }
Ejemplo n.º 7
0
 public SMBFile(ISMBClientFactory smbclientFactory, ISMBCredentialProvider credentialProvider,
                IFileSystem fileSystem, uint maxBufferSize   = 65536,
                ISmbFileSystemSettings smbFileSystemSettings = null, ILoggerFactory loggerFactory = null) : base(new FileSystem())
 {
     _logger = loggerFactory?.CreateLogger <SMBFile>();
     _smbFileSystemSettings = smbFileSystemSettings ?? new SmbFileSystemSettings();
     _smbClientFactory      = smbclientFactory;
     _credentialProvider    = credentialProvider;
     _fileSystem            = fileSystem;
     _maxBufferSize         = maxBufferSize;
     transport = SMBTransportType.DirectTCPTransport;
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public SMBFileSystem(ISMBClientFactory ismbClientfactory,
                             ISMBCredentialProvider credentialProvider,
                             uint maxBufferSize = 65536,
                             ISmbFileSystemSettings smbFileSystemSettings = null,
                             ILoggerFactory loggerFactory = null)
        {
            if (smbFileSystemSettings == null)
            {
                smbFileSystemSettings = new SmbFileSystemSettings();
            }

            File          = new SMBFile(ismbClientfactory, credentialProvider, this, maxBufferSize, smbFileSystemSettings, loggerFactory);
            Directory     = new SMBDirectory(ismbClientfactory, credentialProvider, this, maxBufferSize, smbFileSystemSettings, loggerFactory);
            DirectoryInfo = new SMBDirectoryInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize, loggerFactory);
            FileInfo      = new SMBFileInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize, loggerFactory);
            FileStream    = new SMBFileStreamFactory(this);
            Path          = new SMBPath(this);
            DriveInfo     = new SMBDriveInfoFactory(this, credentialProvider, ismbClientfactory, maxBufferSize, loggerFactory);
        }