Skip to content

Commit f4d21f1

Browse files
committed
Complete complete
1 parent c1a3fa9 commit f4d21f1

117 files changed

Lines changed: 32397 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.nuget/NuGet.exe

1.59 MB
Binary file not shown.

NativeClient-DotNet.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoListService", "TodoListService\TodoListService.csproj", "{047CDEF7-D5BA-4B1E-9748-910B610CCA51}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoListClient", "TodoListClient\TodoListClient.csproj", "{005E6BB1-F422-4366-B548-1BDE150F0073}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

TodoListClient/App.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
<appSettings>
7+
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
8+
<add key="ida:ClientId" value="{Enter the Application Id that you copied from the App Registration Portal.}" />
9+
<add key="ida:RedirectUri" value="{Enter the Redirect Uri copied from the App Registration Portal.}" />
10+
<add key="todo:TodoListBaseAddress" value="https://localhost:44321/" />
11+
</appSettings>
12+
</configuration>

TodoListClient/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="TodoListClient.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

TodoListClient/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace TodoListClient
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

TodoListClient/FileCache.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Security.Cryptography;
9+
10+
namespace TodoListClient
11+
{
12+
13+
// This is a simple persistent cache implementation for a desktop application.
14+
// It uses DPAPI for storing tokens in a local file.
15+
class FileCache : TokenCache
16+
{
17+
public string CacheFilePath;
18+
private static readonly object FileLock = new object();
19+
20+
// Initializes the cache against a local file.
21+
// If the file is already rpesent, it loads its content in the ADAL cache
22+
public FileCache(string filePath=@".\TokenCache.dat")
23+
{
24+
CacheFilePath = filePath;
25+
this.AfterAccess = AfterAccessNotification;
26+
this.BeforeAccess = BeforeAccessNotification;
27+
lock (FileLock)
28+
{
29+
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), null, DataProtectionScope.CurrentUser) : null);
30+
}
31+
}
32+
33+
// Empties the persistent store.
34+
public override void Clear()
35+
{
36+
base.Clear();
37+
File.Delete(CacheFilePath);
38+
}
39+
40+
// Triggered right before ADAL needs to access the cache.
41+
// Reload the cache from the persistent store in case it changed since the last access.
42+
void BeforeAccessNotification(TokenCacheNotificationArgs args)
43+
{
44+
lock (FileLock)
45+
{
46+
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath),null,DataProtectionScope.CurrentUser) : null);
47+
}
48+
}
49+
50+
// Triggered right after ADAL accessed the cache.
51+
void AfterAccessNotification(TokenCacheNotificationArgs args)
52+
{
53+
// if the access operation resulted in a cache update
54+
if (this.HasStateChanged)
55+
{
56+
lock (FileLock)
57+
{
58+
// reflect changes in the persistent store
59+
File.WriteAllBytes(CacheFilePath, ProtectedData.Protect(this.Serialize(),null,DataProtectionScope.CurrentUser));
60+
// once the write operation took place, restore the HasStateChanged bit to false
61+
this.HasStateChanged = false;
62+
}
63+
}
64+
}
65+
}
66+
67+
}

TodoListClient/MainWindow.xaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<Window
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
x:Class="TodoListClient.MainWindow"
5+
Title="To Do List Client" Height="400" Width="400" WindowStartupLocation="CenterScreen">
6+
<Grid Margin="12">
7+
<Grid.Resources>
8+
<VisualBrush x:Key="TodoHint" Stretch="None" AlignmentX="Left" AlignmentY="Top">
9+
<VisualBrush.Transform>
10+
<TranslateTransform X="4" Y="7" />
11+
</VisualBrush.Transform>
12+
<VisualBrush.Visual>
13+
<Grid>
14+
<TextBlock Text="Enter to do item" FontWeight="Normal" Foreground="Gray"
15+
FontSize="12" TextAlignment="Justify"/>
16+
</Grid>
17+
</VisualBrush.Visual>
18+
</VisualBrush>
19+
</Grid.Resources>
20+
<StackPanel Grid.Row="0" Margin="5" VerticalAlignment="Top" Height="351">
21+
<Button HorizontalAlignment="Right" Content="Sign In" Margin="0" Click="SignIn" x:Name="SignInButton" Width="80" Height="30">
22+
<Button.Style>
23+
<Style TargetType="{x:Type Button}">
24+
<!-- "<Setter Property="IsEnabled" Value="False" /> -->
25+
</Style>
26+
</Button.Style>
27+
28+
</Button>
29+
<GroupBox Margin="0,0,0,0" Header="Create a To Do item">
30+
31+
<Grid Margin="0" HorizontalAlignment="Left" Width="388" >
32+
<Grid.ColumnDefinitions>
33+
<ColumnDefinition Width="130*"/>
34+
<ColumnDefinition Width="85*"/>
35+
</Grid.ColumnDefinitions>
36+
<TextBox Grid.Column="0" HorizontalAlignment="Left" Height="34" FontSize="12" TextWrapping="Wrap" VerticalAlignment="Top" Width="199"
37+
x:Name="TodoText" Margin="10,10,0,0" TabIndex="1" Padding="3">
38+
<TextBox.Style>
39+
<Style TargetType="{x:Type TextBox}">
40+
<Setter Property="Background" Value="Transparent" />
41+
<Style.Triggers>
42+
<DataTrigger Binding="{Binding Text, ElementName=TodoText}" Value="">
43+
<Setter Property="Background" Value="{StaticResource TodoHint}"/>
44+
</DataTrigger>
45+
</Style.Triggers>
46+
</Style>
47+
</TextBox.Style>
48+
</TextBox>
49+
<Button Grid.Column="1" Content="Add item" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="101" RenderTransformOrigin="-0.013,0.15" Click="AddTodoItem" Height="34" IsDefault="True" TabIndex="2"/>
50+
</Grid>
51+
52+
</GroupBox>
53+
<DataGrid x:Name="TodoList" Margin="0,0,0,0" AutoGenerateColumns="False" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
54+
IsReadOnly="True" MinWidth="350" CanUserAddRows="False" CanUserDeleteRows="False" Height="230" GridLinesVisibility="None" Background="#FFFFFFFF">
55+
56+
<DataGrid.Columns>
57+
<DataGridTextColumn Header="To Do Items" Binding="{Binding Title}" Width="*"/>
58+
</DataGrid.Columns>
59+
60+
</DataGrid>
61+
</StackPanel>
62+
</Grid>
63+
</Window>

0 commit comments

Comments
 (0)