示例#1
0
        MountSession MountDrive()
        {
            var cancellation = new CancellationTokenSource();
            var factory      = new CloudDriveFactory();
            var drive        = factory.CreateCloudDrive(
                _config.Schema,
                _username,
                _config.Root,
                new CloudDriveParameters()
            {
                ApiKey        = _config.Locator,
                EncryptionKey = _config.Secret,
                Logger        = _logger,
                Cancellation  = cancellation.Token,
                Parameters    = _config.GetParameters()
            }
                );

            if (!drive.TryAuthenticate())
            {
                var displayRoot = drive.DisplayRoot;
                drive.Dispose();
                _logger.Warn($"Authentication failed for drive '{displayRoot}'");
            }

            var operations = new CloudOperations(drive, _logger);

            // HACK: handle non-unique parameter set of DokanOperations.Mount() by explicitely specifying AllocationUnitSize and SectorSize
            var runner = Task.Run(() => operations.Mount(_config.Root,
                                                         DokanOptions.NetworkDrive | DokanOptions.MountManager | DokanOptions.CurrentSession,
                                                         threadCount: 5,
                                                         121,
                                                         TimeSpan.FromSeconds(_config.Timeout != 0 ? _config.Timeout : 20),
                                                         null, 512, 512),
                                  cancellation.Token);

            var session = new MountSession(_config.Root[0], runner, cancellation);

            var driveInfo = new DriveInfo(_config.Root);

            while (!driveInfo.IsReady)
            {
                Thread.Sleep(10);
            }
            _logger.Info($"Drive '{drive.DisplayRoot}' mounted successfully.");

            return(session);
        }
示例#2
0
 public bool Mount()
 {
     if (_session != null)
     {
         return(Mounted);
     }
     try
     {
         _session = MountDrive();
         return(true);
     }
     catch (Exception ex)
     {
         _session = null;
         _logger.Error($"{ex.GetType().Name}: {ex.Message}");
         return(false);
     }
 }
示例#3
0
        public void Unmount()
        {
            if (_session == null)
            {
                return;
            }

            try
            {
                _session.Unmount();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"{ex.GetType().Name}: {ex.Message}");
            }
            finally
            {
                _session = null;
            }
        }