Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="cdmdotnet Limited">
4 : // // Copyright cdmdotnet 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 : public class EventDataResolver<TAuthenticationToken> : IEventDataResolver
18 0 : {
19 : #region Implementation of IServiceParameterResolver
20 :
21 0 : public virtual bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
22 : {
23 : if (dataContractType == typeof(EventData))
24 : {
25 : XmlDictionary dictionary = new XmlDictionary();
26 : typeName = dictionary.Add("EventData");
27 : typeNamespace = dictionary.Add("https://getcqrs.net");
28 : return true;
29 : }
30 :
31 : if (dataContractType == typeof(ServiceRequestWithData<TAuthenticationToken, Guid>))
32 : {
33 : XmlDictionary dictionary = new XmlDictionary();
34 : typeName = dictionary.Add("EventDataGetRequest");
35 : typeNamespace = dictionary.Add("https://getcqrs.net");
36 : return true;
37 : }
38 :
39 : if (dataContractType == typeof(ServiceResponseWithResultData<IEnumerable<EventData>>))
40 : {
41 : XmlDictionary dictionary = new XmlDictionary();
42 : typeName = dictionary.Add("EventDataGetResponse");
43 : typeNamespace = dictionary.Add("https://getcqrs.net");
44 : return true;
45 : }
46 :
47 : typeName = null;
48 : typeNamespace = null;
49 : return false;
50 : }
51 :
52 0 : public virtual Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
53 : {
54 : if (typeName == "EventData" && typeNamespace == "https://getcqrs.net")
55 : return typeof(EventData);
56 :
57 : if (typeName == "EventDataGetRequest" && typeNamespace == "https://getcqrs.net")
58 : return typeof(ServiceRequestWithData<TAuthenticationToken, Guid>);
59 :
60 : if (typeName == "EventDataGetResponse" && typeNamespace == "https://getcqrs.net")
61 : return typeof(ServiceResponseWithResultData<IEnumerable<EventData>>);
62 :
63 : return null;
64 : }
65 :
66 : #endregion
67 : }
68 : }
|