|
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Imaging;
using DeepCast.Services;
namespace DeepCast
{
public partial class MainForm : Form
{
private LocationManager _locationManager;
private Thread _locationThread;
private List<GeoService> _geoServices;
private LocationTextService _formsService = new LocationTextService();
private LocationImageService _mapService = new LocationImageService();
public MainForm()
{
InitializeComponent();
_formsService.LocationChanged += new LocationChangedDelegate(_formsService_LocationChanged);
_mapService.MapChanged += new MapImageChangedDelegate(_mapService_MapChanged);
_locationManager = new LocationManager();
_locationThread = new Thread(new ThreadStart(LoadServices));
_locationThread.Start();
}
private void _mapService_MapChanged(string mapUrl)
{
if (this.InvokeRequired)
{
MapImageChangedDelegate method = new MapImageChangedDelegate(_mapService_MapChanged);
this.Invoke(method, new object[] { mapUrl });
}
else
{
_mapImage.Url = new Uri(mapUrl);
}
}
private void _formsService_LocationChanged(DeepCast.Location.GeoLocation location)
{
if (this.InvokeRequired)
{
LocationChangedDelegate method = new LocationChangedDelegate(_formsService_LocationChanged);
this.Invoke(method, new object[] {location});
}
else
{
_latitudeLabel.Text = location.Latitude.ToStringNumeric();
_longitudeLabel.Text = location.Longitude.ToStringNumeric();
}
}
/// <summary>
/// Load the services to be notified of location changes
/// </summary>
private void LoadServices()
{
_geoServices = new List<GeoService>()
{
_formsService,
_mapService,
//new FireEagleService(),
new TwitterService(),
//new YOURSERVICEHERE()
};
_locationManager.Attach(_formsService);
_locationManager.Attach(_mapService);
//if (Settings.FireEagleEnabled)
//{
// _locationManager.Attach(_geoServices.Find(s => s.Name == "FireEagle"));
//}
//if (Settings.TwitterEnabled)
//{
_locationManager.Attach(_geoServices.Find(s => s.Name == "Twitter"));
//}
}
/// <summary>
/// Toggles the running state of the location providers.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void _startStopMenu_Click(object sender, EventArgs e)
{
_startStopMenu.Text = _locationManager.Running ? "Start" : "Stop";
if (!_locationManager.Running)
{
_locationManager.Start();
}
else
{
_locationManager.Stop();
}
}
/// <summary>
/// Display Fire Eagle settings
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void _fireEagleMenu_Click(object sender, EventArgs e)
{
FireEagleForm form = new FireEagleForm();
DialogResult result = form.ShowDialog();
if (result == DialogResult.OK)
{
var service = _geoServices.Where(s => s.Name == "FireEagle").First();
if (Settings.FireEagleEnabled)
{
_locationManager.Attach(service);
}
else
{
_locationManager.Detatch(service);
}
}
}
/// <summary>
/// Display Twitter settings
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void _twitterMenu_Click(object sender, EventArgs e)
{
TwitterForm form = new TwitterForm();
DialogResult result = form.ShowDialog();
if (result == DialogResult.OK)
{
var service = _geoServices.Where(s => s.Name == "Twitter").First();
if (Settings.TwitterEnabled)// Changed by JoP
{
_locationManager.Attach(service);
}
else
{
_locationManager.Detatch(service);
}
}
}
/// <summary>
/// Redraw the map with a new zoom level
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void _drawButton_Click(object sender, EventArgs e)
{
_mapService.Zoom = _zoomSlider.Value;
_mapService.Update();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm the founder of PageLabs, a web-based performance and SEO optimization site.
Give your site a boost in performance, even take a free speed test!
http://www.pagelabs.com