Move to file scoped namespaces.

This commit is contained in:
2022-03-06 13:29:38 +00:00
parent b6c3a54955
commit 0bc819feab
1322 changed files with 268651 additions and 270003 deletions

View File

@@ -46,116 +46,115 @@ using ReactiveUI;
using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
using Version = Aaru.CommonTypes.Interop.Version;
namespace Aaru.Gui.ViewModels.Dialogs
namespace Aaru.Gui.ViewModels.Dialogs;
public sealed class ConsoleViewModel : ViewModelBase
{
public sealed class ConsoleViewModel : ViewModelBase
readonly Views.Dialogs.Console _view;
bool _debugChecked;
public ConsoleViewModel(Views.Dialogs.Console view)
{
readonly Views.Dialogs.Console _view;
bool _debugChecked;
public ConsoleViewModel(Views.Dialogs.Console view)
{
_view = view;
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand);
ClearCommand = ReactiveCommand.Create(ExecuteClearCommand);
}
[NotNull]
public string Title => "Console";
public ReactiveCommand<Unit, Unit> ClearCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
public ObservableCollection<LogEntry> Entries => ConsoleHandler.Entries;
[NotNull]
public string DebugText => "Enable debug console";
[NotNull]
public string SaveLabel => "Save";
[NotNull]
public string ClearLabel => "Clear";
public bool DebugChecked
{
get => _debugChecked;
set
{
ConsoleHandler.Debug = value;
this.RaiseAndSetIfChanged(ref _debugChecked, value);
}
}
async void ExecuteSaveCommand()
{
var dlgSave = new SaveFileDialog();
dlgSave.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>(new[]
{
"log"
}),
Name = "Log files"
});
string result = await dlgSave.ShowAsync(_view);
if(result is null)
return;
try
{
var logFs = new FileStream(result, FileMode.Create, FileAccess.ReadWrite);
var logSw = new StreamWriter(logFs);
logSw.WriteLine("Log saved at {0}", DateTime.Now);
PlatformID platId = DetectOS.GetRealPlatformID();
string platVer = DetectOS.GetVersion();
var assemblyVersion =
Attribute.GetCustomAttribute(typeof(AaruConsole).Assembly,
typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute;
logSw.WriteLine("################# System information #################");
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
Environment.Is64BitOperatingSystem ? 64 : 32);
logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion());
logSw.WriteLine();
logSw.WriteLine("################# Program information ################");
logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion);
logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32);
#if DEBUG
logSw.WriteLine("DEBUG version");
#endif
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
logSw.WriteLine();
logSw.WriteLine("################# Console ################");
foreach(LogEntry entry in ConsoleHandler.Entries)
if(entry.Type != "Info")
logSw.WriteLine("{0}: ({1}) {2}", entry.Timestamp, entry.Type.ToLower(), entry.Message);
else
logSw.WriteLine("{0}: {1}", entry.Timestamp, entry.Message);
logSw.Close();
logFs.Close();
}
catch(Exception exception)
{
await MessageBoxManager.
GetMessageBoxStandardWindow("Error",
$"Exception {exception.Message} trying to save logfile, details has been sent to console.",
ButtonEnum.Ok, Icon.Error).ShowDialog(_view);
AaruConsole.ErrorWriteLine("Console", exception.Message);
AaruConsole.ErrorWriteLine("Console", exception.StackTrace);
}
}
void ExecuteClearCommand() => ConsoleHandler.Entries.Clear();
_view = view;
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand);
ClearCommand = ReactiveCommand.Create(ExecuteClearCommand);
}
[NotNull]
public string Title => "Console";
public ReactiveCommand<Unit, Unit> ClearCommand { get; }
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
public ObservableCollection<LogEntry> Entries => ConsoleHandler.Entries;
[NotNull]
public string DebugText => "Enable debug console";
[NotNull]
public string SaveLabel => "Save";
[NotNull]
public string ClearLabel => "Clear";
public bool DebugChecked
{
get => _debugChecked;
set
{
ConsoleHandler.Debug = value;
this.RaiseAndSetIfChanged(ref _debugChecked, value);
}
}
async void ExecuteSaveCommand()
{
var dlgSave = new SaveFileDialog();
dlgSave.Filters.Add(new FileDialogFilter
{
Extensions = new List<string>(new[]
{
"log"
}),
Name = "Log files"
});
string result = await dlgSave.ShowAsync(_view);
if(result is null)
return;
try
{
var logFs = new FileStream(result, FileMode.Create, FileAccess.ReadWrite);
var logSw = new StreamWriter(logFs);
logSw.WriteLine("Log saved at {0}", DateTime.Now);
PlatformID platId = DetectOS.GetRealPlatformID();
string platVer = DetectOS.GetVersion();
var assemblyVersion =
Attribute.GetCustomAttribute(typeof(AaruConsole).Assembly,
typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute;
logSw.WriteLine("################# System information #################");
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
Environment.Is64BitOperatingSystem ? 64 : 32);
logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion());
logSw.WriteLine();
logSw.WriteLine("################# Program information ################");
logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion);
logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32);
#if DEBUG
logSw.WriteLine("DEBUG version");
#endif
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
logSw.WriteLine();
logSw.WriteLine("################# Console ################");
foreach(LogEntry entry in ConsoleHandler.Entries)
if(entry.Type != "Info")
logSw.WriteLine("{0}: ({1}) {2}", entry.Timestamp, entry.Type.ToLower(), entry.Message);
else
logSw.WriteLine("{0}: {1}", entry.Timestamp, entry.Message);
logSw.Close();
logFs.Close();
}
catch(Exception exception)
{
await MessageBoxManager.
GetMessageBoxStandardWindow("Error",
$"Exception {exception.Message} trying to save logfile, details has been sent to console.",
ButtonEnum.Ok, Icon.Error).ShowDialog(_view);
AaruConsole.ErrorWriteLine("Console", exception.Message);
AaruConsole.ErrorWriteLine("Console", exception.StackTrace);
}
}
void ExecuteClearCommand() => ConsoleHandler.Entries.Clear();
}