Esempio n. 1
0
 public void AddWatchedFolder(WatchedFolder watchedFolder)
 {
     if (!WatchedFoldersInternal.Contains(watchedFolder))
     {
         WatchedFoldersInternal.Add(watchedFolder);
     }
 }
Esempio n. 2
0
        public bool Matches(WatchedFolder watchedFolder)
        {
            if (watchedFolder == null)
            {
                throw new ArgumentNullException("watchedFolder");
            }

            return(Matches(watchedFolder.Path));
        }
Esempio n. 3
0
        public virtual async Task AddWatchedFolderAsync(WatchedFolder watchedFolder)
        {
            if (watchedFolder == null)
            {
                throw new ArgumentNullException("watchedFolder");
            }

            AddWatchedFolderInternal(watchedFolder);
            await Resolve.SessionNotify.NotifyAsync(new SessionNotification(SessionNotificationType.WatchedFolderAdded, Resolve.KnownIdentities.DefaultEncryptionIdentity, watchedFolder.Path));
        }
Esempio n. 4
0
        private async void watchedFolder_Changed(object sender, FileWatcherEventArgs e)
        {
            WatchedFolder watchedFolder = (WatchedFolder)sender;

            foreach (string fullName in e.FullNames)
            {
                IDataItem dataItem = New <IDataItem>(fullName);
                await HandleWatchedFolderChangesAsync(watchedFolder, dataItem);

                await Resolve.SessionNotify.NotifyAsync(new SessionNotification(SessionNotificationType.WatchedFolderChange, dataItem.FullName));
            }
        }
Esempio n. 5
0
        public WatchedFolder(WatchedFolder watchedFolder, IEnumerable <UserPublicKey> keyShares)
        {
            if (watchedFolder == null)
            {
                throw new ArgumentNullException(nameof(watchedFolder));
            }

            Path = watchedFolder.Path;
            Tag  = watchedFolder.Tag;

            KeyShares = keyShares.Select(ks => ks.Email).ToArray();

            InitializeFileWatcher();
        }
Esempio n. 6
0
 private void AddWatchedFolderInternal(WatchedFolder watchedFolder)
 {
     lock (_watchedFolders)
     {
         watchedFolder.Changed += watchedFolder_Changed;
         int i = _watchedFolders.FindIndex((wf) => wf.Matches(watchedFolder.Path));
         if (i < 0)
         {
             _watchedFolders.Add(watchedFolder);
         }
         else
         {
             _watchedFolders[i].Dispose();
             _watchedFolders[i] = watchedFolder;
         }
     }
 }
Esempio n. 7
0
        private async Task HandleWatchedFolderChangesAsync(WatchedFolder watchedFolder, IDataItem dataItem)
        {
            if (watchedFolder.Path == dataItem.FullName && !dataItem.IsAvailable)
            {
                await RemoveAndDecryptWatchedFolder(dataItem);
                await Save();

                return;
            }
            if (!dataItem.IsEncrypted())
            {
                return;
            }
            if (IsExisting(dataItem))
            {
                return;
            }
            await RemoveDeletedActiveFile(dataItem);
        }
Esempio n. 8
0
 public void RemoveWatchedFolder(WatchedFolder watchedFolder)
 {
     WatchedFoldersInternal.Remove(watchedFolder);
 }
        private async Task HandleNotificationInternalAsync(SessionNotification notification, IProgressContext progress)
        {
            if (Resolve.Log.IsInfoEnabled)
            {
                Resolve.Log.LogInfo("Received notification type '{0}'.".InvariantFormat(notification.NotificationType));
            }
            EncryptionParameters encryptionParameters;

            switch (notification.NotificationType)
            {
            case SessionNotificationType.WatchedFolderAdded:
            case SessionNotificationType.WatchedFolderOptionsChanged:
                progress.NotifyLevelStart();
                try
                {
                    foreach (string fullName in notification.FullNames)
                    {
                        WatchedFolder watchedFolder = _fileSystemState.WatchedFolders.First(wf => wf.Path == fullName);

                        encryptionParameters = new EncryptionParameters(Resolve.CryptoFactory.Default(New <ICryptoPolicy>()).CryptoId, notification.Identity);
                        await encryptionParameters.AddAsync(await watchedFolder.KeyShares.ToAvailableKnownPublicKeysAsync(notification.Identity));

                        IDataContainer container = New <IDataContainer>(watchedFolder.Path);
                        progress.Display = container.Name;
                        IDataContainer[] dc = new IDataContainer[] { container };
                        await _axCryptFile.EncryptFoldersUniqueWithBackupAndWipeAsync(dc, encryptionParameters, progress);
                    }
                }
                finally
                {
                    progress.NotifyLevelFinished();
                }
                progress.Totals.ShowNotification();
                break;

            case SessionNotificationType.WatchedFolderRemoved:
                foreach (string fullName in notification.FullNames)
                {
                    IDataContainer removedFolderInfo = New <IDataContainer>(fullName);
                    progress.Display = removedFolderInfo.Name;
                    if (removedFolderInfo.IsAvailable)
                    {
                        await _axCryptFile.DecryptFilesInsideFolderUniqueWithWipeOfOriginalAsync(removedFolderInfo, notification.Identity, _statusChecker, progress).Free();
                    }
                }
                break;

            case SessionNotificationType.SignIn:
                await EncryptWatchedFoldersIfSupportedAsync(notification.Identity, notification.Capabilities, progress);

                break;

            case SessionNotificationType.SignOut:
                New <IInternetState>().Clear();
                New <ICache>().RemoveItem(CacheKey.RootKey);
                New <UserPublicKeyUpdateStatus>().Clear();
                break;

            case SessionNotificationType.EncryptPendingFiles:
                await _activeFileAction.ClearExceptionState();

                await _activeFileAction.PurgeActiveFiles(progress);

                if (_knownIdentities.DefaultEncryptionIdentity != LogOnIdentity.Empty)
                {
                    await EncryptWatchedFoldersIfSupportedAsync(_knownIdentities.DefaultEncryptionIdentity, notification.Capabilities, progress);
                }
                break;

            case SessionNotificationType.UpdateActiveFiles:
                await _fileSystemState.UpdateActiveFiles(notification.FullNames);

                break;

            case SessionNotificationType.ActiveFileChange:
            case SessionNotificationType.SessionStart:
            case SessionNotificationType.WatchedFolderChange:
            case SessionNotificationType.ProcessExit:
            case SessionNotificationType.KnownKeyChange:
            case SessionNotificationType.SessionChange:
            case SessionNotificationType.WorkFolderChange:
                await _activeFileAction.CheckActiveFiles(progress);

                break;

            case SessionNotificationType.LicensePolicyChanged:
            case SessionNotificationType.RefreshLicensePolicy:
                break;

            default:
                throw new InvalidOperationException("Unhandled notification received");
            }
        }