示例#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
        internal static void Main(string[] args)
        {
            var mountSection = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).Sections[MountSection.Name] as MountSection;

            if (mountSection == null)
            {
                throw new ConfigurationErrorsException("Mount configuration missing");
            }

            CompositionInitializer.Preload(typeof(IgorSoft.CloudFS.Interface.Composition.ICloudGateway));
            CompositionInitializer.Initialize(mountSection.LibPath, "IgorSoft.CloudFS.Gateways.*.dll");
            var factory = new CloudDriveFactory();

            CompositionInitializer.SatisfyImports(factory);

            try {
                var logger = new LogFactory().GetCurrentClassLogger();
                using (var tokenSource = new CancellationTokenSource()) {
                    var tasks = new List <Task>();
                    foreach (var drive in mountSection.Drives.Cast <DriveElement>())
                    {
                        var operations = new CloudOperations(factory.CreateCloudDrive(drive.Schema, drive.UserName, drive.Root, new CloudDriveParameters()
                        {
                            EncryptionKey = drive.EncryptionKey, Parameters = drive.GetParameters()
                        }), logger);

                        // HACK: handle non-unique parameter set of DokanOperations.Mount() by explicitely specifying AllocationUnitSize and SectorSize
                        tasks.Add(Task.Run(() => operations.Mount(drive.Root, DokanOptions.RemovableDrive | DokanOptions.MountManager | DokanOptions.CurrentSession, mountSection.Threads, 1100, TimeSpan.FromSeconds(drive.Timeout != 0 ? drive.Timeout : 20), null, 512, 512), tokenSource.Token));

                        var driveInfo = new DriveInfo(drive.Root);
                        while (!driveInfo.IsReady)
                        {
                            Thread.Sleep(10);
                        }
                    }

                    Console.ReadKey(true);

                    tokenSource.Cancel();
                }
            } finally {
                foreach (var drive in mountSection.Drives.Cast <DriveElement>())
                {
                    Dokan.Unmount(drive.Root[0]);
                }
            }
        }
示例#3
0
 public void CloudOperations_New_WhereDriveIsNull_Throws()
 {
     _sut = new CloudOperations(null, new Mock <ILogger>().Object);
 }
示例#4
0
 public void Cleanup()
 {
     _sut       = null;
     _driveMock = null;
 }
示例#5
0
 public void Initialize()
 {
     _driveMock = new Mock <ICloudDrive>();
     _sut       = new CloudOperations(_driveMock.Object, new Mock <ILogger>().Object);
 }
示例#6
0
 public void Cleanup()
 {
     sut       = null;
     driveMock = null;
 }
示例#7
0
        private int Mount(string passPhrase, IList <string> userNames)
        {
            var mountSection = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).Sections[MountSection.Name] as MountSection;

            if (mountSection == null)
            {
                throw new ConfigurationErrorsException("Mount configuration missing");
            }

            settingsPassPhrase = passPhrase;

            try {
                using (var logFactory = new LogFactory()) {
                    logger = logFactory.GetCurrentClassLogger();
                    var factory = InitializeCloudDriveFactory(mountSection.LibPath);
                    using (var tokenSource = new CancellationTokenSource()) {
                        var tasks = new List <Task>();
                        foreach (var driveElement in mountSection.Drives.Where(d => !userNames.Any() || userNames.Contains(d.UserName)))
                        {
                            var drive = factory.CreateCloudDrive(driveElement.Schema, driveElement.UserName, driveElement.Root, new CloudDriveParameters()
                            {
                                ApiKey = driveElement.ApiKey, EncryptionKey = driveElement.EncryptionKey, Parameters = driveElement.GetParameters()
                            });
                            if (!drive.TryAuthenticate())
                            {
                                var displayRoot = drive.DisplayRoot;
                                drive.Dispose();
                                logger.Warn($"Authentication failed for drive '{displayRoot}'");
                                continue;
                            }

                            var operations = new CloudOperations(drive, logger);

                            // HACK: handle non-unique parameter set of DokanOperations.Mount() by explicitely specifying AllocationUnitSize and SectorSize
                            tasks.Add(Task.Run(() => operations.Mount(driveElement.Root, DokanOptions.RemovableDrive | DokanOptions.MountManager | DokanOptions.CurrentSession, mountSection.Threads, 1100, TimeSpan.FromSeconds(driveElement.Timeout != 0 ? driveElement.Timeout : 20), null, 512, 512), tokenSource.Token));

                            var driveInfo = new DriveInfo(driveElement.Root);
                            while (!driveInfo.IsReady)
                            {
                                Thread.Sleep(10);
                            }
                            logger.Info($"Drive '{drive.DisplayRoot}' mounted successfully.");
                        }

                        Console.WriteLine("Press CTRL-BACKSPACE to clear log, any other key to unmount drives");
                        while (true)
                        {
                            var keyInfo = Console.ReadKey(true);
                            if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control) && keyInfo.Key == ConsoleKey.Backspace)
                            {
                                Console.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }

                        tokenSource.Cancel();

                        return(0);
                    }
                }
            } catch (Exception ex) {
                Console.Error.WriteLine($"{ex.GetType().Name}: {ex.Message}");
                return(-1);
            } finally {
                foreach (var driveElement in mountSection.Drives.Cast <DriveElement>())
                {
                    Dokan.Unmount(driveElement.Root[0]);
                }
                UIThread.Shutdown();
            }
        }