Example #1
0
 public VirtualDriveWrapper(IFSProvider provider)
 {
     virtualDrive = new VirtualDrive(provider)
     {
         OnMount   = () => { Mounted?.Invoke(mountLetter); },
         OnUnmount = () => { Unmounted?.Invoke(mountLetter); }
     };
 }
 public OLD_KohteetController(BFContext context, IFSProvider fsProvider) :
     base(context, fsProvider, "Kohde")
 {
 }
Example #3
0
 public VirtualDrive(IFSProvider provider)
 {
     this.provider = provider;
 }
Example #4
0
        private async Task <char> Mount(bool interactiveAuth = true)
        {
            try
            {
                Instance.OnAuthUpdated = this;
                var authenticated = await Authenticate(Instance, MountCancellation.Token, interactiveAuth);

                if (!authenticated)
                {
                    Log.ErrorTrace("Authentication failed");
                    throw new InvalidOperationException("Authentication failed");
                }

                var origProv = new FSProvider(instance, ProviderStatisticsUpdated)
                {
                    VolumeName          = CloudInfo.Name,
                    CachePath           = Environment.ExpandEnvironmentVariables(Properties.Settings.Default.CacheFolder),
                    SmallFilesCacheSize = Properties.Settings.Default.SmallFilesCacheLimit * (1 << 20),
                    SmallFileSizeLimit  = Properties.Settings.Default.SmallFileSizeLimit * (1 << 20)
                };

                var rfProv = new RootFolderFSProvider(origProv);
                await rfProv.SetRootFolder(CloudInfo.RootFolder);

                Provider = rfProv;

                var cloudDrive = new VirtualDriveWrapper(Provider);

                var mountedEvent = new TaskCompletionSource <char>();

                cloudDrive.Mounted = letter =>
                {
                    mountedEvent.SetResult(letter);
                };

                NotifyMount();

                var task = Task.Factory.StartNew(
                    () =>
                {
                    try
                    {
                        cloudDrive.Mount(CloudInfo.DriveLetter, CloudInfo.ReadOnly);
                        unmountingEvent.Set();
                    }
                    catch (InvalidOperationException)
                    {
                        Log.Warn($"Drive letter {CloudInfo.DriveLetter} is already used");
                        Exception lastException = null;
                        var wasMounted          = false;
                        foreach (var letter in VirtualDriveWrapper.GetFreeDriveLettes())
                        {
                            try
                            {
                                cloudDrive.Mount(letter, CloudInfo.ReadOnly);
                                unmountingEvent.Set();
                                Instance.Dispose();
                                instance   = null;
                                wasMounted = true;
                                break;
                            }
                            catch (InvalidOperationException ex)
                            {
                                lastException = ex;
                                Log.Warn($"Drive letter {letter} is already used");
                            }
                        }

                        if (!wasMounted)
                        {
                            var message = "Could not find free letter";
                            if (lastException?.InnerException != null)
                            {
                                message = lastException.InnerException.Message;
                            }

                            mountedEvent.SetException(new InvalidOperationException(message));
                        }
                    }
                    catch (Exception ex)
                    {
                        mountedEvent.SetException(ex);
                    }
                },
                    TaskCreationOptions.LongRunning);
                return(await mountedEvent.Task);
            }
            finally
            {
                NotifyMount();
            }
        }
Example #5
0
 protected FSQueryController(BFContext context, IFSProvider fsRepository, string repositoryName) : base(context)
 {
     this.FSRepository   = fsRepository;
     this.RepositoryName = repositoryName;
 }
Example #6
0
 public OLD_KayttajatController(BFContext context, IFSProvider fsProvider) :
     base(context, fsProvider, "Kayttaja")
 {
 }
 public OLD_PalveluPaketitController(BFContext context, IFSProvider fsProvider) :
     base(context, fsProvider, "PalveluPaketti")
 {
 }
 public RootFolderFSProvider(IFSProvider provider)
 {
     this.provider = provider;
 }