Rename Managed.Windows.Forms to System.Windows.Forms for consistency.
[mono.git] / mcs / class / System.ServiceModel / Test / SwitchMode / Program.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Xml;
6 using System.Xml.Linq;
7
8 namespace SwitchMode
9 {
10         class Program
11         {
12                 static void Main (string [] args) {
13                         string file = args [0];
14                         string mode = args [1];
15                         XElement config = XElement.Load(file,LoadOptions.PreserveWhitespace);
16                         
17                         XElement appSettings = config.Element("appSettings");
18                         if (appSettings == null) {
19                                 appSettings = new XElement ("appSettings");
20                                 config.Add (appSettings);
21                         }
22                         var results = from el in appSettings.Elements ()
23                                                   where el.Attribute ("key").Value == "onlyClients"
24                                                   select el;
25                         XElement onlyClients;
26                         if (results.Count() == 1)
27                                 onlyClients = results.First ();
28                         else if (results.Count() == 0) {
29                                 onlyClients = new XElement ("add");
30                                 onlyClients.SetAttributeValue ("key", "onlyClients");
31                                 appSettings.Add (onlyClients);
32                         }
33                         else 
34                                 throw new Exception ("Too many onlyClients appSettings clauses");
35                         if (mode == "client")
36                                 onlyClients.SetAttributeValue("value","true");
37                         else if (mode == "inproc")
38                                 onlyClients.SetAttributeValue ("value", "false");
39                         else {
40                                 throw new Exception ("Unrecognized mode: " + mode);
41                         }
42                         config.Save (file,SaveOptions.DisableFormatting);
43                         Console.WriteLine ("Successfully switched to mode : " + mode);
44                 }
45         }
46 }