Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 2aa5fd5

Browse files
committed
Refined the cache, service updated 2 latest nuget
1 parent 6dcd5e2 commit 2aa5fd5

File tree

71 files changed

+16004
-11195
lines changed

Some content is hidden

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

71 files changed

+16004
-11195
lines changed

TodoListClient/FileCache.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,35 @@
1010
namespace TodoListClient
1111
{
1212

13-
// TODO OVERRIDE Clear()
13+
// This is a simple persistent cache implementation for a desktop application.
14+
// It uses DPAPI for storing tokens in a local file.
1415
class FileCache : TokenCache
1516
{
1617
public string CacheFilePath;
1718
private static readonly object FileLock = new object();
1819

20+
// Initializes the cache against a local file.
21+
// If the file is already rpesent, it loads its content in the ADAL cache
1922
public FileCache(string filePath=@".\TokenCache.dat")
2023
{
2124
CacheFilePath = filePath;
2225
this.AfterAccess = AfterAccessNotification;
2326
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);
2438
}
2539

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.
2642
void BeforeAccessNotification(TokenCacheNotificationArgs args)
2743
{
2844
lock (FileLock)
@@ -31,14 +47,19 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
3147
}
3248
}
3349

50+
// Triggered right after ADAL accessed the cache.
3451
void AfterAccessNotification(TokenCacheNotificationArgs args)
3552
{
53+
// if the access operation resulted in a cache update
3654
if (this.HasStateChanged)
3755
{
3856
lock (FileLock)
3957
{
58+
// reflect changes in the persistent store
4059
File.WriteAllBytes(CacheFilePath, ProtectedData.Protect(this.Serialize(),null,DataProtectionScope.CurrentUser));
41-
}
60+
// once the write operation took place, restore the HasStateChanged bit to false
61+
this.HasStateChanged = false;
62+
}
4263
}
4364
}
4465
}

TodoListClient/MainWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public MainWindow()
8080
AuthenticationResult result = null;
8181
try
8282
{
83+
84+
//result = authContext.AcquireToken(todoListResourceId, clientId, redirectUri);
8385
result = authContext.AcquireToken(todoListResourceId, clientId, redirectUri, PromptBehavior.Never);
8486

8587
// A valid token is in the cache - get the To Do list.

TodoListClient/TodoListClient.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
<WarningLevel>4</WarningLevel>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
37+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
3838
<SpecificVersion>False</SpecificVersion>
39-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.6.3-alpha\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
39+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.0-alpha\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
4040
</Reference>
41-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4242
<SpecificVersion>False</SpecificVersion>
43-
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.6.3-alpha\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
43+
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.0-alpha\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
4444
</Reference>
4545
<Reference Include="System" />
4646
<Reference Include="System.Configuration" />

TodoListClient/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.6.3-alpha" targetFramework="net45" />
3+
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.7.0-alpha" targetFramework="net45" />
44
</packages>

TodoListService/Areas/HelpPage/ApiDescriptionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static string GetFriendlyId(this ApiDescription description)
3131
localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty));
3232
if (queryKeyString != null)
3333
{
34-
friendlyPath.AppendFormat("_{0}", queryKeyString);
34+
friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-'));
3535
}
3636
return friendlyPath.ToString();
3737
}

TodoListService/Areas/HelpPage/App_Start/HelpPageConfig.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
// Uncomment the following to provide samples for PageResult<T>. Must also add the Microsoft.AspNet.WebApi.OData
2+
// package to your project.
3+
////#define Handle_PageResultOfT
4+
15
using System;
6+
using System.Collections;
27
using System.Collections.Generic;
8+
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
10+
using System.Linq;
311
using System.Net.Http.Headers;
12+
using System.Reflection;
413
using System.Web;
514
using System.Web.Http;
15+
#if Handle_PageResultOfT
16+
using System.Web.Http.OData;
17+
#endif
618

719
namespace TodoListService.Areas.HelpPage
820
{
@@ -13,6 +25,12 @@ namespace TodoListService.Areas.HelpPage
1325
/// </summary>
1426
public static class HelpPageConfig
1527
{
28+
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
29+
MessageId = "TodoListService.Areas.HelpPage.TextSample.#ctor(System.String)",
30+
Justification = "End users may choose to merge this string with existing localized resources.")]
31+
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly",
32+
MessageId = "bsonspec",
33+
Justification = "Part of a URI.")]
1634
public static void Register(HttpConfiguration config)
1735
{
1836
//// Uncomment the following to use the documentation from XML documentation file.
@@ -27,6 +45,20 @@ public static void Register(HttpConfiguration config)
2745
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
2846
//});
2947

48+
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
49+
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
50+
// since automatic handling will fail and GeneratePageResult handles only a single type.
51+
#if Handle_PageResultOfT
52+
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
53+
#endif
54+
55+
// Extend the following to use a preset object directly as the sample for all actions that support a media
56+
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
57+
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
58+
config.SetSampleForMediaType(
59+
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
60+
new MediaTypeHeaderValue("application/bson"));
61+
3062
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
3163
//// and have IEnumerable<string> as the body parameter or return type.
3264
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
@@ -47,5 +79,35 @@ public static void Register(HttpConfiguration config)
4779
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
4880
//config.SetActualResponseType(typeof(string), "Values", "Post");
4981
}
82+
83+
#if Handle_PageResultOfT
84+
private static object GeneratePageResult(HelpPageSampleGenerator sampleGenerator, Type type)
85+
{
86+
if (type.IsGenericType)
87+
{
88+
Type openGenericType = type.GetGenericTypeDefinition();
89+
if (openGenericType == typeof(PageResult<>))
90+
{
91+
// Get the T in PageResult<T>
92+
Type[] typeParameters = type.GetGenericArguments();
93+
Debug.Assert(typeParameters.Length == 1);
94+
95+
// Create an enumeration to pass as the first parameter to the PageResult<T> constuctor
96+
Type itemsType = typeof(List<>).MakeGenericType(typeParameters);
97+
object items = sampleGenerator.GetSampleObject(itemsType);
98+
99+
// Fill in the other information needed to invoke the PageResult<T> constuctor
100+
Type[] parameterTypes = new Type[] { itemsType, typeof(Uri), typeof(long?), };
101+
object[] parameters = new object[] { items, null, (long)ObjectGenerator.DefaultCollectionSize, };
102+
103+
// Call PageResult(IEnumerable<T> items, Uri nextPageLink, long? count) constructor
104+
ConstructorInfo constructor = type.GetConstructor(parameterTypes);
105+
return constructor.Invoke(parameters);
106+
}
107+
}
108+
109+
return null;
110+
}
111+
#endif
50112
}
51113
}

TodoListService/Areas/HelpPage/Controllers/HelpController.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Web.Http;
33
using System.Web.Mvc;
4+
using TodoListService.Areas.HelpPage.ModelDescriptions;
45
using TodoListService.Areas.HelpPage.Models;
56

67
namespace TodoListService.Areas.HelpPage.Controllers
@@ -10,6 +11,8 @@ namespace TodoListService.Areas.HelpPage.Controllers
1011
/// </summary>
1112
public class HelpController : Controller
1213
{
14+
private const string ErrorViewName = "Error";
15+
1316
public HelpController()
1417
: this(GlobalConfiguration.Configuration)
1518
{
@@ -39,7 +42,22 @@ public ActionResult Api(string apiId)
3942
}
4043
}
4144

42-
return View("Error");
45+
return View(ErrorViewName);
46+
}
47+
48+
public ActionResult ResourceModel(string modelName)
49+
{
50+
if (!String.IsNullOrEmpty(modelName))
51+
{
52+
ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator();
53+
ModelDescription modelDescription;
54+
if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription))
55+
{
56+
return View(modelDescription);
57+
}
58+
}
59+
60+
return View(ErrorViewName);
4361
}
4462
}
4563
}
Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
pre.wrapped {
1+
.help-page h1,
2+
.help-page .h1,
3+
.help-page h2,
4+
.help-page .h2,
5+
.help-page h3,
6+
.help-page .h3,
7+
#body.help-page,
8+
.help-page-table th,
9+
.help-page-table pre,
10+
.help-page-table p {
11+
font-family: "Segoe UI Light", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif;
12+
}
13+
14+
.help-page pre.wrapped {
215
white-space: -moz-pre-wrap;
316
white-space: -pre-wrap;
417
white-space: -o-pre-wrap;
518
white-space: pre-wrap;
619
}
720

8-
.warning-message-container {
21+
.help-page .warning-message-container {
922
margin-top: 20px;
1023
padding: 0 10px;
1124
color: #525252;
@@ -18,23 +31,24 @@ pre.wrapped {
1831
border-collapse: collapse;
1932
text-align: left;
2033
margin: 0px 0px 20px 0px;
21-
border-top: 2px solid #D4D4D4;
34+
border-top: 1px solid #D4D4D4;
2235
}
2336

2437
.help-page-table th {
2538
text-align: left;
2639
font-weight: bold;
27-
border-bottom: 2px solid #D4D4D4;
28-
padding: 8px 6px 8px 6px;
40+
border-bottom: 1px solid #D4D4D4;
41+
padding: 5px 6px 5px 6px;
2942
}
3043

3144
.help-page-table td {
32-
border-bottom: 2px solid #D4D4D4;
33-
padding: 15px 8px 15px 8px;
45+
border-bottom: 1px solid #D4D4D4;
46+
padding: 10px 8px 10px 8px;
3447
vertical-align: top;
3548
}
3649

37-
.help-page-table pre, .help-page-table p {
50+
.help-page-table pre,
51+
.help-page-table p {
3852
margin: 0px;
3953
padding: 0px;
4054
font-family: inherit;
@@ -45,21 +59,21 @@ pre.wrapped {
4559
background-color: #F3F3F3;
4660
}
4761

48-
a:hover {
62+
.help-page a:hover {
4963
background-color: transparent;
5064
}
5165

52-
.sample-header {
66+
.help-page .sample-header {
5367
border: 2px solid #D4D4D4;
54-
background: #76B8DB;
68+
background: #00497E;
5569
color: #FFFFFF;
5670
padding: 8px 15px;
5771
border-bottom: none;
5872
display: inline-block;
5973
margin: 10px 0px 0px 0px;
6074
}
6175

62-
.sample-content {
76+
.help-page .sample-content {
6377
display: block;
6478
border-width: 0;
6579
padding: 15px 20px;
@@ -68,22 +82,53 @@ a:hover {
6882
margin: 0px 0px 10px 0px;
6983
}
7084

71-
.api-name {
85+
.help-page .api-name {
7286
width: 40%;
7387
}
7488

75-
.api-documentation {
89+
.help-page .api-documentation {
7690
width: 60%;
7791
}
7892

79-
.parameter-name {
93+
.help-page .parameter-name {
8094
width: 20%;
8195
}
8296

83-
.parameter-documentation {
84-
width: 50%;
97+
.help-page .parameter-documentation {
98+
width: 40%;
99+
}
100+
101+
.help-page .parameter-type {
102+
width: 20%;
103+
}
104+
105+
.help-page .parameter-annotations {
106+
width: 20%;
107+
}
108+
109+
.help-page h1,
110+
.help-page .h1 {
111+
font-size: 36px;
112+
line-height: normal;
113+
}
114+
115+
.help-page h2,
116+
.help-page .h2 {
117+
font-size: 24px;
118+
}
119+
120+
.help-page h3,
121+
.help-page .h3 {
122+
font-size: 20px;
123+
}
124+
125+
#body.help-page {
126+
font-size: 14px;
127+
line-height: 143%;
128+
color: #333;
85129
}
86130

87-
.parameter-source {
88-
width: 30%;
131+
.help-page a {
132+
color: #0000EE;
133+
text-decoration: none;
89134
}

0 commit comments

Comments
 (0)