Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.47 KB | None | 0 0
  1. using Sentinel.Kiosk.Core;
  2. using Sentinel.Kiosk.Core.Classes;
  3. using Sentinel.Kiosk.Core.Configuration;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Windows;
  7. using Sentinel.Kiosk.Communication;
  8. using Sentinel.Core;
  9. using Sentinel.Kiosk.Core.Enums;
  10.  
  11. namespace Sentinel.Kiosk
  12. {
  13.     /// <summary>
  14.     /// Interaction logic for App.xaml
  15.     /// </summary>
  16.     public partial class App : Application
  17.     {
  18.  
  19. #if DEBUG
  20.  
  21.         #region Development Settings
  22.  
  23.         enum DevelopmentModes : int
  24.         {
  25.             DevelopmentModeDefault = 0,
  26.             DevelopmentModeArabic = 1,
  27.             DevelopmentModeTestApplication = 2,
  28.             DevelopmentModeEngineer = 3,                            // Sign In
  29.             DevelopmentModeEngineer1 = 4,                           // Administrator
  30.             DevelopmentModeEngineer2 = 5,                           // Engineer
  31.             DevelopmentModeEngineer3 = 6,                           // CIT
  32.             DevelopmentModeEngineerTestMode = 7,
  33.             DevelopmentModeEngineerTestModeReplaceHardware = 8,
  34.             DevelopmentModeEngineerTestModeReplaceConsumable = 9,
  35.         }
  36.  
  37.         enum DevelopmentScreenModes : int
  38.         {
  39.             DevelopmentScreenModeDefault = 0,
  40.             DevelopmentScreenModePortrait = 1,
  41.             DevelopmentScreenModePrimary = 2,
  42.             DevelopmentScreenModeSecondary = 3,
  43.             DevelopmentScreenModeCustom = 4
  44.         }
  45.  
  46.         bool ApplyDevelopmentMode()
  47.         {
  48.             // =============================================================================================
  49.             // Modify
  50.             // =============================================================================================
  51.             DevelopmentModes dm = DevelopmentModes.DevelopmentModeEngineer1;
  52.             DevelopmentScreenModes dsm = DevelopmentScreenModes.DevelopmentScreenModeSecondary;
  53.             // ---------------------------------------------------------------------------------------------
  54.             // Common Settings
  55.             // ---------------------------------------------------------------------------------------------
  56.             bool startupEnabled = false;
  57.             bool timeoutEnabled = true;
  58.             int timeoutInterval = 60;
  59.             // ---------------------------------------------------------------------------------------------
  60.             // Custom Screen Mode Settings
  61.             // ---------------------------------------------------------------------------------------------
  62.             double left = 1920;         // 0 | 1920 | 2560 | -1920
  63.             double top = 0;
  64.             double width = 1920;        // 1920 | 1080
  65.             double height = 1080;       // 1080 | 1920
  66.             double designWidth = 1920;  // 1920 | 1080
  67.             double designHeight = 1080; // 1080 | 1920
  68.             // =============================================================================================
  69.             // Do Not Modify
  70.             // =============================================================================================
  71.             #region Do Not Modify
  72.             bool retVal = false;
  73.             // Set the Default Settings (See KioskConfiguration.cs for additional options)
  74.             KioskHostController.Instance.KioskConfiguration = new KioskConfiguration
  75.             {
  76.                 Version = 0,
  77.                 Description = "Sentinel.Kiosk Development Mode",
  78.                 DebugEnabled = true,
  79.                 TraceEnabled = true,
  80.                 ConsoleEnabled = true,
  81.                 Topmost = false,
  82.                 ShowInTaskbar = true,
  83.                 HideCursor = false,
  84.                 Stretch = System.Windows.Media.Stretch.Uniform,
  85.                 StartupEnabled = startupEnabled,
  86.                 StartupModule = @"{KioskApplicationsPath}Startup\Startup.dll",
  87.                 StartupAssembly = "Startup",
  88.                 StartupPage = "Pages/StartupPage.xaml",
  89.                 StartupData = null,
  90.                 StartupDelay = 3000,
  91.                 AdministrationEnabled = true,
  92.                 AdministrationModule = @"{KioskApplicationsPath}Engineer\Engineer.dll",
  93.                 AdministrationAssembly = "Engineer",
  94.                 AdministrationPage = "Pages/Engineer.xaml",
  95.                 AdministrationData = null,
  96.                 OfflineEnabled = true,
  97.                 OfflineModule = @"{KioskApplicationsPath}Offline\Offline.dll",
  98.                 OfflineAssembly = "Offline",
  99.                 OfflinePage = "Pages/OfflinePage.xaml",
  100.                 OfflineData = null,
  101.                 ClosedEnabled = true,
  102.                 ClosedModule = @"{KioskApplicationsPath}Closed\Closed.dll",
  103.                 ClosedAssembly = "Closed",
  104.                 ClosedPage = "Pages/ClosedPage.xaml",
  105.                 ClosedData = null,
  106.                 AttractLoopEnabled = true,
  107.                 AttractLoopModule = @"{KioskApplicationsPath}AttractLoop\AttractLoop.dll",
  108.                 AttractLoopAssembly = "AttractLoop",
  109.                 AttractLoopPage = "Pages/AttractLoopPage.xaml",
  110.                 AttractLoopData = null,
  111.                 HomeEnabled = true,
  112.                 HomeModule = @"{KioskApplicationsPath}DynamicDispatcher\DynamicDispatcher.dll",
  113.                 HomeAssembly = "DynamicDispatcher",
  114.                 HomePage = "Pages/DynamicDispatcherPage.xaml",
  115.                 HomeData = null,
  116.                 TimeoutEnabled = timeoutEnabled,
  117.                 TimeoutModule = @"{KioskApplicationsPath}Timeout\Timeout.dll",
  118.                 TimeoutAssembly = "Timeout",
  119.                 TimeoutPage = "Pages/TimeoutPage.xaml",
  120.                 TimeoutData = null,
  121.                 TimeoutInterval = timeoutInterval,
  122.                 TimeoutShowDialog = false,
  123.                 TransitionEnabled = true,
  124.                 TransitionType = TransitionTypes.Fade,
  125.                 OverlayTransitionType = TransitionTypes.Fade,
  126.                 TimeoutTransitionType = TransitionTypes.Fade
  127.             };
  128.             // Apply the Development Mode
  129.             switch (dm)
  130.             {
  131.                 case DevelopmentModes.DevelopmentModeArabic:
  132.                     KioskHostController.Instance.KioskConfiguration.DefaultLanguage = "ar-SA";
  133.                     KioskHostController.Instance.KioskConfiguration.DefaultFlowDirection = System.Windows.FlowDirection.RightToLeft;
  134.                     break;
  135.                 case DevelopmentModes.DevelopmentModeTestApplication:
  136.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}TestApplication1\TestApplication1.dll";
  137.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "TestApplication1";
  138.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/HomePage.xaml";
  139.                     break;
  140.                 case DevelopmentModes.DevelopmentModeEngineer:
  141.                     KioskHostController.Instance.KioskConfiguration.StartupEnabled = false;
  142.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  143.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  144.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  145.                     break;
  146.                 case DevelopmentModes.DevelopmentModeEngineer1:
  147.                     KioskHostController.Instance.KioskConfiguration.StartupEnabled = false;
  148.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  149.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  150.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  151.                     KioskHostController.Instance.KioskConfiguration.HomeData = "BypassAuthentication1";
  152.                     break;
  153.                 case DevelopmentModes.DevelopmentModeEngineer2:
  154.                     KioskHostController.Instance.KioskConfiguration.StartupEnabled = false;
  155.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  156.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  157.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  158.                     KioskHostController.Instance.KioskConfiguration.HomeData = "BypassAuthentication2";
  159.                     break;
  160.                 case DevelopmentModes.DevelopmentModeEngineer3:
  161.                     KioskHostController.Instance.KioskConfiguration.StartupEnabled = false;
  162.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  163.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  164.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  165.                     KioskHostController.Instance.KioskConfiguration.HomeData = "BypassAuthentication3";
  166.                     break;
  167.                 case DevelopmentModes.DevelopmentModeEngineerTestMode:
  168.                     KioskHostController.Instance.KioskConfiguration.AttractLoopModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  169.                     KioskHostController.Instance.KioskConfiguration.AttractLoopAssembly = "Engineer";
  170.                     KioskHostController.Instance.KioskConfiguration.AttractLoopPage = "Pages/EngineerTestMode.xaml";
  171.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  172.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  173.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  174.                     KioskHostController.Instance.KioskConfiguration.HomeData = null; // null | BypassAuthentication | TestReplaceHardware1 | TestReplaceConsumable1
  175.                     retVal = true;
  176.                     break;
  177.                 case DevelopmentModes.DevelopmentModeEngineerTestModeReplaceHardware:
  178.                     KioskHostController.Instance.KioskConfiguration.AttractLoopModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  179.                     KioskHostController.Instance.KioskConfiguration.AttractLoopAssembly = "Engineer";
  180.                     KioskHostController.Instance.KioskConfiguration.AttractLoopPage = "Pages/EngineerTestMode.xaml";
  181.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  182.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  183.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  184.                     KioskHostController.Instance.KioskConfiguration.HomeData = "TestReplaceHardware1"; // BypassAuthentication | TestReplaceHardware1 | TestReplaceConsumable1
  185.                     retVal = true;
  186.                     break;
  187.                 case DevelopmentModes.DevelopmentModeEngineerTestModeReplaceConsumable:
  188.                     KioskHostController.Instance.KioskConfiguration.AttractLoopModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  189.                     KioskHostController.Instance.KioskConfiguration.AttractLoopAssembly = "Engineer";
  190.                     KioskHostController.Instance.KioskConfiguration.AttractLoopPage = "Pages/EngineerTestMode.xaml";
  191.                     KioskHostController.Instance.KioskConfiguration.HomeModule = @"{KioskApplicationsPath}Engineer\Engineer.dll";
  192.                     KioskHostController.Instance.KioskConfiguration.HomeAssembly = "Engineer";
  193.                     KioskHostController.Instance.KioskConfiguration.HomePage = "Pages/Engineer.xaml";
  194.                     KioskHostController.Instance.KioskConfiguration.HomeData = "TestReplaceConsumable1"; // BypassAuthentication | TestReplaceHardware1 | TestReplaceConsumable1
  195.                     retVal = true;
  196.                     break;
  197.                 default: // DevelopmentModes.DevelopmentModeDefault
  198.                     // Uses default constructor settings
  199.                     break;
  200.             }
  201.             // Apply the Development Screen Mode
  202.             System.Drawing.Rectangle primaryWorkingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
  203.             switch (dsm)
  204.             {
  205.                 case DevelopmentScreenModes.DevelopmentScreenModePortrait:
  206.                     KioskHostController.Instance.KioskConfiguration.FullScreen = false;
  207.                     KioskHostController.Instance.KioskConfiguration.Left = left;
  208.                     KioskHostController.Instance.KioskConfiguration.Top = top;
  209.                     KioskHostController.Instance.KioskConfiguration.Width = 1080;
  210.                     KioskHostController.Instance.KioskConfiguration.Height = 1920;
  211.                     KioskHostController.Instance.KioskConfiguration.DesignWidth = 1080;
  212.                     KioskHostController.Instance.KioskConfiguration.DesignHeight = 1920;
  213.                     break;
  214.                 case DevelopmentScreenModes.DevelopmentScreenModePrimary:
  215.                     KioskHostController.Instance.KioskConfiguration.FullScreen = false;
  216.                     KioskHostController.Instance.KioskConfiguration.Left = primaryWorkingArea.X;
  217.                     KioskHostController.Instance.KioskConfiguration.Top = primaryWorkingArea.Y;
  218.                     KioskHostController.Instance.KioskConfiguration.Width = primaryWorkingArea.Width;
  219.                     KioskHostController.Instance.KioskConfiguration.Height = primaryWorkingArea.Height;
  220.                     KioskHostController.Instance.KioskConfiguration.DesignWidth = designWidth;
  221.                     KioskHostController.Instance.KioskConfiguration.DesignHeight = designHeight;
  222.                     break;
  223.                 case DevelopmentScreenModes.DevelopmentScreenModeSecondary:  
  224.                     foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
  225.                     {
  226.                         if (!screen.Primary)
  227.                         {
  228.                             primaryWorkingArea = screen.WorkingArea;
  229.                             break;
  230.                         }
  231.                     }                
  232.                     KioskHostController.Instance.KioskConfiguration.FullScreen = false;
  233.                     KioskHostController.Instance.KioskConfiguration.Left = primaryWorkingArea.X;
  234.                     KioskHostController.Instance.KioskConfiguration.Top = primaryWorkingArea.Y;
  235.                     KioskHostController.Instance.KioskConfiguration.Width = primaryWorkingArea.Width;
  236.                     KioskHostController.Instance.KioskConfiguration.Height = primaryWorkingArea.Height;
  237.                     KioskHostController.Instance.KioskConfiguration.DesignWidth = designWidth;
  238.                     KioskHostController.Instance.KioskConfiguration.DesignHeight = designHeight;
  239.                     break;
  240.                 case DevelopmentScreenModes.DevelopmentScreenModeCustom:
  241.                     KioskHostController.Instance.KioskConfiguration.FullScreen = false;
  242.                     KioskHostController.Instance.KioskConfiguration.Left = left;
  243.                     KioskHostController.Instance.KioskConfiguration.Top = top;
  244.                     KioskHostController.Instance.KioskConfiguration.Width = width;
  245.                     KioskHostController.Instance.KioskConfiguration.Height = height;
  246.                     KioskHostController.Instance.KioskConfiguration.DesignWidth = designWidth;
  247.                     KioskHostController.Instance.KioskConfiguration.DesignHeight = designHeight;
  248.                     break;
  249.                 default: // DevelopmentScreenModes.DevelopmentScreenModeDefault
  250.                     KioskHostController.Instance.KioskConfiguration.FullScreen = true;
  251.                     KioskHostController.Instance.KioskConfiguration.Left = 0;
  252.                     KioskHostController.Instance.KioskConfiguration.Top = 0;
  253.                     KioskHostController.Instance.KioskConfiguration.Width = 1920;
  254.                     KioskHostController.Instance.KioskConfiguration.Height = 1080;
  255.                     KioskHostController.Instance.KioskConfiguration.DesignWidth = 1920;
  256.                     KioskHostController.Instance.KioskConfiguration.DesignHeight = 1080;
  257.                     break;
  258.             }
  259.             // Save the Configuration: Default or Engineer Test Mode
  260.             if (!retVal)
  261.                 // Default
  262.                 KioskHostController.Instance.KioskConfiguration.Save(Path.Combine(Paths.KioskDataPath, KioskConfiguration.CONFIGURATION_FILENAME));
  263.             else
  264.                 // Engineer Test Mode
  265.                 KioskHostController.Instance.KioskConfiguration.Save(Path.Combine(Paths.KioskDataPath, KioskConfiguration.ENGINEER_TEST_MODE_CONFIGURATION_FILENAME));
  266.             // Return
  267.             return retVal;
  268.             #endregion
  269.         }
  270.  
  271.         #endregion
  272.  
  273. #endif
  274.  
  275.         private void Application_Startup(object sender, StartupEventArgs e)
  276.         {
  277.             bool loadEngineerTestModeConfiguration = false;
  278.             if (e.Args.Length > 0)
  279.             {
  280.                 for (int i = 0; i != e.Args.Length; ++i)
  281.                 {
  282.                     if (e.Args[i] == "/EngineerTestMode")
  283.                     {
  284.                         loadEngineerTestModeConfiguration = true;
  285.                     }
  286.                 }
  287.             }
  288.  
  289. #if DEBUG
  290.  
  291.             loadEngineerTestModeConfiguration = ApplyDevelopmentMode();
  292.  
  293. #endif
  294.  
  295.             // Set the Application in Engineer Test Mode
  296.             if (loadEngineerTestModeConfiguration && File.Exists(Path.Combine(Paths.KioskDataPath, KioskConfiguration.ENGINEER_TEST_MODE_CONFIGURATION_FILENAME)))
  297.             {
  298.                 // Add the Global Test Mode Variables
  299.                 GlobalVariables.Instance.Variables["Sentinel.Kiosk.EngineerTestMode"] = true;
  300.                 // Load the Test Mode Configuration
  301.                 KioskHostController.Instance.KioskConfiguration = KioskConfiguration.Load(Path.Combine(Paths.KioskDataPath, KioskConfiguration.ENGINEER_TEST_MODE_CONFIGURATION_FILENAME));
  302.             }
  303.             else
  304.             {
  305.                 // Load the Runtime Configuration
  306.                 KioskHostController.Instance.KioskConfiguration = KioskConfiguration.Load(Path.Combine(Paths.KioskDataPath, KioskConfiguration.CONFIGURATION_FILENAME));
  307.             }
  308.             // Start the Message Server
  309.             bool startServerRes = InterAppMsgServer.Instance.StartServer(KioskHostController.Instance.KioskConfiguration.CommunicationAddress);
  310.             // Only let one instance of the application run?
  311.             if (KioskHostController.Instance.KioskConfiguration.SingleInstance)
  312.                 if ((Process.GetProcessesByName(ResourceAssembly.GetName().Name).Length > 1))
  313.                     Current.Shutdown();
  314.             // Ignore unhandled exceptions when the process terminates unexpectedly
  315.             if (KioskHostController.Instance.KioskConfiguration.UnhandledExceptionFilterEnabled)
  316.                 ExceptionHandler.DisableExceptionReport();
  317.             // Add the Kiosk Configuration
  318.             GlobalVariables.Instance.Variables.Add("Sentinel.Kiosk.Configuration", KioskHostController.Instance.KioskConfiguration);
  319.             KioskHostController.Instance.KioskConfiguration.PropertyChanged += KioskConfiguration_PropertyChanged;
  320.         }
  321.  
  322.         private void KioskConfiguration_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  323.         {
  324.             GlobalVariables.Instance.Variables.NotifyObserversOfChange("Sentinel.Kiosk.Configuration");
  325.         }
  326.  
  327.         private void Application_Exit(object sender, ExitEventArgs e)
  328.         {
  329.             // N/A
  330.         }
  331.  
  332.         private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  333.         {
  334.             try
  335.             {
  336.                 // Unexpected error, log this to the system
  337.                 LogController.Instance.LogSystemEvent(e.Exception);
  338.                 // Handle the Event
  339.                 e.Handled = KioskHostController.Instance.KioskConfiguration.IgnoreUnhandledExceptions;
  340.             }
  341.             catch (System.Exception)
  342.             {
  343.                 // Handle the Event
  344.                 e.Handled = true;
  345.             }
  346.         }
  347.     }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement