/// <summary> /// Export all RamUsage objects to the disk /// </summary> /// <param name="ramController">The RamController object that can be used to retrieve the RamUsage objects</param> /// <param name="logController">The LogController object that can be used to add logs</param> /// <returns>True if the operation completed successfully, otherwise false</returns> internal static bool ExportRamUsage(RamController ramController, LogController logController) { if (ramController.GetRamUsageHistory().Count == 0) { return(false); } SaveFileDialog sfd = new SaveFileDialog { Filter = "Text file (*.txt)|*.txt|HTML file (*.html)|*.html|CSV file (*.csv)|*.csv|Excel file (*.csv)|*.csv" }; if (sfd.ShowDialog() != true) { return(false); } ExportType type; switch (sfd.FilterIndex) { default: type = ExportType.Text; break; case 2: type = ExportType.Html; break; case 3: type = ExportType.Csv; break; case 4: type = ExportType.Excel; break; } try { ramController.Export(sfd.FileName, type); return(true); } catch (Exception ex) { logController.AddLog(new ErrorLog(ex.Message)); MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); }
/// <inheritdoc /> /// <summary> /// Initialize a new LogWindow object /// </summary> /// /// <param name="ramController">The RamController object that can be used to view RamUsage objects</param> /// <param name="logController">The LogController object that can be used to add logs</param> internal RamStatisticsWindow(RamController ramController, LogController logController) { _logController = logController; _logController.AddLog(new ApplicationLog("Initializing RamStatisticsWindow")); InitializeComponent(); ChangeVisualStyle(); LoadProperties(); _ramController = ramController; FillLogView(); _ramController.RamUsageAddedEvent += RamUsageAddedEvent; _ramController.RamUsageRemovedEvent += RamUsageRemovedEvent; _ramController.RamUsageClearedEvent += RamUsageClearedEvent; _autoScroll = true; _logController.AddLog(new ApplicationLog("Done initializing RamStatisticsWindow")); }
/// <inheritdoc /> /// <summary> /// Initialize a new MainWindow object /// </summary> public MainWindow() { _warningBrush = new SolidColorBrush(); try { if (Properties.Settings.Default.SaveLogsToFile) { if (string.IsNullOrEmpty(Properties.Settings.Default.LogPath)) { Properties.Settings.Default.SaveLogsToFile = false; Properties.Settings.Default.Save(); } } _logController = new LogController ( Properties.Settings.Default.LoggingEnabled, Properties.Settings.Default.LogClearAuto, Properties.Settings.Default.LogClearInterval, Properties.Settings.Default.SaveLogsToFile, Properties.Settings.Default.LogPath ); } catch (Exception ex) { _logController = new LogController(); _logController.AddLog(new ErrorLog(ex.Message)); } _logController.AddLog(new ApplicationLog("Initializing MainWindow")); _clearingMemory = false; LoadLanguage(); InitializeComponent(); ChangeVisualStyle(); LblAvailablePhysicalMemory.Foreground = _warningBrush; _updateManager = new UpdateManager(Assembly.GetExecutingAssembly().GetName().Version, "https://codedead.com/Software/MemPlus/update.xml", LoadUpdateManagerStrings()); try { _ramController = new RamController ( UpdateGuiStatistics, RamClearingCompleted, Properties.Settings.Default.RamMonitorInterval, Properties.Settings.Default.EnableRamStatistics, Properties.Settings.Default.RamMaxUsageHistoryCount, _logController ); } catch (Exception ex) { _logController.AddLog(new ErrorLog(ex.Message)); } Application app = Application.Current; app.Activated += Active; app.Deactivated += Passive; LoadProperties(); try { if (!Utils.IsAdministrator()) { if (Properties.Settings.Default.RunAsAdministrator) { Utils.RunAsAdministrator(_logController); } else if (Properties.Settings.Default.AdministrativeWarning) { MessageBox.Show((string)Application.Current.FindResource("AdministrativeRightsWarning"), "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information); } } _logController.AddLog(new ApplicationLog("Checking for application updates")); if (Properties.Settings.Default.AutoUpdate) { _updateManager.CheckForUpdate(false, false); } _logController.AddLog(new ApplicationLog("Done checking for application updates")); if (Properties.Settings.Default.HideOnStart) { Hide(); } if (Properties.Settings.Default.StartMinimized) { WindowState = WindowState.Minimized; } if (Properties.Settings.Default.StartupMemoryClear) { ClearMemory(0); } } catch (Exception ex) { _logController.AddLog(new ErrorLog(ex.Message)); MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error); } _logController.AddLog(new ApplicationLog("Done initializing MainWindow")); }