Esempio n. 1
0
        private void UserControlLoaded(UserControl1 control)
        {
            // The user control should be set here for easy accessibility
            // This leaves the UIElement variable alone to be dealt with by the DeskBand parent functionality
            deskbandControl = control;

            // Provide the function in this class that performs the device enable/disable action
            deskbandControl.SetEnabledDisabledDeviceFunction(EnableDisableDevice);

            // Provide the function to show the settings window
            deskbandControl.SetShowSettingsWindowFunction(ShowSettingsWindow);

            // Initialise the connection to the Windows service
            if (InitialiseServiceConnection(false))
            {
                // Get the selected touch screen device hardware ID
                try
                {
                    string deviceHardwareId = TTService.GetSelectedHardwareID();
                    if (deviceHardwareId == null)
                    {
                        // If no ID is specified, show the settings window
                        ShowSettingsWindow();
                    }
                }
                catch (CommunicationException)
                {
                    // Do nothing
                }
            }

            // Set up the watcher for hardware changes
            WqlEventQuery          query   = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent");
            ManagementEventWatcher watcher = new ManagementEventWatcher(query);

            watcher.EventArrived += new EventArrivedEventHandler(HardwareChangeEvent);
            watcher.Start();

            // Set the serivce connection ticker event
            serviceConnectionTicker.Elapsed += (object source, System.Timers.ElapsedEventArgs e2) =>
            {
                if (TTService != null)
                {
                    // If a connection exists
                    try
                    {
                        // Test the connection
                        TTService.TestServiceConnection();
                    }
                    catch (CommunicationException)
                    {
                        // Retry the connection
                        ServiceCommunicationFailure(false);
                    }
                }
                else
                {
                    // Attempt to make a connection
                    InitialiseServiceConnection(allowUserAdminActionInput: false);
                }
            };
        }