Skip to content

Commit

Permalink
Adding PC monitoring application by Francis Longpre
Browse files Browse the repository at this point in the history
  • Loading branch information
myrobots committed Jan 20, 2012
1 parent 15038e7 commit df5954a
Show file tree
Hide file tree
Showing 18 changed files with 1,132 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pcRobot", "pcRobot\pcRobot.csproj", "{252BC4BA-4F1F-4493-94A8-FA6CCC838348}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{252BC4BA-4F1F-4493-94A8-FA6CCC838348}.Debug|x86.ActiveCfg = Debug|x86
{252BC4BA-4F1F-4493-94A8-FA6CCC838348}.Debug|x86.Build.0 = Debug|x86
{252BC4BA-4F1F-4493-94A8-FA6CCC838348}.Release|x86.ActiveCfg = Release|x86
{252BC4BA-4F1F-4493-94A8-FA6CCC838348}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added Supported Devices/PC/pcRobot/pcRobot.suo
Binary file not shown.
8 changes: 8 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot/App.xaml
@@ -0,0 +1,8 @@
<Application x:Class="pcRobot.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot/App.xaml.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace pcRobot {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application {
}
}
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,75 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;

namespace pcRobot.Infrastructure {
public static class MinimizeToTray {
/// <summary>
/// Enables "minimize to tray" behavior for the specified Window.
/// </summary>
/// <param name="window">Window to enable the behavior for.</param>
public static void Enable(Window window) {
// No need to track this instance; its event handlers will keep it alive
new MinimizeToTrayInstance(window);
}

/// <summary>
/// Class implementing "minimize to tray" functionality for a Window instance.
/// </summary>
private class MinimizeToTrayInstance {
private Window _window;
private NotifyIcon _notifyIcon;
private bool _balloonShown;

/// <summary>
/// Initializes a new instance of the MinimizeToTrayInstance class.
/// </summary>
/// <param name="window">Window instance to attach to.</param>
public MinimizeToTrayInstance(Window window) {
Debug.Assert(window != null, "window parameter is null.");
_window = window;
_window.StateChanged += new EventHandler(HandleStateChanged);
}

/// <summary>
/// Handles the Window's StateChanged event.
/// </summary>
/// <param name="sender">Event source.</param>
/// <param name="e">Event arguments.</param>
private void HandleStateChanged(object sender, EventArgs e) {
if (_notifyIcon == null) {
// Initialize NotifyIcon instance "on demand"
_notifyIcon = new NotifyIcon();
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);
_notifyIcon.MouseClick += new MouseEventHandler(HandleNotifyIconOrBalloonClicked);
_notifyIcon.BalloonTipClicked += new EventHandler(HandleNotifyIconOrBalloonClicked);
}
// Update copy of Window Title in case it has changed
_notifyIcon.Text = _window.Title;

// Show/hide Window and NotifyIcon
var minimized = (_window.WindowState == WindowState.Minimized);
_window.ShowInTaskbar = !minimized;
_notifyIcon.Visible = minimized;
if (minimized && !_balloonShown) {
// If this is the first time minimizing to the tray, show the user what happened
_notifyIcon.ShowBalloonTip(1000, null, _window.Title, ToolTipIcon.None);
_balloonShown = true;
}
}

/// <summary>
/// Handles a click on the notify icon or its balloon.
/// </summary>
/// <param name="sender">Event source.</param>
/// <param name="e">Event arguments.</param>
private void HandleNotifyIconOrBalloonClicked(object sender, EventArgs e) {
// Restore the Window
_window.WindowState = WindowState.Normal;
}
}
}
}
180 changes: 180 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot/MainWindow.xaml
@@ -0,0 +1,180 @@
<Window x:Class="pcRobot.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PC-Robot"
SizeToContent="WidthAndHeight"
ResizeMode="CanMinimize"
Icon="Images/icon.ico"
WindowStyle="SingleBorderWindow">
<Window.Resources>

<Style TargetType="TextBlock">
<Setter Property="Height" Value="25"/>
<Setter Property="Margin" Value="3, 3, 0, 0"/>
<Setter Property="Foreground" Value="#E8E8E8"/>
</Style>

<Style TargetType="TextBox">
<Setter Property="Height" Value="25"/>
<Setter Property="Margin" Value="0, 3, 0, 0"/>
<Setter Property="Foreground" Value="#E8E8E8"/>
<Setter Property="Background" Value="#212121"/>
<Setter Property="BorderBrush" Value="#559A7B"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>

<Style TargetType="Border" x:Key="SensorBorder">
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="80"/>
<Setter Property="Background" Value="#212121"/>
<Setter Property="BorderBrush" Value="#559A7B"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="CornerRadius" Value="5"/>
<Setter Property="Margin" Value="10"/>
</Style>

<Style TargetType="TextBlock" x:Key="SensorTitle">
<Setter Property="Foreground" Value="#999999"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Margin" Value="3"/>
</Style>

<Style TargetType="TextBlock" x:Key="SensorValue">
<Setter Property="Foreground" Value="#559A7B"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>

<Style TargetType="TextBlock" x:Key="MyRobotsStatus">
<Setter Property="Foreground" Value="#ECA624"/>
<Setter Property="FontSize" Value="10"/>
<Setter Property="Margin" Value="3"/>
</Style>

</Window.Resources>

<Window.Background>
<ImageBrush ImageSource="Images\myRobots.png" />
</Window.Background>

<Grid Margin="5" Width="500" Background="#120F08" Opacity="0.90">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<UniformGrid Grid.Row="0" Columns="2">
<TextBlock Text="Robot Key:"/>
<TextBox Text="{Binding RobotKey}"/>

<TextBlock Text="Robot Url:"/>
<TextBox Text="{Binding RobotUrl}"/>

<TextBlock Text="MyRobots update interval (seconds):"/>
<TextBox Text="{Binding MyRobotsUpdateInterval}"/>

<TextBlock Text="Robot Status:"/>
<TextBox Text="{Binding Status}"/>
</UniformGrid>

<WrapPanel Grid.Row="2" HorizontalAlignment="Center">
<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="CPU Usage (%)" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding CPUUsage}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="RAM Usage (%)" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding RAMUsage}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Nb Processes" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding NbProcesses}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Nb Threads" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding NbThreads}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="System Up Time" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding UpTime, StringFormat=d\\:hh\\:mm\\:ss}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Disk I/O (KB/sec)" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding DiskIO}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

<Border Style="{StaticResource ResourceKey=SensorBorder}">
<StackPanel Orientation="Vertical">
<TextBlock Text="Network I/O (Kbps)" Style="{StaticResource ResourceKey=SensorTitle}"/>
<TextBlock Text="{Binding NetworkIO}" Style="{StaticResource ResourceKey=SensorValue}"/>
</StackPanel>
</Border>

</WrapPanel>

<TextBlock Grid.Row="4" Text="{Binding MyRobotsUpdateStatus}" Style="{StaticResource ResourceKey=MyRobotsStatus}"/>

</Grid>
<!--
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" >Robot Key:</TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding RobotKey}"/>
<TextBlock Grid.Row="0" Grid.Column="3">Url:</TextBlock>
<TextBox Grid.Row="0" Grid.Column="4" Text="{Binding RobotUrl}"/>
<TextBlock Grid.Row="1" Grid.Column="0">Robot Status:</TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Status}"/>
<TextBlock Grid.Row="1" Grid.Column="3">MyRobots update interval (seconds):</TextBlock>
<TextBox Grid.Row="1" Grid.Column="4" Text="{Binding MyRobotsUpdateInterval}"/>
<StackPanel Grid.Row="3" Grid.ColumnSpan="5">
<TextBlock Text="{Binding CPUUsage}"/>
<TextBlock Text="{Binding NbProcesses}"/>
<TextBlock Text="{Binding NbThreads}"/>
<TextBlock Text="{Binding RAMUsage}"/>
</StackPanel>
<TextBlock Grid.Row="4" Grid.ColumnSpan="5" Text="{Binding MyRobotsUpdateStatus}" HorizontalAlignment="Right"/>
</Grid>
-->
</Window>
39 changes: 39 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot/MainWindow.xaml.cs
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using pcRobot.Robots;
using pcRobot.Services;
using pcRobot.Infrastructure;

namespace pcRobot {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {

public MainWindow() {
InitializeComponent();

MinimizeToTray.Enable(this);

// Let the window shoe right away
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
new Action(
delegate() {
this.DataContext = new PCRobot();
}
));
}
}
}
55 changes: 55 additions & 0 deletions Supported Devices/PC/pcRobot/pcRobot/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("pcRobot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("pcRobot")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit df5954a

Please sign in to comment.