Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a basic Logger.
  • Loading branch information
ejr06006 committed Apr 4, 2012
1 parent 80ec55a commit 396a0d7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions DataScraperGUI/DataScraperGUI.csproj
Expand Up @@ -63,6 +63,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Infrastructure\Logger.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
42 changes: 42 additions & 0 deletions DataScraperGUI/Infrastructure/Logger.cs
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace DataScraperGUI.Infrastructure {
class Logger {
private TextBox logBox = null;

public Logger (TextBox lBox) {
logBox = lBox;
}

private void Log (string message, string severity) {
var sb = new StringBuilder();

sb.Append("[");
sb.Append(DateTime.Now.ToLocalTime());
sb.Append("] ");
sb.Append(severity);
sb.Append(": ");
sb.Append(message);
sb.AppendLine();
sb.Append(logBox.Text);

logBox.Text = sb.ToString();
}

public void LogMessage (string message) {
Log(message, "MESSAGE");
}

public void LogWarning (string message) {
Log(message, "WARNING");
}

public void LogError (string message) {
Log(message, "ERROR");
}
}
}
9 changes: 6 additions & 3 deletions DataScraperGUI/MainWindow.xaml
Expand Up @@ -4,13 +4,16 @@
Title="UConn ECE Senior Design - Group 155 - DataScraper" Height="400" Width="525">
<Grid>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="12,46,0,0" Name="programComboBox" VerticalAlignment="Top" Width="479">
<ComboBoxItem Content="Normal program. (Minor variations, no major events.)" />
<ComboBoxItem Content="Normal program. (Minor variations, no major events.)" IsSelected="True" />
<ComboBoxItem Content="Temperature too cold in office." />
<ComboBoxItem Content="Humidity too high in office." />
<ComboBoxItem Content="VAV is not responding." />
</ComboBox>
<Label Content="Step 1: Choose a program." Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Step 2: Choose a run-time duration." Height="28" HorizontalAlignment="Left" Margin="12,75,0,0" Name="label2" VerticalAlignment="Top" />
<ProgressBar Height="25" HorizontalAlignment="Left" Margin="12,324,0,0" Name="progressBar" VerticalAlignment="Top" Width="479" />
<Button Content="Button" Height="50" HorizontalAlignment="Left" Margin="12,109,0,0" Name="runButton" VerticalAlignment="Top" Width="150" />
<Button Content="Run" Height="50" HorizontalAlignment="Left" Margin="12,109,0,0" Name="runButton" VerticalAlignment="Top" Width="150" Click="runButton_Click"/>
<Button Content="Cancel" Height="50" HorizontalAlignment="Left" Margin="341,109,0,0" Name="cancelButton" VerticalAlignment="Top" Width="150" IsCancel="False" IsEnabled="False" />
<TextBox Height="153" HorizontalAlignment="Left" Margin="12,165,0,0" Name="logBox" VerticalAlignment="Top" Width="479" IsReadOnly="True" />
<TextBox Height="153" HorizontalAlignment="Left" Margin="12,165,0,0" Name="logBox" VerticalAlignment="Top" Width="479" IsReadOnly="True" TextWrapping="NoWrap" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
</Grid>
</Window>
11 changes: 11 additions & 0 deletions DataScraperGUI/MainWindow.xaml.cs
Expand Up @@ -11,14 +11,25 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataScraperGUI.Infrastructure;

namespace DataScraperGUI {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private Logger logger = null;

public MainWindow() {
InitializeComponent();

logger = new Logger(logBox);

logger.LogMessage("Successfully started application.");
}

private void runButton_Click (object sender, RoutedEventArgs e) {
logger.LogWarning("Run button pressed!");
}
}
}

0 comments on commit 396a0d7

Please sign in to comment.