Mono exception to SocketException
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Core.Presentation / System / ServiceModel / Activities / Presentation / SendReplyValidationFeature.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.ServiceModel.Activities.Presentation
6 {
7     using System.Runtime;
8     using System.Activities.Presentation;
9     using System.Activities.Presentation.Validation;
10     using System.Activities.Validation;
11     using System.Collections.Generic;
12     using System.Activities;
13     using System.Activities.Statements;
14     using System.Globalization;
15
16     class SendReplyValidationFeature : DesignTimeValidationFeature
17     {
18         List<Constraint> constraints;
19
20         protected override Type ApplyTo
21         {
22             get { return typeof(SendReply); }
23         }
24
25         protected override IList<Constraint> DesignTimeConstraints
26         {
27             get
28             {
29                 if (this.constraints == null)
30                 {
31                     this.constraints = new List<Constraint> { UnrootedRequestRule() };
32                 }
33                 return this.constraints;
34             }
35         }
36
37         Constraint UnrootedRequestRule()
38         {
39             DelegateInArgument<SendReply> sendReply = new DelegateInArgument<SendReply>();
40             DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
41             DelegateInArgument<Activity> activityInTree = new DelegateInArgument<Activity>();
42             Variable<bool> requestInTree = new Variable<bool> { Default = false };
43
44             return new Constraint<SendReply>
45             {
46                 Body = new ActivityAction<SendReply, ValidationContext>
47                 {
48                     Argument1 = sendReply,
49                     Argument2 = context,
50                     Handler = new Sequence
51                     {
52                         Variables = { requestInTree },
53                         Activities =
54                         {
55                             new If
56                             {
57                                 Condition = new InArgument<bool>(ctx => sendReply.Get(ctx).Request != null),
58                                 Then = new Sequence
59                                 {
60                                     Activities = 
61                                     {
62                                         new ForEach<Activity>
63                                         {
64                                             Values = new GetWorkflowTree
65                                             {
66                                                 ValidationContext = context,
67                                             },
68                                             Body = new ActivityAction<Activity>
69                                             {
70                                                 Argument = activityInTree,
71                                                 Handler = new If
72                                                 {
73                                                     Condition = new InArgument<bool>(ctx => activityInTree.Get(ctx) == sendReply.Get(ctx).Request),
74                                                     Then = new Assign<bool>
75                                                     {
76                                                         To = requestInTree,
77                                                         Value = true,
78                                                     }                                                    
79                                                 }
80                                             }
81                                         },                            
82                                         new AssertValidation
83                                         {                                
84                                             Assertion = new InArgument<bool>(ctx => requestInTree.Get(ctx)),
85                                             IsWarning = false,
86                                             Message = new InArgument<string>(ctx => string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.UnrootedRequestInSendReply, sendReply.Get(ctx).DisplayName))
87                                         }
88                                     }
89                                 }
90                             }
91                         }
92                     }
93                 }
94             };
95         }
96     }
97 }