LCOV - code coverage report
Current view: top level - Cqrs/Services - WcfDataContractResolverConfiguration.cs Hit Total Coverage
Test: doc-coverage.info Lines: 0 5 0.0 %
Date: 2017-07-26

          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.Linq;
      12             : 
      13             : namespace Cqrs.Services
      14             : {
      15             :         public class WcfDataContractResolverConfiguration
      16           0 :         {
      17             :                 public static WcfDataContractResolverConfiguration Current { get; protected set; }
      18             : 
      19             :                 protected IDictionary<Type, IDictionary<string, Type>> DataContracts { get; private set; }
      20             : 
      21           0 :                 public WcfDataContractResolverConfiguration()
      22             :                 {
      23             :                         DataContracts = new Dictionary<Type, IDictionary<string, Type>>();
      24             :                 }
      25             : 
      26             :                 static WcfDataContractResolverConfiguration()
      27             :                 {
      28             :                         Current = new WcfDataContractResolverConfiguration();
      29             :                 }
      30             : 
      31           0 :                 public virtual void RegisterDataContract<TService, TDataContract>(string operationName, RegistrationHandling registraionHandling = RegistrationHandling.Replace)
      32             :                         where TDataContract : new ()
      33             :                 {
      34             :                         Type serviceType = typeof (TService);
      35             :                         IDictionary<string, Type> dataContracts;
      36             :                         if (!DataContracts.TryGetValue(serviceType, out dataContracts))
      37             :                         {
      38             :                                 lock (DataContracts)
      39             :                                 {
      40             :                                         if (!DataContracts.TryGetValue(serviceType, out dataContracts))
      41             :                                         {
      42             :                                                 dataContracts = new Dictionary<string, Type>();
      43             :                                                 DataContracts.Add(serviceType, dataContracts);
      44             :                                         }
      45             :                                 }
      46             :                         }
      47             :                         if (dataContracts.ContainsKey(operationName))
      48             :                         {
      49             :                                 switch (registraionHandling)
      50             :                                 {
      51             :                                         case RegistrationHandling.ThrowExceptionOnDuplicate:
      52             :                                                 dataContracts.Add(operationName, typeof(TDataContract));
      53             :                                                 break;
      54             :                                         case RegistrationHandling.Replace:
      55             :                                                 dataContracts[operationName] = typeof(TDataContract);
      56             :                                                 break;
      57             :                                         case RegistrationHandling.Nothing:
      58             :                                                 return;
      59             :                                 }
      60             :                         }
      61             :                         else
      62             :                                 dataContracts.Add(operationName, typeof(TDataContract));
      63             :                 }
      64             : 
      65           0 :                 public virtual Type GetDataContracts<TService>(string operationName)
      66             :                 {
      67             :                         Type serviceType = typeof (TService);
      68             :                         IDictionary<string, Type> dataContracts;
      69             :                         if (!DataContracts.TryGetValue(serviceType, out dataContracts))
      70             :                         {
      71             :                                 lock (DataContracts)
      72             :                                 {
      73             :                                         if (!DataContracts.TryGetValue(serviceType, out dataContracts))
      74             :                                         {
      75             :                                                 dataContracts = new Dictionary<string, Type>();
      76             :                                                 DataContracts.Add(serviceType, dataContracts);
      77             :                                         }
      78             :                                 }
      79             :                         }
      80             : 
      81             :                         Type dataContractType;
      82             :                         if (dataContracts.TryGetValue(operationName, out dataContractType))
      83             :                                 return dataContractType;
      84             :                         if (operationName == "GetEventData")
      85             :                                 return dataContracts.Values.FirstOrDefault();
      86             :                         return null;
      87             :                 }
      88             : 
      89             :                 public enum RegistrationHandling
      90           0 :                 {
      91             :                         Replace = 0,
      92             : 
      93             :                         ThrowExceptionOnDuplicate = 1,
      94             : 
      95             :                         Nothing = 2
      96             :                 }
      97             :         }
      98             : }

Generated by: LCOV version 1.10