Added global settings, added register function
This commit is contained in:
+16
-7
@@ -1,16 +1,17 @@
|
||||
using System;
|
||||
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
|
||||
namespace BindingToCommandsUWP
|
||||
{
|
||||
class APIHandler
|
||||
{
|
||||
public static ApplicationData APP_DATA = ApplicationData.Current;
|
||||
public static ApplicationDataContainer LOCAL_SETTINGS = APP_DATA.LocalSettings;
|
||||
|
||||
|
||||
NetworkHandler nwh;
|
||||
public APIHandler(NetworkHandler nwh)
|
||||
@@ -18,10 +19,18 @@ namespace HueUWP
|
||||
this.nwh = nwh;
|
||||
}
|
||||
|
||||
public void Register()
|
||||
private JObject ObjectifyfJson(string json)
|
||||
{
|
||||
string id = nwh.RegisterName("Hue", "Kenneth&Yorick").ToString();
|
||||
//write to file;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<Application
|
||||
x:Class="HueUWP.App"
|
||||
x:Class="BindingToCommandsUWP.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:HueUWP"
|
||||
xmlns:local="using:BindingToCommandsUWP"
|
||||
RequestedTheme="Light">
|
||||
|
||||
</Application>
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace HueUWP
|
||||
namespace BindingToCommandsUWP
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
@@ -43,7 +43,7 @@ namespace HueUWP
|
||||
#if DEBUG
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
this.DebugSettings.EnableFrameRateCounter = true;
|
||||
this.DebugSettings.EnableFrameRateCounter = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Light.cs" />
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HueUWP", "HueUWP.csproj", "{88414ECD-0462-41DE-ABA9-462D2F154595}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|ARM = Release|ARM
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.Build.0 = Debug|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.Build.0 = Debug|x86
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.Build.0 = Release|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.ActiveCfg = Release|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.Build.0 = Release|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x64.Deploy.0 = Release|x64
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.ActiveCfg = Release|x86
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.Build.0 = Release|x86
|
||||
{88414ECD-0462-41DE-ABA9-462D2F154595}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace BindingToCommandsUWP
|
||||
{
|
||||
public class Light : INotifyPropertyChanged
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
|
||||
private string checkedInDateTime;
|
||||
|
||||
public string CheckedInDateTime
|
||||
{
|
||||
get { return checkedInDateTime; }
|
||||
set
|
||||
{
|
||||
checkedInDateTime = value;
|
||||
NotifyPropertyChanged(nameof(CheckedInDateTime));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Light()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void CheckInCar()
|
||||
{
|
||||
this.CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class LightDataSource
|
||||
{
|
||||
private static ObservableCollection<Light> _cars
|
||||
= new ObservableCollection<Light>();
|
||||
|
||||
public static ObservableCollection<Light> GetCars()
|
||||
{
|
||||
if (_cars.Count == 0)
|
||||
{
|
||||
_cars.Add(new Light() { ID = 1, Make = "Tesla", Model = "Model S" });
|
||||
_cars.Add(new Light() { ID = 2, Make = "Tesla", Model = "Model 3" });
|
||||
_cars.Add(new Light() { ID = 3, Make = "Tesla", Model = "Model X" });
|
||||
}
|
||||
return _cars;
|
||||
}
|
||||
|
||||
//public static void CheckInCar(Car car)
|
||||
//{
|
||||
// _cars.FirstOrDefault(p => p.ID == car.ID).CheckedInDateTime = String.Format("{0:t}", DateTime.Now);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+31
-3
@@ -1,13 +1,41 @@
|
||||
<Page
|
||||
x:Class="HueUWP.MainPage"
|
||||
x:Class="BindingToCommandsUWP.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:HueUWP"
|
||||
xmlns:local="using:BindingToCommandsUWP"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
DataContext="{Binding CarsViewModel, RelativeSource={RelativeSource Self}}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid>
|
||||
<StackPanel Margin="20,40,20,40">
|
||||
<ListView x:Name="myListView" ItemsSource="{Binding}" >
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="dataTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel Orientation="Vertical" Width="110" Margin="0,0,0,20">
|
||||
<TextBlock Text="{Binding Make}" FontSize="24" />
|
||||
<TextBlock Text="{Binding Model}" FontSize="24" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Content="Check In"
|
||||
Width="100"
|
||||
Height="50"
|
||||
Margin="0,0,20,0"
|
||||
Click="CheckInButton_Click"
|
||||
|
||||
/>
|
||||
|
||||
<TextBlock Text="{Binding CheckedInDateTime}"
|
||||
FontSize="24" />
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
</ListView>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
Binary file not shown.
+21
-11
@@ -7,11 +7,19 @@ using System.Threading.Tasks;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.Web.Http;
|
||||
|
||||
namespace HueUWP
|
||||
namespace BindingToCommandsUWP
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity
|
||||
Name="f92196db-26a4-4fab-8aa6-ed6892357fd3"
|
||||
Publisher="CN=kenny"
|
||||
Name="ce9a0222-308a-470c-a219-f3b5a133de19"
|
||||
Publisher="CN=Paul de Mast"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="f92196db-26a4-4fab-8aa6-ed6892357fd3" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
<mp:PhoneIdentity PhoneProductId="ce9a0222-308a-470c-a219-f3b5a133de19" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
<Properties>
|
||||
<DisplayName>HueUWP</DisplayName>
|
||||
<PublisherDisplayName>kenny</PublisherDisplayName>
|
||||
<DisplayName>CarCheckInUWP</DisplayName>
|
||||
<PublisherDisplayName>Paul de Mast</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
@@ -30,12 +30,12 @@
|
||||
<Applications>
|
||||
<Application Id="App"
|
||||
Executable="$targetnametoken$.exe"
|
||||
EntryPoint="HueUWP.App">
|
||||
EntryPoint="CarCheckInUWP.App">
|
||||
<uap:VisualElements
|
||||
DisplayName="HueUWP"
|
||||
DisplayName="CarCheckInUWP"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png"
|
||||
Description="HueUWP"
|
||||
Description="CarCheckInUWP"
|
||||
BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
|
||||
Reference in New Issue
Block a user