Implemented basic browser window and moved log file paths to settings.
This commit is contained in:
parent
d2e08e3278
commit
8e4f818159
10 changed files with 65 additions and 32 deletions
|
@ -33,7 +33,8 @@ namespace SafeExamBrowser.Browser
|
||||||
{
|
{
|
||||||
var cefSettings = new CefSettings
|
var cefSettings = new CefSettings
|
||||||
{
|
{
|
||||||
CachePath = settings.BrowserCachePath
|
CachePath = settings.BrowserCachePath,
|
||||||
|
LogFile = settings.BrowserLogFile
|
||||||
};
|
};
|
||||||
|
|
||||||
var success = Cef.Initialize(cefSettings, true, null);
|
var success = Cef.Initialize(cefSettings, true, null);
|
||||||
|
@ -64,8 +65,6 @@ namespace SafeExamBrowser.Browser
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CreateNewInstance();
|
CreateNewInstance();
|
||||||
CreateNewInstance();
|
|
||||||
CreateNewInstance();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ namespace SafeExamBrowser.Browser
|
||||||
instance.RegisterWindow(window);
|
instance.RegisterWindow(window);
|
||||||
button.RegisterInstance(instance);
|
button.RegisterInstance(instance);
|
||||||
|
|
||||||
window.Display();
|
window.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,26 @@ namespace SafeExamBrowser.Configuration
|
||||||
public class Settings : ISettings
|
public class Settings : ISettings
|
||||||
{
|
{
|
||||||
private const string AppDataFolder = "SafeExamBrowser";
|
private const string AppDataFolder = "SafeExamBrowser";
|
||||||
|
private static readonly string LogFileDate = DateTime.Now.ToString("yyyy-MM-dd HH\\hmm\\mss\\s");
|
||||||
|
|
||||||
|
public string ApplicationLogFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(LogFolderPath, $"{LogFileDate} Application.txt"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string BrowserLogFile
|
||||||
|
{
|
||||||
|
get { return Path.Combine(LogFolderPath, $"{LogFileDate} Browser.txt"); }
|
||||||
|
}
|
||||||
|
|
||||||
public string BrowserCachePath
|
public string BrowserCachePath
|
||||||
{
|
{
|
||||||
get
|
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Cache"); }
|
||||||
{
|
|
||||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Cache");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string LogFolderPath
|
public string LogFolderPath
|
||||||
{
|
{
|
||||||
get
|
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Logs"); }
|
||||||
{
|
|
||||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Logs");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ProgramCopyright
|
public string ProgramCopyright
|
||||||
|
|
|
@ -10,11 +10,21 @@ namespace SafeExamBrowser.Contracts.Configuration
|
||||||
{
|
{
|
||||||
public interface ISettings
|
public interface ISettings
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file path under which the application log is to be stored.
|
||||||
|
/// </summary>
|
||||||
|
string ApplicationLogFile { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The path where the browser cache is to be stored.
|
/// The path where the browser cache is to be stored.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string BrowserCachePath { get; }
|
string BrowserCachePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The file path under which the browser log is to be stored.
|
||||||
|
/// </summary>
|
||||||
|
string BrowserLogFile { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The path where the log files are to be stored.
|
/// The path where the log files are to be stored.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -18,6 +18,6 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shows the window to the user.
|
/// Shows the window to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Display();
|
void Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
browserController.RegisterApplicationButton(browserButton);
|
browserController.RegisterApplicationButton(browserButton);
|
||||||
|
|
||||||
taskbar.AddButton(browserButton);
|
taskbar.AddButton(browserButton);
|
||||||
|
logger.Info("Browser successfully initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Revert()
|
public void Revert()
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace SafeExamBrowser.Core.Behaviour
|
||||||
InitializeApplicationLog();
|
InitializeApplicationLog();
|
||||||
InitializeSplashScreen(operations.Count);
|
InitializeSplashScreen(operations.Count);
|
||||||
|
|
||||||
PerformOperations(operations);
|
Perform(operations);
|
||||||
|
|
||||||
FinishInitialization();
|
FinishInitialization();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace SafeExamBrowser.Core.Behaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PerformOperations(Queue<IOperation> operations)
|
private void Perform(Queue<IOperation> operations)
|
||||||
{
|
{
|
||||||
foreach (var operation in operations)
|
foreach (var operation in operations)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SafeExamBrowser.Contracts.Configuration;
|
using SafeExamBrowser.Contracts.Configuration;
|
||||||
|
@ -21,14 +20,12 @@ namespace SafeExamBrowser.Core.Logging
|
||||||
|
|
||||||
public LogFileWriter(ISettings settings)
|
public LogFileWriter(ISettings settings)
|
||||||
{
|
{
|
||||||
var fileName = $"{DateTime.Now.ToString("yyyy-MM-dd HH\\hmm\\mss\\s")}.txt";
|
|
||||||
|
|
||||||
if (!Directory.Exists(settings.LogFolderPath))
|
if (!Directory.Exists(settings.LogFolderPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(settings.LogFolderPath);
|
Directory.CreateDirectory(settings.LogFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath = Path.Combine(settings.LogFolderPath, fileName);
|
filePath = settings.ApplicationLogFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Notify(ILogContent content)
|
public void Notify(ILogContent content)
|
||||||
|
|
|
@ -5,8 +5,24 @@
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface"
|
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="BrowserWindow" Height="300" Width="300">
|
Title="BrowserWindow" Height="500" Width="500" WindowState="Maximized">
|
||||||
<Grid>
|
<Grid>
|
||||||
<WindowsFormsHost x:Name="BrowserControlHost" />
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="30" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid Grid.Row="0">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBox Grid.Column="0" x:Name="UrlTextBox" Margin="5,5,2.5,5" Height="20" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
|
||||||
|
<Button Grid.Column="1" x:Name="ReloadButton" Margin="2.5,5,2.5,5" HorizontalAlignment="Center" VerticalAlignment="Center">Reload</Button>
|
||||||
|
<Button Grid.Column="2" x:Name="BackButton" Margin="2.5,5,2.5,5" HorizontalAlignment="Center" VerticalAlignment="Center">Back</Button>
|
||||||
|
<Button Grid.Column="3" x:Name="ForwardButton" Margin="2.5,5,5,5" HorizontalAlignment="Center" VerticalAlignment="Center">Forward</Button>
|
||||||
|
</Grid>
|
||||||
|
<WindowsFormsHost Grid.Row="1" x:Name="BrowserControlHost" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
@ -16,21 +16,25 @@ namespace SafeExamBrowser.UserInterface
|
||||||
public BrowserWindow(IBrowserControl browserControl)
|
public BrowserWindow(IBrowserControl browserControl)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
InitializeBrowserWindow(browserControl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BringToForeground()
|
||||||
|
{
|
||||||
|
if (WindowState == WindowState.Minimized)
|
||||||
|
{
|
||||||
|
WindowState = WindowState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeBrowserWindow(IBrowserControl browserControl)
|
||||||
|
{
|
||||||
if (browserControl is System.Windows.Forms.Control)
|
if (browserControl is System.Windows.Forms.Control)
|
||||||
{
|
{
|
||||||
BrowserControlHost.Child = browserControl as System.Windows.Forms.Control;
|
BrowserControlHost.Child = browserControl as System.Windows.Forms.Control;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BringToForeground()
|
|
||||||
{
|
|
||||||
Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Display()
|
|
||||||
{
|
|
||||||
Show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
|
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Controls"
|
||||||
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Taskbar" Height="40" Width="750" WindowStyle="None" AllowsTransparency="True" Topmost="True" Visibility="Collapsed" Icon="./Images/SafeExamBrowser.ico">
|
Title="Taskbar" Height="40" Width="750" WindowStyle="None" AllowsTransparency="True" Topmost="True" Visibility="Collapsed"
|
||||||
|
ResizeMode="NoResize" Icon="./Images/SafeExamBrowser.ico">
|
||||||
<Window.Background>
|
<Window.Background>
|
||||||
<SolidColorBrush Color="Black" Opacity="0.8" />
|
<SolidColorBrush Color="Black" Opacity="0.8" />
|
||||||
</Window.Background>
|
</Window.Background>
|
||||||
|
|
Loading…
Reference in a new issue