protected override void OnClick(EventArgs e)
 {
     try
     {
         SEBWindowHandler.BringWindowToTop(SEBWindowHandler.GetOpenWindows().First <KeyValuePair <IntPtr, string> >((Func <KeyValuePair <IntPtr, string>, bool>)(w => w.Key.GetProcess().GetExecutableName().Contains("xul"))).Key);
         if ((bool)SEBSettings.settingsCurrent["touchOptimized"])
         {
             if ((bool)SEBSettings.settingsCurrent["showReloadWarning"])
             {
                 if (SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage, MessageBoxIcon.Exclamation, MessageBoxButtons.YesNo, false) != DialogResult.Yes)
                 {
                     return;
                 }
                 SEBXULRunnerWebSocketServer.SendReloadPage();
             }
             else
             {
                 SEBXULRunnerWebSocketServer.SendReloadPage();
             }
         }
         else
         {
             SEBXULRunnerWebSocketServer.SendReloadPage();
         }
     }
     catch
     {
     }
 }
        protected override void OnClick(EventArgs e)
        {
            try
            {
                SEBWindowHandler.BringWindowToTop(
                    SEBWindowHandler.GetOpenWindows()
                    .First(w => w.Key.GetProcess().GetExecutableName().Contains("xul")).Key);

                if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyTouchOptimized])
                {
                    if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyShowReloadWarning])
                    {
                        if (
                            SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage,
                                               MessageBoxIcon.Warning, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            SEBXULRunnerWebSocketServer.SendReloadPage();
                        }
                    }
                    else
                    {
                        SEBXULRunnerWebSocketServer.SendReloadPage();
                    }
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendReloadPage();
                }
            }
            catch {}
        }
Ejemplo n.º 3
0
        private void OpenResource(DictObj resource)
        {
            var showMessage = resource[SEBSettings.KeyAdditionalResourcesConfirm] is true;

            if (showMessage)
            {
                var title          = resource[SEBSettings.KeyAdditionalResourcesTitle] as string;
                var customMessage  = resource[SEBSettings.KeyAdditionalResourcesConfirmText] as string;
                var defaultMessage = SEBUIStrings.AdditionalResourceConfirmMessage;
                var message        = (String.IsNullOrWhiteSpace(customMessage) ? defaultMessage : customMessage).Replace("%%TITLE%%", title);
                var result         = SEBMessageBox.Show(SEBUIStrings.AdditionalResourceConfirmTitle, message, MessageBoxIcon.Question, MessageBoxButtons.YesNo);

                if (result != DialogResult.Yes)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty((string)resource[SEBSettings.KeyAdditionalResourcesResourceData]))
            {
                OpenEmbededResource(resource);
            }
            else if (!string.IsNullOrEmpty((string)resource[SEBSettings.KeyAdditionalResourcesUrl]))
            {
                SEBXULRunnerWebSocketServer.SendMessage(new SEBXULMessage(SEBXULMessage.SEBXULHandler.AdditionalResources, new { id = resource[SEBSettings.KeyAdditionalResourcesIdentifier] }));
            }
        }
Ejemplo n.º 4
0
        protected override void OnClick(EventArgs e)
        {
            string restartExamTitle = (String)SEBClientInfo.getSebSetting(SEBSettings.KeyRestartExamText)[SEBSettings.KeyRestartExamText];

            // If there was no individual restart exam text set, we use the default text (which is localized)
            if (String.IsNullOrEmpty(restartExamTitle))
            {
                restartExamTitle = SEBUIStrings.restartExamDefaultTitle;
            }

            string quitPassword = (String)SEBClientInfo.getSebSetting(SEBSettings.KeyHashedQuitPassword)[SEBSettings.KeyHashedQuitPassword];

            if ((Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyRestartExamPasswordProtected)[SEBSettings.KeyRestartExamPasswordProtected] && !String.IsNullOrWhiteSpace(quitPassword))
            {
                var password = SebPasswordDialogForm.ShowPasswordDialogForm(restartExamTitle, SEBUIStrings.restartExamEnterPassword);

                //cancel button has been clicked
                if (password == null)
                {
                    return;
                }

                var hashedPassword = SEBProtectionController.ComputePasswordHash(password);
                if (String.IsNullOrWhiteSpace(password) ||
                    String.Compare(quitPassword, hashedPassword, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    SEBMessageBox.Show(restartExamTitle, SEBUIStrings.wrongQuitRestartPasswordText, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendRestartExam();
                    return;
                }
            }

            if (SEBMessageBox.Show(restartExamTitle, SEBUIStrings.restartExamConfirm, MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                SEBXULRunnerWebSocketServer.SendRestartExam();
            }
        }
Ejemplo n.º 5
0
        private void OpenEmbededResource(DictObj resource)
        {
            var launcher = (int)resource[SEBSettings.KeyAdditionalResourcesResourceDataLauncher];
            var filename = (string)resource[SEBSettings.KeyAdditionalResourcesResourceDataFilename];
            var path     =
                _fileCompressor.DecompressDecodeAndSaveFile(
                    (string)resource[SEBSettings.KeyAdditionalResourcesResourceData], filename, resource[SEBSettings.KeyAdditionalResourcesIdentifier].ToString());

            //XulRunner
            if (launcher == 0)
            {
                SEBXULRunnerWebSocketServer.SendMessage(
                    new SEBXULMessage(
                        SEBXULMessage.SEBXULHandler.AdditionalResources, new
                {
                    id   = resource[SEBSettings.KeyAdditionalResourcesIdentifier],
                    path = path
                }
                        )
                    );
            }
            else
            {
                var permittedProcess = (DictObj)SEBSettings.permittedProcessList[launcher];
                var fullPath         = SEBClientInfo.SebWindowsClientForm.GetPermittedApplicationPath(permittedProcess);
                try
                {
                    Process process = SEBClientInfo.SebWindowsClientForm.CreateProcessWithExitHandler(string.Join(" ", fullPath, "\"" + path + filename + "\""));
                    if (SEBClientInfo.SebWindowsClientForm.permittedProcessesReferences[launcher] == null)
                    {
                        SEBClientInfo.SebWindowsClientForm.permittedProcessesReferences[launcher] = process;
                    }
                }
                catch (Exception ex)
                {
                    SEBMessageBox.Show(SEBUIStrings.errorOpeningResource, ex.Message, MessageBoxIcon.Error, MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnClick(EventArgs e)
        {
            string examDefaultTitle = (string)SEBClientInfo.getSebSetting("restartExamText")["restartExamText"];

            if (string.IsNullOrEmpty(examDefaultTitle))
            {
                examDefaultTitle = SEBUIStrings.restartExamDefaultTitle;
            }
            string strA = (string)SEBClientInfo.getSebSetting("hashedQuitPassword")["hashedQuitPassword"];

            if ((bool)SEBClientInfo.getSebSetting("restartExamPasswordProtected")["restartExamPasswordProtected"] && !string.IsNullOrWhiteSpace(strA))
            {
                string input = SebPasswordDialogForm.ShowPasswordDialogForm(examDefaultTitle, SEBUIStrings.restartExamEnterPassword);
                if (input == null)
                {
                    return;
                }
                string passwordHash = SEBProtectionController.ComputePasswordHash(input);
                if (string.IsNullOrWhiteSpace(input) || string.Compare(strA, passwordHash, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    int num = (int)SEBMessageBox.Show(examDefaultTitle, SEBUIStrings.wrongQuitRestartPasswordText, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendRestartExam();
                }
            }
            else
            {
                if (SEBMessageBox.Show(examDefaultTitle, SEBUIStrings.restartExamConfirm, MessageBoxIcon.Question, MessageBoxButtons.YesNo, false) != DialogResult.Yes)
                {
                    return;
                }
                SEBXULRunnerWebSocketServer.SendRestartExam();
            }
        }
Ejemplo n.º 7
0
 public static void CloseProcess(Process processToClose)
 {
     try
     {
         if (processToClose == null)
         {
             return;
         }
         Logger.AddInformation("Closing " + processToClose.ProcessName, (object)null, (Exception)null, (string)null);
         if (processToClose.ProcessName.Contains("xulrunner"))
         {
             Logger.AddInformation("Closing XulRunner over Socket", (object)null, (Exception)null, (string)null);
             SEBXULRunnerWebSocketServer.SendAllowCloseToXulRunner();
             Thread.Sleep(500);
         }
         string str = "processHasExitedTrue";
         if (!processToClose.HasExited)
         {
             Logger.AddInformation("Process " + processToClose.ProcessName + " hasnt closed yet, try again", (object)null, (Exception)null, (string)null);
             if (processToClose.MainWindowHandle != IntPtr.Zero)
             {
                 str = processToClose.ProcessName;
                 Logger.AddError("Send CloseMainWindow to process " + str, (object)null, (Exception)null, (string)null);
                 processToClose.CloseMainWindow();
                 for (int index = 0; index < 5; ++index)
                 {
                     processToClose.Refresh();
                     if (processToClose != null && !processToClose.HasExited)
                     {
                         Logger.AddError("Process " + str + " hasn't exited by closing its main window, wait up to one more second and check again.", (object)null, (Exception)null, (string)null);
                         processToClose.WaitForExit(1000);
                     }
                     else
                     {
                         Logger.AddError("Process " + str + " has exited.", (object)null, (Exception)null, (string)null);
                         break;
                     }
                 }
             }
         }
         processToClose.Refresh();
         if (!processToClose.HasExited)
         {
             Logger.AddError("Send Kill to process " + str, (object)null, (Exception)null, (string)null);
             processToClose.Kill();
             for (int index = 0; index < 10; ++index)
             {
                 processToClose.Refresh();
                 if (!processToClose.HasExited)
                 {
                     Logger.AddError("Process " + str + " still hasn't exited, wait up to one more second and check again.", (object)null, (Exception)null, (string)null);
                     try
                     {
                         processToClose.WaitForExit(1000);
                     }
                     catch (Exception ex)
                     {
                         Logger.AddError("Unable to processToClose.WaitForExit(1000)", (object)null, ex, (string)null);
                     }
                 }
                 else
                 {
                     Logger.AddError("Process " + str + " has exited.", (object)null, (Exception)null, (string)null);
                     break;
                 }
             }
         }
         processToClose.Refresh();
         if (processToClose.HasExited)
         {
             return;
         }
         Logger.AddError("Process " + str + " has not exited after killing it and waiting in total 11 seconds!", (object)null, (Exception)null, (string)null);
     }
     catch (Exception ex)
     {
         Logger.AddError("Error when killing process", (object)null, ex, (string)null);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Closes process by process name.
        /// </summary>
        /// <returns></returns>
        public static void CloseProcess(Process processToClose)
        {
            try
            {
                if (processToClose != null)         // && !processToClose.HasExited)
                {
                    Logger.AddInformation("Closing " + processToClose.ProcessName);
                    if (processToClose.ProcessName.Contains("xulrunner"))
                    {
                        Logger.AddInformation("Closing XulRunner over Socket");
                        SEBXULRunnerWebSocketServer.SendAllowCloseToXulRunner();
                        Thread.Sleep(500);
                    }

                    string name = "processHasExitedTrue";

                    // Try to close process nicely with CloseMainWindow
                    if (!processToClose.HasExited)
                    {
                        Logger.AddInformation("Process " + processToClose.ProcessName + " hasnt closed yet, try again");
                        //If the process handles the mainWindow
                        if (processToClose.MainWindowHandle != IntPtr.Zero)
                        {
                            name = processToClose.ProcessName;
                            // Close process by sending a close message to its main window.
                            Logger.AddError("Send CloseMainWindow to process " + name, null, null);
                            processToClose.CloseMainWindow();
                            // Wait max. 5 seconds till the process exits
                            for (int i = 0; i < 5; i++)
                            {
                                processToClose.Refresh();
                                // If process still hasn't exited, we wait another second
                                if (processToClose != null && !processToClose.HasExited)
                                {
                                    Logger.AddError("Process " + name + " hasn't exited by closing its main window, wait up to one more second and check again.", null, null);
                                    //Thread.Sleep(1000);
                                    processToClose.WaitForExit(1000);
                                }
                                else
                                {
                                    Logger.AddError("Process " + name + " has exited.", null, null);
                                    break;
                                }
                            }
                        }
                    }
                    processToClose.Refresh();

                    // Check if process has exited now and otherwise kill it
                    if (!processToClose.HasExited)
                    {
                        // If process still hasn't exited, we kill it
                        Logger.AddError("Send Kill to process " + name, null, null);
                        processToClose.Kill();
                        // Wait max. 10 seconds till the process exits
                        for (int i = 0; i < 10; i++)
                        {
                            processToClose.Refresh();
                            // If process still hasn't exited, we wait another second
                            if (!processToClose.HasExited)
                            {
                                Logger.AddError("Process " + name + " still hasn't exited, wait up to one more second and check again.", null, null);
                                //Thread.Sleep(1000);
                                try
                                {
                                    processToClose.WaitForExit(1000);
                                }
                                catch (Exception ex)
                                {
                                    Logger.AddError("Unable to processToClose.WaitForExit(1000)", null, ex);
                                }
                            }
                            else
                            {
                                Logger.AddError("Process " + name + " has exited.", null, null);
                                break;
                            }
                        }
                    }
                    processToClose.Refresh();

                    // If process still hasn't exited or wasn't closed, we log this
                    if (!processToClose.HasExited)
                    {
                        //Logger.AddError("Process " + name + " has not exited after trying to close its main window and killing it and waiting in total 20 seconds!", null, null);
                        Logger.AddError("Process " + name + " has not exited after killing it and waiting in total 11 seconds!", null, null);
                    }

                    //// Close the process if it has exited (freeing resources)
                    //if (processToClose.HasExited)
                    //    //if (processToClose.HasExited && processToClose != SEBClientInfo.SebWindowsClientForm.xulRunner)
                    //    {
                    //    Logger.AddError("Send Close to process " + name, null, null);
                    //    processToClose.Close();

                    //    // Wait max. 10 seconds till the process exits
                    //    for (int i = 0; i < 10; i++)
                    //    {
                    //        processToClose.Refresh();
                    //        // If process still wasn't closed, we wait another second
                    //        if (processToClose.Handle != IntPtr.Zero)
                    //        {
                    //            Logger.AddError("Process " + name + " still wasn't closed, wait up to one more second and check again.", null, null);
                    //            //Thread.Sleep(1000);
                    //            processToClose.WaitForExit(1000);
                    //        }
                    //        else
                    //        {
                    //            Logger.AddError("Process " + name + " was successfully closed.", null, null);
                    //            break;
                    //        }
                    //    }

                    //    // If process still wasn't closed, we log this
                    //    processToClose.Refresh();
                    //    if (processToClose.Handle != IntPtr.Zero)
                    //    {
                    //        Logger.AddError("Process " + name + " didn't close.", null, null);
                    //    }
                    //}
                    //else
                    //{
                    //    Logger.AddError("Although it didn't exit yet, send Close anyways to process " + name, null, null);
                    //    processToClose.Close();
                    //}
                }
            }
            catch (Exception ex)
            {
                Logger.AddError("Error when killing process", null, ex);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Closes process by process name.
        /// </summary>
        /// <returns></returns>
        public static bool CloseProcess(Process processToClose)
        {
            try
            {
                if (processToClose == null) // && !processToClose.HasExited)
                {
                    return(true);
                }
                else
                {
                    string name = "processHasExitedTrue";
                    name = processToClose.ProcessName;
                    Logger.AddInformation("Closing " + name);
                    if (name.Contains("xulrunner"))
                    {
                        Logger.AddInformation("Closing XULRunner over Socket");
                        SEBXULRunnerWebSocketServer.SendAllowCloseToXulRunner();
                        Thread.Sleep(500);
                    }

                    // Try to close process nicely with CloseMainWindow
                    try
                    {
                        if (processToClose.HasExited)
                        {
                            return(true);
                        }
                    }
                    catch (Exception)
                    {
                        Logger.AddInformation("Send Kill to process " + name);
                        // processToClose.Kill();
                        Logger.AddInformation("Successfully sent Kill to process " + name);
                        processToClose.Refresh();
                    }

                    Logger.AddInformation("Process " + name + " hasn't exited yet, try again");
                    //If the process handles the mainWindow
                    if (processToClose != null && !processToClose.HasExited && processToClose.MainWindowHandle != IntPtr.Zero)
                    {
                        // Close process by sending a close message to its main window.
                        Logger.AddError("Send CloseMainWindow to process " + name, null, null);
                        processToClose.CloseMainWindow();
                        // Wait max. 5 seconds till the process exits
                        for (int i = 0; i < 5; i++)
                        {
                            processToClose.Refresh();
                            // If process still hasn't exited, we wait another second
                            if (processToClose != null && !processToClose.HasExited)
                            {
                                Logger.AddError("Process " + name + " hasn't exited by closing its main window, wait up to one more second and check again.", null, null);
                                //Thread.Sleep(1000);
                                processToClose.WaitForExit(1000);
                            }
                            else
                            {
                                Logger.AddInformation("Process " + name + " has exited.", null, null);
                                break;
                            }
                        }
                    }

                    processToClose.Refresh();

                    // Check if process has exited now and otherwise kill it
                    if (!processToClose.HasExited)
                    {
                        // If process still hasn't exited, we kill it
                        Logger.AddInformation("Send Kill to process " + name);
                        // processToClose.Kill();
                        // Wait max. 10 seconds till the process exits
                        for (int i = 0; i < 10; i++)
                        {
                            processToClose.Refresh();
                            // If process still hasn't exited, we wait another second
                            if (!processToClose.HasExited)
                            {
                                Logger.AddError("Process " + name + " still hasn't exited, wait up to one more second and check again.", null, null);
                                //Thread.Sleep(1000);
                                try
                                {
                                    processToClose.WaitForExit(1000);
                                }
                                catch (Exception ex)
                                {
                                    Logger.AddError("Unable to processToClose.WaitForExit(1000)", null, ex);
                                }
                            }
                            else
                            {
                                Logger.AddError("Process " + name + " has exited.", null, null);
                                break;
                            }
                        }
                    }
                    processToClose.Refresh();

                    // If process still hasn't exited or wasn't closed, we log this
                    if (processToClose.HasExited)
                    {
                        Logger.AddInformation("Successfully closed process " + name);
                        return(true);
                    }
                    else
                    {
                        //Logger.AddError("Process " + name + " has not exited after trying to close its main window and killing it and waiting in total 20 seconds!", null, null);
                        Logger.AddError("Process " + name + " has not exited after killing it and waiting in total 11 seconds!", null, null);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.AddError("Error when killing process", null, ex);
                return(false);
            }
        }