public FactoryResult TryCreate(WhitelistApplication settings, out IApplication application)
        {
            var name = $"'{settings.DisplayName}' ({ settings.ExecutableName})";

            application = default(IApplication);

            try
            {
                var success = TryFindApplication(settings, out var executablePath);

                if (success)
                {
                    application = BuildApplication(executablePath, settings);
                    application.Initialize();

                    logger.Debug($"Successfully initialized application {name}.");

                    return(FactoryResult.Success);
                }

                logger.Error($"Could not find application {name}!");

                return(FactoryResult.NotFound);
            }
            catch (Exception e)
            {
                logger.Error($"Unexpected error while trying to initialize application {name}!", e);
            }

            return(FactoryResult.Error);
        }
        private List <IFeatureConfiguration> LoadFromFile()
        {
            var configurations = new List <IFeatureConfiguration>();

            try
            {
                if (File.Exists(filePath))
                {
                    var context = new StreamingContext(StreamingContextStates.All, logger);

                    logger.Debug($"Attempting to load backup data from '{filePath}'...");

                    using (var stream = File.Open(filePath, FileMode.Open))
                    {
                        configurations = (List <IFeatureConfiguration>) new BinaryFormatter(null, context).Deserialize(stream);
                    }

                    logger.Debug($"Backup data successfully loaded, found {configurations.Count} items.");
                }
                else
                {
                    logger.Debug($"No backup data found under '{filePath}'.");
                }
            }
            catch (Exception e)
            {
                logger.Error($"Failed to load backup data from '{filePath}'!", e);
            }

            return(configurations);
        }
 public void Start()
 {
     try
     {
         logger.Info("Starting application...");
         InitializeInstance(processFactory.StartNew(executablePath, BuildArguments()));
         logger.Info("Successfully started application.");
     }
     catch (Exception e)
     {
         logger.Error("Failed to start application!", e);
     }
 }
Exemple #4
0
        public bool TryGetById(int id, out IProcess process)
        {
            process = default(IProcess);

            try
            {
                var raw = System.Diagnostics.Process.GetProcessById(id);
                var(name, originalName) = LoadProcessNamesFor(raw);

                process = new Process(raw, name, originalName, LoggerFor(raw, name));
            }
            catch (Exception e)
            {
                logger.Error($"Failed to get process with ID = {id}!", e);
            }

            return(process != default(IProcess));
        }
Exemple #5
0
 private void DeleteCache()
 {
     try
     {
         Directory.Delete(appConfig.BrowserCachePath, true);
         logger.Info("Deleted browser cache.");
     }
     catch (Exception e)
     {
         logger.Error("Failed to delete browser cache!", e);
     }
 }
Exemple #6
0
        private void StartProctoring()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                try
                {
                    var content = LoadContent(settings);

                    filePath = Path.Combine(appConfig.TemporaryDirectory, $"{Path.GetRandomFileName()}_index.html");
                    fileSystem.Save(content, filePath);

                    control = new ProctoringControl(logger.CloneFor(nameof(ProctoringControl)));
                    control.EnsureCoreWebView2Async().ContinueWith(_ =>
                    {
                        control.Dispatcher.Invoke(() =>
                        {
                            control.CoreWebView2.Navigate(filePath);
                        });
                    });

                    window = uiFactory.CreateProctoringWindow(control);
                    window.SetTitle(settings.JitsiMeet.Enabled ? settings.JitsiMeet.Subject : settings.Zoom.UserName);
                    window.Show();

                    if (settings.WindowVisibility == WindowVisibility.AllowToShow || settings.WindowVisibility == WindowVisibility.Hidden)
                    {
                        window.Hide();
                    }

                    IconResource = new XamlIconResource {
                        Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/ProctoringNotification_Active.xaml")
                    };
                    Tooltip = text.Get(TextKey.Notification_ProctoringActiveTooltip);
                    NotificationChanged?.Invoke();

                    logger.Info($"Started proctoring with {(settings.JitsiMeet.Enabled ? "Jitsi Meet" : "Zoom")}.");
                }
                catch (Exception e)
                {
                    logger.Error($"Failed to start proctoring! Reason: {e.Message}", e);
                }
            });
        }