PageRenderTime 72ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/ServiceModel/ServiceModelDataContext.cs

https://github.com/ACher/bltoolkit
C# | 102 lines | 78 code | 24 blank | 0 comment | 20 complexity | 855e8185ef81063ab960a8b350f0a7e0 MD5 | raw file
  1. using System;
  2. using System.ServiceModel;
  3. using System.ServiceModel.Channels;
  4. using JetBrains.Annotations;
  5. namespace BLToolkit.ServiceModel
  6. {
  7. using Data.Linq;
  8. using NotNullAttribute = NotNullAttribute;
  9. public class ServiceModelDataContext : RemoteDataContextBase
  10. {
  11. #region Init
  12. ServiceModelDataContext()
  13. {
  14. }
  15. public ServiceModelDataContext([NotNull] string endpointConfigurationName)
  16. : this()
  17. {
  18. if (endpointConfigurationName == null) throw new ArgumentNullException("endpointConfigurationName");
  19. _endpointConfigurationName = endpointConfigurationName;
  20. }
  21. public ServiceModelDataContext([NotNull] string endpointConfigurationName, [NotNull] string remoteAddress)
  22. : this()
  23. {
  24. if (endpointConfigurationName == null) throw new ArgumentNullException("endpointConfigurationName");
  25. if (remoteAddress == null) throw new ArgumentNullException("remoteAddress");
  26. _endpointConfigurationName = endpointConfigurationName;
  27. _remoteAddress = remoteAddress;
  28. }
  29. public ServiceModelDataContext([NotNull] string endpointConfigurationName, [NotNull] EndpointAddress endpointAddress)
  30. : this()
  31. {
  32. if (endpointConfigurationName == null) throw new ArgumentNullException("endpointConfigurationName");
  33. if (endpointAddress == null) throw new ArgumentNullException("endpointAddress");
  34. _endpointConfigurationName = endpointConfigurationName;
  35. _endpointAddress = endpointAddress;
  36. }
  37. public ServiceModelDataContext([NotNull] Binding binding, [NotNull] EndpointAddress endpointAddress)
  38. : this()
  39. {
  40. if (binding == null) throw new ArgumentNullException("binding");
  41. if (endpointAddress == null) throw new ArgumentNullException("endpointAddress");
  42. Binding = binding;
  43. _endpointAddress = endpointAddress;
  44. }
  45. string _endpointConfigurationName;
  46. string _remoteAddress;
  47. EndpointAddress _endpointAddress;
  48. public Binding Binding { get; private set; }
  49. #endregion
  50. #region Overrides
  51. protected override ILinqService GetClient()
  52. {
  53. if (Binding != null)
  54. return new LinqServiceClient(Binding, _endpointAddress);
  55. if (_endpointAddress != null)
  56. return new LinqServiceClient(_endpointConfigurationName, _endpointAddress);
  57. if (_remoteAddress != null)
  58. return new LinqServiceClient(_endpointConfigurationName, _remoteAddress);
  59. return new LinqServiceClient(_endpointConfigurationName);
  60. }
  61. protected override IDataContext Clone()
  62. {
  63. return new ServiceModelDataContext
  64. {
  65. MappingSchema = MappingSchema,
  66. Binding = Binding,
  67. _endpointConfigurationName = _endpointConfigurationName,
  68. _remoteAddress = _remoteAddress,
  69. _endpointAddress = _endpointAddress,
  70. };
  71. }
  72. protected override string ContextIDPrefix
  73. {
  74. get { return "LinqService_"; }
  75. }
  76. #endregion
  77. }
  78. }