Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using System.Runtime.Serialization;
11 : using System.Xml;
12 : using Cqrs.Services;
13 :
14 : namespace Cqrs.Authentication
15 : {
16 : /// <summary>
17 : /// Resolves parameter types when serialising with WCF of <see cref="Type"/>
18 : /// <see cref="SingleSignOnToken"/>, <see cref="SingleSignOnTokenWithUserRsn"/>, <see cref="SingleSignOnTokenWithCompanyRsn"/> and <see cref="SingleSignOnTokenWithUserRsnAndCompanyRsn"/>
19 : /// </summary>
20 : public class SingleSignOnTokenResolver : ISingleSignOnTokenResolver
21 1 : {
22 : #region Implementation of IServiceParameterResolver
23 :
24 : /// <summary>
25 : /// Indicates if the provided <paramref name="dataContractType"/> is of type <see cref="SingleSignOnToken"/>, <see cref="SingleSignOnTokenWithUserRsn"/>, <see cref="SingleSignOnTokenWithCompanyRsn"/>, <see cref="SingleSignOnTokenWithUserRsnAndCompanyRsn"/>
26 : /// OR if it is other resolvable.
27 : /// </summary>
28 1 : public virtual bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
29 : {
30 : if (dataContractType == typeof(SingleSignOnTokenWithUserRsnAndCompanyRsn))
31 : {
32 : XmlDictionary dictionary = new XmlDictionary();
33 : typeName = dictionary.Add("SingleSignOnTokenWithUserAndCompanyRsn");
34 : typeNamespace = dictionary.Add("https://getcqrs.net");
35 : return true;
36 : }
37 :
38 : if (dataContractType == typeof(SingleSignOnTokenWithUserRsn))
39 : {
40 : XmlDictionary dictionary = new XmlDictionary();
41 : typeName = dictionary.Add("SingleSignOnTokenWithUserRsn");
42 : typeNamespace = dictionary.Add("https://getcqrs.net");
43 : return true;
44 : }
45 :
46 : if (dataContractType == typeof(SingleSignOnTokenWithCompanyRsn))
47 : {
48 : XmlDictionary dictionary = new XmlDictionary();
49 : typeName = dictionary.Add("SingleSignOnTokenWithCompanyRsn");
50 : typeNamespace = dictionary.Add("https://getcqrs.net");
51 : return true;
52 : }
53 :
54 : if (dataContractType == typeof(SingleSignOnToken))
55 : {
56 : XmlDictionary dictionary = new XmlDictionary();
57 : typeName = dictionary.Add("SingleSignOnToken");
58 : typeNamespace = dictionary.Add("https://getcqrs.net");
59 : return true;
60 : }
61 :
62 : typeName = null;
63 : typeNamespace = null;
64 : return false;
65 : }
66 :
67 : /// <summary>
68 : /// Returns the <see cref="Type"/> if the <paramref name="typeName"/> is resolvable or if it is
69 : /// of type <see cref="SingleSignOnToken"/>, <see cref="SingleSignOnTokenWithUserRsn"/>, <see cref="SingleSignOnTokenWithCompanyRsn"/> and <see cref="SingleSignOnTokenWithUserRsnAndCompanyRsn"/>
70 : /// </summary>
71 1 : public virtual Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
72 : {
73 : switch (typeNamespace)
74 : {
75 : case "https://getcqrs.net":
76 : switch (typeName)
77 : {
78 : case "SingleSignOnToken":
79 : return typeof(SingleSignOnToken);
80 : case "SingleSignOnTokenWithCompanyRsn":
81 : return typeof(SingleSignOnTokenWithCompanyRsn);
82 : case "SingleSignOnTokenWithUserRsn":
83 : return typeof(SingleSignOnTokenWithUserRsn);
84 : case "SingleSignOnTokenWithUserAndCompanyRsn":
85 : return typeof(SingleSignOnTokenWithUserRsnAndCompanyRsn);
86 : }
87 : break;
88 : }
89 :
90 : return null;
91 : }
92 :
93 : #endregion
94 : }
95 : }
|