diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ce0a42d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,33 @@ +#Microsoft Public License (MS-PL) +[OSI Approved License] + +This license governs use of the accompanying software. If you use the software, you +accept this license. If you do not accept the license, do not use the software. + +##1. Definitions + +The terms "reproduce," "reproduction," "derivative works," and "distribution" have the +same meaning here as under U.S. copyright law. + +A "contribution" is the original software, or any additions or changes to the software. + +A "contributor" is any person that distributes its contribution under this license. +"Licensed patents" are a contributor's patent claims that read directly on its contribution. + +##2. Grant of Rights + +(A) Copyright Grant – Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. + +(B) Patent Grant – Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. + +##3. Conditions and Limitations + +(A) No Trademark License – This license does not grant you rights to use any contributors' name, logo, or trademarks. + +(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. + +(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. + +(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. + +(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. \ No newline at end of file diff --git a/README.md b/README.md index fd45481..90ae712 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,42 @@ -#WygwamToolkit - -Toolkit published by the [Wygwam](http://www.wygwam.com) team. - -You can use the nuget package: [https://nuget.org/packages/Wygwam.Toolkit/](https://nuget.org/packages/Wygwam.Toolkit/) - -#Summary - -Provides some useful stuff for your developments on WinRT and Windows Phone. -You can use our Interfaces or Abstract Classes to get some tools like: - -##AStorageManager - -Implemented on Windows Phone 8 and WinRT (*StorageManager* classes) - -Allows you to manage your file and settings in a easy way -```csharp -Task SaveSettingAsync(string key, object data) -Task LoadSettingAsync(string key) -Task ClearSettingAsync(string key) -Task SaveDataAsync(string path, object data) -Task LoadDataAsync(string path) -Task ClearDataAsync(string path) -``` -##ILocationManager - -Implemented on Windows Phone 8 and WinRT (*LocationManager* classes) - -Allows you to manage geoposition in a easy way -```csharp -GeoPosition LastKnowPosition { get; set; } -Task GetLocationAsync(); -Task AskForRightAsync(); -``` -##ANetworkManager - -Implemented on Windows Phone 8 and WinRT (*NetworkManager* classes) - -Allows you to know if network is available -```csharp -bool IsNetworkAvailable { get; } -``` +#WygwamToolkit + +Toolkit published by the [Wygwam](http://www.wygwam.com) team. + +You can use the nuget package: [https://nuget.org/packages/Wygwam.Toolkit/](https://nuget.org/packages/Wygwam.Toolkit/) + +#Summary + +Provides some useful stuff for your developments on WinRT and Windows Phone. +You can use our Interfaces or Abstract Classes to get some tools like: + +##AStorageManager + +Implemented on Windows Phone 8 and WinRT (*StorageManager* classes) + +Allows you to manage your file and settings in a easy way +```csharp +Task SaveSettingAsync(string key, object data) +Task LoadSettingAsync(string key) +Task ClearSettingAsync(string key) +Task SaveDataAsync(string path, object data) +Task LoadDataAsync(string path) +Task ClearDataAsync(string path) +``` +##ILocationManager + +Implemented on Windows Phone 8 and WinRT (*LocationManager* classes) + +Allows you to manage geoposition in a easy way +```csharp +GeoPosition LastKnowPosition { get; set; } +Task GetLocationAsync(); +Task AskForRightAsync(); +``` +##ANetworkManager + +Implemented on Windows Phone 8 and WinRT (*NetworkManager* classes) + +Allows you to know if network is available +```csharp +bool IsNetworkAvailable { get; } +``` diff --git a/WygwamToolkit.sln b/Wygwam.Windows.sln similarity index 81% rename from WygwamToolkit.sln rename to Wygwam.Windows.sln index 8e6085f..c3d94a8 100644 --- a/WygwamToolkit.sln +++ b/Wygwam.Windows.sln @@ -1,66 +1,72 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WygwamToolkit.Common", "WygwamToolkit.Common\WygwamToolkit.Common.csproj", "{C7C6E456-EF0F-455F-A21D-567E3B5676B7}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WygwamToolkit.Phone", "WygwamToolkit.Phone\WygwamToolkit.Phone.csproj", "{BFC3B021-B066-4194-AE6E-21217F43576A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WygwamToolkit.WinRT", "WygwamToolkit.WinRT\WygwamToolkit.WinRT.csproj", "{8AD870BE-26B6-4290-92D8-6DACDA602512}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|ARM.ActiveCfg = Debug|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|x64.ActiveCfg = Debug|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|x86.ActiveCfg = Debug|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|Any CPU.Build.0 = Release|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|ARM.ActiveCfg = Release|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|x64.ActiveCfg = Release|Any CPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|x86.ActiveCfg = Release|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|ARM.ActiveCfg = Debug|ARM - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|ARM.Build.0 = Debug|ARM - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x64.ActiveCfg = Debug|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x86.ActiveCfg = Debug|x86 - {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x86.Build.0 = Debug|x86 - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|Any CPU.Build.0 = Release|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|ARM.ActiveCfg = Release|ARM - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|ARM.Build.0 = Release|ARM - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x64.ActiveCfg = Release|Any CPU - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x86.ActiveCfg = Release|x86 - {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x86.Build.0 = Release|x86 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|ARM.ActiveCfg = Debug|ARM - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|ARM.Build.0 = Debug|ARM - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x64.ActiveCfg = Debug|x64 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x64.Build.0 = Debug|x64 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x86.ActiveCfg = Debug|x86 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x86.Build.0 = Debug|x86 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|Any CPU.Build.0 = Release|Any CPU - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|ARM.ActiveCfg = Release|ARM - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|ARM.Build.0 = Release|ARM - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x64.ActiveCfg = Release|x64 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x64.Build.0 = Release|x64 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x86.ActiveCfg = Release|x86 - {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wygwam.Windows", "WygwamToolkit.Common\Wygwam.Windows.csproj", "{C7C6E456-EF0F-455F-A21D-567E3B5676B7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wygwam.Windows.Phone", "WygwamToolkit.Phone\Wygwam.Windows.Phone.csproj", "{BFC3B021-B066-4194-AE6E-21217F43576A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wygwam.Windows.WinRT", "WygwamToolkit.WinRT\Wygwam.Windows.WinRT.csproj", "{8AD870BE-26B6-4290-92D8-6DACDA602512}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AC537702-9371-4EAB-901C-2AEBF5F0DDD4}" + ProjectSection(SolutionItems) = preProject + LICENSE.md = LICENSE.md + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|ARM.ActiveCfg = Debug|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|x64.ActiveCfg = Debug|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Debug|x86.ActiveCfg = Debug|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|Any CPU.Build.0 = Release|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|ARM.ActiveCfg = Release|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|x64.ActiveCfg = Release|Any CPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7}.Release|x86.ActiveCfg = Release|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|ARM.ActiveCfg = Debug|ARM + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|ARM.Build.0 = Debug|ARM + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x64.ActiveCfg = Debug|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x86.ActiveCfg = Debug|x86 + {BFC3B021-B066-4194-AE6E-21217F43576A}.Debug|x86.Build.0 = Debug|x86 + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|Any CPU.Build.0 = Release|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|ARM.ActiveCfg = Release|ARM + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|ARM.Build.0 = Release|ARM + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x64.ActiveCfg = Release|Any CPU + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x86.ActiveCfg = Release|x86 + {BFC3B021-B066-4194-AE6E-21217F43576A}.Release|x86.Build.0 = Release|x86 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|ARM.ActiveCfg = Debug|ARM + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|ARM.Build.0 = Debug|ARM + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x64.ActiveCfg = Debug|x64 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x64.Build.0 = Debug|x64 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x86.ActiveCfg = Debug|x86 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Debug|x86.Build.0 = Debug|x86 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|Any CPU.Build.0 = Release|Any CPU + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|ARM.ActiveCfg = Release|ARM + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|ARM.Build.0 = Release|ARM + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x64.ActiveCfg = Release|x64 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x64.Build.0 = Release|x64 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x86.ActiveCfg = Release|x86 + {8AD870BE-26B6-4290-92D8-6DACDA602512}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WygwamToolkit.Common/Managers/ANetworkManager.cs b/WygwamToolkit.Common/Managers/ANetworkManager.cs deleted file mode 100644 index 5cea389..0000000 --- a/WygwamToolkit.Common/Managers/ANetworkManager.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WygwamToolkit.Common.Managers -{ - public abstract class ANetworkManager - { - public event EventHandler InternetConnectionChanged; - - public abstract bool IsNetworkAvailable { get; } - - protected void NetworkInformation_NetworkStatusChanged(object sender) - { - var arg = new NetworkChangedEventArgs { IsConnected = this.IsNetworkAvailable }; - - if (InternetConnectionChanged != null) - InternetConnectionChanged(null, arg); - } - } - - public class NetworkChangedEventArgs : EventArgs - { - public bool IsConnected { get; set; } - } -} diff --git a/WygwamToolkit.Common/Managers/AStorageManager.cs b/WygwamToolkit.Common/Managers/AStorageManager.cs index cac2bc9..46e43f4 100644 --- a/WygwamToolkit.Common/Managers/AStorageManager.cs +++ b/WygwamToolkit.Common/Managers/AStorageManager.cs @@ -1,118 +1,118 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WygwamToolkit.Common.Tools; - -namespace WygwamToolkit.Common.Managers -{ - public abstract class AStorageManager - { - private readonly AsyncSemaphore _lock = new AsyncSemaphore(1); - - #region Settings - public async Task SaveSettingAsync(string key, object data) - { - bool ret = false; - - await _lock.WaitAsync(); - try - { - ret = await this.SavePlatformAsync(key, data); - } - finally { _lock.Release(); } - return ret; - } - - public async Task LoadSettingAsync(string key) - { - T ret; - - await _lock.WaitAsync(); - try - { - ret = await this.LoadPlatformAsync(key); - } - finally { _lock.Release(); } - - return ret; - } - - public async Task ClearSettingAsync(string key) - { - bool ret; - - await _lock.WaitAsync(); - try - { - ret = await this.ClearPlatformAsync(key); - } - finally { _lock.Release(); } - - return ret; - } - - #endregion - - #region Data - public async Task SaveDataAsync(string path, object data) - { - bool ret; - - await _lock.WaitAsync(); - try - { - ret = await this.SaveDataPlatformAsync(path, data); - } - finally { _lock.Release(); } - - return ret; - } - - public async Task LoadDataAsync(string path) - { - T ret; - - await _lock.WaitAsync(); - try - { - ret = await this.LoadDataPlatformAsync(path); - } - finally { _lock.Release(); } - - return ret; - } - - public async Task ClearDataAsync(string path) - { - bool ret; - - await _lock.WaitAsync(); - try - { - ret = await this.ClearDataPlatformAsync(path); - } - finally { _lock.Release(); } - - return ret; - } - - #endregion - - #region virtual - protected abstract Task SavePlatformAsync(string key, object data); - - protected abstract Task LoadPlatformAsync(string key); - - protected abstract Task ClearPlatformAsync(string key); - - - protected abstract Task SaveDataPlatformAsync(string path, object data); - - protected abstract Task LoadDataPlatformAsync(string path); - - protected abstract Task ClearDataPlatformAsync(string path); - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Wygwam.Windows; + +namespace WygwamToolkit.Common.Managers +{ + public abstract class AStorageManager + { + private readonly AsyncSemaphore _lock = new AsyncSemaphore(1); + + #region Settings + public async Task SaveSettingAsync(string key, object data) + { + bool ret = false; + + await _lock.WaitAsync(); + try + { + ret = await this.SavePlatformAsync(key, data); + } + finally { _lock.Release(); } + return ret; + } + + public async Task LoadSettingAsync(string key) + { + T ret; + + await _lock.WaitAsync(); + try + { + ret = await this.LoadPlatformAsync(key); + } + finally { _lock.Release(); } + + return ret; + } + + public async Task ClearSettingAsync(string key) + { + bool ret; + + await _lock.WaitAsync(); + try + { + ret = await this.ClearPlatformAsync(key); + } + finally { _lock.Release(); } + + return ret; + } + + #endregion + + #region Data + public async Task SaveDataAsync(string path, object data) + { + bool ret; + + await _lock.WaitAsync(); + try + { + ret = await this.SaveDataPlatformAsync(path, data); + } + finally { _lock.Release(); } + + return ret; + } + + public async Task LoadDataAsync(string path) + { + T ret; + + await _lock.WaitAsync(); + try + { + ret = await this.LoadDataPlatformAsync(path); + } + finally { _lock.Release(); } + + return ret; + } + + public async Task ClearDataAsync(string path) + { + bool ret; + + await _lock.WaitAsync(); + try + { + ret = await this.ClearDataPlatformAsync(path); + } + finally { _lock.Release(); } + + return ret; + } + + #endregion + + #region virtual + protected abstract Task SavePlatformAsync(string key, object data); + + protected abstract Task LoadPlatformAsync(string key); + + protected abstract Task ClearPlatformAsync(string key); + + + protected abstract Task SaveDataPlatformAsync(string path, object data); + + protected abstract Task LoadDataPlatformAsync(string path); + + protected abstract Task ClearDataPlatformAsync(string path); + #endregion + } +} diff --git a/WygwamToolkit.Common/Managers/ILocationManager.cs b/WygwamToolkit.Common/Managers/ILocationManager.cs index 61576f0..a763d5b 100644 --- a/WygwamToolkit.Common/Managers/ILocationManager.cs +++ b/WygwamToolkit.Common/Managers/ILocationManager.cs @@ -1,51 +1,51 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WygwamToolkit.Common.Managers -{ - public interface ILocationManager - { - GeoPosition LastKnowPosition { get; set; } - - Task GetLocationAsync(); - Task AskForRightAsync(); - } - - public class GeoPosition - { - public enum Unit - { - Km, - Miles, - } - - public double Latitude { get; set; } - public double Longitude { get; set; } - - public GeoPosition(double latitude, double longitude) - { - this.Latitude = latitude; - this.Longitude = longitude; - } - - public double DistanceTo(GeoPosition pos, Unit unit = Unit.Km) - { - var rlat1 = Math.PI * this.Latitude / 180; - var rlat2 = Math.PI * pos.Latitude / 180; - var rlon1 = Math.PI * this.Longitude / 180; - var rlon2 = Math.PI * pos.Longitude / 180; - var theta = this.Longitude - pos.Longitude; - var rtheta = Math.PI * theta / 180; - var dist = Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) * Math.Cos(rlat2) * Math.Cos(rtheta); - dist = Math.Acos(dist); - dist = dist * 180 / Math.PI; - dist = dist * 60 * 1.1515; - if (unit == Unit.Km) { dist = dist * 1.609344; } - if (unit == Unit.Miles) { dist = dist * 0.8684; } - return dist; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WygwamToolkit.Common.Managers +{ + public interface ILocationManager + { + GeoPosition LastKnowPosition { get; set; } + + Task GetLocationAsync(); + Task AskForRightAsync(); + } + + public class GeoPosition + { + public enum Unit + { + Km, + Miles, + } + + public double Latitude { get; set; } + public double Longitude { get; set; } + + public GeoPosition(double latitude, double longitude) + { + this.Latitude = latitude; + this.Longitude = longitude; + } + + public double DistanceTo(GeoPosition pos, Unit unit = Unit.Km) + { + var rlat1 = Math.PI * this.Latitude / 180; + var rlat2 = Math.PI * pos.Latitude / 180; + var rlon1 = Math.PI * this.Longitude / 180; + var rlon2 = Math.PI * pos.Longitude / 180; + var theta = this.Longitude - pos.Longitude; + var rtheta = Math.PI * theta / 180; + var dist = Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) * Math.Cos(rlat2) * Math.Cos(rtheta); + dist = Math.Acos(dist); + dist = dist * 180 / Math.PI; + dist = dist * 60 * 1.1515; + if (unit == Unit.Km) { dist = dist * 1.609344; } + if (unit == Unit.Miles) { dist = dist * 0.8684; } + return dist; + } + } +} diff --git a/WygwamToolkit.Common/Networking/InternetConnectionType.cs b/WygwamToolkit.Common/Networking/InternetConnectionType.cs new file mode 100644 index 0000000..a2887d8 --- /dev/null +++ b/WygwamToolkit.Common/Networking/InternetConnectionType.cs @@ -0,0 +1,34 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) 2013 Wygwam. +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wygwam.Windows.Networking +{ + public enum InternetConnectionType + { + None, + Ethernet, + WiFi, + Cell, + Unknown + } +} diff --git a/WygwamToolkit.Common/Networking/NetworkChangedEventArgs.cs b/WygwamToolkit.Common/Networking/NetworkChangedEventArgs.cs new file mode 100644 index 0000000..3b0aecf --- /dev/null +++ b/WygwamToolkit.Common/Networking/NetworkChangedEventArgs.cs @@ -0,0 +1,49 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) 2013 Wygwam. +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wygwam.Windows.Networking +{ + + public class NetworkChangedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// set to true if an Internet connection is available. + public NetworkChangedEventArgs(bool isConnected, InternetConnectionType connectionType = InternetConnectionType.Unknown) + { + this.IsConnected = isConnected; + this.ConnectionType = connectionType; + } + + /// + /// Gets a value indicating whether an Internet connection is available. + /// + public bool IsConnected { get; private set; } + + /// + /// Gets the type of the connection. + /// + public InternetConnectionType ConnectionType { get; private set; } + } +} diff --git a/WygwamToolkit.Common/Networking/NetworkManager.cs b/WygwamToolkit.Common/Networking/NetworkManager.cs new file mode 100644 index 0000000..4210460 --- /dev/null +++ b/WygwamToolkit.Common/Networking/NetworkManager.cs @@ -0,0 +1,89 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) 2013 Wygwam. +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------- + +using System; + +namespace Wygwam.Windows.Networking +{ + /// + /// Serves as a base for platform-specific classes that provide access to network connection information. + /// + public abstract class NetworkManager : IDisposable + { + /// + /// Occurs when the Internet connection changes. + /// + public event EventHandler InternetConnectionChanged; + + /// + /// Gets a value indicating whether a network connection is available. + /// + public abstract bool IsNetworkAvailable { get; } + + /// + /// Gets the type of the connection. + /// + public abstract InternetConnectionType ConnectionType { get; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Gets the current network status. + /// + /// The object notifying that network status changed. + /// An instance of describing the current network status. + protected abstract NetworkChangedEventArgs GetCurrentNetworkStatus(object sender); + + /// + /// Called when network status changes. + /// + /// The object notifying that network status changed. + protected virtual void OnNetworkStatusChanged(object sender) + { + this.OnInternetConnectionChanged(this.GetCurrentNetworkStatus(sender)); + } + + /// + /// Raises the event. + /// + /// The instance containing the event data. + protected virtual void OnInternetConnectionChanged(NetworkChangedEventArgs e) + { + EventHandler handler = this.InternetConnectionChanged; + + if (handler != null) + { + handler(this, e); + } + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + } + } +} diff --git a/WygwamToolkit.Common/Properties/AssemblyInfo.cs b/WygwamToolkit.Common/Properties/AssemblyInfo.cs index e0816c3..f8767d4 100644 --- a/WygwamToolkit.Common/Properties/AssemblyInfo.cs +++ b/WygwamToolkit.Common/Properties/AssemblyInfo.cs @@ -1,30 +1,30 @@ -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 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("WygwamToolkit.Common")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WygwamToolkit.Common")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// 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")] +using System.Resources; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("Wygwam.Windows")] +[assembly: AssemblyDescription("A toolkit for cross-platform development between WinRT and Windows Phone.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Wygwam")] +[assembly: AssemblyProduct("Wygwam.Windows")] +[assembly: AssemblyCopyright("Copyright © 2013 Wygwam")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] + +// 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")] diff --git a/WygwamToolkit.Common/Tools/AsyncSemaphore.cs b/WygwamToolkit.Common/Tools/AsyncSemaphore.cs index ad42400..fce17c2 100644 --- a/WygwamToolkit.Common/Tools/AsyncSemaphore.cs +++ b/WygwamToolkit.Common/Tools/AsyncSemaphore.cs @@ -1,53 +1,70 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WygwamToolkit.Common.Tools -{ - public class AsyncSemaphore - { - private readonly static Task s_completed = Task.FromResult(true); - private readonly Queue> m_waiters = new Queue>(); - private int m_currentCount; - - public AsyncSemaphore(int initialCount) - { - if (initialCount < 0) throw new ArgumentOutOfRangeException("initialCount"); - m_currentCount = initialCount; - } - - public Task WaitAsync() - { - lock (m_waiters) - { - if (m_currentCount > 0) - { - --m_currentCount; - return s_completed; - } - else - { - var waiter = new TaskCompletionSource(); - m_waiters.Enqueue(waiter); - return waiter.Task; - } - } - } - - public void Release() - { - TaskCompletionSource toRelease = null; - lock (m_waiters) - { - if (m_waiters.Count > 0) - toRelease = m_waiters.Dequeue(); - else - ++m_currentCount; - } - if (toRelease != null) - toRelease.SetResult(true); - } - } -} +//----------------------------------------------------------------------- +// +// Copyright (c) 2013 Wygwam. +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wygwam.Windows +{ + public class AsyncSemaphore + { + private readonly static Task s_completed = Task.FromResult(true); + private readonly Queue> m_waiters = new Queue>(); + private int m_currentCount; + + public AsyncSemaphore(int initialCount) + { + if (initialCount < 0) throw new ArgumentOutOfRangeException("initialCount"); + m_currentCount = initialCount; + } + + public Task WaitAsync() + { + lock (m_waiters) + { + if (m_currentCount > 0) + { + --m_currentCount; + return s_completed; + } + else + { + var waiter = new TaskCompletionSource(); + m_waiters.Enqueue(waiter); + return waiter.Task; + } + } + } + + public void Release() + { + TaskCompletionSource toRelease = null; + lock (m_waiters) + { + if (m_waiters.Count > 0) + toRelease = m_waiters.Dequeue(); + else + ++m_currentCount; + } + if (toRelease != null) + toRelease.SetResult(true); + } + } +} diff --git a/WygwamToolkit.Common/WygwamToolkit.Common.csproj b/WygwamToolkit.Common/Wygwam.Windows.csproj similarity index 88% rename from WygwamToolkit.Common/WygwamToolkit.Common.csproj rename to WygwamToolkit.Common/Wygwam.Windows.csproj index 50a6f30..5caf633 100644 --- a/WygwamToolkit.Common/WygwamToolkit.Common.csproj +++ b/WygwamToolkit.Common/Wygwam.Windows.csproj @@ -1,53 +1,55 @@ - - - - - 11.0 - Debug - AnyCPU - {C7C6E456-EF0F-455F-A21D-567E3B5676B7} - Library - Properties - WygwamToolkit.Common - WygwamToolkit.Common - v4.5 - Profile78 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - + + + + + 11.0 + Debug + AnyCPU + {C7C6E456-EF0F-455F-A21D-567E3B5676B7} + Library + Properties + Wygwam.Windows + Wygwam.Windows + v4.5 + Profile78 + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WygwamToolkit.Phone/Managers/NetworkManager.cs b/WygwamToolkit.Phone/Managers/NetworkManager.cs index 857c5d9..364eb27 100644 --- a/WygwamToolkit.Phone/Managers/NetworkManager.cs +++ b/WygwamToolkit.Phone/Managers/NetworkManager.cs @@ -1,27 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.NetworkInformation; -using System.Text; -using System.Threading.Tasks; -using Windows.Networking.Connectivity; -using WygwamToolkit.Common.Managers; - -namespace WygwamToolkit.Phone.Managers -{ - public class NetworkManager : ANetworkManager - { - public override bool IsNetworkAvailable - { - get - { - return NetworkInterface.GetIsNetworkAvailable(); - } - } - - public NetworkManager() - { - NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; +using Windows.Networking.Connectivity; +using WygwamToolkit.Common.Managers; + +namespace WygwamToolkit.Phone.Managers +{ + public class NetworkManager : Wygwam.Windows.Networking.NetworkManager + { + public override bool IsNetworkAvailable + { + get + { + return NetworkInterface.GetIsNetworkAvailable(); + } + } + + public NetworkManager() + { + NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged; + } + + protected override Wygwam.Windows.Networking.NetworkChangedEventArgs GetCurrentNetworkStatus(object sender) + { + throw new NotImplementedException(); + } + } +} diff --git a/WygwamToolkit.Phone/Properties/AssemblyInfo.cs b/WygwamToolkit.Phone/Properties/AssemblyInfo.cs index d28e687..421cdd5 100644 --- a/WygwamToolkit.Phone/Properties/AssemblyInfo.cs +++ b/WygwamToolkit.Phone/Properties/AssemblyInfo.cs @@ -1,37 +1,37 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Resources; - -// 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("WygwamToolkit.Phone")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WygwamToolkit.Phone")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[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)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("bfc3b021-b066-4194-ae6e-21217f43576a")] - -// 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 Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: NeutralResourcesLanguageAttribute("en-US")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Resources; + +// 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("Wygwam.Windows.Phone")] +[assembly: AssemblyDescription("A toolkit for Windows Phone development.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Wygwam")] +[assembly: AssemblyProduct("Wygwam.Windows.Phone")] +[assembly: AssemblyCopyright("Copyright © 2013 Wygwam")] +[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)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bfc3b021-b066-4194-ae6e-21217f43576a")] + +// 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 Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("en-US")] diff --git a/WygwamToolkit.Phone/WygwamToolkit.Phone.csproj b/WygwamToolkit.Phone/Wygwam.Windows.Phone.csproj similarity index 93% rename from WygwamToolkit.Phone/WygwamToolkit.Phone.csproj rename to WygwamToolkit.Phone/Wygwam.Windows.Phone.csproj index 0057ba8..2efc622 100644 --- a/WygwamToolkit.Phone/WygwamToolkit.Phone.csproj +++ b/WygwamToolkit.Phone/Wygwam.Windows.Phone.csproj @@ -1,107 +1,107 @@ - - - - Debug - AnyCPU - 10.0.20506 - 2.0 - {BFC3B021-B066-4194-AE6E-21217F43576A} - {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - WygwamToolkit.Phone - WygwamToolkit.Phone - WindowsPhone - v8.0 - $(TargetFrameworkVersion) - false - true - 11.0 - true - - - true - full - false - Bin\Debug - DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - pdbonly - true - Bin\Release - TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - true - full - false - Bin\x86\Debug - DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - pdbonly - true - Bin\x86\Release - TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - true - full - false - Bin\ARM\Debug - DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - pdbonly - true - Bin\ARM\Release - TRACE;SILVERLIGHT;WINDOWS_PHONE - true - true - prompt - 4 - - - - - - - - - - {C7C6E456-EF0F-455F-A21D-567E3B5676B7} - WygwamToolkit.Common - - - - - - + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {BFC3B021-B066-4194-AE6E-21217F43576A} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Wygwam.Windows.Phone + Wygwam.Windows.Phone + WindowsPhone + v8.0 + $(TargetFrameworkVersion) + false + true + 11.0 + true + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\x86\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\x86\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + true + full + false + Bin\ARM\Debug + DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + pdbonly + true + Bin\ARM\Release + TRACE;SILVERLIGHT;WINDOWS_PHONE + true + true + prompt + 4 + + + + + + + + + + {C7C6E456-EF0F-455F-A21D-567E3B5676B7} + Wygwam.Windows + + + + + + \ No newline at end of file diff --git a/WygwamToolkit.WinRT/Managers/LocationManager.cs b/WygwamToolkit.WinRT/Managers/LocationManager.cs index 83daf33..7aebbc3 100644 --- a/WygwamToolkit.WinRT/Managers/LocationManager.cs +++ b/WygwamToolkit.WinRT/Managers/LocationManager.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.Devices.Geolocation; -using WygwamToolkit.Common.Managers; - -namespace WygwamToolkit.WinRT.Managers -{ - public class LocationManager : ILocationManager - { - public GeoPosition LastKnowPosition { get; set; } - - public async Task GetLocationAsync() - { - Geolocator gl = new Geolocator(); - Geoposition gp = await gl.GetGeopositionAsync(); - - return new GeoPosition(gp.Coordinate.Latitude, gp.Coordinate.Longitude); - } - - public Task AskForRightAsync() - { - throw new NotImplementedException(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using WygwamToolkit.Common.Managers; + +namespace WygwamToolkit.WinRT.Managers +{ + public class LocationManager : ILocationManager + { + public GeoPosition LastKnowPosition { get; set; } + + public async Task GetLocationAsync() + { + Geolocator gl = new Geolocator(); + Geoposition gp = await gl.GetGeopositionAsync(); + + return new GeoPosition(gp.Coordinate.Latitude, gp.Coordinate.Longitude); + } + + public Task AskForRightAsync() + { + throw new NotImplementedException(); + } + } +} diff --git a/WygwamToolkit.WinRT/Managers/NetworkManager.cs b/WygwamToolkit.WinRT/Managers/NetworkManager.cs index cc7adfa..558bfeb 100644 --- a/WygwamToolkit.WinRT/Managers/NetworkManager.cs +++ b/WygwamToolkit.WinRT/Managers/NetworkManager.cs @@ -1,21 +1,127 @@ -using Windows.Networking.Connectivity; -using WygwamToolkit.Common.Managers; - -namespace PMV.Windows8.Common.Managers -{ - public class NetworkManager : ANetworkManager - { - public override bool IsNetworkAvailable - { - get - { - return NetworkInformation.GetInternetConnectionProfile() != null; - } - } - - public NetworkManager() - { - NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged; - } - } -} +//----------------------------------------------------------------------- +// +// Copyright (c) 2013 Wygwam. +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//----------------------------------------------------------------------- + +using Windows.Networking.Connectivity; +using Wygwam.Windows.Networking; + +namespace Wygwam.Windows.WinRT +{ + /// + /// Provide access to network connection information. + /// + public class NetworkManager : Wygwam.Windows.Networking.NetworkManager + { + private bool _usedCachedProfile; + + private ConnectionProfile _cachedProfile; + + /// + /// Initializes a new instance of the class. + /// + public NetworkManager() + { + NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged; + } + + /// + /// Gets a value indicating whether a network connection is available. + /// + public override bool IsNetworkAvailable + { + get + { + return this.CurrentInternetConnectionProfile != null && + this.CurrentInternetConnectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; + } + } + + /// + /// Gets the type of the connection. + /// + public override InternetConnectionType ConnectionType + { + get + { + if (!this.IsNetworkAvailable) + { + return InternetConnectionType.None; + } + + switch (this.CurrentInternetConnectionProfile.NetworkAdapter.IanaInterfaceType) + { + case 6: + return InternetConnectionType.Ethernet; + case 71: + return InternetConnectionType.WiFi; + case 243: + return InternetConnectionType.Cell; + } + + return InternetConnectionType.Unknown; + } + } + + /// + /// Gets the current Internet connection profile. + /// + /// Can use a cached version. + private ConnectionProfile CurrentInternetConnectionProfile + { + get + { + return _usedCachedProfile ? _cachedProfile : NetworkInformation.GetInternetConnectionProfile(); + } + } + + /// + /// Gets the current network status. + /// + /// The object notifying that network status changed. + /// + /// An instance of describing the current network status. + /// + protected override NetworkChangedEventArgs GetCurrentNetworkStatus(object sender) + { + try + { + _cachedProfile = NetworkInformation.GetInternetConnectionProfile(); + _usedCachedProfile = true; + + return new NetworkChangedEventArgs(this.IsNetworkAvailable, this.ConnectionType); + } + finally + { + _cachedProfile = null; + _usedCachedProfile = false; + } + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChanged; + } + } + } +} diff --git a/WygwamToolkit.WinRT/Managers/StorageManager.cs b/WygwamToolkit.WinRT/Managers/StorageManager.cs index ccf63b7..a8f31a0 100644 --- a/WygwamToolkit.WinRT/Managers/StorageManager.cs +++ b/WygwamToolkit.WinRT/Managers/StorageManager.cs @@ -1,120 +1,120 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using System.Xml.Serialization; -using Windows.Storage; -using WygwamToolkit.Common.Managers; - -namespace PMV.Windows8.Common.Managers -{ - public class StorageManager : AStorageManager - { - public static StorageFolder DefaultFolder = ApplicationData.Current.RoamingFolder; - public static ApplicationDataContainer DefaultSettings = ApplicationData.Current.RoamingSettings; - - #region Settings - protected override async Task ClearPlatformAsync(string key) - { - return await Task.Run(() => - { - if (DefaultSettings.Values.ContainsKey(key)) - return DefaultSettings.Values.Remove(key); - - return false; - }); - } - - protected override async Task LoadPlatformAsync(string key) - { - return await Task.Run(() => - { - if (!DefaultSettings.Values.ContainsKey(key)) - return default(T); - - return (T)DefaultSettings.Values[key]; - }); - } - - protected override async Task SavePlatformAsync(string key, object data) - { - return await Task.Run(() => - { - if (null == data) - return false; - - if (DefaultSettings.Values.ContainsKey(key)) - DefaultSettings.Values[key] = data; - else - DefaultSettings.Values.Add(key, data); - - return true; - }); - } - #endregion - - #region Data - protected override async Task SaveDataPlatformAsync(string path, object data) - { - const CreationCollisionOption option = CreationCollisionOption.ReplaceExisting; - - try - { - var file = await DefaultFolder.CreateFileAsync(path, option); - var saveData = new MemoryStream(); - - var x = new XmlSerializer(data.GetType()); - x.Serialize(saveData, data); - - if (saveData.Length > 0) - { - using (var fileStream = await file.OpenStreamForWriteAsync()) - { - saveData.Seek(0, SeekOrigin.Begin); - await saveData.CopyToAsync(fileStream); - await fileStream.FlushAsync(); - } - return true; - } - } - catch (Exception ex) - { - } - - return false; - } - - protected override async Task LoadDataPlatformAsync(string path) - { - try - { - var file = await DefaultFolder.GetFileAsync(path); - - using (var inStream = await file.OpenSequentialReadAsync()) - { - var x = new XmlSerializer(typeof(T)); - return (T)x.Deserialize(inStream.AsStreamForRead()); - } - } - catch - { - return default(T); - } - } - - protected override async Task ClearDataPlatformAsync(string path) - { - try - { - var file = await DefaultFolder.GetFileAsync(path); - await file.DeleteAsync(); - return true; - } - catch (Exception ex) - { - } - - return false; - } - #endregion - } -} +using System; +using System.IO; +using System.Threading.Tasks; +using System.Xml.Serialization; +using Windows.Storage; +using WygwamToolkit.Common.Managers; + +namespace PMV.Windows8.Common.Managers +{ + public class StorageManager : AStorageManager + { + public static StorageFolder DefaultFolder = ApplicationData.Current.RoamingFolder; + public static ApplicationDataContainer DefaultSettings = ApplicationData.Current.RoamingSettings; + + #region Settings + protected override async Task ClearPlatformAsync(string key) + { + return await Task.Run(() => + { + if (DefaultSettings.Values.ContainsKey(key)) + return DefaultSettings.Values.Remove(key); + + return false; + }); + } + + protected override async Task LoadPlatformAsync(string key) + { + return await Task.Run(() => + { + if (!DefaultSettings.Values.ContainsKey(key)) + return default(T); + + return (T)DefaultSettings.Values[key]; + }); + } + + protected override async Task SavePlatformAsync(string key, object data) + { + return await Task.Run(() => + { + if (null == data) + return false; + + if (DefaultSettings.Values.ContainsKey(key)) + DefaultSettings.Values[key] = data; + else + DefaultSettings.Values.Add(key, data); + + return true; + }); + } + #endregion + + #region Data + protected override async Task SaveDataPlatformAsync(string path, object data) + { + const CreationCollisionOption option = CreationCollisionOption.ReplaceExisting; + + try + { + var file = await DefaultFolder.CreateFileAsync(path, option); + var saveData = new MemoryStream(); + + var x = new XmlSerializer(data.GetType()); + x.Serialize(saveData, data); + + if (saveData.Length > 0) + { + using (var fileStream = await file.OpenStreamForWriteAsync()) + { + saveData.Seek(0, SeekOrigin.Begin); + await saveData.CopyToAsync(fileStream); + await fileStream.FlushAsync(); + } + return true; + } + } + catch (Exception ex) + { + } + + return false; + } + + protected override async Task LoadDataPlatformAsync(string path) + { + try + { + var file = await DefaultFolder.GetFileAsync(path); + + using (var inStream = await file.OpenSequentialReadAsync()) + { + var x = new XmlSerializer(typeof(T)); + return (T)x.Deserialize(inStream.AsStreamForRead()); + } + } + catch + { + return default(T); + } + } + + protected override async Task ClearDataPlatformAsync(string path) + { + try + { + var file = await DefaultFolder.GetFileAsync(path); + await file.DeleteAsync(); + return true; + } + catch (Exception ex) + { + } + + return false; + } + #endregion + } +} diff --git a/WygwamToolkit.WinRT/Properties/AssemblyInfo.cs b/WygwamToolkit.WinRT/Properties/AssemblyInfo.cs index 6000576..77b5665 100644 --- a/WygwamToolkit.WinRT/Properties/AssemblyInfo.cs +++ b/WygwamToolkit.WinRT/Properties/AssemblyInfo.cs @@ -1,29 +1,29 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 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("WygwamToolkit.WinRT")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WygwamToolkit.WinRT")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 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")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("Wygwam.Windows.WinRT")] +[assembly: AssemblyDescription("A toolkit for WinRT development.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Wygwam")] +[assembly: AssemblyProduct("Wygwam.Windows.WinRT")] +[assembly: AssemblyCopyright("Copyright © 2013 Wygwam")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 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")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/WygwamToolkit.WinRT/WygwamToolkit.WinRT.csproj b/WygwamToolkit.WinRT/Wygwam.Windows.WinRT.csproj similarity index 94% rename from WygwamToolkit.WinRT/WygwamToolkit.WinRT.csproj rename to WygwamToolkit.WinRT/Wygwam.Windows.WinRT.csproj index 5188840..9c0c0ec 100644 --- a/WygwamToolkit.WinRT/WygwamToolkit.WinRT.csproj +++ b/WygwamToolkit.WinRT/Wygwam.Windows.WinRT.csproj @@ -1,125 +1,125 @@ - - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {8AD870BE-26B6-4290-92D8-6DACDA602512} - Library - Properties - WygwamToolkit.WinRT - WygwamToolkit.WinRT - en-US - 512 - {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE;NETFX_CORE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE;NETFX_CORE - prompt - 4 - - - true - bin\ARM\Debug\ - DEBUG;TRACE;NETFX_CORE - ;2008 - full - ARM - false - prompt - true - - - bin\ARM\Release\ - TRACE;NETFX_CORE - true - ;2008 - pdbonly - ARM - false - prompt - true - - - true - bin\x64\Debug\ - DEBUG;TRACE;NETFX_CORE - ;2008 - full - x64 - false - prompt - true - - - bin\x64\Release\ - TRACE;NETFX_CORE - true - ;2008 - pdbonly - x64 - false - prompt - true - - - true - bin\x86\Debug\ - DEBUG;TRACE;NETFX_CORE - ;2008 - full - x86 - false - prompt - true - - - bin\x86\Release\ - TRACE;NETFX_CORE - true - ;2008 - pdbonly - x86 - false - prompt - true - - - - - {c7c6e456-ef0f-455f-a21d-567e3b5676b7} - WygwamToolkit.Common - - - - - - - - - - 11.0 - - - + + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {8AD870BE-26B6-4290-92D8-6DACDA602512} + Library + Properties + Wygwam.Windows.WinRT + Wygwam.Windows.WinRT + en-US + 512 + {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE + prompt + 4 + + + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + ARM + false + prompt + true + + + bin\ARM\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + ARM + false + prompt + true + + + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x64 + false + prompt + true + + + bin\x64\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x64 + false + prompt + true + + + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE + ;2008 + full + x86 + false + prompt + true + + + bin\x86\Release\ + TRACE;NETFX_CORE + true + ;2008 + pdbonly + x86 + false + prompt + true + + + + + {c7c6e456-ef0f-455f-a21d-567e3b5676b7} + Wygwam.Windows + + + + + + + + + + 11.0 + + + \ No newline at end of file