1 namespace System
.ServiceModel
.Samples
.CustomChannelsTester
4 using System
.Collections
.Generic
;
5 using System
.Collections
.ObjectModel
;
6 using System
.Diagnostics
;
8 using System
.Reflection
;
9 using System
.ServiceModel
;
10 using System
.ServiceModel
.Channels
;
13 using System
.Xml
.Schema
;
14 using System
.Xml
.Serialization
;
15 using System
.Xml
.XPath
;
18 //This class parses the XML files and sets up the parameters for the tests accordingly.
22 readonly SchemaValidator validator
;
24 public static readonly string TestSpecNamespace
= "http://WCF/TestSpec";
25 public static readonly string TestSpecXsdLocation
= Path
.Combine(Path
.GetDirectoryName(Assembly
.GetEntryAssembly().Location
), "testspec.xsd");
29 this.validator
= new SchemaValidator(Loader
.TestSpecNamespace
, Loader
.TestSpecXsdLocation
);
32 internal void LoadSpec(string inputFileName
)
34 if (Parameters
.InputFileName
!= null)
37 XmlDocument doc
= new XmlDocument();
38 doc
.Load(inputFileName
);
39 validator
.Validate(doc
);
41 XmlSerializer serializer
= new XmlSerializer(typeof(TestSpec
));
43 TextReader reader
= new StreamReader(inputFileName
);
44 TestSpec ts
= (TestSpec
)serializer
.Deserialize(reader
);
47 Parameters
.IsAsync
= GetContractOption(ts
.ServiceContract
.IsAsync
);
48 Parameters
.IsSession
= GetContractOption(ts
.ServiceContract
.IsSession
);
49 Parameters
.IsOneWay
= GetContractOption(ts
.ServiceContract
.IsOneWay
);
50 Parameters
.IsCallBack
= GetContractOption(ts
.ServiceContract
.IsCallBack
);
52 if (ts
.TestDetails
.ServerMachineName
== null)
53 Log
.Trace("Running both Server and Client on the same machine");
55 Parameters
.ServerMachineName
= ts
.TestDetails
.ServerMachineName
;
57 if (ts
.TestDetails
.ServerPortNumber
== null)
58 Log
.Trace("No port number on the server machine specified");
60 Parameters
.ServerPortNumber
= Int32
.Parse(ts
.TestDetails
.ServerPortNumber
);
62 if (ts
.TestDetails
.ClientCallBackAddress
== null)
63 Log
.Trace("No Client CallBack Address specified, using default address for Duplex CallBack contracts if required");
66 //The ClientBaseAddress specified should be a valid URI
69 Parameters
.ClientCallBackAddress
= new Uri(ts
.TestDetails
.ClientCallBackAddress
);
73 if (Parameters
.IsCallBack
!= ContractOption
.False
)
78 if (ts
.TestDetails
.ServerTimeout
== null)
79 Log
.Trace("Default value used - Server will timeout after 120 seconds");
81 Parameters
.ServerTimeout
= new TimeSpan(0, 0, Int32
.Parse(ts
.TestDetails
.ServerTimeout
));
83 if (ts
.TestDetails
.ClientTimeout
== null)
84 Log
.Trace("Default value used - Client will wait for 30 seconds before starting");
86 Parameters
.ClientTimeout
= new TimeSpan(0, 0, Int32
.Parse(ts
.TestDetails
.ClientTimeout
));
88 if (ts
.TestDetails
.NumberOfClients
== null)
89 Log
.Trace("Default value used - Number of Client per Service = 1");
91 Parameters
.NumberOfClients
= Int32
.Parse(ts
.TestDetails
.NumberOfClients
);
93 if (ts
.TestDetails
.MessagesPerClient
== null)
94 Log
.Trace("Default value used - Number of Messages sent per Client = 1");
96 Parameters
.MessagesPerClient
= Int32
.Parse(ts
.TestDetails
.MessagesPerClient
);
99 Log
.Trace("ServerMachineName = " + Parameters
.ServerMachineName
);
100 Log
.Trace("ServerPortNumber Number = " + Parameters
.ServerPortNumber
);
101 if (Parameters
.IsCallBack
!= ContractOption
.False
)
102 Log
.Trace("ClientCallBack Address = " + Parameters
.ClientCallBackAddress
.ToString());
103 Log
.Trace("ServerTimeout = " + Parameters
.ServerTimeout
.ToString());
104 Log
.Trace("ClientTimeout = " + Parameters
.ClientTimeout
.ToString());
105 Log
.Trace("NumberOfClients = " + Parameters
.NumberOfClients
);
106 Log
.Trace("MessagesPerClient = " + Parameters
.MessagesPerClient
);
109 private ContractOption
GetContractOption(Contract contractChoice
)
111 if (contractChoice
== null)
112 return ContractOption
.False
;
113 if (contractChoice
.ExpandAllSpecified
== true && contractChoice
.ExpandAll
== true)
114 return ContractOption
.Both
;
115 else if (contractChoice
.Value
== false)
116 return ContractOption
.False
;
117 else if (contractChoice
.Value
== true)
118 return ContractOption
.True
;
120 return ContractOption
.Both
;
123 internal void UpdateParameters()
125 if (Parameters
.IsAsync
== ContractOption
.True
|| Parameters
.IsAsync
== ContractOption
.Both
)
127 if(Parameters
.IsSession
== ContractOption
.True
|| Parameters
.IsSession
== ContractOption
.Both
)
129 if(Parameters
.IsOneWay
== ContractOption
.False
|| Parameters
.IsOneWay
== ContractOption
.Both
)
130 Parameters
.ServiceContracts
.Add(ServiceContract
.IAsyncSessionTwoWay
);
131 if(Parameters
.IsOneWay
== ContractOption
.True
|| Parameters
.IsOneWay
== ContractOption
.Both
)
132 Parameters
.ServiceContracts
.Add(ServiceContract
.IAsyncSessionOneWay
);
134 if(Parameters
.IsSession
== ContractOption
.False
|| Parameters
.IsSession
== ContractOption
.Both
)
136 if(Parameters
.IsOneWay
== ContractOption
.True
|| Parameters
.IsOneWay
== ContractOption
.Both
)
137 Parameters
.ServiceContracts
.Add(ServiceContract
.IAsyncOneWay
);
138 if(Parameters
.IsOneWay
== ContractOption
.False
|| Parameters
.IsOneWay
== ContractOption
.Both
)
139 Parameters
.ServiceContracts
.Add(ServiceContract
.IAsyncTwoWay
);
143 if (Parameters
.IsAsync
== ContractOption
.False
|| Parameters
.IsAsync
== ContractOption
.Both
)
145 if(Parameters
.IsSession
== ContractOption
.True
|| Parameters
.IsSession
== ContractOption
.Both
)
147 if(Parameters
.IsOneWay
== ContractOption
.False
|| Parameters
.IsOneWay
== ContractOption
.Both
)
148 Parameters
.ServiceContracts
.Add(ServiceContract
.ISyncSessionTwoWay
);
149 if(Parameters
.IsOneWay
== ContractOption
.True
|| Parameters
.IsOneWay
== ContractOption
.Both
)
150 Parameters
.ServiceContracts
.Add(ServiceContract
.ISyncSessionOneWay
);
152 if(Parameters
.IsSession
== ContractOption
.False
|| Parameters
.IsSession
== ContractOption
.Both
)
154 if(Parameters
.IsOneWay
== ContractOption
.True
|| Parameters
.IsOneWay
== ContractOption
.Both
)
155 Parameters
.ServiceContracts
.Add(ServiceContract
.ISyncOneWay
);
156 if(Parameters
.IsOneWay
== ContractOption
.False
|| Parameters
.IsOneWay
== ContractOption
.Both
)
157 Parameters
.ServiceContracts
.Add(ServiceContract
.ISyncTwoWay
);
161 if (Parameters
.IsCallBack
== ContractOption
.True
|| Parameters
.IsCallBack
== ContractOption
.Both
)
163 if (Parameters
.IsSession
== ContractOption
.True
|| Parameters
.IsSession
== ContractOption
.Both
)
164 Parameters
.ServiceContracts
.Add(ServiceContract
.IDuplexSessionContract
);
165 if (Parameters
.IsSession
== ContractOption
.False
|| Parameters
.IsSession
== ContractOption
.Both
)
166 Parameters
.ServiceContracts
.Add(ServiceContract
.IDuplexContract
);
168 Log
.Trace("Number of service contracts === " + Parameters
.ServiceContracts
.Count
);
171 Parameters
.TotalMessages
= Parameters
.NumberOfClients
* Parameters
.MessagesPerClient
* Parameters
.ServiceContracts
.Count
;