Example #1
0
        public FileNodes(Config config, Screensaver screensaver)
        {
            this.config       = config;
            this.screensaver  = screensaver;
            this.fileDatabase = new FileDatabase(this.screensaver.readOnly);
            //this.fileDatabase.MetadataReadEvent += new MetadataReadEventHandler(metadataShow);

            if (screensaver.action != Screensaver.Actions.Wallpaper)
            {
                this.resetFoldersQueue();

                this.backgroundWorker = new System.ComponentModel.BackgroundWorker();
                this.backgroundWorker.WorkerReportsProgress      = true;
                this.backgroundWorker.WorkerSupportsCancellation = true;
                this.backgroundWorker.DoWork             += new DoWorkEventHandler(DoWorkImageFolder);
                this.backgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(progressChanged);
                this.backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(runWorkerCompleted);

                // Use local folders as this.folders is used in backgroundWorker
                //var folders = Utils.stringToConcurrentQueue(Convert.ToString(this.config.getPersistant("folders")));
                // Purge database in main thread rather, to avoid having to run database filter twice
                this.purgeNotMatchingParentFolders(this.folders);

                this.backgroundWorker.RunWorkerAsync();
            }
        }
        /// <summary>
        /// Creates a new <c>SystemEventNotifier</c> instance and sets up some
        /// required resources.
        /// </summary>
        /// <param name="maxIdleSeconds">The maximum system idle time in seconds before the
        /// <c>Idle</c> event is being raised.</param>
        public SystemEventNotifier(int maxIdleSeconds)
        {
            _maxIdleSeconds = maxIdleSeconds;
            _helperWindow   = new SystemEventHelperWindow(this);
            _cts            = new CancellationTokenSource();
            _ct             = _cts.Token;

            _pollTask = new Task(() =>
            {
                Log.Information("SystemEventNotifier polling task started");

                while (!_ct.IsCancellationRequested)
                {
                    // Check for screensaver activation
                    if (IsScreensaverRunning())
                    {
                        if (!_screensaverDetected)
                        {
                            Screensaver?.Invoke(this, new SystemEventArgs("Screensaver"));
                            Log.Information("Detected screensaver start");
                            _screensaverDetected = true;
                        }
                    }
                    else
                    {
                        if (_screensaverDetected)
                        {
                            _screensaverDetected = false;
                        }
                    }

                    // Check system idle time
                    uint idleTime = GetIdleTimeSeconds();
                    Log.Debug("Idle time: {IdleTime}", idleTime);
                    if (idleTime > _maxIdleSeconds)
                    {
                        if (!_idleDetected)
                        {
                            Idle?.Invoke(this, new SystemEventArgs("Idle Timeout"));
                            Log.Information("Detected idle timeout");
                            _idleDetected = true;
                        }
                    }
                    else
                    {
                        if (_idleDetected)
                        {
                            _idleDetected = false;
                        }
                    }

                    Thread.Sleep(POLL_INTERVAL);
                }

                Log.Information("SystemEventNotifier polling task ending");
            }, _ct);

            _pollTask.Start();
        }
Example #3
0
        private void ScreensaverOn()
        {
            if (Screensaver.Status == false)
            {
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Screensaver -> ON");

                Screensaver.Enable();
            }
        }
Example #4
0
 void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     Screensaver.KillScreenSaver(false);
     if (TopMost)
     {
         Invoke((MethodInvoker) delegate()
         {
             Activate();
         });
     }
 }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        screensaver = FindObjectOfType <Screensaver>();
        screensaver.switchEvent.AddListener(RefreshUI);

        RefreshUI();

        bubbleFontSize.text = bubbleButton.text.fontSize.ToString();

        bubbleWidth.text = bubbleRect.sizeDelta.x.ToString();
    }
Example #6
0
        private void ScreensaverOff()
        {
            if (Screensaver.Status)
            {
                if (Screensaver.IsRunning())
                {
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Screensaver -> KILL");
                    Screensaver.Kill();
                }

                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Screensaver -> OFF");
                Screensaver.Disable();
            }
        }
Example #7
0
        public void Start()
        {
            try
            {
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Starting");
                var _stopWatch = new Stopwatch();
                _stopWatch.Start();

                IsRunning = false;

                //Load monitor weekplan
                _monitorSettings   = Serializer.Deserialize <SettingsMonitor>(Settings.Default.Monitor_Weekplan);
                _alarmWindows      = new List <AlarmWindow>();
                _timeFmsElapsed    = null;
                _timePagerElapsed  = null;
                _timeWindowElapsed = null;
                _timeMouseElapsed  = DateTime.Now.Add(new TimeSpan(0, 1, 0));

                //Initialize Screen and Screensaver
                Screen.SwitchOn();
                Screensaver.Enable();

                //Timer to check
                _monitorTimer = new Timer
                {
                    Interval  = 1000,
                    AutoReset = false,
                    Enabled   = true
                };
                _monitorTimer.Elapsed += monitorTimer_Elapsed;
                _monitorTimer.Start();

                registerEvents();
                IsRunning = true;

                _stopWatch.Stop();
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), $"Started -> {_stopWatch.Elapsed}");
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
            }
        }
Example #8
0
        public void Stop()
        {
            try
            {
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Stopping");
                var _stopWatch = new Stopwatch();
                _stopWatch.Start();

                unregisterEvents();

                //Close all open alarmWindows
                foreach (var _alarmWindow in _alarmWindows)
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() => { _alarmWindow.Close(); });
                }

                _alarmWindows.Clear();

                //Disable timer for Monitor on/off
                if (_monitorTimer != null)
                {
                    _monitorTimer.Stop();
                    _monitorTimer = null;
                }

                //Switch Monitor on,
                Screen.SwitchOn();
                Screensaver.Enable();

                _stopWatch.Stop();
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), $"Stopped -> {_stopWatch.Elapsed}");
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
            }
            finally
            {
                IsRunning = false;
            }
        }
Example #9
0
 /// <summary>
 /// Raises the <see cref="E:Screensaver"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
 private void OnScreensaver(CancelEventArgs e)
 {
     Screensaver?.Invoke(this, e);
 }
Example #10
0
        public SystemEventNotifier(int maxIdleSeconds = 60 * 15)
        {
            _cts = new CancellationTokenSource();
            _ct  = _cts.Token;

            this._maxIdleSeconds = maxIdleSeconds;
            Display   = X11.Xlib.XOpenDisplay(null);
            xsi       = new X11.XScreenSaverInfo();
            lastCheck = DateTime.Now;
            _pollTask = new Task(() =>
            {
                Log.Information("SystemEventNotifier polling task started");

                while (!_ct.IsCancellationRequested)
                {
                    // Check system idle time
                    X11.Xlib.XScreenSaverQueryInfo(Display, X11.Xlib.XRootWindow(Display, 0), ref xsi);

                    Log.Debug("Idle time: {IdleTime}", xsi.idle.ToString());
                    if ((xsi.idle / 1000) > (ulong)_maxIdleSeconds)
                    {
                        if (!_idleDetected)
                        {
                            Idle?.Invoke(this, new SystemEventArgs("Idle Timeout"));
                            Log.Information("Detected idle timeout");
                            _idleDetected = true;
                        }
                    }
                    else
                    {
                        if (_idleDetected)
                        {
                            _idleDetected = false;
                        }
                    }

                    if ((ScreenSaverState)xsi.state == ScreenSaverState.ScreenSaverOn)
                    {
                        if (!_screenSaver)
                        {
                            Screensaver?.Invoke(this, new SystemEventArgs("Screen Saver"));
                            Log.Information("Detected Screen Saver On");
                            _screenSaver = true;
                        }
                    }
                    else if (_screenSaver)
                    {
                        _screenSaver = false;
                    }


                    //Since we can't check for Lock, Logout or Restart we are going to
                    //Do a bit of  a hack and assume that if our loop took longer than triple the standard time to run
                    //then we want to go ahead and clear the quick pass;
                    if ((DateTime.Now - lastCheck).TotalSeconds > (POLL_INTERVAL / 1000) * 3)
                    {
                        Log.Information("Detected an Anommaly System Loop took > 3X to run, clearing quick pass");
                        Standby?.Invoke(this, new SystemEventArgs("System Hiccup Clearing QuickPass Just in Case"));
                    }
                    lastCheck = DateTime.Now;


                    Thread.Sleep(POLL_INTERVAL);
                }

                Log.Information("SystemEventNotifier polling task ending");
            }, _ct);

            _pollTask.Start();
        }
Example #11
0
 public Wallpaper(Screensaver screensaver)
 {
     this.screensaver = screensaver;
 }
        /// <summary>
        /// Creates a new <c>SystemEventNotifier</c> instance and sets up some
        /// required resources.
        /// </summary>
        /// <param name="maxIdleSeconds">The maximum system idle time in seconds before the
        /// <c>Idle</c> event is being raised.</param>
        public SystemEventNotifier(int maxIdleSeconds = 60 * 15)
        {
            Log.Information($"Instanciating System Event Notifier");
            _cts = new CancellationTokenSource();
            _ct  = _cts.Token;

            this._maxIdleSeconds = maxIdleSeconds;

            //Subscribe to an apple notification fired when the screen is locked
            ((NSDistributedNotificationCenter)NSDistributedNotificationCenter.DefaultCenter).AddObserver(new NSString("com.apple.screenIsLocked"), (obj) =>
            {
                Log.Information("Detected session lock");
                SessionLock?.Invoke(this, new SystemEventArgs("Session Lock"));
            });

            //Subscribe to an apple notification fired when the screen saver starts
            ((NSDistributedNotificationCenter)NSDistributedNotificationCenter.DefaultCenter).AddObserver(new NSString("com.apple.screensaver.didstart"), (obj) =>
            {
                Log.Information("Detected Screen Saver");
                Screensaver?.Invoke(this, new SystemEventArgs("Screensaver"));
            });


            //Subscribe to an apple notification fired when the System goes to Sleep
            NSWorkspace.Notifications.ObserveWillSleep((s, e) =>
            {
                Log.Information("Detected Standy");
                Standby?.Invoke(this, new SystemEventArgs("Stand By"));
            });


            //Subscribe to an apple notification fired when the System goes to power off / reboot
            NSWorkspace.Notifications.ObserveWillPowerOff((s, e) =>
            {
                Log.Information("Detected PowerOff / Reboot");
                ShutdownOrRestart?.Invoke(this, new SystemEventArgs("System ShutDown / Reboot"));
            });



            //Subscribe to an apple notification fired when the System goes to Log off the current User
            NSWorkspace.Notifications.ObserveSessionDidResignActive((s, e) =>
            {
                Log.Information("Detected PowerOff / Reboot");
                SessionLogoff?.Invoke(this, new SystemEventArgs("Session Log Off"));
            });


            // Start a task to poll Idle Time Global Environment Variable
            _pollTask = new Task(() =>
            {
                Log.Information("SystemEventNotifier polling task started");
                Thread.Sleep(POLL_INTERVAL); //Sleep at first to give Mac Delegate time
                while (!_ct.IsCancellationRequested)
                {
                    // Check system idle time
                    TimeSpan idletime = AppDelegate.CheckIdleTime();
                    Log.Debug("Idle time: {IdleTime}", idletime.ToString());
                    if (idletime.TotalSeconds > _maxIdleSeconds)
                    {
                        if (!_idleDetected)
                        {
                            Idle?.Invoke(this, new SystemEventArgs("Idle Timeout"));
                            Log.Information("Detected idle timeout");
                            _idleDetected = true;
                        }
                    }
                    else
                    {
                        if (_idleDetected)
                        {
                            _idleDetected = false;
                        }
                    }

                    Thread.Sleep(POLL_INTERVAL);
                }

                Log.Information("SystemEventNotifier polling task ending");
            }, _ct);

            _pollTask.Start();
            Log.Information($"System Event Notifier was Innitialized Successfully");
        }