3 using System
.Collections
;
7 using System
.Xml
.Serialization
;
8 using System
.ComponentModel
;
9 using System
.Diagnostics
;
10 using System
.Threading
;
11 using System
.Web
.Services
.Discovery
;
12 using System
.Web
.Services
.Description
;
17 static bool foundErrors
= false;
18 static string basePath
;
19 static int runningCount
;
21 static ServiceCollection services
;
22 static ServiceStatusCollection serviceStatus
;
24 public static void Main (string[] args
)
29 Console
.WriteLine ("Usage: wstest [options]");
31 Console
.WriteLine ("Options:");
32 Console
.WriteLine (" ur <url>: Update service references from DISCO or WSDL document");
33 Console
.WriteLine (" dw: download wsdl documents for registered services");
34 Console
.WriteLine (" gp: Generate proxies");
35 Console
.WriteLine (" gc <url>: Generate test client class");
46 BuildProxies (GetArg (args
,1));
48 else if (args
[0] == "gc")
50 BuildClients (GetArg (args
,1));
52 else if (args
[0] == "ur")
54 UpdateReferences (GetArg (args
,1), GetArg (args
,2));
56 else if (args
[0] == "stat")
60 else if (args
[0] == "dw")
62 DownloadWsdls (GetArg (args
,1));
64 else if (args
[0] == "clean")
68 else if (args
[0] == "checkdiff")
70 CheckDiff (GetArg (args
,1));
72 else if (args
[0] == "msfix")
74 MsFix (GetArg (args
,1));
76 else if (args
[0] == "genfiles")
78 GenerateFiles (GetArg (args
,1));
84 Console
.WriteLine ("Please check error log at " + Path
.Combine (GetErrorPath(), "error.log"));
87 static void LoadInfo ()
89 XmlSerializer ser
= new XmlSerializer (typeof(ServiceCollection
));
91 string servicesFile
= Path
.Combine (basePath
, "services.xml");
92 if (!File
.Exists (servicesFile
))
93 services
= new ServiceCollection ();
96 StreamReader sr
= new StreamReader (servicesFile
);
97 services
= (ServiceCollection
) ser
.Deserialize (sr
);
101 ser
= new XmlSerializer (typeof(ServiceStatusCollection
));
103 servicesFile
= Path
.Combine (basePath
, "serviceStatus.xml");
104 if (!File
.Exists (servicesFile
))
105 serviceStatus
= new ServiceStatusCollection ();
108 StreamReader sr
= new StreamReader (servicesFile
);
109 serviceStatus
= (ServiceStatusCollection
) ser
.Deserialize (sr
);
114 static void SaveInfo ()
116 XmlSerializer ser
= new XmlSerializer (typeof(ServiceCollection
));
117 string servicesFile
= Path
.Combine (basePath
, "services.xml");
118 StreamWriter sw
= new StreamWriter (servicesFile
);
119 ser
.Serialize (sw
, services
);
122 ser
= new XmlSerializer (typeof(ServiceStatusCollection
));
123 servicesFile
= Path
.Combine (basePath
, "serviceStatus.xml");
124 sw
= new StreamWriter (servicesFile
);
125 ser
.Serialize (sw
, serviceStatus
);
129 static string GetArg (string[] args
, int n
)
131 if (n
>= args
.Length
) return null;
135 static void Cleanup ()
137 string pp
= GetProxyPath ();
138 DirectoryInfo di
= new DirectoryInfo (pp
);
139 if (di
.Exists
) di
.Delete (true);
145 Hashtable clientHash
= new Hashtable ();
147 foreach (ServiceData sd
in services
.services
)
150 clientHash
[GetClientFile (sd
)] = sd
;
152 if (sd
.Protocols
!= null)
154 foreach (string prot
in sd
.Protocols
)
155 clientHash
[GetProxyFile (sd
, prot
)] = sd
;
157 clientHash
[GetWsdlFile (sd
)] = sd
;
160 Clean (clientHash
, GetClientPath ());
161 Clean (clientHash
, GetProxyPath ());
162 Clean (clientHash
, GetWsdlPath ());
165 static void Clean (Hashtable clientHash
, string path
)
167 if (Path
.GetFileName (path
) == "CVS") return;
169 string[] files
= Directory
.GetFiles (path
);
171 foreach (string file
in files
)
173 ServiceData sd
= clientHash
[file
] as ServiceData
;
174 if (sd
!= null) continue;
177 Console
.WriteLine ("Deleted file '" + file
+ "'");
180 string [] dirs
= Directory
.GetDirectories (path
);
181 foreach (string dir
in dirs
)
182 Clean (clientHash
, dir
);
184 int count
= Directory
.GetFiles (path
).Length
+ Directory
.GetDirectories (path
).Length
;
185 if (count
== 0 && path
!= GetClientPath () && path
!= GetProxyPath ())
187 Directory
.Delete (path
);
188 Console
.WriteLine ("Deleted directory '" + path
+ "'");
192 static void UpdateReferences (string url
, string ignoreFile
)
194 Console
.WriteLine ();
195 Console
.WriteLine ("Updating service references");
196 Console
.WriteLine ("---------------------------");
198 ArrayList ignoreList
= new ArrayList ();
200 if (ignoreFile
!= null)
202 StreamReader sr
= new StreamReader (ignoreFile
);
204 while ((line
= sr
.ReadLine ()) != null)
206 int i
= line
.IndexOfAny (new char[] {' ','\t'}
);
207 if (i
!= -1) line
= line
.Substring (0,i
);
208 ignoreList
.Add (line
);
212 DiscoveryClientProtocol client
= new DiscoveryClientProtocol ();
213 client
.DiscoverAny (url
);
215 ArrayList list
= new ArrayList (client
.References
.Values
);
216 foreach (DiscoveryReference re
in list
)
218 if (!(re
is ContractReference
)) continue;
220 bool ignore
= ignoreList
.Contains (re
.Url
);
222 ServiceData sd
= FindService (re
.Url
);
227 RemoveService (re
.Url
);
228 Console
.WriteLine ("Removed " + re
.Url
);
235 sd
= CreateServiceData (re
);
236 Console
.WriteLine ("Added " + re
.Url
);
237 services
.services
.Add (sd
);
240 Console
.WriteLine ("Done");
241 Console
.WriteLine ();
244 static void DownloadWsdls (string host
)
246 Console
.WriteLine ();
247 Console
.WriteLine ("Downloading WSDL documents");
248 Console
.WriteLine ("---------------------------");
250 foreach (ServiceData sd
in services
.services
) {
251 if (host
!= null && host
!= new Uri (sd
.Wsdl
).Host
) continue;
252 if (!File
.Exists (GetWsdlFile(sd
)))
256 Console
.WriteLine ("Done");
257 Console
.WriteLine ();
260 static void Resolve (ServiceData sd
)
262 Console
.Write ("Resolving " + sd
.Wsdl
+ " ");
265 DiscoveryClientProtocol contract
= new DiscoveryClientProtocol ();
266 contract
.DiscoverAny (sd
.Wsdl
);
268 if (sd
.Protocols
== null || sd
.Protocols
.Length
==0)
269 RetrieveServiceData (sd
, contract
);
271 string wsdlFile
= GetWsdlFile (sd
);
272 CreateFolderForFile (wsdlFile
);
274 ServiceDescription doc
= (ServiceDescription
) contract
.Documents
[sd
.Wsdl
];
275 doc
.Write (wsdlFile
);
277 Console
.WriteLine ("OK");
282 Console
.WriteLine ("FAILED");
283 ReportError ("Error resolving: " + sd
.Wsdl
, ex
.ToString ());
284 RegisterFailure (sd
);
288 public static ServiceData
CreateServiceData (DiscoveryReference dref
)
290 ServiceData sd
= new ServiceData ();
292 string name
= GetServiceName (dref
);
295 while (FindServiceByName (sd
.Name
) != null)
305 public static void RetrieveServiceData (ServiceData sd
, DiscoveryClientProtocol contract
)
307 ServiceDescriptionCollection col
= new ServiceDescriptionCollection ();
308 foreach (object doc
in contract
.Documents
.Values
)
309 if (doc
is ServiceDescription
) col
.Add ((ServiceDescription
)doc
);
311 string loc
= GetLocation (col
[0]);
314 WebResponse res
= null;
317 WebRequest req
= (WebRequest
)WebRequest
.Create (loc
);
319 res
= req
.GetResponse ();
323 WebException wex
= ex
as WebException
;
324 if (wex
!= null) res
= wex
.Response
;
328 sd
.ServerType
= res
.Headers
["Server"] + " # " + res
.Headers
["X-Powered-By"];
332 ArrayList bins
= GetBindingTypes (col
);
333 sd
.Protocols
= (string[]) bins
.ToArray(typeof(string));
336 static ArrayList
GetBindingTypes (ServiceDescriptionCollection col
)
338 ServiceDescription doc
= col
[0];
339 ArrayList list
= new ArrayList ();
340 foreach (Service s
in doc
.Services
)
342 foreach (Port p
in s
.Ports
)
344 Binding bin
= col
.GetBinding (p
.Binding
);
345 if (bin
.Extensions
.Find (typeof (System
.Web
.Services
.Description
.SoapBinding
)) != null)
346 if (!list
.Contains ("Soap")) list
.Add ("Soap");
348 HttpBinding ext
= (HttpBinding
) bin
.Extensions
.Find (typeof (HttpBinding
));
351 if (ext
.Verb
== "POST") list
.Add ("HttpPost");
352 else list
.Add ("HttpGet");
359 static string GetLocation (ServiceDescription doc
)
361 foreach (Service s
in doc
.Services
)
363 foreach (Port p
in s
.Ports
)
365 SoapAddressBinding loc
= (SoapAddressBinding
) p
.Extensions
.Find (typeof (System
.Web
.Services
.Description
.SoapAddressBinding
));
373 static string GetServiceName (DiscoveryReference dref
)
375 string name
= dref
.DefaultFilename
;
377 if (name
.EndsWith (".wsdl")) name
= name
.Substring (0,name
.Length
-5);
380 int i
= dref
.Url
.IndexOf ("service=");
381 if (i
== -1) name
= dref
.Url
.Substring (7);
382 else name
= dref
.Url
.Substring (i
+8);
385 name
= name
+ "Test";
386 if (Char
.IsDigit (name
,0)) name
= "Ws" + name
;
387 return Normalize (name
);
390 static string Normalize (string s
)
392 System
.Text
.StringBuilder sb
= new System
.Text
.StringBuilder ();
393 for (int n
=0; n
<s
.Length
; n
++)
394 if (Char
.IsLetterOrDigit (s
[n
]) || s
[n
] == '_') sb
.Append (s
[n
]);
396 return sb
.ToString ();
399 /* static string GetFileName (DiscoveryReference dref)
401 return Path.Combine (classPath, GetServiceName (dref) + ".cs");
405 static ServiceData
FindService (string url
)
407 foreach (ServiceData sd
in services
.services
)
408 if (sd
.Wsdl
== url
) return sd
;
413 static void RemoveService (string url
)
415 for (int n
=0; n
<services
.services
.Count
; n
++)
417 ServiceData sd
= (ServiceData
) services
.services
[n
];
418 if (sd
.Wsdl
== url
) { services.services.RemoveAt (n); return; }
422 static ServiceData
FindServiceByName (string name
)
424 foreach (ServiceData sd
in services
.services
)
425 if (sd
.Name
== name
) return sd
;
430 static void ShowStatus ()
438 Hashtable servers
= new Hashtable ();
440 foreach (ServiceData sd
in services
.services
)
442 if (sd
.Protocols
!= null)
444 if (Array
.IndexOf(sd
.Protocols
, "Soap") != -1) soap
++;
445 if (Array
.IndexOf(sd
.Protocols
, "HttpPost") != -1) post
++;
446 if (Array
.IndexOf(sd
.Protocols
, "HttpGet") != -1) get++;
449 if (sd
.ClientTest
) tests
++;
451 string st
= sd
.ServerType
;
452 if (st
== null) st
= "Unknown";
453 object on
= servers
[st
];
458 servers
[st
] = ((int)on
)+1;
461 Console
.WriteLine ("Total services: " + services
.services
.Count
);
462 Console
.WriteLine ("Soap Protocol: " + soap
);
463 Console
.WriteLine ("HttpPost Protocol: " + post
);
464 Console
.WriteLine ("HttpGet Protocol: " + get);
465 Console
.WriteLine ("Total proxies: " + (soap
+ post
+ get));
466 Console
.WriteLine ("Nunit Tests: " + tests
);
467 Console
.WriteLine ();
468 Console
.WriteLine ("Server Types:");
470 string[] serverNames
= new string[servers
.Count
];
471 int[] serverCounts
= new int[servers
.Count
];
474 foreach (DictionaryEntry ent
in servers
)
476 serverNames
[n
] = (string) ent
.Key
;
477 serverCounts
[n
++] = (int) ent
.Value
;
480 Array
.Sort (serverCounts
, serverNames
);
481 for (n
=serverNames
.Length
-1; n
>=0; n
--)
482 Console
.WriteLine ("{0,-3} {1}", serverCounts
[n
], serverNames
[n
]);
485 static void BuildProxies (string host
)
487 Console
.WriteLine ();
488 Console
.WriteLine ("Generating proxies");
489 Console
.WriteLine ("------------------");
491 XmlDocument doc
= new XmlDocument ();
492 XmlElement ele
= doc
.CreateElement ("errors");
493 doc
.AppendChild (ele
);
495 bool buildAll
= host
== "*";
496 if (buildAll
) host
= null;
498 ArrayList proxies
= new ArrayList ();
500 foreach (ServiceData fd
in services
.services
) {
501 if (host
!= null && host
!= new Uri (fd
.Wsdl
).Host
) continue;
502 BuildProxy (fd
, buildAll
, proxies
, ele
);
505 StreamWriter sw
= new StreamWriter (Path
.Combine (basePath
, "proxies.sources"));
506 foreach (string f
in proxies
)
510 doc
.Save ("proxy-gen-error.xml");
511 Console
.WriteLine ("Done");
512 Console
.WriteLine ();
515 static void BuildProxy (ServiceData fd
, bool rebuild
, ArrayList proxies
, XmlElement errdoc
)
517 string wsdl
= GetWsdlFile (fd
);
518 if (!File
.Exists (wsdl
))
521 if (fd
.Protocols
== null)
523 ReportError ("Client test '" + fd
.Name
+ "': no protocols declared", "");
527 foreach (string prot
in fd
.Protocols
)
529 string ns
= fd
.Namespace
;
530 ns
= CodeIdentifier
.MakeValid (ns
) + "." + prot
;
532 string pfile
= GetProxyFile (fd
, prot
);
533 if (File
.Exists (pfile
) && !rebuild
) { proxies.Add (pfile); continue; }
535 CreateFolderForFile (pfile
);
537 Console
.Write (prot
+ " proxy for " + wsdl
+ "... ");
538 Process proc
= new Process ();
539 proc
.StartInfo
.UseShellExecute
= false;
540 proc
.StartInfo
.RedirectStandardOutput
= true;
541 proc
.StartInfo
.RedirectStandardError
= true;
542 proc
.StartInfo
.FileName
= "wsdl";
543 proc
.StartInfo
.Arguments
= "/out:" + pfile
+ " /nologo /namespace:" + ns
+ " /protocol:" + prot
+ " " + wsdl
;
546 if (!proc
.WaitForExit (30000))
552 Console
.WriteLine ("FAIL (timeout)");
553 if (File
.Exists (pfile
)) File
.Delete (pfile
);
554 WriteError (errdoc
, ns
, "Errors found while generating " + prot
+ " proxy for WSDL: " + wsdl
, "wsdl.exe timeout");
556 else if (proc
.ExitCode
!= 0)
558 Console
.WriteLine ("FAIL " + proc
.ExitCode
);
560 string err
= proc
.StandardOutput
.ReadToEnd ();
561 err
+= "\n" + proc
.StandardError
.ReadToEnd ();
563 if (File
.Exists (pfile
))
565 if (proc
.ExitCode
== 1) {
566 string fn
= fd
.Name
+ prot
+ "Proxy.cs";
567 fn
= Path
.Combine (GetErrorPath(), fn
);
568 CreateFolderForFile (fn
);
569 File
.Move (pfile
, fn
);
571 StreamWriter sw
= new StreamWriter (fn
, true);
573 sw
.WriteLine ("// " + fd
.Wsdl
);
582 WriteError (errdoc
, ns
, "Errors found while generating " + prot
+ " proxy for WSDL: " + wsdl
, err
);
586 if (File
.Exists (pfile
)) {
587 Console
.WriteLine ("OK");
591 Console
.WriteLine ("FAIL");
592 string err
= proc
.StandardOutput
.ReadToEnd ();
593 err
+= "\n" + proc
.StandardError
.ReadToEnd ();
594 WriteError (errdoc
, ns
, "Errors found while generating " + prot
+ " proxy for WSDL: " + wsdl
, err
);
600 static void WriteError (XmlElement err
, string ns
, string error
, string detail
)
602 XmlElement ele
= err
.OwnerDocument
.CreateElement ("error");
603 ele
.SetAttribute ("ns",ns
);
604 XmlText text
= err
.OwnerDocument
.CreateTextNode (error
+ "\n" + detail
);
605 ele
.AppendChild (text
);
606 err
.AppendChild (ele
);
609 static void BuildClients (string wsdl
)
611 StreamWriter sw
= new StreamWriter (Path
.Combine (basePath
, "client.sources"));
613 foreach (ServiceData fd
in services
.services
)
615 if (wsdl
!= null && fd
.Wsdl
== wsdl
) fd
.ClientTest
= true;
617 if (!fd
.ClientTest
) continue;
620 sw
.WriteLine (GetClientFile (fd
));
626 public static void BuildClient (ServiceData sd
)
628 string file
= GetClientFile (sd
);
630 if (File
.Exists (file
)) return;
632 CreateFolderForFile (file
);
634 StreamWriter sw
= new StreamWriter (file
);
635 sw
.WriteLine ("// Web service test for WSDL document:");
636 sw
.WriteLine ("// " + sd
.Wsdl
);
639 sw
.WriteLine ("using System;");
640 sw
.WriteLine ("using NUnit.Framework;");
642 foreach (string prot
in sd
.Protocols
)
643 sw
.WriteLine ("using " + sd
.Namespace
+ "." + prot
+ ";");
646 sw
.WriteLine ("namespace " + sd
.Namespace
);
648 sw
.WriteLine ("\tpublic class " + sd
.Name
+ ": WebServiceTest");
649 sw
.WriteLine ("\t{");
650 sw
.WriteLine ("\t\t[Test]");
651 sw
.WriteLine ("\t\tpublic void TestService ()");
652 sw
.WriteLine ("\t\t{");
653 sw
.WriteLine ("\t\t}");
654 sw
.WriteLine ("\t}");
658 Console
.WriteLine ("Written file '" + file
+ "'");
661 public static void CheckDiff (string diffFile
)
663 int suc
=0, tot
=0, ign
=0;
664 XmlDocument doc
= new XmlDocument ();
667 XmlDocument errdoc
= new XmlDocument ();
668 errdoc
.Load ("proxy-gen-error.xml");
670 XmlDocument result
= new XmlDocument ();
671 XmlElement res
= result
.CreateElement ("test-results");
672 res
.SetAttribute ("name", "wsdl-tests");
673 res
.SetAttribute ("date", DateTime
.Now
.ToShortDateString ());
674 res
.SetAttribute ("time", DateTime
.Now
.ToShortTimeString ());
675 result
.AppendChild (res
);
677 XmlElement ts
= result
.CreateElement ("test-suite");
678 ts
.SetAttribute ("name", "wsdl");
679 ts
.SetAttribute ("asserts", "0");
680 ts
.SetAttribute ("time", "0");
681 res
.AppendChild (ts
);
683 XmlElement tsres
= result
.CreateElement ("results");
684 ts
.AppendChild (tsres
);
686 XslTransform xsl
= new XslTransform ();
687 xsl
.Load ("cormissing.xsl");
689 foreach (ServiceData sd
in services
.services
)
691 if (sd
.Protocols
== null) continue;
693 foreach (string prot
in sd
.Protocols
)
695 string ns
= sd
.Namespace
+ "." + prot
;
697 XmlElement elem
= doc
.SelectSingleNode ("assemblies/assembly/namespaces/namespace[@name='" + ns
+ "']") as XmlElement
;
703 if (!File
.Exists (GetWsdlFile(sd
))) {
704 Console
.WriteLine ("WARNING: wsdl file not found: " + GetWsdlFile(sd
));
711 bool extrans
= elem
.GetAttribute ("presence") == "extra";
713 if ((elem
.GetAttribute ("error") != "" || elem
.GetAttribute ("missing") != "" || elem
.GetAttribute ("extra") != "") && !extrans
)
715 XmlElement errelem
= errdoc
.SelectSingleNode ("/errors/error[@ns='" + ns
+ "']") as XmlElement
;
716 if (errelem
!= null) {
717 WriteResult (tsres
, ns
, false, sd
.Wsdl
+ "\n" + errelem
.InnerText
);
720 StringWriter str
= new StringWriter ();
721 xsl
.Transform (elem
, null, str
, null);
722 WriteResult (tsres
, ns
, false, sd
.Wsdl
+ "\n" + str
.ToString ());
727 if (extrans
) Console
.WriteLine ("BONUS CLASS: " + ns
);
729 WriteResult (tsres
, ns
, true, sd
.Wsdl
);
734 ts
.SetAttribute ("success", (suc
< tot
).ToString());
736 res
.SetAttribute ("total", tot
.ToString());
737 res
.SetAttribute ("failures", (tot
-suc
).ToString());
738 res
.SetAttribute ("not-run", "0");
740 result
.Save ("WsdlTestResult.xml");
741 Console
.WriteLine ("Compared:" + tot
+ " Ignored:" + ign
+ " Sucess:" + suc
+ " Fail:" + (tot
- suc
));
744 static void WriteResult (XmlElement res
, string name
, bool success
, string msg
)
746 XmlDocument doc
= res
.OwnerDocument
;
747 XmlElement test
= doc
.CreateElement ("test-case");
748 test
.SetAttribute ("name", name
);
749 test
.SetAttribute ("executed", "True");
750 test
.SetAttribute ("success", success
.ToString());
751 test
.SetAttribute ("time", "0");
752 test
.SetAttribute ("asserts", "0");
755 XmlElement fail
= doc
.CreateElement ("failure");
756 test
.AppendChild (fail
);
757 XmlElement xmsg
= doc
.CreateElement ("message");
758 fail
.AppendChild (xmsg
);
759 xmsg
.AppendChild (doc
.CreateCDataSection (msg
));
760 fail
.AppendChild (doc
.CreateElement ("stack-trace"));
762 res
.AppendChild (test
);
765 static void MsFix (string fileName
)
767 StreamReader sr
= new StreamReader ("msfix");
768 XmlDocument doc
= new XmlDocument ();
772 while ((line
= sr
.ReadLine ()) != null)
774 string[] ss
= line
.Split ('/');
775 XmlElement elem
= doc
.SelectSingleNode ("assemblies/assembly/namespaces/namespace[@name='" + ss
[0] + "']/classes/class[@name='" + ss
[1] + "']") as XmlElement
;
776 if (elem
!= null) elem
.ParentNode
.RemoveChild (elem
);
782 static void GenerateFiles (string templateFile
)
784 XmlDocument doc
= new XmlDocument ();
785 doc
.Load (templateFile
);
787 XmlNodeList targets
= doc
.SelectNodes ("fileGeneration/targets/target");
788 XmlElement gvarset
= (XmlElement
) doc
.SelectSingleNode ("fileGeneration/vars[@name='_global']");
790 foreach (XmlElement node
in targets
) {
791 string tid
= node
.GetAttribute ("template");
792 string file
= node
.GetAttribute ("file");
793 XmlElement xtemp
= (XmlElement
) doc
.SelectSingleNode ("fileGeneration/templates/template[@id='" + tid
+ "']");
794 if (xtemp
== null) throw new Exception ("Template " + tid
+ " not found");
795 string tempFile
= xtemp
.GetAttribute ("file");
797 StreamReader sr
= new StreamReader (tempFile
);
798 string template
= sr
.ReadToEnd ();
801 string content
= ReplaceVars (template
, node
);
802 content
= ReplaceVars (content
, gvarset
);
804 StreamWriter sw
= new StreamWriter (file
);
807 Console
.WriteLine ("Writen " + file
);
811 static string ReplaceVars (string content
, XmlElement root
)
813 XmlNodeList nodes
= root
.SelectNodes ("var");
814 foreach (XmlElement elem
in nodes
) {
815 string include
= elem
.GetAttribute ("include");
817 XmlElement varset
= (XmlElement
) root
.OwnerDocument
.SelectSingleNode ("fileGeneration/vars[@name='" + include
+ "']");
818 if (varset
== null) throw new Exception ("varset '" + include
+ "' not found");
819 content
= ReplaceVars (content
, varset
);
822 content
= content
.Replace ("$" + elem
.GetAttribute ("name") + "$", elem
.InnerText
);
829 static void RegisterFailure (ServiceData sd
)
831 ServiceStatus status
= null;
832 foreach (ServiceStatus ss
in serviceStatus
.services
)
834 if (ss
.Name
== sd
.Name
)
843 status
= new ServiceStatus ();
844 status
.Name
= sd
.Name
;
846 status
.LastTestDate
= DateTime
.Now
;
847 serviceStatus
.services
.Add (status
);
851 if ((DateTime
.Now
- status
.LastTestDate
).TotalHours
>= 24)
856 static void CleanFailures (ServiceData sd
)
858 ServiceStatus status
= null;
859 foreach (ServiceStatus ss
in serviceStatus
.services
)
861 if (ss
.Name
== sd
.Name
)
863 serviceStatus
.services
.Remove (ss
);
869 static string GetProxyFile (ServiceData fd
, string protocol
)
871 string fn
= Path
.Combine (new Uri (fd
.Wsdl
).Host
, fd
.Name
+ protocol
+ "Proxy.cs");
872 return Path
.Combine (GetProxyPath(), fn
);
875 static string GetClientFile (ServiceData sd
)
877 return Path
.Combine (GetClientPath(), sd
.TestFile
);
880 static string GetWsdlFile (ServiceData fd
)
882 string fn
= Path
.Combine (new Uri (fd
.Wsdl
).Host
, fd
.Name
+ ".wsdl");
883 return Path
.Combine (GetWsdlPath(), fn
);
886 static void ReportError (string error
, string detail
)
888 string fn
= Path
.Combine (GetErrorPath(), "error.log");
889 CreateFolderForFile (fn
);
891 StreamWriter sw
= new StreamWriter (fn
, true);
892 sw
.WriteLine ("*** " + error
);
893 sw
.WriteLine (" " + detail
.Replace ("\n","\n "));
899 static string GetProxyPath ()
901 return Path
.Combine (basePath
, "proxies");
904 static string GetClientPath ()
906 return Path
.Combine (basePath
, "client");
909 static string GetErrorPath ()
911 return Path
.Combine (basePath
, "error");
914 static string GetWsdlPath ()
916 return Path
.Combine (basePath
, "wsdlcache");
919 static string GetTempWsdlPath ()
921 return Path
.Combine (basePath
, "wsdlcache");
924 static void CreateFolderForFile (string file
)
926 string dir
= Path
.GetDirectoryName (file
);
927 DirectoryInfo di
= new DirectoryInfo (dir
);
928 if (!di
.Exists
) di
.Create ();
932 [XmlType("services")]
933 public class ServiceCollection
935 [XmlElement("service", typeof(ServiceData
))]
936 public ArrayList services
= new ArrayList ();
940 public class ServiceData
948 [XmlElement("serverType")]
949 public string ServerType
;
951 [XmlArray("protocols")]
952 [XmlArrayItem("protocol")]
953 public string[] Protocols
;
955 [XmlElement("clientTest")]
956 public bool ClientTest
;
959 public string Namespace
961 get { return Name + "s"; }
965 public string TestFile
969 string dir
= new Uri (Wsdl
).Host
;
970 if (dir
!= "localhost") dir
= "external";
971 return Path
.Combine (dir
, Name
+ ".cs");
976 [XmlType("serviceStatus")]
977 public class ServiceStatusCollection
979 [XmlElement("service", typeof(ServiceStatus
))]
980 public ArrayList services
= new ArrayList ();
983 public class ServiceStatus
988 [XmlElement("lastTestDate")]
989 public DateTime LastTestDate
;
991 [XmlElement("retries")]