internal void InitializeOnceAtStartup(EgsHostAppBaseComponents egsHostAppBaseComponents) { Trace.Assert(egsHostAppBaseComponents != null); ownerEgsHostAppBaseComponents = egsHostAppBaseComponents; // TODO: low priority. Decide the specification about multiple device connections. deviceIsConnectedIcon = new Icon("Resources/HandIcon_DeviceIsConnected.ico", new Size(16, 16)); deviceIsNotConnectedIcon = new Icon("Resources/HandIcon_DeviceIsDisconnected.ico", new Size(16, 16)); OnBindableResourcesCurrentCultureChanged(); ownerEgsHostAppBaseComponents.Device.IsConnectedChanged += (sender, e) => { // NOTE: Before I derived this class from System.Windows.Forms.Form, and it caused various problems. Now I derive this class from System.ComponentModel.Component, it solved the problems. try { // MUSTDO: FIX: In some cases, NullReferenceException occurs, after I changed the update way of IsConnected. if (deviceIsConnectedIcon != null && deviceIsNotConnectedIcon != null) { notifyIconInTray.Icon = ownerEgsHostAppBaseComponents.Device.IsConnected ? deviceIsConnectedIcon : deviceIsNotConnectedIcon; } IsConnectedMenuItemLabel.Text = ownerEgsHostAppBaseComponents.Device.DeviceStatusString; } catch (Exception ex) { if (ApplicationCommonSettings.IsDebugging) { Debugger.Break(); } Debug.WriteLine(ex.Message); } }; ownerEgsHostAppBaseComponents.CameraViewWindowModel.WindowStateChanged += CameraViewWindowModel_WindowStateChanged; ownerEgsHostAppBaseComponents.SettingsWindow.IsVisibleChanged += SettingsWindow_IsVisibleChanged; notifyIconInTray.MouseDoubleClick += (sender, e) => { ownerEgsHostAppBaseComponents.CameraViewWindowModel.ToggleWindowStateControlMethodOnAutoOrOff(); }; CameraViewMenuItem.Click += (sender, e) => { ownerEgsHostAppBaseComponents.CameraViewWindowModel.ToggleWindowStateControlMethodOnAutoOrOff(); }; SettingsMenuItem.Click += (sender, e) => { ownerEgsHostAppBaseComponents.SettingsWindow.ToggleVisibility(); }; ExitMenuItem.Click += (sender, e) => { ownerEgsHostAppBaseComponents.Dispose(); }; notifyIconInTray.Visible = true; notifyIconInTray.Icon = ownerEgsHostAppBaseComponents.Device.IsConnected ? deviceIsConnectedIcon : deviceIsNotConnectedIcon; IsConnectedMenuItemLabel.Text = ownerEgsHostAppBaseComponents.Device.DeviceStatusString; CameraViewMenuItem.Checked = ownerEgsHostAppBaseComponents.CameraViewWindowModel.IsNormalOrElseMinimized; SettingsMenuItem.Checked = ownerEgsHostAppBaseComponents.SettingsWindow.IsVisible; }
public ZkooTutorialModel(EgsHostAppBaseComponents hostApp) { Trace.Assert(hostApp != null); RefToHostApp = hostApp; CurrentResources = new ZkooTutorialResourcesModel(); Launcher = new LauncherPageModel(); TutorialAppHeaderMenu = new TutorialAppHeaderMenuViewModel(); Tutorial01StartGestureTraining = new Tutorial01StartGestureTrainingPageModel(); Tutorial02MoveCursorTraining = new Tutorial02MoveCursorTrainingPageModel(); Tutorial03TapGestureTraining = new Tutorial03TapGestureTrainingPageModel(); Tutorial04DragGestureTraining = new Tutorial04DragGestureTrainingPageModel(); Tutorial05FlickGestureTraining = new Tutorial05FlickGestureTrainingPageModel(); TutorialLargeCircleAreaButtonRightTop = new TutorialLargeCircleAreaButtonModel() { Index = 0, ImageSourceDisabledFileName = "tutorial_common_circle1_button_disabled.png", ImageSourcePressedFileName = "tutorial_common_circle1_button_pressed.png", ImageSourceHoveredFileName = "tutorial_common_circle1_button_hovered.png", ImageSourceSelectedFileName = "tutorial_common_circle1_button_pressed.png", ImageSourceEnabledFileName = "tutorial_common_circle1_button_enabled.png", }; TutorialLargeCircleAreaButtonRightBottom = new TutorialLargeCircleAreaButtonModel() { Index = 1, ImageSourceDisabledFileName = "tutorial_common_circle2_button_disabled.png", ImageSourcePressedFileName = "tutorial_common_circle2_button_pressed.png", ImageSourceHoveredFileName = "tutorial_common_circle2_button_hovered.png", ImageSourceSelectedFileName = "tutorial_common_circle2_button_pressed.png", ImageSourceEnabledFileName = "tutorial_common_circle2_button_enabled.png", }; TutorialLargeCircleAreaButtonLeftBottom = new TutorialLargeCircleAreaButtonModel() { Index = 2, ImageSourceDisabledFileName = "tutorial_common_circle3_button_disabled.png", ImageSourcePressedFileName = "tutorial_common_circle3_button_pressed.png", ImageSourceHoveredFileName = "tutorial_common_circle3_button_hovered.png", ImageSourceSelectedFileName = "tutorial_common_circle3_button_pressed.png", ImageSourceEnabledFileName = "tutorial_common_circle3_button_enabled.png", }; TutorialLargeCircleAreaButtonLeftTop = new TutorialLargeCircleAreaButtonModel() { Index = 3, ImageSourceDisabledFileName = "tutorial_common_circle4_button_disabled.png", ImageSourcePressedFileName = "tutorial_common_circle4_button_pressed.png", ImageSourceHoveredFileName = "tutorial_common_circle4_button_hovered.png", ImageSourceSelectedFileName = "tutorial_common_circle4_button_pressed.png", ImageSourceEnabledFileName = "tutorial_common_circle4_button_enabled.png", }; }
public FaceDetectionCompletedEventExample1App() : base() { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = "FaceDetectionCompletedEventExample1"; }; Egs.BindableResources.Current.ChangeCulture(""); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); Application.Current.Shutdown(); return; } ApplicationCommonSettings.IsDebugging = true; Components = new EgsHostAppBaseComponents(); Components.InitializeOnceAtStartup(); Components.Device.Settings.FaceDetectionMethod.Value = Egs.PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication; Components.CameraViewWindow.KeyDown += (sender, e) => { switch (e.Key) { case System.Windows.Input.Key.Escape: Components.CameraViewWindow.Close(); break; } }; Components.Device.FaceDetectionOnHost.FaceDetectionCompleted += FaceDetectionOnHost_FaceDetectionCompleted; Window = new FaceDetectionCompletedEventExample1MainWindow(); this.Exit += delegate { Window.Close(); if (Components != null) { Components.Dispose(); Components = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; }
public void InitializeOnceAtStartup(EgsHostAppBaseComponents hostApp) { Trace.Assert(hostApp != null); RefToHostApp = hostApp; if (ApplicationCommonSettings.IsDebuggingInternal) { CheckIfAllSoundFilesExistOrNot(); } RefToHostApp.CameraViewWindowModel.WindowStateHostApplicationsControlMethod.Value = CameraViewWindowStateHostApplicationsControlMethods.KeepMinimized; RefToHostApp.CameraViewBordersAndPointersAreDrawnBy.Value = CameraViewBordersAndPointersAreDrawnByKind.HostApplication; RefToHostApp.Device.Settings.IsToSendTouchScreenHidReport.Value = true; // In Windows 10, users cannot often tap by sending Hovering State if (false) { RefToHostApp.Device.Settings.IsToSendHoveringStateOnTouchScreenHidReport.Value = true; } RefToHostApp.Device.Settings.IsToSendEgsGestureHidReport.Value = true; // Now this settings cannot be set from SettingsWindow, so I comment out the next line. RefToHostApp.Device.Settings.IsToDrawBordersOnCameraViewImageByDevice.Value = false; Launcher.InitializeOnceAtStartup(this); RefToHostApp.OnePersonBothHandsViewModel.RightHand.IsToUpdateVelocities = false; RefToHostApp.OnePersonBothHandsViewModel.LeftHand.IsToUpdateVelocities = false; TutorialLargeCircleAreaButtonList = new List <TutorialLargeCircleAreaButtonModel>(); TutorialLargeCircleAreaButtonList.Add(TutorialLargeCircleAreaButtonRightTop); TutorialLargeCircleAreaButtonList.Add(TutorialLargeCircleAreaButtonRightBottom); TutorialLargeCircleAreaButtonList.Add(TutorialLargeCircleAreaButtonLeftBottom); TutorialLargeCircleAreaButtonList.Add(TutorialLargeCircleAreaButtonLeftTop); Tutorial01StartGestureTraining.InitializeOnceAtStartup(this); Tutorial02MoveCursorTraining.InitializeOnceAtStartup(this); Tutorial03TapGestureTraining.InitializeOnceAtStartup(this); Tutorial04DragGestureTraining.InitializeOnceAtStartup(this); Tutorial05FlickGestureTraining.InitializeOnceAtStartup(this); OnCultureInfoChanged(); }
void ShutdownApplicationByException(Exception ex) { if (ex is EgsHostApplicationIsClosingException) { // NOTE: Assuming that this is the correct way to shutdown the application. MessageBox.Show(Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_ApplicationWillExit, ApplicationCommonSettings.HostApplicationName, MessageBoxButton.OK); if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } } else { // NOTE: This is not handled exceptions. At first it saves safer settings, and then it shows "we're sorry" window. try { // NOTE: But in some cases, application is already shutdown, so this code itself can occur exceptions var window = new NotHandledExceptionReportWindow(); window.Initialize(ex); window.ShowDialog(); } catch (Exception ex2) { if (ApplicationCommonSettings.IsDebugging) { Debugger.Break(); } MessageBox.Show(ex2.Message); } } if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } if (Application.Current != null) { Application.Current.Shutdown(); } DuplicatedProcessStartBlocking.ReleaseMutex(); }
public ZkooHostAppWithTutorialApplication() : base() { // TODO: Check the correct way to catch all exceptions and show it "We're sorry" dialog. But the next way is still meaningless now, and sometimes this code can cause a problem that application cannot exit. //AppDomain.CurrentDomain.UnhandledException += (sender, e) => { ShutdownApplicationByException((Exception)e.ExceptionObject); }; try { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Zkoo; Egs.ZkooTutorial.BindableResources.Current.ChangeCulture(Egs.EgsDeviceControlCore.Properties.Resources.Culture.Name); }; Egs.BindableResources.Current.ChangeCulture(ApplicationCommonSettings.DefaultCultureInfoName); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); if (Application.Current != null) { Application.Current.Shutdown(); } return; } hostAppComponents = new EgsHostAppBaseComponents(); hostAppComponents.InitializeOnceAtStartup(); hostAppComponents.HasResetSettings += delegate { // You can modify the application default settings here. hostAppComponents.Device.Settings.FaceDetectionMethod.Value = Egs.PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication; hostAppComponents.IsToStartTutorialWhenHostApplicationStart = true; }; if (SettingsSerialization.LoadSettingsJsonFile(hostAppComponents) == false) { hostAppComponents.Reset(); } hostAppComponents.CameraViewWindow.Closed += delegate { hostAppComponents.Dispose(); }; hostAppComponents.Disposing += delegate { // NOTE: Save settings before Dispose(). Target event is not Disposed but Disposing. if (hostAppComponents.CanSaveSettingsJsonFileSafely) { SettingsSerialization.SaveSettingsJsonFile(hostAppComponents); } if (navigator != null) { // detach static event Microsoft.Win32.SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; } // NOTE: IMPORTANT! if (navigator != null) { navigator.Close(); navigator = null; } zkooTutorialModel = null; }; base.Exit += delegate { if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; hostAppComponents.CheckIfDeviceFirmwareIsLatestOrNotAndExitApplicationIfFailed(); // NOTE: If users exit the application by the button on Camera View while "Firmware Update" dialog, exception occurs. // MUSTDO: We will fix this. if (hostAppComponents.SettingsWindow == null) { return; } // NOTE: Codes about "Tutorial" application. // TODO: Tutorial application should be independent from this host application, so I wrote it as an event handler. var hasZkooTutorialLaunched = false; var zkooTutorialLaunchAction = new Action(() => { if (hasZkooTutorialLaunched == false) { zkooTutorialModel = new ZkooTutorialModel(hostAppComponents); navigator = new MainNavigationWindow(); // attach static event Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; // NOTE: TODO: When exceptions occur in Initialize, we have to distinguish whether from Settings files or from source code. zkooTutorialModel.TutorialAppHeaderMenu.InitializeOnceAtStartup(navigator, zkooTutorialModel); zkooTutorialModel.InitializeOnceAtStartup(hostAppComponents); navigator.InitializeOnceAtStartup(zkooTutorialModel); hasZkooTutorialLaunched = true; } navigator.StartTutorial(); }); hostAppComponents.SettingsWindow.SettingsUserControl.TutorialAppSettingsGroupBoxVisibility = Visibility.Visible; hostAppComponents.StartTutorialCommand.PerformEventHandler += delegate { zkooTutorialLaunchAction.Invoke(); }; hostAppComponents.IsStartingDeviceFirmwareUpdate += delegate { if (navigator != null) { navigator.ExitTutorial(); } }; hostAppComponents.IsStartingHostApplicationUpdate += delegate { if (navigator != null) { navigator.ExitTutorial(); } }; if (ApplicationCommonSettings.IsInternalRelease || ApplicationCommonSettings.IsDebuggingInternal) { var exvisionInternalSettingsTabItem = new System.Windows.Controls.TabItem() { Header = "Exvision" }; exvisionInternalSettingsTabItem.Content = new Egs.Views.ExvisionSettingsUserControl(); hostAppComponents.SettingsWindow.SettingsUserControl.SettingsTabControl.Items.Add(exvisionInternalSettingsTabItem); } if (hostAppComponents.IsToStartTutorialWhenHostApplicationStart) { zkooTutorialLaunchAction.Invoke(); } } catch (Exception ex) { ShutdownApplicationByException(ex); } }
public ZkooHostAppApplication() : base() { hostAppComponents = null; try { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_GestureCamera; }; Egs.BindableResources.Current.ChangeCulture(ApplicationCommonSettings.DefaultCultureInfoName); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); if (Application.Current != null) { Application.Current.Shutdown(); } return; } hostAppComponents = new EgsHostAppBaseComponents(); hostAppComponents.InitializeOnceAtStartup(); hostAppComponents.HasResetSettings += delegate { // You can modify the application default settings here. hostAppComponents.Device.Settings.CursorSpeedAndPrecisionMode.Value = Egs.PropertyTypes.CursorSpeedAndPrecisionModes.Standard; hostAppComponents.Device.Settings.FaceDetectionMethod.Value = Egs.PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication; }; if (SettingsSerialization.LoadSettingsJsonFile(hostAppComponents) == false) { hostAppComponents.Reset(); } hostAppComponents.CameraViewWindow.Closed += delegate { hostAppComponents.Dispose(); }; hostAppComponents.Disposing += delegate { // NOTE: Save settings before Dispose(). Target event is not Disposed but Disposing. if (hostAppComponents.CanSaveSettingsJsonFileSafely) { SettingsSerialization.SaveSettingsJsonFile(hostAppComponents); } }; base.Exit += delegate { if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; hostAppComponents.CheckIfDeviceFirmwareIsLatestOrNotAndExitApplicationIfFailed(); // NOTE: If users exit the application by the button on Camera View while "Firmware Update" dialog, exception occurs. // MUSTDO: We will fix this. if (hostAppComponents.SettingsWindow == null) { return; } // TODO: The tutorial program will be separated into an independent application. hostAppComponents.SettingsWindow.SettingsUserControl.TutorialAppSettingsGroupBoxVisibility = Visibility.Collapsed; hostAppComponents.StartTutorialCommand.CanPerform = false; } catch (Exception ex) { ShutdownApplicationByException(ex); } }
public App() : base() { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_GestureCamera; //ApplicationCommonSettings.HostApplicationName = "WpfApplication1"; }; // You can change the application CultureInfo to some cultures. // The next line lets it use OS culture Egs.BindableResources.Current.ChangeCulture(""); //Egs.BindableResources.Current.ChangeCulture(ApplicationCommonSettings.DefaultCultureInfoName); //Egs.BindableResources.Current.ChangeCulture("en"); //Egs.BindableResources.Current.ChangeCulture("ja"); //Egs.BindableResources.Current.ChangeCulture("zh-Hans"); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { // Currently, the ZkooHostApp is not service, so only one instance can run. var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); Application.Current.Shutdown(); return; } // The next line shows "Developer" tab on SettingsWindow. ApplicationCommonSettings.IsDebugging = true; // This object has all Views and Models var hostAppComponents = new EgsHostAppBaseComponents(); // A lot of classes in "Egs" namespace have "InitializeOnceAtStartup..." methods. Please call them. hostAppComponents.InitializeOnceAtStartup(); hostAppComponents.HasResetSettings += delegate { // You can modify the application default settings here. hostAppComponents.Device.Settings.CursorSpeedAndPrecisionMode.Value = Egs.PropertyTypes.CursorSpeedAndPrecisionModes.Standard; }; hostAppComponents.CameraViewWindow.KeyDown += (sender, e) => { switch (e.Key) { case System.Windows.Input.Key.Escape: // NOTE: The specification changed. // When you use EgsHostAppBaseComponents, it disposes itself when CameraViewWindow is closed. // So you need not to attach "event handler which calls host.Dispose()" to "event CameraViewWindow.Closed". hostAppComponents.CameraViewWindow.Close(); break; } }; this.Exit += delegate { if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; }
public void InitializeOnceAtStartup(EgsHostAppBaseComponents host) { // NOTE: The settings window set the settings of CameraViewWindowModel, so the type of the argument is not EgsHostOnUserControl but EgsHostAppBaseComponents. Trace.Assert(host != null); this.DataContext = host; }