Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Conflicts:
	CadenceHost/Windows/MainWindow.xaml.cs
  • Loading branch information
brandonscott committed May 12, 2014
2 parents dd107cc + 64a622e commit b456dda
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 30 deletions.
9 changes: 9 additions & 0 deletions CadenceHost/CadenceHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>CadenceIcon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Pubnub.3.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -113,6 +116,12 @@
<Folder Include="Enums\" />
<Folder Include="Interfaces\" />
</ItemGroup>
<ItemGroup>
<Resource Include="CadenceIcon.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\CadenceIcon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Binary file added CadenceHost/CadenceIcon.ico
Binary file not shown.
13 changes: 8 additions & 5 deletions CadenceHost/Helpers/Cadence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static class Cadence
{
public static readonly String ServerUri = "http://cadence-bu.cloudapp.net/servers";
public static readonly String PulseUri = "http://cadence-bu.cloudapp.net/pulses";

public static readonly String ServerUriUpdate = "http://cadence-bu.cloudapp.net/servers/" + Properties.Settings.Default.ServerID;
public static readonly String Username = "[email protected]";
public static readonly String Password = "Cadenc3!";

Expand Down Expand Up @@ -70,18 +70,21 @@ public static int SendPulse(NameValueCollection kvpData)
/// <param name="kvpData">The server data to update for the current server</param>
public static void UpdateServer(NameValueCollection kvpData)
{
PutRequest(kvpData);
PutRequest(kvpData, ServerUriUpdate);
}

/// <summary>
/// The base Put web request to send to the server
/// </summary>
/// <param name="kvpData">The data to send to the server</param>
private static void PutRequest(NameValueCollection kvpData)
/// <param name="serverUriUpdate"></param>
private static void PutRequest(NameValueCollection kvpData, string serverUriUpdate)
{
using (var wb = new WebClient())
var nc = new NetworkCredential("[email protected]", "Cadenc3!");
string responseJson;
using (var wb = new WebClient { Credentials = nc })
{
var response = wb.UploadValues(ServerUri, "PUT", kvpData);
var response = wb.UploadValues(serverUriUpdate, "PUT", kvpData);
}
}

Expand Down
36 changes: 34 additions & 2 deletions CadenceHost/Helpers/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Statistics
{
private readonly PerformanceCounter _cpuCounter;
private readonly PerformanceCounter _ramCounter;
private readonly PerformanceCounter _totalRamCounter;

public Statistics()
{
Expand Down Expand Up @@ -108,9 +107,42 @@ public String GetOsVersion()
public String GetTotalDiskStorage()
{
var driveInfo = new DriveInfo(@"C");
var freeSpaceAsMb = driveInfo.TotalSize / 1048576;
var totalSizeAsMb = driveInfo.TotalSize / 1048576;
return totalSizeAsMb.ToString(CultureInfo.InvariantCulture);
}

public String GetFreeDiskStorage()
{
var driveInfo = new DriveInfo(@"C");
var freeSpaceAsMb = driveInfo.AvailableFreeSpace / 1048576;
return freeSpaceAsMb.ToString(CultureInfo.InvariantCulture);
}

public String GetFreeDiskStorageAsPercentage()
{
return (100 - Convert.ToDouble(GetFreeDiskStorage())/Convert.ToDouble(GetTotalDiskStorage())*100).ToString(CultureInfo.InvariantCulture);
}

public int GetUptime()
{
var uptime = new PerformanceCounter("System", "System Up Time");
//This would otherwise be zero
uptime.NextValue();
return Convert.ToInt32(uptime.NextValue());
}

public uint GetCpuFrequency()
{
var searcher = new ManagementObjectSearcher(
"select MaxClockSpeed from Win32_Processor");

uint freq = 0;

foreach (var item in searcher.Get())
{
freq = (uint)item["MaxClockSpeed"];
}
return freq;
}
}
}
Binary file added CadenceHost/Images/CadenceIcon.ico
Binary file not shown.
12 changes: 7 additions & 5 deletions CadenceHost/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:helpers="clr-namespace:CadenceHost.Helpers"
Title="MainWindow" Height="418.06" Width="1089.657" ResizeMode="NoResize" WindowStyle="None" MouseDown="Window_MouseDown" Closing="OnWindowClosing">
Title="MainWindow" Height="418.06" Width="1089.657" ResizeMode="NoResize" WindowStyle="None" MouseDown="Window_MouseDown" Closing="OnWindowClosing" Icon="../Images/CadenceIcon.ico">
<Grid>
<Border BorderBrush="#FF7C7C7C" BorderThickness="4,4,4,4" />
<StackPanel Background="#FFDB1818" Margin="4,4,3.6,341.4" Orientation="Horizontal">
<StackPanel Background="#FF4A90E2" Margin="4,4,3.6,341.4" Orientation="Horizontal">
<TextBlock HorizontalAlignment="Left" x:Name="tbAppLabel" Padding="8,12,8,8" TextWrapping="Wrap" Text="Cadence Server Host" Foreground="#FFFFFFFF" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="36"/>
<TextBlock HorizontalAlignment="Right" x:Name="tbStatusLabel" Margin="200,0,0,0" Padding="8,12,2,8" TextWrapping="Wrap" Text="Status: " Foreground="#FFFFFFFF" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="36"/>
<TextBlock HorizontalAlignment="Right" x:Name="tbStatus" Margin="4,0,0,0" Padding="8,12,8,8" TextWrapping="Wrap" Text="Running" Foreground="#FFFFFFFF" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="36"/>
</StackPanel>
<TextBlock HorizontalAlignment="Left" x:Name="tbDebug" Padding="8,12,8,8" TextWrapping="Wrap" Text="Debug" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="2,77,0,0"/>
<Button Margin="930,357,0,10.4" Content="Start" FontSize="22" HorizontalAlignment="Left" Width="150" Click="OnStatusClick" Background="#FFDB1818" Foreground="White" BorderBrush="#FFDB1818" Name="StatusButton"/>
<Button Margin="930,357,0,10.4" Content="Stop" FontSize="22" HorizontalAlignment="Left" Width="150" Click="OnStatusClick" Background="#FF4A90E2" Foreground="White" BorderBrush="#FF4A90E2" Name="StatusButton"/>
<ListView Name="DebugListView" Margin="10,121,541.6,10.4" BorderBrush="#FF7C7C7C" BorderThickness="4,4,4,4" Foreground="#FF7C7C7C">
<ListView.View>
<GridView>
Expand All @@ -21,8 +21,10 @@
</GridView>
</ListView.View>
</ListView>
<TextBlock HorizontalAlignment="Left" x:Name="tbDebug_Copy" Padding="8,12,8,8" TextWrapping="Wrap" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="553,77,0,0" Height="46"><Run Text="Server Management"/><LineBreak/><Run/></TextBlock>
<TextBlock HorizontalAlignment="Left" x:Name="tbDebug_Copy1" Padding="8,12,8,8" TextWrapping="Wrap" Text="UUID:" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="553,121,0,0" Width="98"/>
<TextBlock HorizontalAlignment="Left" x:Name="ServerManagemenTextBlock" Padding="8,12,8,8" TextWrapping="Wrap" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="553,77,0,0" Height="46"><Run Text="Server Management"/><LineBreak/><Run/></TextBlock>
<TextBlock HorizontalAlignment="Left" x:Name="UdidTextBlock" Padding="8,12,8,8" TextWrapping="Wrap" Text="UUID:" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="553,121,0,0" Width="98"/>
<TextBox Name="UuidTextBox" Margin="632,128,9.6,250.4" BorderBrush="#FF7C7C7C" SelectionBrush="#FFFF4D4D" BorderThickness="4,4,4,4" IsReadOnly="True" Foreground="#FF7C7C7C" FontSize="22"/>
<TextBlock HorizontalAlignment="Left" x:Name="IdTextBlock" Padding="8,12,8,8" TextWrapping="Wrap" Text="ID:" Foreground="#FF7C7C7C" VerticalAlignment="Top" FontFamily="Gill Sans MT" FontSize="22" Margin="553,168,0,0" Width="98"/>
<TextBox x:Name="IdTextBox" Margin="632,172,305.6,206.4" BorderBrush="#FF7C7C7C" SelectionBrush="#FFFF4D4D" BorderThickness="4,4,4,4" IsReadOnly="True" Foreground="#FF7C7C7C" FontSize="22"/>
</Grid>
</Window>
38 changes: 20 additions & 18 deletions CadenceHost/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public partial class MainWindow : Window
private readonly Pubnub _pn;
private readonly Statistics _statsHelper;
private readonly DispatcherTimer _timer;
private bool _isRunning;
private int _serverID;
private bool _isRunning = true;
private int _serverId;

public MainWindow()
{
Expand All @@ -77,11 +77,12 @@ public MainWindow()
else
{
_pn.SessionUUID = Settings.Default.ServerGUID;
_serverID = Settings.Default.ServerID;
//UpdateCurrentServer();
_serverId = Settings.Default.ServerID;
UpdateCurrentServer();
}

UuidTextBox.Text = _pn.SessionUUID;
IdTextBox.Text = Settings.Default.ServerID.ToString(CultureInfo.InvariantCulture);

_pn.Subscribe("test", delegate { }, delegate { }, delegate { });
//pn.Presence<string>("test", OnUserPresence, OnPresenceConnect, OnPresenceError);
Expand All @@ -95,18 +96,19 @@ private void OnPulse(object sender, EventArgs e)
var currentCpu = _statsHelper.GetCurrentCpu();

AddDebugInfo(
String.Format("Sending Pulse to server with CPU: {0}, RAM: {1}, Disk Usage: {2} and Uptime: {3} with a Total RAM Size of: {4}",
currentCpu, _statsHelper.GetCurrentRam(), "%DISK%", "%UPTIME%", _statsHelper.GetTotalRamSize()));

String.Format("Sending Pulse - CPU: {0}, RAM: {1}, Disk Usage: {2} and Uptime: {3}",
_statsHelper.GetCurrentCpu(), _statsHelper.GetCurrentRamPercent(), _statsHelper.GetFreeDiskStorageAsPercentage(), _statsHelper.GetUptime()));

var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));

var dataToSend = new NameValueCollection
{
{"server_id", _serverID.ToString()},
{"server_id", _serverId.ToString(CultureInfo.InvariantCulture)},
{"ram_usage", _statsHelper.GetCurrentRamPercent()},
{"cpu_usage", currentCpu},
{"disk_usage", "0"},
{"uptime", "0"},
{"cpu_usage", _statsHelper.GetCurrentCpu()},
{"disk_usage", _statsHelper.GetFreeDiskStorageAsPercentage()},
{"uptime", _statsHelper.GetUptime().ToString(CultureInfo.InvariantCulture)},
{"timestamp", timeSpan.TotalSeconds.ToString(CultureInfo.InvariantCulture)}
};
Cadence.SendPulse(dataToSend);
Expand All @@ -119,13 +121,13 @@ private void UpdateCurrentServer()
{
var dataToSend = new NameValueCollection
{
{"available_disk", "0"},
{"available_ram", "0"},
{"cpu_speed", "0"},
{"os_name", "0"},
{"os_version", "0"}
{"available_disk", _statsHelper.GetTotalDiskStorage()},
{"available_ram", _statsHelper.GetTotalRamSize()},
{"cpu_speed", _statsHelper.GetCpuFrequency().ToString(CultureInfo.InvariantCulture)},
{"os_name", _statsHelper.GetOsName()},
{"os_version", _statsHelper.GetOsVersion()},
};
Cadence.CreateServer(dataToSend);
Cadence.UpdateServer(dataToSend);
}

private void OnPresenceError(PubnubClientError obj)
Expand All @@ -143,7 +145,7 @@ private void AddNewServer()
{"name", Environment.MachineName},
{"available_disk", _statsHelper.GetTotalDiskStorage()},
{"available_ram", _statsHelper.GetTotalRamSize()},
{"cpu_speed", "0"},
{"cpu_speed", _statsHelper.GetCpuFrequency().ToString(CultureInfo.InvariantCulture)},
{"os_name", _statsHelper.GetOsName()},
{"os_version", _statsHelper.GetOsVersion()},
{"guid", Settings.Default.ServerGUID}
Expand All @@ -154,7 +156,7 @@ private void AddNewServer()
Settings.Default.ServerID = serverId;
Settings.Default.Save();

_serverID = Settings.Default.ServerID;
_serverId = Settings.Default.ServerID;
}

private void OnPresenceConnect(object obj)
Expand Down

0 comments on commit b456dda

Please sign in to comment.