Esempio n. 1
0
        /// <summary>
        /// Closes the talk window.  Unsubscribe from events.  Set
        /// force to true to close the window even if it was not
        /// previously active
        /// </summary>
        /// <param name="force"></param>
        public void CloseTalkWindow(bool force = false)
        {
            if ((IsTalkWindowActive || force) && _talkWindow != null)
            {
                IsPaused = false;

                _fontSize = _talkWindow.FontSize;

                Log.Debug("_fontsize: " + _fontSize);

                IsTalkWindowActive = false;

                _zoomModeTalkWindowEmpty = false;

                TTSManager.Instance.ActiveEngine.Stop();

                PanelManagement.Glass.HideGlass();

                unsubscribeEvents();

                if (CoreGlobals.AppPreferences.RetainTalkWindowContentsOnHide)
                {
                    _talkWindowText = _talkWindow.TalkWindowText;
                }

                Windows.CloseForm(_talkWindowForm);

                _talkWindowForm = null;
                _talkWindow     = null;

                AuditLog.Audit(new AuditEventTalkWindow("close"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an audit log entry for the scanner activity
        /// </summary>
        /// <param name="form">the panel form</param>
        /// <param name="operation">type of activity</param>
        private void auditLogScannerEvent(Form form, String operation)
        {
            var title = String.Empty;

            if (form is MenuPanelBase)
            {
                var menu = (MenuPanelBase)form;
                title = menu.Title;
            }

            String panelClass;

            if (form is MenuPanelBase)
            {
                panelClass = PanelCategory.Menu.ToString();
            }
            else if (form is IScannerPanel)
            {
                panelClass = PanelCategory.Scanner.ToString();
            }
            else if (form is IDialogPanel)
            {
                panelClass = PanelCategory.Dialog.ToString();
            }
            else
            {
                panelClass = "Unknown";
            }

            AuditLog.Audit(new AuditEventScannerActivity(operation, panelClass, form.Name, title));
        }
        /// <summary>
        /// Triggered when a widget is actuated. Call this in the OnWidgetActuated
        /// function in the Alphabet scanner.
        /// </summary>
        /// <param name="widget">widget that was actuated</param>
        /// <param name="handled">set to true if handled</param>
        public virtual void OnWidgetActuated(Widget widget, ref bool handled)
        {
            if (widget is WordListItemWidget)
            {
                _form.Invoke(new MethodInvoker(delegate
                {
                    Log.Debug("wordListItemName : " + widget.Name);
                    var item = widget as WordListItemWidget;
                    Log.Debug("Value: " + item.Value);
                    var wordSelected = item.Value.Trim();

                    if (!String.IsNullOrEmpty(wordSelected))
                    {
                        KeyStateTracker.ClearAlt();
                        KeyStateTracker.ClearCtrl();

                        _scannerCommon.AutoCompleteWord(wordSelected);
                        AuditLog.Audit(new AuditEventAutoComplete(widget.Name));
                    }
                }));
                handled = true;
            }
            else
            {
                handled = false;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Thread proc to close the form and quit
        /// </summary>
        private void unlockDoneProc()
        {
            const int UNLOCK_DONE_PROC_SLEEP_TIME = 1000;

            _animationManager.Stop();
            Thread.Sleep(UNLOCK_DONE_PROC_SLEEP_TIME);

            AuditLog.Audit(new AuditEventMuteScreen("close"));

            Windows.CloseForm(this);
        }
Esempio n. 5
0
        /// <summary>
        /// Converts the specified text to speech
        /// </summary>
        /// <param name="text">text to convert</param>
        private void textToSpeech(String text)
        {
            if (!String.IsNullOrEmpty(text))
            {
                Log.Debug("*** TTS *** : " + text);
                TTSManager.Instance.ActiveEngine.Speak(text);
                Log.Debug("*** TTS *** : sent text!");

                AuditLog.Audit(new AuditEventTextToSpeech(TTSManager.Instance.ActiveEngine.Descriptor.Name));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Clears the text in the talk window
 /// </summary>
 public void Clear()
 {
     if (_talkWindow != null && Windows.GetVisible(_talkWindowForm))
     {
         KeyStateTracker.ClearAll();
         _talkWindow.Clear();
         AuditLog.Audit(new AuditEventTalkWindow("clear"));
         if (EvtTalkWindowCleared != null)
         {
             EvtTalkWindowCleared(this, EventArgs.Empty);
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Starts moving the mouse in the grid mode, in the specified
        /// direction
        /// </summary>
        /// <param name="direction">down or up</param>
        private void startGridSweep(GridMouseMover.GridSweepDirections direction)
        {
            if (_gridMouseMover.IsIdle())
            {
                _mode = MouseMode.Grid;

                pause();
                _gridMouseMover.SetGridSweepDirection(direction);

                AuditLog.Audit(new AuditEventMouseMover("grid", direction.ToString()));

                _gridMouseMover.Start();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Starts moving the mouse in the radar mode, in the specified
        /// direction
        /// </summary>
        /// <param name="direction">clockwise/counter-clockwise</param>
        private void startRadarSweep(RadarMouseMover.RadarSweepDirections direction)
        {
            if (_radarMouseMover.IsIdle())
            {
                _mode = MouseMode.Radar;

                pause();

                _radarMouseMover.SetSweepDirection(direction);

                AuditLog.Audit(new AuditEventMouseMover("radar", direction.ToString()));

                _radarMouseMover.Start();
            }
        }
Esempio n. 9
0
        private void autoComplete(WordListItemWidget wordListWidget)
        {
            Log.Debug("wordListItemName : " + wordListWidget.Name + ", value: " + wordListWidget.Value);

            var wordSelected = wordListWidget.Value.Trim();

            if (!String.IsNullOrEmpty(wordSelected))
            {
                KeyStateTracker.ClearAlt();
                KeyStateTracker.ClearCtrl();

                _scannerCommon.AutoCompleteWord(wordSelected);
                AuditLog.Audit(new AuditEventAutoComplete(wordListWidget.Name));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Starts moving the mouse in the grid mode, in the specified
        /// direction
        /// </summary>
        /// <param name="direction">down or up</param>
        private void startGridSweep(GridMouseMover.Direction direction)
        {
            pause();

            _gridMouseMover = createGridMouseMover();

            AuditLog.Audit(new AuditEventMouseMover(direction.ToString()));

            _gridMouseMover.GridRectangleDirection = direction;

            _gridMouseMover.Start();

            _gridMouseMover = null;

            resume();
        }
Esempio n. 11
0
        /// <summary>
        /// Event handler for the event raised when the autoposition
        /// timer stops
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void _autoPostionScanner_EvtAutoPostionScannerStopped(object sender, EventArgs e)
        {
            AutoPosition = _prevAutoPositionScannerValue;
            if (_savePositionOnAutoPositionStop)
            {
                CoreGlobals.AppPreferences.ScannerPosition = Context.AppWindowPosition;
                AuditLog.Audit(new AuditEvent("ScannerPositionChange", Context.AppWindowPosition.ToString()));
                CoreGlobals.AppPreferences.Save();
            }

            _scannerCommon.StatusBarController.UpdateLockStatus(CoreGlobals.AppPreferences.AutoSaveScannerLastPosition);

            if (EvtAutoRepositionScannerStop != null)
            {
                EvtAutoRepositionScannerStop(this, new EventArgs());
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Closes the talk window.  Unsubscribe from events.  Set
        /// force to true to close the window even if it was not
        /// previously active
        /// </summary>
        /// <param name="force"></param>
        public void CloseTalkWindow(bool force = false)
        {
            if ((IsTalkWindowActive || force) && _talkWindow != null)
            {
                if (_showingTalkWindow)
                {
                    return;
                }

                _closingTalkWindow = true;

                IsPaused = false;

                _fontSize = _talkWindow.FontSize;

                Log.Debug("_fontsize: " + _fontSize);

                IsTalkWindowActive = false;

                _zoomModeTalkWindowEmpty = false;

                TTSManager.Instance.ActiveEngine.Stop();

                hideGlass();

                unsubscribeEvents();

                if (CoreGlobals.AppPreferences.RetainTalkWindowContentsOnHide)
                {
                    _talkWindowText = _talkWindow.TalkWindowText;
                }

                Log.Debug("Removing talkwindowagent");

                Context.AppAgentMgr.RemoveAgent(_talkWindowForm.Handle);

                Windows.CloseForm(_talkWindowForm);

                _talkWindowForm = null;
                _talkWindow = null;
                _closingTalkWindow = false;

                AuditLog.Audit(new AuditEventTalkWindow("close"));
            }
        }
Esempio n. 13
0
        /// <summary>
        /// The 'value' is the pin the user entered. Verify
        /// if this is a valid pin and 'unlock' the digits
        /// entered so far. If the whole pin has been entered
        /// unlock the mute screen.
        /// After each digit is entered, transitions the animation to
        /// the next one
        /// </summary>
        /// <param name="value">pin value entered so far</param>
        private void handlePinInput(String value)
        {
            int nextIndex = _pinEntered.Length;

            if (nextIndex >= _pin.Length)
            {
                return;
            }

            if (value[0] == _pin[nextIndex])
            {
                _pinEntered = _pinEntered + value;
                Log.Debug("pin: " + _pin + ", _pinEntered: " + _pinEntered);
                switch (_pinEntered.Length)
                {
                case 1:
                    _animationManager.Transition("FirstKey");
                    break;

                case 2:
                    _animationManager.Transition("SecondKey");
                    break;

                case 3:
                    _animationManager.Transition("ThirdKey");
                    break;

                case 4:
                    _animationManager.Transition("FourthKey");
                    break;
                }

                if (_pinEntered.Length == _pin.Length)
                {
                    unlockMuteScreen();
                }
            }
            else
            {
                AuditLog.Audit(new AuditEventMuteScreen("invalidpin"));

                _pinEntered = String.Empty;
                _animationManager.Transition("TopLevel");
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Notifies that a switch was triggered
        /// </summary>
        /// <param name="switchObj">The switch that caused the trigger</param>
        private void notifySwitchActivated(IActuatorSwitch switchObj)
        {
            AuditLog.Audit(new AuditEventSwitchActuate(switchObj.Name, "Actuate", switchObj.Actuator.Name, switchObj.Tag, 0));

            if (EvtSwitchActivated == null)
            {
                Log.Debug("No subscribers. Returning");
                return;
            }

            var delegates = EvtSwitchActivated.GetInvocationList();

            foreach (var del in delegates)
            {
                var switchActivated = (SwitchActivated)del;
                Log.Debug("Calling begininvoke for " + switchObj.Name);
                switchActivated.BeginInvoke(this, new ActuatorSwitchEventArgs(switchObj), null, null);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Form has been loaded. Initialize the UI
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void ScreenLockForm_Load(object sender, EventArgs e)
        {
            subscribeToEvents();

            // Hide all the buttons that are not reqd.  Pin length is
            // configurable.  Any numeric buttons past the pin length should be hidden
            for (int ii = Common.AppPreferences.ScreenLockPinMaxDigitValue + 1; ii < _keypadButtonArray.Length; ii++)
            {
                var buttonWidget = _rootWidget.Finder.FindChild(_keypadButtonArray[ii]);
                if (buttonWidget != null)
                {
                    buttonWidget.Hide();
                }
            }

            // Display the pin
            for (int ii = 0; ii < _pin.Length && ii < _pinButtonArray.Length; ii++)
            {
                Widget widget = _rootWidget.Finder.FindChild(_pinButtonArray[ii]);
                if (widget != null)
                {
                    widget.Value = _pin[ii].ToString();
                    widget.SetText(_pin[ii].ToString());
                }
            }

            // hide remaining buttons
            for (int ii = _pin.Length; ii < _pinButtonArray.Length; ii++)
            {
                Widget widget = _rootWidget.Finder.FindChild(_pinButtonArray[ii]);
                if (widget != null)
                {
                    widget.Hide();
                }
            }

            AuditLog.Audit(new AuditEventScreenLock("show"));

            positionControls();

            _animationManager.Start(_rootWidget);
        }
Esempio n. 16
0
        public static void Main(String[] args)
        {
            // Disallow multiple instances
            if (FileUtils.IsACATRunning())
            {
                return;
            }

            Windows.TurnOffDPIAwareness();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var assembly = Assembly.GetExecutingAssembly();

            // get appname and copyright information
            object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            var      appName    = (attributes.Length != 0)
                ? ((AssemblyTitleAttribute)attributes[0]).Title
                : String.Empty;

            var appVersion = "Version " + assembly.GetName().Version;

            attributes = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            var appCopyright = (attributes.Length != 0)
                ? ((AssemblyCopyrightAttribute)attributes[0]).Copyright
                : String.Empty;

            Log.Info("***** " + appName + ". " + appVersion + ". " + appCopyright + " *****");

            parseCommandLine(args);

            CoreGlobals.AppGlobalPreferences =
                GlobalPreferences.Load(FileUtils.GetPreferencesFileFullPath(GlobalPreferences.FileName));

            //Set the active user/profile information
            setUserName();
            setProfileName();

            //Create user and profile if they don't already exist
            if (!createUserAndProfile())
            {
                return;
            }

            if (!loadUserPreferences())
            {
                return;
            }

            Log.SetupListeners();

            if (!String.IsNullOrEmpty(_panelConfig))
            {
                Common.AppPreferences.PreferredPanelConfigNames = _panelConfig + ";" +
                                                                  Common.AppPreferences.PreferredPanelConfigNames;
            }

            Splash splash = new Splash(FileUtils.GetImagePath("SplashScreenImage.png"), appName, appVersion, appCopyright, 1000);

            splash.Show();

            Context.PreInit();
            Common.PreInit();

            if (!Context.Init())
            {
                splash.Close();
                splash = null;

                TimedMessageBox.Show(Context.GetInitCompletionStatus());
                if (Context.IsInitFatal())
                {
                    return;
                }
            }

            AuditLog.Audit(new AuditEvent("Application", "start"));

            Context.ShowTalkWindowOnStartup = Common.AppPreferences.ShowTalkWindowOnStartup;
            Context.AppAgentMgr.EnableContextualMenusForDialogs = Common.AppPreferences.EnableContextualMenusForDialogs;
            Context.AppAgentMgr.EnableContextualMenusForMenus   = Common.AppPreferences.EnableContextualMenusForMenus;

            if (splash != null)
            {
                splash.Close();
            }

            if (!Context.PostInit())
            {
                MessageBox.Show(Context.GetInitCompletionStatus(), "Initialization Error");
                return;
            }

            Common.Init();

            try
            {
                Application.Run();

                AuditLog.Audit(new AuditEvent("Application", "stop"));

                Context.Dispose();

                Common.Uninit();

                //Utils.Dispose();

                Log.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Creates the a talk window form and show it. Restores talk window
        /// contents if configuredto do so.  Raises an event indicating the
        /// talk window was created.  Window creation is done in a separate
        /// thread with its own message loop
        /// </summary>
        private void createAndShowTalkWindow()
        {
#if TALKWINDOW_DISPATCHER_THREAD
            var viewerThread = new Thread(delegate()
            {
                if (!_inTalkWindowCreationThread)
                {
                    _inTalkWindowCreationThread = true;

                    // Create our context, and install it:
                    SynchronizationContext.SetSynchronizationContext(
                        new System.Windows.Threading.DispatcherSynchronizationContext(
                            System.Windows.Threading.Dispatcher.CurrentDispatcher));
#endif
            IsTalkWindowActive = true;

            CreateTalkWindow();

            showGlass();

            Windows.SetTopMost(_talkWindowForm);

            Form form = null;
            if (PanelManager.Instance.GetCurrentForm() != null)
            {
                form = PanelManager.Instance.GetCurrentForm() as Form;
            }

            if (form != null)
            {
                SetTalkWindowPosition(PanelManager.Instance.GetCurrentForm() as Form);
            }

            var talkWindowAgent = Context.AppAgentMgr.GetAgentByName("TalkWindow Agent");
            Log.IsNull("Talkwindowagent", talkWindowAgent);
            if (talkWindowAgent != null)
            {
                Context.AppAgentMgr.AddAgent(_talkWindowForm.Handle, talkWindowAgent);
                Log.Debug("Added talkwindowagent");
            }

            Windows.ShowForm(_talkWindowForm);

            Windows.ActivateForm(_talkWindowForm);

            AuditLog.Audit(new AuditEventTalkWindow("show"));

            if (CoreGlobals.AppPreferences.RetainTalkWindowContentsOnHide)
            {
                _talkWindow.TalkWindowText = _talkWindowText;
            }

            if (EvtTalkWindowCreated != null)
            {
                EvtTalkWindowCreated(this, new TalkWindowCreatedEventArgs(_talkWindowForm));
            }

#if TALKWINDOW_DISPATCHER_THREAD
                    System.Windows.Threading.Dispatcher.Run();
                    Log.Debug("Exited DISPATCHER.RUN");
                    _inTalkWindowCreationThread = false;
                }
            });

            viewerThread.SetApartmentState(ApartmentState.STA);
            Log.Debug("Starting thread, _inTalkWindowCreationThread is :  " + _inTalkWindowCreationThread);
            viewerThread.Start();
#endif
        }
Esempio n. 18
0
 /// <summary>
 /// Convers the indicated text to speech thorugh the
 /// active text-to-speech engine
 /// </summary>
 /// <param name="text">text to convert</param>
 private void textToSpeech(String text)
 {
     Log.Debug("about to speak text=" + text);
     Context.AppTTSManager.ActiveEngine.Speak(text);
     AuditLog.Audit(new AuditEventTextToSpeech(Context.AppTTSManager.ActiveEngine.Descriptor.Name));
 }
Esempio n. 19
0
        public static void Main(String[] args)
        {
            if (AppCommon.OtherInstancesRunning())
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FileUtils.LogAssemblyInfo();

            parseCommandLine(args);

            AppCommon.LoadGlobalSettings();

            AppCommon.SetUserName(_userName);
            AppCommon.SetProfileName(_profile);

            if (!AppCommon.CreateUserAndProfile())
            {
                return;
            }

            if (!AppCommon.LoadUserPreferences())
            {
                return;
            }

            Common.AppPreferences.AppId   = "ACATApp";
            Common.AppPreferences.AppName = "ACAT App";

            CommandDescriptors.Init();

            Log.SetupListeners();

            if (!AppCommon.SetCulture())
            {
                return;
            }

            CommandDescriptors.Init();

            if (!String.IsNullOrEmpty(_panelConfig))
            {
                Common.AppPreferences.PreferredPanelConfigNames = _panelConfig;
            }

            Splash splash = new Splash(2000);

            splash.Show();

            Context.PreInit();
            Common.PreInit();

            if (!Context.Init())
            {
                splash.Close();
                splash = null;

                TimedMessageBox.Show(Context.GetInitCompletionStatus());
                if (Context.IsInitFatal())
                {
                    return;
                }
            }

            if (splash != null)
            {
                splash.Close();
            }

            AuditLog.Audit(new AuditEvent("Application", "start"));

            Context.ShowTalkWindowOnStartup = Common.AppPreferences.ShowTalkWindowOnStartup;
            Context.AppAgentMgr.EnableContextualMenusForDialogs = Common.AppPreferences.EnableContextualMenusForDialogs;
            Context.AppAgentMgr.EnableContextualMenusForMenus   = Common.AppPreferences.EnableContextualMenusForMenus;

            if (Context.ShowTalkWindowOnStartup)
            {
                Context.AppTalkWindowManager.ToggleTalkWindow();
                Context.ShowTalkWindowOnStartup = false;
            }

            if (!Context.PostInit())
            {
                MessageBox.Show(Context.GetInitCompletionStatus(), R.GetString("InitializationError"));
                return;
            }

            Common.Init();

            try
            {
                Application.Run();

                AppCommon.ExitMessageShow();

                AuditLog.Audit(new AuditEvent("Application", "stop"));

                Context.Dispose();

                Common.Uninit();

                AppCommon.ExitMessageClose();

                Log.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            AppCommon.OnExit();
        }
Esempio n. 20
0
        public static void Main(String[] args)
        {
            if (AppCommon.OtherInstancesRunning())
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FileUtils.LogAssemblyInfo();

            parseCommandLine(args);

            AppCommon.LoadGlobalSettings();

            AppCommon.SetUserName();
            AppCommon.SetProfileName();

            if (!AppCommon.CreateUserAndProfile())
            {
                return;
            }

            if (!AppCommon.LoadUserPreferences())
            {
                return;
            }

            Common.AppPreferences.AppId   = "ACATTalk";
            Common.AppPreferences.AppName = "ACAT Talk";

            if (!AppCommon.SetCulture())
            {
                return;
            }

            Log.SetupListeners();

            CommandDescriptors.Init();

            setSwitchMapCommands();

            Common.AppPreferences.PreferredPanelConfigNames = !String.IsNullOrEmpty(_panelConfig) ? _panelConfig : "TalkApplicationABC";

            Splash splash = new Splash(1000);

            splash.Show();

            Context.PreInit();
            Common.PreInit();

            Context.AppAgentMgr.EnableAppAgentContextSwitch = false;

            if (!Context.Init(Context.StartupFlags.Minimal |
                              Context.StartupFlags.TextToSpeech |
                              Context.StartupFlags.WordPrediction |
                              Context.StartupFlags.AgentManager |
                              Context.StartupFlags.WindowsActivityMonitor |
                              Context.StartupFlags.Abbreviations))
            {
                splash.Close();
                splash = null;

                TimedMessageBox.Show(Context.GetInitCompletionStatus());
                if (Context.IsInitFatal())
                {
                    return;
                }
            }

            AuditLog.Audit(new AuditEvent("Application", "start"));

            Context.ShowTalkWindowOnStartup = false;
            Context.AppAgentMgr.EnableContextualMenusForDialogs     = false;
            Context.AppAgentMgr.EnableContextualMenusForMenus       = false;
            Context.AppAgentMgr.DefaultAgentForContextSwitchDisable = Context.AppAgentMgr.NullAgent;

            if (splash != null)
            {
                splash.Close();
            }

            if (!Context.PostInit())
            {
                MessageBox.Show(Context.GetInitCompletionStatus(), R.GetString("InitializationError"));
                return;
            }

            Common.Init();

            Context.AppWindowPosition = Windows.WindowPosition.CenterScreen;

            try
            {
                var form = PanelManager.Instance.CreatePanel("TalkApplicationScanner");
                if (form != null)
                {
                    // Add ad-hoc agent that will handle the form
                    IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Talk Application Agent");
                    if (agent == null)
                    {
                        MessageBox.Show("Could not find application agent for this application.");
                        return;
                    }

                    Context.AppAgentMgr.AddAgent(form.Handle, agent);

                    Context.AppPanelManager.ShowDialog(form as IPanel);
                }
                else
                {
                    MessageBox.Show(String.Format(R.GetString("InvalidFormName"), "TalkApplicationScanner"), R.GetString("Error"));
                    return;
                }

                AppCommon.ExitMessageShow();

                AuditLog.Audit(new AuditEvent("Application", "stop"));

                Context.Dispose();

                Common.Uninit();

                AppCommon.ExitMessageClose();

                Log.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            AppCommon.OnExit();
        }
Esempio n. 21
0
        /// <summary>
        /// Disambigates signals from various switches and acts upon them.  Disambiguation
        /// logic has not been implemented.  this is  TODO.
        /// Maintains a list of switches that are currently held down.  When the swithches
        /// are released, it checks to see how long they were held and then triggers an
        /// event.
        /// </summary>
        /// <param name="switches">switch collection</param>
        /// <param name="switchObj">Which switch to act on</param>
        private void disambiguateAndAct(Dictionary <String, IActuatorSwitch> switches, IActuatorSwitch switchObj)
        {
            IActuatorSwitch switchActivated = null;
            long            elapsedTime     = 0;

            switch (switchObj.Action)
            {
            case SwitchAction.Down:
                lock (switches)
                {
                    if (!switches.ContainsKey(switchObj.Name))
                    {
                        Log.Debug("switches does not contain " + switchObj.Name + ". adding it");

                        // add it to the current list of active switches
                        switches.Add(switchObj.Name, switchObj);

                        switchObj.AcceptTimer.Restart();
                    }
                    else
                    {
                        Log.Debug("switches already contains " + switchObj.Name);
                    }
                }

                break;

            case SwitchAction.Up:
                // remove from the list of currently accepted switches
                lock (switches)
                {
                    switchObj.RegisterSwitchUp();
                    if (switches.ContainsKey(switchObj.Name))
                    {
                        Log.Debug("switches contains " + switchObj.Name);
                        var activeSwitch = switches[switchObj.Name];

                        elapsedTime = (activeSwitch != null && activeSwitch.AcceptTimer.IsRunning) ? activeSwitch.AcceptTimer.ElapsedMilliseconds : 0;

                        if (switchObj.Actuate &&
                            activeSwitch != null &&
                            activeSwitch.AcceptTimer.IsRunning &&
                            activeSwitch.AcceptTimer.ElapsedMilliseconds >= CoreGlobals.AppPreferences.AcceptTime)
                        {
                            Log.Debug("Switch accepted!");
                            switchActivated = switchObj;
                        }
                        else
                        {
                            Log.Debug("Switch not found or actuate is false or timer not running or elapsedTime < accept time");
                        }

                        switches.Remove(switchObj.Name);
                    }
                    else
                    {
                        Log.Debug("switches does not contain " + switchObj.Name);
                    }
                }

                break;

            case SwitchAction.Trigger:
                lock (switches)
                {
                    if (switches.ContainsKey(switchObj.Name))
                    {
                        switches.Remove(switchObj.Name);
                    }
                }

                if (switchObj.Actuate)
                {
                    switchActivated = switchObj;
                }

                break;
            }

            AuditLog.Audit(new AuditEventSwitchActuate(switchObj.Name, switchObj.Action.ToString(), switchObj.Actuator.Name, switchObj.Tag, elapsedTime));

            if (switchActivated != null)
            {
                act(switchObj);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// A switch was activated. Figure out the context and execute the
        /// appropriate action. The input manager triggers this event.  Every
        /// switch has an action that is configured in the swtichconfigmap file.
        /// The action is executed depending on the state of the animation player.
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void actuatorManager_EvtSwitchActivated(object sender, ActuatorSwitchEventArgs e)
        {
            IActuatorSwitch switchObj = e.SwitchObj;

            try
            {
                if (_player == null || _currentPanel == null)
                {
                    return;
                }

                Log.Debug("switch: " + switchObj.Name);
                Log.Debug("   Panel: " + _currentPanel.Name);

                if (_currentPanel.UIControl is System.Windows.Forms.Form)
                {
                    bool visible = Windows.GetVisible(_currentPanel.UIControl);
                    Log.Debug("Form: " + _currentPanel.UIControl.Name + ", playerState: " + _player.State + ", visible: " + visible);
                    if (!visible)
                    {
                        return;
                    }
                }

                // get the action associated with the switch
                PCode onTrigger = getOnTrigger(switchObj);
                if (onTrigger == null)
                {
                    Log.Debug("OnTrigger is null. returning");
                    return;
                }

                Log.Debug("onTrigger.HasCode: " + onTrigger.HasCode());

                // execute action if the player is in the right state.
                if (_player.State != PlayerState.Stopped &&
                    _player.State != PlayerState.Unknown &&
                    _player.State != PlayerState.Paused &&
                    onTrigger.HasCode())
                {
                    Log.Debug("Executing OnTrigger for panel..." + _currentPanel.Name);
                    _interpreter.Execute(onTrigger);
                    return;
                }

                if (_player.State == PlayerState.Timeout || _player.State == PlayerState.Interrupted)
                {
                    Log.Debug("Calling player transition for firstanimation");
                    _player.Transition(_firstAnimation);
                    return;
                }

                Log.Debug("PLayer state is " + _player.State);
                if (_player.State != PlayerState.Running)
                {
                    Log.Debug(_currentPanel.Name + ": Player is not Running. Returning");
                    return;
                }

                playBeep(switchObj);

                AnimationWidget highlightedWidget = _player.HighlightedWidget;
                Animation       currentAnimation  = _player.CurrentAnimation;

                highlightedWidget = _switchDownHighlightedWidget;
                currentAnimation  = _switchDownAnimation;

                if (highlightedWidget == null)
                {
                    highlightedWidget = _switchAcceptedHighlightedWidget;
                    currentAnimation  = _switchAcceptedAnimation;
                }

                if (highlightedWidget == null)
                {
                    highlightedWidget = _player.HighlightedWidget;
                    currentAnimation  = _player.CurrentAnimation;
                }

                resetSwitchEventStates();

                if (currentAnimation != null && highlightedWidget != null)
                {
                    setSwitchState(false);

                    var widgetName = (highlightedWidget.UIWidget is IButtonWidget) ?
                                     "Button" :
                                     highlightedWidget.UIWidget.Name;

                    AuditLog.Audit(new AuditEventUISwitchDetect(switchObj.Name,
                                                                _currentPanel.Name,
                                                                highlightedWidget.UIWidget.GetType().Name,
                                                                widgetName));

                    Log.Debug(_currentPanel.Name + ": Switch on " +
                              highlightedWidget.UIWidget.Name + " type: " +
                              highlightedWidget.UIWidget.GetType().Name);

                    // check if the widget has a onSelect code fragment. If so execute it.  Otherwise
                    // then check if the animation seq that this widget is a part of, has a onSelect.
                    // If it does, execute that.

                    PCode code;
                    SetSelectedWidget(highlightedWidget.UIWidget);
                    if (highlightedWidget.OnSelect.HasCode())
                    {
                        code = highlightedWidget.OnSelect;
                        _interpreter.Execute(code);
                    }
                    else if (currentAnimation.OnSelect.HasCode())
                    {
                        code = currentAnimation.OnSelect;
                        _interpreter.Execute(code);
                    }
                }
                else
                {
                    Log.Debug(_currentPanel.Name + ": No current animation or highlighed widget!!");
                }
            }
            catch (Exception ex)
            {
                Log.Debug(ex.ToString());
            }
            finally
            {
                setSwitchState(false);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Creates the a talk window form and show it. Restores talk window
        /// contents if configuredto do so.  Raises an event indicating the
        /// talk window was created.  Window creation is done in a separate
        /// thread with its own message loop
        /// </summary>
        private void createAndShowTalkWindow()
        {
            var viewerThread = new Thread(delegate()
            {
                if (!_inTalkWindowCreationThread)
                {
                    _inTalkWindowCreationThread = true;

                    IsTalkWindowActive = true;

                    // Create our context, and install it:
                    SynchronizationContext.SetSynchronizationContext(
                        new System.Windows.Threading.DispatcherSynchronizationContext(
                            System.Windows.Threading.Dispatcher.CurrentDispatcher));

                    CreateTalkWindow();

                    showGlass();


                    //notifyTalkWindowPreVisibilityChanged(true);

                    Windows.SetTopMost(_talkWindowForm);

                    Form form = null;
                    if (PanelManagement.PanelManager.Instance.GetCurrentForm() != null)
                    {
                        form = PanelManagement.PanelManager.Instance.GetCurrentForm() as Form;
                    }

                    if (form != null)
                    {
                        SetTalkWindowPosition(PanelManagement.PanelManager.Instance.GetCurrentForm() as Form);
                    }

                    Windows.ShowForm(_talkWindowForm);

                    Windows.ActivateForm(_talkWindowForm);

                    AuditLog.Audit(new AuditEventTalkWindow("show"));

                    if (CoreGlobals.AppPreferences.RetainTalkWindowContentsOnHide)
                    {
                        _talkWindow.TalkWindowText = _talkWindowText;
                    }

                    if (EvtTalkWindowCreated != null)
                    {
                        EvtTalkWindowCreated(this, new TalkWindowCreatedEventArgs(_talkWindowForm));
                    }

                    System.Windows.Threading.Dispatcher.Run();
                    Log.Debug("Exited DISPATCHER.RUN");
                    _inTalkWindowCreationThread = false;
                }
            });

            viewerThread.SetApartmentState(ApartmentState.STA);
            Log.Debug("Starting thread, _inTalkWindowCreationThread is :  " + _inTalkWindowCreationThread);
            viewerThread.Start();
        }
Esempio n. 24
0
        public static void Main(String[] args)
        {
            if (AppCommon.OtherInstancesRunning())
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FileUtils.LogAssemblyInfo();

            AppCommon.LoadGlobalSettings();

            AppCommon.SetUserName();
            AppCommon.SetProfileName();

            if (!AppCommon.CreateUserAndProfile())
            {
                return;
            }

            if (!AppCommon.LoadUserPreferences())
            {
                return;
            }

            Common.AppPreferences.AppId   = "ACATPhrase";
            Common.AppPreferences.AppName = "ACAT Phrases";

            if (!AppCommon.SetCulture())
            {
                return;
            }

            Log.SetupListeners();

            CommandDescriptors.Init();

            setSwitchMapCommands();

            if (!createPanelClassConfig())
            {
                return;
            }

            Common.AppPreferences.PreferredPanelConfigNames = _panelConfigClassName;

            Splash splash = new Splash(1000);

            splash.Show();

            Context.PreInit();
            Common.PreInit();

            Context.AppAgentMgr.EnableAppAgentContextSwitch = false;

            if (!Context.Init(Context.StartupFlags.Minimal |
                              Context.StartupFlags.TextToSpeech |
                              Context.StartupFlags.AgentManager |
                              Context.StartupFlags.WindowsActivityMonitor |
                              Context.StartupFlags.Abbreviations))
            {
                splash.Close();
                splash = null;

                TimedMessageBox.Show(Context.GetInitCompletionStatus());
                if (Context.IsInitFatal())
                {
                    return;
                }
            }

            AuditLog.Audit(new AuditEvent("Application", "start"));

            Context.ShowTalkWindowOnStartup = false;
            Context.AppAgentMgr.EnableContextualMenusForDialogs     = false;
            Context.AppAgentMgr.EnableContextualMenusForMenus       = false;
            Context.AppAgentMgr.DefaultAgentForContextSwitchDisable = Context.AppAgentMgr.NullAgent;

            if (splash != null)
            {
                splash.Close();
            }

            if (!Context.PostInit())
            {
                MessageBox.Show(Context.GetInitCompletionStatus(), R.GetString("InitializationError"));
                return;
            }

            Common.Init();

            Context.AppWindowPosition = Windows.WindowPosition.CenterScreen;

            try
            {
                var phraseSpeakScanner = Context.AppPanelManager.CreatePanel(_phraseSpeakScannerName);
                if (phraseSpeakScanner != null)
                {
                    var invoker = (phraseSpeakScanner as IExtension).GetInvoker();
                    invoker.SetValue("ShowSearchButton", false);
                    Context.AppPanelManager.ShowDialog(phraseSpeakScanner as IPanel);
                }

                AppCommon.ExitMessageShow();

                AuditLog.Audit(new AuditEvent("Application", "stop"));

                Context.Dispose();

                Common.Uninit();

                AppCommon.ExitMessageClose();

                Log.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            AppCommon.OnExit();
        }
Esempio n. 25
0
        /// <summary>
        /// This function is the heart beat of ACAT.  All animations are handled in this
        /// event.  It unhighlights the currenlty highlighted animation widget and
        /// highlights the next one in the sequence.  If it has reached the end of the
        /// sequence, it wraps around and repeats the animation until the number of
        /// iterations has reached.
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (_syncObj.Status == SyncLock.StatusValues.Closing ||
                _syncObj.Status == SyncLock.StatusValues.Closed)
            {
                Log.Debug("Form is closing. Returning" + _rootWidget.UIControl.Name);
                return;
            }

            if (_inTimer)
            {
                Log.Debug("Timer is busy. returning");
                return;
            }

            _inTimer = true;

            try
            {
                Log.Debug("Before tryEnter " + _rootWidget.UIControl.Name + ", threadid: " + GetCurrentThreadId());

                if (!tryEnter(_transitionSync))
                {
                    Log.Debug("_transition sync will block returning");
                    return;
                }

                Log.Debug("After tryEnter" + _rootWidget.UIControl.Name + ", status: " + _syncObj.Status);
                if (_syncObj.Status == SyncLock.StatusValues.Closing ||
                    _syncObj.Status == SyncLock.StatusValues.Closed)
                {
                    Log.Debug("Form is closing. Returning" + _rootWidget.UIControl.Name);
                    return;
                }

                check();

                Log.Debug("CurrentAnimation: " + _currentAnimation.Name +
                          ". Count: " + _currentAnimation.AnimationWidgetList.Count +
                          ". currentWidgetIndex: " + _currentWidgetIndex);

                if (animatedWidgetCount() == 0)
                {
                    Log.Debug("No widgets to animate.");
                    _interpreter.Execute(_currentAnimation.OnEnd);
                    return;
                }

                check();

                var animationWidget = _currentAnimation.AnimationWidgetList[_currentWidgetIndex];

                Log.Debug(_rootWidget.UIControl.Name + ", status: " + _syncObj.Status);

                // if any switch is currently engaged, keep the current widget
                // highlighted until the user releases the switch
                //if (ActuatorManager.Instance.IsSwitchActive())
                if (IsSwitchActive)
                {
                    Log.Debug("Some switch is active. Will try again");
                    return;
                }

                // if there is code associated with an onEnter, execute that
                if (_currentAnimation.OnEnterExecutionNotDone && _currentAnimation.OnEnter != null)
                {
                    _interpreter.Execute(_currentAnimation.OnEnter);
                    _currentAnimation.OnEnterExecutionNotDone = false;
                }

                check();

                Log.Debug(_rootWidget.UIControl.Name + ", status: " + _syncObj.Status);

                // we have reached the end of the iteration. Turn off
                // the widget that was last highlighed and stop the
                // animation sequence
                if (_lastIteration)
                {
                    _lastIteration = false;

                    Widget selectedWidget = (_highlightedWidget != null &&
                                             _highlightedWidget.UIWidget != null) ? _highlightedWidget.UIWidget.Parent : null;

                    _rootWidget.HighlightOff();
                    if (animationWidget.OnHighlightOff.HasCode())
                    {
                        _interpreter.Execute(animationWidget.OnHighlightOff);
                    }

                    if (_currentAnimation.IsFirst)
                    {
                        setPlayerState(PlayerState.Timeout);
                    }

                    if (_timer != null)
                    {
                        _timer.Stop();
                    }
                    else
                    {
                        Log.Debug("Timer is null. returning");
                        return;
                    }

                    check();

                    AuditLog.Audit(new AuditEventAnimationEnd(
                                       _rootWidget.Name,
                                       (selectedWidget != null) ? selectedWidget.Name : string.Empty,
                                       (selectedWidget != null) ? selectedWidget.GetType().Name : string.Empty,
                                       _currentAnimation.Name));

                    // is there an onEnd code that we have to execute
                    _interpreter.Execute(_currentAnimation.OnEnd);

                    return;
                }

                check();

                if (_highlightedWidget != null && _highlightedWidget != animationWidget)
                {
                    Log.Debug(string.Format("Animation: {0}. Turning off . name = {1}. Count: {2}",
                                            _currentAnimation.Name,
                                            _highlightedWidget.UIWidget.Name,
                                            _currentAnimation.AnimationWidgetList.Count));

                    check();

                    _highlightedWidget.UIWidget.HighlightOff();

                    check();

                    if (_highlightedWidget.OnHighlightOff.HasCode())
                    {
                        _interpreter.Execute(_highlightedWidget.OnHighlightOff);
                    }
                }

                check();

                // now turn the highlight on on the next widget in the  sequence
                animationWidget = _currentAnimation.AnimationWidgetList[_currentWidgetIndex];

                Log.Debug("Animation: " + _currentAnimation.Name +
                          ". Turning on " + _currentWidgetIndex +
                          ". name = " + animationWidget.UIWidget.Name);

                check();

                animationWidget.UIWidget.HighlightOn();

                _highlightedWidget = animationWidget;

                // calculate how long to wait before triggering the
                // next timer event.  (this is how long the highlighted
                // widget will stay highlighted)

                int hesitateTime = animationWidget.HesitateTime;

                check();

                if (hesitateTime == 0 && isFirstAnimatedWidget(_currentWidgetIndex))
                {
                    hesitateTime = _currentAnimation.HesitateTime;
                }

                if (_timer != null)
                {
                    _timer.Interval = _currentAnimation.SteppingTime + hesitateTime;
                }
                else
                {
                    Log.Debug("timer is null. returning");
                    return;
                }

                check();

                if (animationWidget.OnHighlightOn.HasCode())
                {
                    _interpreter.Execute(animationWidget.OnHighlightOn);
                }

                check();

                int nextIndex = getNextAnimatedWidget(_currentWidgetIndex);

                // if we have reached the end of the animation sequence, wrap around
                if (nextIndex < 0)
                {
                    _iterationCount++;
                    int iterations = CoreGlobals.AppPreferences.ResolveVariableInt(_currentAnimation.Iterations, 1, 1);
                    if (iterations >= 0 && _iterationCount >= iterations)
                    {
                        _lastIteration = true;
                        return;
                    }

                    _currentWidgetIndex = getFirstAnimatedWidget();
                }
                else
                {
                    _currentWidgetIndex = nextIndex;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("AnimationPlayerexception " + ex);
            }
            finally
            {
                Log.Debug("Before release " + _rootWidget.UIControl.Name);
                release(_transitionSync);
                Log.Debug("After release " + _rootWidget.UIControl.Name);

                Log.Debug("Setting intimer to false " + _rootWidget.UIControl.Name);
                _inTimer = false;

                Log.Debug("Exiting timer " + _rootWidget.UIControl.Name);
            }
        }
Esempio n. 26
0
        public static void Main(String[] args)
        {
            // Disallow multiple instances
            if (FileUtils.IsACATRunning())
            {
                return;
            }

            Windows.TurnOffDPIAwareness();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            parseCommandLine(args);

            var assembly = Assembly.GetExecutingAssembly();

            // get appname and copyright information
            object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            var      appName    = (attributes.Length != 0)
                                ? ((AssemblyTitleAttribute)attributes[0]).Title
                                : String.Empty;

            var appVersion = string.Format(Resources.Version0, assembly.GetName().Version);
            //attributes = assembly.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
            //var appCopyright = (attributes.Length != 0)
            //                        ? ((AssemblyCopyrightAttribute) attributes[0]).Copyright
            //                        : String.Empty;
            var appCopyright = Resources.AssemblyCopyright.Replace("\\n", Environment.NewLine);

            Log.Info("***** " + appName + ". " + appVersion + ". " + appCopyright + " *****");

            CoreGlobals.AppGlobalPreferences = GlobalPreferences.Load(FileUtils.GetPreferencesFileFullPath(GlobalPreferences.FileName));

            //Set the active user/profile information
            setUserName();
            setProfileName();

            //Create user and profile if they don't already exist
            if (!createUserAndProfile())
            {
                return;
            }

            if (!loadUserPreferences())
            {
                return;
            }

            Log.SetupListeners();

            Splash splash = new Splash(FileUtils.GetImagePath("SplashScreenImage.png"), appName, appVersion, appCopyright, 1000);

            splash.Show();

            Context.PreInit();
            Common.PreInit();

            Context.AppAgentMgr.EnableAppAgentContextSwitch = false;

            if (!Context.Init(Context.StartupFlags.Minimal |
                              Context.StartupFlags.TextToSpeech |
                              Context.StartupFlags.WordPrediction |
                              Context.StartupFlags.AgentManager |
                              Context.StartupFlags.WindowsActivityMonitor |
                              Context.StartupFlags.Abbreviations))
            {
                splash.Close();
                splash = null;

                TimedMessageBox.Show(Context.GetInitCompletionStatus());
                if (Context.IsInitFatal())
                {
                    return;
                }
            }

            AuditLog.Audit(new AuditEvent("Application", "start"));

            Context.ShowTalkWindowOnStartup = false;
            Context.AppAgentMgr.EnableContextualMenusForDialogs     = false;
            Context.AppAgentMgr.EnableContextualMenusForMenus       = false;
            Context.AppAgentMgr.DefaultAgentForContextSwitchDisable = Context.AppAgentMgr.NullAgent;

            if (splash != null)
            {
                splash.Close();
            }

            if (!Context.PostInit())
            {
                MessageBox.Show(Context.GetInitCompletionStatus(), "Initialization Error");
                return;
            }

            Common.Init();

            Context.AppWindowPosition = Windows.WindowPosition.CenterScreen;

            var formName = String.IsNullOrEmpty(_formName) ? "TalkApplicationScanner" : _formName;
            var form     = PanelManager.Instance.CreatePanel(formName);

            if (form != null)
            {
                // Add ad-hoc agent that will handle the form
                IApplicationAgent agent = new TalkAppAgent();
                Context.AppAgentMgr.AddAgent(form.Handle, agent);

                Context.AppPanelManager.Show(form as IPanel);
            }
            else
            {
                MessageBox.Show("Invalid form name " + form, "Error");
                return;
            }

            try
            {
                Application.Run();

                AuditLog.Audit(new AuditEvent("Application", "stop"));

                Context.Dispose();

                Common.Uninit();

                //Utils.Dispose();

                Log.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 27
0
        private static void getActiveWindow(bool flag = false)
        {
            AutomationElement focusedElement = null;

            try
            {
                IntPtr foregroundWindow = Windows.GetForegroundWindow();
                var    title            = Windows.GetWindowTitle(foregroundWindow);

                Log.Debug("fgHwnd = " + ((foregroundWindow != IntPtr.Zero) ? foregroundWindow.ToString() : "null") + ", title: " + title);

                if (Windows.GetOSVersion() == Windows.WindowsVersion.Win10 &&
                    title.StartsWith("Jump List for"))
                {
                    return;
                }

                focusedElement = AutomationElement.FocusedElement;

                Log.Debug("focusedElement is " + ((focusedElement != null) ? "not null" : "null"));
                Log.Debug("_currentfocusedElement is " + ((_currentFocusedElement != null) ? "not null" : "null"));

                bool elementChanged = true;

                var process = GetProcessForWindow(foregroundWindow);

                // check if anything changed. did the window focus change?
                // did focus change within the window?
                if (focusedElement != null &&
                    (_forceGetActiveWindow || flag || foregroundWindow != _currentHwnd || _currentFocusedElement == null ||
                     (elementChanged = IsDifferent(focusedElement, _currentFocusedElement))))
                {
                    //Log.Debug("Reason: _forceGetActiveWindow: " + _forceGetActiveWindow);
                    //Log.Debug("Reason: flag: " + flag);
                    //Log.Debug("Reason: fgHwnd != _currentHwnd : " + (fgHwnd != _currentHwnd));
                    //Log.Debug("Reason: _currentFocusedElement == null : " + (_currentFocusedElement == null));
                    //Log.Debug("Reason: elementChanged : " + elementChanged);

                    if (_forceGetActiveWindow)
                    {
                        _forceGetActiveWindow = false;
                    }

                    if (EvtFocusChanged != null)
                    {
                        var monitorInfo = new WindowActivityMonitorInfo
                        {
                            FgHwnd         = foregroundWindow,
                            Title          = title,
                            FgProcess      = process,
                            FocusedElement = focusedElement,
                            IsNewWindow    = _currentHwnd != foregroundWindow
                        };

                        if (flag)
                        {
                            monitorInfo.IsNewWindow = true;
                        }

                        if (monitorInfo.IsNewWindow || _currentFocusedElement == null || elementChanged)
                        {
                            monitorInfo.IsNewFocusedElement = true;
                        }

#if VERBOSE
                        Log.Debug("#$#>>>>>>>>>>>>>>>> Triggering FOCUS changed event");

                        Log.Debug("#$#    title: " + title);
                        Log.Debug("#$#    fgHwnd " + monitorInfo.FgHwnd);
                        Log.Debug("#$#    nativewinhandle: " + focusedElement.Current.NativeWindowHandle);
                        Log.Debug("#$#    Process: " + process.ProcessName);
                        Log.Debug("#$#    class: " + focusedElement.Current.ClassName);
                        Log.Debug("#$#    controltype:  " + focusedElement.Current.ControlType.ProgrammaticName);
                        Log.Debug("#$#    automationid: " + focusedElement.Current.AutomationId);
                        Log.Debug("#$#    newWindow: " + monitorInfo.IsNewWindow);
                        Log.Debug("#$#    newFocusElement: " + monitorInfo.IsNewFocusedElement);
                        Log.Debug("#$#    IsMinimized :  " + Windows.IsMinimized(monitorInfo.FgHwnd));
#endif

                        if (monitorInfo.IsNewWindow)
                        {
                            AuditLog.Audit(new AuditEventActiveWindowChange(process.ProcessName, title));
                        }

                        if (EvtFocusChanged != null)
                        {
                            EvtFocusChanged(monitorInfo);
                        }

                        _currentFocusedElement = focusedElement;
                    }
                    else
                    {
                        Log.Debug("EvtFocusChanged is null");
                    }
                }

                _currentHwnd = foregroundWindow;

                // raise the heartbeat event
                if (EvtWindowMonitorHeartbeat != null && focusedElement != null && _heartbeatToggle)
                {
                    var monitorInfo = new WindowActivityMonitorInfo
                    {
                        FgHwnd         = foregroundWindow,
                        FocusedElement = focusedElement,
                        Title          = title,
                        FgProcess      = process
                    };
                    EvtWindowMonitorHeartbeat(monitorInfo);
                }

                _heartbeatToggle = !_heartbeatToggle;
            }
            catch (Exception e)
            {
                Log.Debug("exception: " + e);
                _currentFocusedElement = null;
            }
        }