PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/ResourceManagement.Client/ClientHelper.cs

#
C# | 81 lines | 74 code | 7 blank | 0 comment | 22 complexity | 21e213fdddf5b025094f102a7ea3882f MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using Microsoft.ResourceManagement.Client.Faults;
 4using System.ServiceModel;
 5using System.ServiceModel.Channels;
 6using System.Text;
 7
 8namespace Microsoft.ResourceManagement.Client
 9{
10    public class ClientHelper
11    {
12        private ClientHelper()
13        {
14        }
15
16        public static void HandleFault(Message message)
17        {
18            MessageFault fault = MessageFault.CreateFault(message, Int32.MaxValue);
19            throw System.ServiceModel.FaultException.CreateFault(fault,
20                typeof(PermissionDeniedFault),
21                typeof(AuthenticationRequiredFault),
22                typeof(AuthorizationRequiredFault),
23                typeof(EndpointUnavailable),
24                typeof(FragmentDialectNotSupported),
25                typeof(InvalidRepresentationFault),
26                typeof(UnwillingToPerformFault),
27                typeof(CannotProcessFilter),
28                typeof(FilterDialectRequestedUnavailable),
29                typeof(UnsupportedExpiration)
30            );
31        }
32
33        public static void AddRmHeaders(WsTransfer.TransferRequest transferRequest, Message message)
34        {
35            if (transferRequest == null)
36                return;
37
38            if (transferRequest.ResourceLocaleProperty != null && String.IsNullOrEmpty(transferRequest.ResourceLocaleProperty.Value) == false)
39            {
40                if (message.Headers.FindHeader(Constants.Rm.ResourceLocaleProperty, Constants.Rm.Namespace) < 0)
41                {
42                    MessageHeader newHeader = MessageHeader.CreateHeader(Constants.Rm.ResourceLocaleProperty, Constants.Rm.Namespace, transferRequest.ResourceLocaleProperty.Value);
43                    message.Headers.Add(newHeader);
44                }
45            }
46
47            if (transferRequest.ResourceReferenceProperty != null && String.IsNullOrEmpty(transferRequest.ResourceReferenceProperty.Value) == false)
48            {
49                if (message.Headers.FindHeader(Constants.Rm.ResourceReferenceProperty, Constants.Rm.Namespace) < 0)
50                {
51                    MessageHeader newHeader = MessageHeader.CreateHeader(Constants.Rm.ResourceReferenceProperty, Constants.Rm.Namespace, transferRequest.ResourceReferenceProperty.Value);
52                    message.Headers.Add(newHeader);
53                }
54            }
55
56            if (transferRequest.ResourceTimeProperty != null && String.IsNullOrEmpty(transferRequest.ResourceTimeProperty.Value) == false)
57            {
58                if (message.Headers.FindHeader(Constants.Rm.ResourceTimeProperty, Constants.Rm.Namespace) < 0)
59                {
60                    MessageHeader newHeader = MessageHeader.CreateHeader(Constants.Rm.ResourceTimeProperty, Constants.Rm.Namespace, transferRequest.ResourceTimeProperty.Value);
61                    message.Headers.Add(newHeader);
62                }
63            }
64        }
65
66        public static void AddImdaHeaders(WsTransfer.ImdaRequest imdaRequest, Message message)
67        {
68            if (imdaRequest == null)
69                return;
70            if (message == null)
71            {
72                throw new ArgumentNullException("message");
73            }
74            if (message.Headers.FindHeader(Constants.Imda.ExtensionHeaderName, Constants.Imda.Namespace) < 0)
75            {
76                MessageHeader newHeader = MessageHeader.CreateHeader(Constants.Imda.ExtensionHeaderName, Constants.Imda.Namespace, String.Empty, true);
77                message.Headers.Add(newHeader);
78            }
79        }
80    }
81}