Added IP-based location tracker that runs async (closes #6)
pls no steal api key kthx :)
This commit is contained in:
parent
a9556ba259
commit
f847abdffc
@ -74,6 +74,10 @@
|
|||||||
<HintPath>..\packages\AForge.Video.DirectShow.2.2.5\lib\AForge.Video.DirectShow.dll</HintPath>
|
<HintPath>..\packages\AForge.Video.DirectShow.2.2.5\lib\AForge.Video.DirectShow.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net20\Newtonsoft.Json.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Speech" />
|
<Reference Include="System.Speech" />
|
||||||
@ -81,8 +85,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="GlobalHooks.cs" />
|
<Compile Include="GlobalHooks.cs" />
|
||||||
|
<Compile Include="LocationTracker.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Settings.cs" />
|
||||||
<Compile Include="Toolbar.cs">
|
<Compile Include="Toolbar.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
92
FemboyWatchdog/LocationTracker.cs
Normal file
92
FemboyWatchdog/LocationTracker.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace FemboyWatchdog
|
||||||
|
{
|
||||||
|
class LocationTracker
|
||||||
|
{
|
||||||
|
private WebClient _wcIp;
|
||||||
|
private WebClient _wcLocation;
|
||||||
|
private Timer _timer;
|
||||||
|
|
||||||
|
public IPLocationData LocationData { get; private set; }
|
||||||
|
|
||||||
|
internal class IPLocationData
|
||||||
|
{
|
||||||
|
public double latitude;
|
||||||
|
public double longitude;
|
||||||
|
public string region_name;
|
||||||
|
public string city;
|
||||||
|
public string country_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public LocationTracker(double interval = 15.0)
|
||||||
|
{
|
||||||
|
_wcIp = new WebClient();
|
||||||
|
_wcLocation = new WebClient();
|
||||||
|
_wcIp.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ip_DownloadStringCompleted);
|
||||||
|
_wcLocation.DownloadStringCompleted += new DownloadStringCompletedEventHandler(loc_DownloadStringCompleted);
|
||||||
|
|
||||||
|
// get location for the first time
|
||||||
|
GetLocationFromIp();
|
||||||
|
|
||||||
|
_timer = new Timer();
|
||||||
|
_timer.Interval = Convert.ToInt32(interval * 1000);
|
||||||
|
_timer.Tick += new EventHandler(_timer_Tick);
|
||||||
|
_timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _timer_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// i would use GeoCoordinateWatcher, but it is broken
|
||||||
|
GetLocationFromIp();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GetLocationFromIp()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_wcIp.IsBusy)
|
||||||
|
_wcIp.DownloadStringAsync(new Uri("http://ipv4.icanhazip.com"));
|
||||||
|
}
|
||||||
|
catch (WebException err)
|
||||||
|
{
|
||||||
|
// fail silently
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Cancelled || e.Error != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LocationData = JsonConvert.DeserializeObject<IPLocationData>(e.Result);
|
||||||
|
}
|
||||||
|
catch (JsonSerializationException err) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
void ip_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Cancelled || e.Error != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_wcLocation.IsBusy)
|
||||||
|
_wcLocation.DownloadStringAsync(new Uri(
|
||||||
|
string.Format(
|
||||||
|
"http://api.ipstack.com/{0}?access_key={1}&fields=latitude,longitude,region_name,country_name,city",
|
||||||
|
e.Result,
|
||||||
|
"31d59064bb7ef00a9daff4794b73118c"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
catch (WebException err) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
FemboyWatchdog/Properties/Resources.Designer.cs
generated
2
FemboyWatchdog/Properties/Resources.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.1008
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
|
2
FemboyWatchdog/Properties/Settings.Designer.cs
generated
2
FemboyWatchdog/Properties/Settings.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.1008
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||||
<Profiles>
|
<Profiles />
|
||||||
<Profile Name="(Default)" />
|
|
||||||
</Profiles>
|
|
||||||
<Settings />
|
<Settings />
|
||||||
</SettingsFile>
|
</SettingsFile>
|
28
FemboyWatchdog/Settings.cs
Normal file
28
FemboyWatchdog/Settings.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
namespace FemboyWatchdog.Properties {
|
||||||
|
|
||||||
|
|
||||||
|
// This class allows you to handle specific events on the settings class:
|
||||||
|
// The SettingChanging event is raised before a setting's value is changed.
|
||||||
|
// The PropertyChanged event is raised after a setting's value is changed.
|
||||||
|
// The SettingsLoaded event is raised after the setting values are loaded.
|
||||||
|
// The SettingsSaving event is raised before the setting values are saved.
|
||||||
|
internal sealed partial class Settings {
|
||||||
|
|
||||||
|
public Settings() {
|
||||||
|
// // To add event handlers for saving and changing settings, uncomment the lines below:
|
||||||
|
//
|
||||||
|
// this.SettingChanging += this.SettingChangingEventHandler;
|
||||||
|
//
|
||||||
|
// this.SettingsSaving += this.SettingsSavingEventHandler;
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
|
||||||
|
// Add code to handle the SettingChangingEvent event here.
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||||
|
// Add code to handle the SettingsSaving event here.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
FemboyWatchdog/Toolbar.Designer.cs
generated
1
FemboyWatchdog/Toolbar.Designer.cs
generated
@ -20,6 +20,7 @@ namespace FemboyWatchdog
|
|||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseCurrentVideoSource();
|
||||||
GlobalHooks.UnhookWindowsHookEx(_hookID);
|
GlobalHooks.UnhookWindowsHookEx(_hookID);
|
||||||
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
|
@ -2,21 +2,23 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
using System.Media;
|
using System.Media;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Speech.Synthesis;
|
using System.Speech.Synthesis;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using AForge.Video;
|
using AForge.Video;
|
||||||
using AForge.Video.DirectShow;
|
using AForge.Video.DirectShow;
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace FemboyWatchdog
|
namespace FemboyWatchdog
|
||||||
{
|
{
|
||||||
public partial class Toolbar : Form
|
public partial class Toolbar : Form
|
||||||
{
|
{
|
||||||
private DateTime clockIn = DateTime.Now;
|
private DateTime clockIn = DateTime.Now;
|
||||||
|
private LocationTracker tracker;
|
||||||
|
|
||||||
private FilterInfoCollection videoDevices;
|
private FilterInfoCollection videoDevices;
|
||||||
private VideoCaptureDevice videoDevice;
|
private VideoCaptureDevice videoDevice;
|
||||||
@ -47,6 +49,8 @@ namespace FemboyWatchdog
|
|||||||
|
|
||||||
ss = new SpeechSynthesizer();
|
ss = new SpeechSynthesizer();
|
||||||
|
|
||||||
|
tracker = new LocationTracker();
|
||||||
|
|
||||||
ttsTimer = new Timer();
|
ttsTimer = new Timer();
|
||||||
ttsTimer.Interval = 15000;
|
ttsTimer.Interval = 15000;
|
||||||
labelBlinkTimer = new Timer();
|
labelBlinkTimer = new Timer();
|
||||||
@ -67,13 +71,13 @@ namespace FemboyWatchdog
|
|||||||
OpenCamera();
|
OpenCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lastmousemvmtTimer_Tick(object sender, EventArgs e)
|
private void lastmousemvmtTimer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
++mousemvmtCount;
|
++mousemvmtCount;
|
||||||
lastmousemvmtTimer.Stop();
|
lastmousemvmtTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mousemoveTimer_Tick(object sender, EventArgs e)
|
private void mousemoveTimer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (mousemvmtCount < 5)
|
if (mousemvmtCount < 5)
|
||||||
{
|
{
|
||||||
@ -121,15 +125,21 @@ namespace FemboyWatchdog
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
MessageBox.Show(this, "Camera device not found! Get a webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(this, "Camera device not found! Get a webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
Environment.Exit(-2);
|
Environment.Exit(-2);
|
||||||
|
*/
|
||||||
|
vsp.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
videoCapabilities = videoDevice.VideoCapabilities;
|
videoCapabilities = videoDevice.VideoCapabilities;
|
||||||
if (videoCapabilities.Length == 0)
|
if (videoCapabilities.Length == 0)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
MessageBox.Show(this, "Camera does not support video capture! Get a better webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(this, "Camera does not support video capture! Get a better webcam!", "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
Environment.Exit(-3);
|
Environment.Exit(-3);
|
||||||
|
*/
|
||||||
|
vsp.Dispose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,19 +151,25 @@ namespace FemboyWatchdog
|
|||||||
}
|
}
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
MessageBox.Show(this, err.ToString(), "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(this, err.ToString(), "Error initializing camera", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
Environment.Exit(-1);
|
Environment.Exit(-1);
|
||||||
|
*/
|
||||||
|
vsp.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void labelBlinkTimer_Tick(object sender, EventArgs e)
|
private void labelBlinkTimer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.label2.Visible = !this.label2.Visible;
|
this.label2.Visible = !this.label2.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ttsTimer_Tick(object sender, EventArgs e)
|
private void ttsTimer_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ss.SpeakAsync("You are being monitored");
|
string msg = "You are being monitored.";
|
||||||
|
if (tracker.LocationData != null)
|
||||||
|
msg += string.Format(" Your location is: {0}, {1}", tracker.LocationData.latitude, tracker.LocationData.longitude);
|
||||||
|
ss.SpeakAsync(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenVideoSource(IVideoSource source)
|
public void OpenVideoSource(IVideoSource source)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
|
<configSections>
|
||||||
|
</configSections>
|
||||||
|
<startup><supportedRuntime version="v2.0.50727"/></startup>
|
||||||
|
</configuration>
|
||||||
|
@ -6,4 +6,5 @@
|
|||||||
<package id="AForge.Math" version="2.2.5" targetFramework="net30" />
|
<package id="AForge.Math" version="2.2.5" targetFramework="net30" />
|
||||||
<package id="AForge.Video" version="2.2.5" targetFramework="net30" />
|
<package id="AForge.Video" version="2.2.5" targetFramework="net30" />
|
||||||
<package id="AForge.Video.DirectShow" version="2.2.5" targetFramework="net30" />
|
<package id="AForge.Video.DirectShow" version="2.2.5" targetFramework="net30" />
|
||||||
|
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net30" />
|
||||||
</packages>
|
</packages>
|
@ -4,7 +4,7 @@ The ultimate corporate surveillance mechanism!
|
|||||||
|
|
||||||
## User Requirements
|
## User Requirements
|
||||||
|
|
||||||
- .NET Framework 3.0
|
- .NET Framework 3.5
|
||||||
|
|
||||||
- Windows XP and up
|
- Windows XP and up
|
||||||
|
|
||||||
@ -14,4 +14,6 @@ The ultimate corporate surveillance mechanism!
|
|||||||
|
|
||||||
- AForge.NET
|
- AForge.NET
|
||||||
|
|
||||||
|
- NuGet
|
||||||
|
|
||||||
- Visual C# 2010
|
- Visual C# 2010
|
||||||
|
Loading…
x
Reference in New Issue
Block a user