public static void TestConstructors()
        {
            SessionNotification sessionEvent;

            sessionEvent = new SessionNotification(SessionNotificationType.ProcessExit);
            Assert.That(sessionEvent.NotificationType, Is.EqualTo(SessionNotificationType.ProcessExit));
            Assert.That(sessionEvent.FullNames.Count(), Is.EqualTo(0));
            Assert.That(sessionEvent.Identity.Equals(LogOnIdentity.Empty));

            LogOnIdentity key = new LogOnIdentity("key");

            sessionEvent = new SessionNotification(SessionNotificationType.KnownKeyChange, key);
            Assert.That(sessionEvent.NotificationType, Is.EqualTo(SessionNotificationType.KnownKeyChange));
            Assert.That(sessionEvent.FullNames.Count(), Is.EqualTo(0));
            Assert.That(sessionEvent.Identity, Is.EqualTo(key));

            string fullName = @"C:\Test\Test.txt".NormalizeFilePath();

            sessionEvent = new SessionNotification(SessionNotificationType.ActiveFileChange, fullName);
            Assert.That(sessionEvent.NotificationType, Is.EqualTo(SessionNotificationType.ActiveFileChange));
            Assert.That(sessionEvent.FullNames.First(), Is.EqualTo(fullName));
            Assert.That(sessionEvent.Identity.Equals(LogOnIdentity.Empty));

            fullName     = @"C:\Test\".NormalizeFolderPath();
            sessionEvent = new SessionNotification(SessionNotificationType.WatchedFolderAdded, key, fullName);
            Assert.That(sessionEvent.NotificationType, Is.EqualTo(SessionNotificationType.WatchedFolderAdded));
            Assert.That(sessionEvent.FullNames.First(), Is.EqualTo(fullName));
            Assert.That(sessionEvent.Identity, Is.EqualTo(key));
        }
        /// <summary>
        /// Registers a Preset of Device and Power Notifications to match the default service notifications
        /// </summary>
        /// <param name="handle">Window handle</param>
        /// <param name="notifyType">Window/Service</param>
        public void RegisterNotifications(IntPtr handle, NotifyType notifyType)
        {
            //device notifications
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_DEVCLASS_USB);
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_DEVCLASS_VOLUME);
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_IO_VOLUME_MOUNT);
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_DEVCLASS_WCEUSBS);
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_DEVINTERFACE_DISK);
            RegisterDeviceNotification(handle, notifyType, DeviceNotification.IOEvents.GUID_DEVINTERFACE_USB_DEVICE);

            //power notifications

            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_ACDC_POWER_SOURCE);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_ACTIVE_POWERSCHEME);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_BATTERY_PERCENTAGE_REMAINING);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_CONSOLE_DISPLAY_STATE);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_GLOBAL_USER_PRESENCE);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_IDLE_BACKGROUND_TASK);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_LIDSWITCH_STATE_CHANGE);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_MONITOR_POWER_ON);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_POWERSCHEME_PERSONALITY);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_SESSION_DISPLAY_STATUS);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_SESSION_USER_PRESENCE);
            RegisterPowerNotification(handle, notifyType, PowerNotification.PowerSettings.GUID_SYSTEM_AWAYMODE);

            SessionNotification.WTSRegisterSessionNotificationEx(SessionNotification.WTS_CURRENT_SERVER, handle, SessionNotification.SessionTarget.NOTIFY_FOR_ALL_SESSIONS);
        }
 private async Task HandleSessionChangedAsync(SessionNotification notification)
 {
     try
     {
         await HandleSessionChangedInternalAsync(notification);
     }
     catch (Exception ex)
     {
         ex.ReportAndDisplay();
     }
 }
 private Task HandleSessionChanged(SessionNotification notification)
 {
     switch (notification.NotificationType)
     {
     case SessionNotificationType.SignOut:
     case SessionNotificationType.SignIn:
     case SessionNotificationType.SessionStart:
         ((AsyncDelegateAction <string>)OpenFilesFromFolder).RaiseCanExecuteChanged();
         break;
     }
     return(Constant.CompletedTask);
 }
Beispiel #5
0
 private Task HandleLogOnLogOffNotifications(SessionNotification notification)
 {
     switch (notification.NotificationType)
     {
     case SessionNotificationType.SignIn:
     case SessionNotificationType.SignOut:
         LogOnAsync.RaiseCanExecuteChanged();
         LogOff.RaiseCanExecuteChanged();
         break;
     }
     return(Constant.CompletedTask);
 }
        private async Task HandleSessionChangedInternalAsync(SessionNotification notification)
        {
            switch (notification.NotificationType)
            {
            case SessionNotificationType.WatchedFolderAdded:
                await SetWatchedFoldersAsync();

                break;

            case SessionNotificationType.WatchedFolderRemoved:
                await SetWatchedFoldersAsync();

                break;

            case SessionNotificationType.SignIn:
            case SessionNotificationType.SignOut:
                LoggedOn = Resolve.KnownIdentities.IsLoggedOn;
                break;

            case SessionNotificationType.WatchedFolderChange:
                FilesArePending = AreFilesPending();
                break;

            case SessionNotificationType.KnownKeyChange:
                if (notification.Identity == LogOnIdentity.Empty)
                {
                    throw new InvalidOperationException("Attempt to add the empty identity as a known key.");
                }
                if (!_fileSystemState.KnownPassphrases.Any(p => p.Thumbprint == notification.Identity.Passphrase.Thumbprint))
                {
                    _fileSystemState.KnownPassphrases.Add(notification.Identity.Passphrase);
                    await _fileSystemState.Save();
                }
                break;

            case SessionNotificationType.SessionStart:
            case SessionNotificationType.ActiveFileChange:
                FilesArePending = AreFilesPending();
                SetRecentFiles();
                break;

            case SessionNotificationType.LicensePolicyChanged:
                LicenseUpdate.Execute(null);
                break;

            case SessionNotificationType.WorkFolderChange:
            case SessionNotificationType.ProcessExit:
            case SessionNotificationType.SessionChange:
            default:
                break;
            }
        }
        /// <summary>
        /// Unregisters all Device and Power Notifications previously registered with RegisterPowerNotification and RegisterDeviceNotification
        /// </summary>
        /// <param name="handle">Window handle</param>
        public void UnRegisterNotifications(IntPtr handle)
        {
            foreach (var item in _registeredDeviceNotifications)
            {
                DeviceNotification.UnregisterDeviceNotification(item);
            }

            foreach (var item in _registeredPowerNotifications)
            {
                PowerNotification.UnregisterPowerSettingNotification(item);
            }

            SessionNotification.WTSUnRegisterSessionNotificationEx(SessionNotification.WTS_CURRENT_SERVER, handle);
        }
        private async Task HandleKnownFolderAffectingEventsAsync(SessionNotification notification)
        {
            switch (notification.NotificationType)
            {
            case SessionNotificationType.LicensePolicyChanged:
            case SessionNotificationType.KnownKeyChange:
            case SessionNotificationType.SignOut:
                if (notification.Capabilities.Has(LicenseCapability.SecureFolders))
                {
                    await EnsureKnownFoldersWatched(KnownFolders);
                }
                KnownFolders = await UpdateEnabledStateAsync(KnownFolders);

                break;
            }
        }
Beispiel #9
0
        private Task HandleSessionChanged(SessionNotification notification)
        {
            switch (notification.NotificationType)
            {
            case SessionNotificationType.WatchedFolderAdded:
            case SessionNotificationType.WatchedFolderRemoved:
                SetWatchedFolders();
                break;

            case SessionNotificationType.SignIn:
            case SessionNotificationType.SignOut:
                SetLogOnState(Resolve.KnownIdentities.IsLoggedOn);
                SetWatchedFolders();
                break;
            }
            return(Constant.CompletedTask);
        }
        private async Task LicensePolicy_CommandAsync(SessionNotification notification)
        {
            switch (notification.NotificationType)
            {
            case SessionNotificationType.RefreshLicensePolicy:
            case SessionNotificationType.SignIn:
                await RefreshAsync(notification.Identity);

                break;

            case SessionNotificationType.SessionStart:
            case SessionNotificationType.SignOut:
                await RefreshAsync(LogOnIdentity.Empty);

                break;

            default:
                break;
            }
        }
 protected override void SessionChange(ServicesAPI.SERVICE_CONTROL_SESSIONCHANGE_Control dwControl, SessionNotification.SessionEventData e)
 {
     this.Log(EventLogEntryType.Information, string.Format("SessionChange {0}", dwControl));
 }
Beispiel #12
0
 //protected virtual void RequestAdditionalTime(int milliseconds) { throw new NotImplementedException(); }
 protected override void SessionChange(ServicesAPI.SERVICE_CONTROL_SESSIONCHANGE_Control dwControl, SessionNotification.SessionEventData e) { }
Beispiel #13
0
 protected virtual void OnNotified(ClientNotificationEventArgs e)
 {
     SessionNotification?.Invoke(this, e);
 }
Beispiel #14
0
 internal void ServiceSendSessionChange(ServicesAPI.SERVICE_CONTROL_SESSIONCHANGE_Control dwControl, SessionNotification.SessionEventData e)
 {
     SessionChange(dwControl, e);
 }