Merge remote-tracking branch 'origin/dev' into dev

Conflicts:
	HueUWP/MainPage.xaml.cs
This commit is contained in:
2015-11-27 13:36:08 +01:00
9 changed files with 176 additions and 40 deletions
+36
View File
@@ -0,0 +1,36 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace HueUWP
{
class APIHandler
{
NetworkHandler nwh;
public APIHandler(NetworkHandler nwh)
{
this.nwh = nwh;
}
private JObject ObjectifyfJson(string json)
{
json = json.Replace("[", "").Replace("]", "");
return JObject.Parse(json);
}
public async void Register()
{
var json = await nwh.RegisterName("Hue", "Kenneth&Yorick");
JObject o = ObjectifyfJson(json);
string id= o["success"]["username"].ToString();
MainPage.LOCAL_SETTINGS.Values["id"] = id;
}
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
<Application
x:Class="BindingToCommandsUWP.App"
x:Class="HueUWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BindingToCommandsUWP"
+1 -1
View File
@@ -15,7 +15,7 @@ using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace BindingToCommandsUWP
namespace HueUWP
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
+7 -6
View File
@@ -93,6 +93,7 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="APIHandler.cs" />
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
@@ -133,11 +134,11 @@
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+2 -2
View File
@@ -1,5 +1,5 @@
<Page
x:Class="BindingToCommandsUWP.MainPage"
x:Class="HueUWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BindingToCommandsUWP"
@@ -11,7 +11,7 @@
<Grid>
<StackPanel Margin="20,40,20,40">
<ListView x:Name="myListView" ItemsSource="{Binding}" >
<ListView x:Name="myListView" ItemsSource="{Binding}" >
<ListView.ItemTemplate>
<DataTemplate x:Name="dataTemplate">
<StackPanel Orientation="Horizontal">
+12 -4
View File
@@ -1,4 +1,3 @@
using HueUWP;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -8,6 +7,7 @@ using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
@@ -18,7 +18,7 @@ using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace BindingToCommandsUWP
namespace HueUWP
{
@@ -28,6 +28,8 @@ namespace BindingToCommandsUWP
/// </summary>
public sealed partial class MainPage : Page
{
public static ApplicationDataContainer LOCAL_SETTINGS = ApplicationData.Current.LocalSettings;
private ObservableCollection<Light> _lightsViewModel = LightDataSource.GetLights();
public ObservableCollection<Light> LightsViewModel
@@ -38,8 +40,13 @@ namespace BindingToCommandsUWP
public MainPage()
{
this.InitializeComponent();
Debug.WriteLine(new NetworkHandler().RegisterName("Kaas", "Henk"));
Debug.WriteLine(new NetworkHandler().Test());
LOCAL_SETTINGS.Values["ip"] = "localhost";
LOCAL_SETTINGS.Values["port"] = 8000;
NetworkHandler nwh = new NetworkHandler();
APIHandler api = new APIHandler(nwh);
//api.Register();
Debug.WriteLine(LOCAL_SETTINGS.Values["id"]);
}
private void ColorChanged(object sender, RoutedEventArgs e)
@@ -57,5 +64,6 @@ namespace BindingToCommandsUWP
light.UpdateState(button.IsOn);
}
}
}
+20 -10
View File
@@ -11,7 +11,15 @@ namespace HueUWP
{
class NetworkHandler
{
private async Task<String> Put(string ip, int port, string path, string json)
string ip;
int port;
public NetworkHandler()
{
this.ip = (string) MainPage.LOCAL_SETTINGS.Values["ip"];
this.port = (int)MainPage.LOCAL_SETTINGS.Values["port"];
}
private async Task<String> Put(string path, string json)
{
var cts = new CancellationTokenSource();
cts.CancelAfter(5000);
@@ -31,7 +39,7 @@ namespace HueUWP
string jsonResponse = await response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine(jsonResponse);
//System.Diagnostics.Debug.WriteLine(jsonResponse);
return jsonResponse;
}
@@ -43,7 +51,7 @@ namespace HueUWP
}
private async Task<String> Post(string ip, int port, string path, string json)
private async Task<String> Post(string path, string json)
{
var cts = new CancellationTokenSource();
cts.CancelAfter(5000);
@@ -63,7 +71,7 @@ namespace HueUWP
string jsonResponse = await response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine(jsonResponse);
//System.Diagnostics.Debug.WriteLine(jsonResponse);
return jsonResponse;
}
@@ -74,7 +82,7 @@ namespace HueUWP
}
}
private async Task<String> Get(string ip, int port, string path)
private async Task<String> Get(string path)
{
var cts = new CancellationTokenSource();
cts.CancelAfter(5000);
@@ -94,7 +102,7 @@ namespace HueUWP
string jsonResponse = await response.Content.ReadAsStringAsync();
System.Diagnostics.Debug.WriteLine(jsonResponse);
//System.Diagnostics.Debug.WriteLine(jsonResponse);
return jsonResponse;
}
@@ -106,18 +114,20 @@ namespace HueUWP
}
public async Task RegisterName(string AppName, string UserName)
public async Task<String> RegisterName(string AppName, string UserName)
{
var response = await Post("localhost",8000,"",$"{{\"devicetype\":\"{AppName}#{UserName}\"}}");
var response = await Post("",$"{{\"devicetype\":\"{AppName}#{UserName}\"}}");
if (string.IsNullOrEmpty(response))
await new MessageDialog("Error while setting username. ….").ShowAsync();
return response;
}
public async Task Test()
public async Task<String> Test()
{
var response = await Get("localhost", 8000, "/111bb033202ac68b5812245c22f77eb/lights");
var response = await Get( "/111bb033202ac68b5812245c22f77eb/lights");
if (string.IsNullOrEmpty(response))
await new MessageDialog("Error while setting username. ….").ShowAsync();
return response;
}
+16 -15
View File
@@ -1,16 +1,17 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Newtonsoft.Json": "7.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
+81 -1
View File
@@ -201,6 +201,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -1779,6 +1787,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -3390,6 +3406,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -5006,6 +5030,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -6617,6 +6649,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -8233,6 +8273,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -9844,6 +9892,14 @@
"lib/dotnet/Microsoft.Win32.Primitives.dll": {}
}
},
"Newtonsoft.Json/7.0.1": {
"compile": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll": {}
}
},
"System.AppContext/4.0.0": {
"dependencies": {
"System.Collections": "[4.0.0, )",
@@ -11868,6 +11924,29 @@
"ref/xamarinmac20/_._"
]
},
"Newtonsoft.Json/7.0.1": {
"sha512": "q3V4KLetMLnt1gpAVWgtXnHjKs0UG/RalBc29u2ZKxd5t5Ze4JBL5WiiYIklJyK/5CRiIiNwigVQUo0FgbsuWA==",
"type": "Package",
"files": [
"[Content_Types].xml",
"_rels/.rels",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml",
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll",
"lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.xml",
"Newtonsoft.Json.nuspec",
"package/services/metadata/core-properties/49e907fc018c4c7ab632e6d4ad4766f8.psmdcp",
"tools/install.ps1"
]
},
"System.AppContext/4.0.0": {
"sha512": "gUoYgAWDC3+xhKeU5KSLbYDhTdBYk9GssrMSCcWUADzOglW+s0AmwVhOUGt2tL5xUl7ZXoYTPdA88zCgKrlG0A==",
"type": "Package",
@@ -14566,7 +14645,8 @@
},
"projectFileDependencyGroups": {
"": [
"Microsoft.NETCore.UniversalWindowsPlatform >= 5.0.0"
"Microsoft.NETCore.UniversalWindowsPlatform >= 5.0.0",
"Newtonsoft.Json >= 7.0.1"
],
"UAP,Version=v10.0": []
}