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.Collections.Generic;
11 : using System.Runtime.Serialization;
12 : using System.Xml;
13 : using Cqrs.Services;
14 :
15 : namespace Cqrs.Events
16 : {
17 : /// <summary>
18 : /// Resolves <see cref="EventData"/>, <see cref="ServiceRequestWithData{TAuthenticationToken, Guid}" /> and <see cref="ServiceResponseWithResultData{IEnumerableEventData}"/> parameter types when serialising with WCF.
19 : /// </summary>
20 : public class EventDataResolver<TAuthenticationToken> : IEventDataResolver
21 1 : {
22 : #region Implementation of IServiceParameterResolver
23 :
24 : /// <summary>
25 : /// Indicates if the provided <paramref name="dataContractType"/> is of type <see cref="EventData"/>, <see cref="ServiceRequestWithData{TAuthenticationToken, Guid}" />, <see cref="ServiceResponseWithResultData{IEnumerableEventData}"/>0
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(EventData))
31 : {
32 : XmlDictionary dictionary = new XmlDictionary();
33 : typeName = dictionary.Add("EventData");
34 : typeNamespace = dictionary.Add("https://getcqrs.net");
35 : return true;
36 : }
37 :
38 : if (dataContractType == typeof(ServiceRequestWithData<TAuthenticationToken, Guid>))
39 : {
40 : XmlDictionary dictionary = new XmlDictionary();
41 : typeName = dictionary.Add("EventDataGetRequest");
42 : typeNamespace = dictionary.Add("https://getcqrs.net");
43 : return true;
44 : }
45 :
46 : if (dataContractType == typeof(ServiceResponseWithResultData<IEnumerable<EventData>>))
47 : {
48 : XmlDictionary dictionary = new XmlDictionary();
49 : typeName = dictionary.Add("EventDataGetResponse");
50 : typeNamespace = dictionary.Add("https://getcqrs.net");
51 : return true;
52 : }
53 :
54 : typeName = null;
55 : typeNamespace = null;
56 : return false;
57 : }
58 :
59 : /// <summary>
60 : /// Returns the <see cref="Type"/> if the <paramref name="typeName"/> is resolvable or if it is
61 : /// of type <paramref name="typeName"/> is of type <see cref="EventData"/>, <see cref="ServiceRequestWithData{TAuthenticationToken, Guid}" />, <see cref="ServiceResponseWithResultData{IEnumerableEventData}"/>
62 : /// </summary>
63 1 : public virtual Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
64 : {
65 : if (typeName == "EventData" && typeNamespace == "https://getcqrs.net")
66 : return typeof(EventData);
67 :
68 : if (typeName == "EventDataGetRequest" && typeNamespace == "https://getcqrs.net")
69 : return typeof(ServiceRequestWithData<TAuthenticationToken, Guid>);
70 :
71 : if (typeName == "EventDataGetResponse" && typeNamespace == "https://getcqrs.net")
72 : return typeof(ServiceResponseWithResultData<IEnumerable<EventData>>);
73 :
74 : return null;
75 : }
76 :
77 : #endregion
78 : }
79 : }
|