Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TouchOptions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under Apache 2.0 License. See LICENSE.md for details.
3 //
4 // TouchOptions.cs: MonoTouch.Dialog-based options
5 //
6 // Authors:
7 // Sebastien Pouliot <sebastien@xamarin.com>
8 //
9 // Copyright 2011-2012 Xamarin Inc.
10 //
11 // Licensed under the Apache License, Version 2.0 (the "License");
12 // you may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at
14 //
15 // http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
22 //
23 
24 using System;
25 
26 #if XAMCORE_2_0
27 using Foundation;
28 using UIKit;
29 #else
30 using MonoTouch.Foundation;
31 using MonoTouch.UIKit;
32 #endif
33 
34 using MonoTouch.Dialog;
35 
36 using Mono.Options;
37 
38 namespace SiliconStudio.Paradox.UnitTesting.UI {
39 
40  public class TouchOptions {
41 
42  static public TouchOptions Current = new TouchOptions ();
43 
44  public TouchOptions ()
45  {
46  var defaults = NSUserDefaults.StandardUserDefaults;
47  EnableNetwork = defaults.BoolForKey ("network.enabled");
48  HostName = defaults.StringForKey ("network.host.name");
49  HostPort = (int)defaults.IntForKey ("network.host.port");
50  SortNames = defaults.BoolForKey ("display.sort");
51 
52  //var os = new OptionSet () {
53  // { "autoexit", "If the app should exit once the test run has completed.", v => TerminateAfterExecution = true },
54  // { "autostart", "If the app should automatically start running the tests.", v => AutoStart = true },
55  // { "hostname=", "Comma-separated list of host names or IP address to (try to) connect to", v => HostName = v },
56  // { "hostport=", "TCP port to connect to.", v => HostPort = int.Parse (v) },
57  // { "enablenetwork", "Enable the network reporter.", v => EnableNetwork = true },
58  //};
59  //
60  //try {
61  // os.Parse (Environment.GetCommandLineArgs ());
62  //} catch (OptionException oe) {
63  // Console.WriteLine ("{0} for options '{1}'", oe.Message, oe.OptionName);
64  //}
65  }
66 
67  private bool EnableNetwork { get; set; }
68 
69  public string HostName { get; private set; }
70 
71  public int HostPort { get; private set; }
72 
73  public bool AutoStart { get; set; }
74 
75  public bool TerminateAfterExecution { get; set; }
76 
77  public bool ShowUseNetworkLogger {
78  get { return (EnableNetwork && !String.IsNullOrWhiteSpace (HostName) && (HostPort > 0)); }
79  }
80 
81  public bool SortNames { get; set; }
82 
83  [CLSCompliant (false)]
84  public UIViewController GetViewController ()
85  {
86  var network = new BooleanElement ("Enable", EnableNetwork);
87 
88  var host = new EntryElement ("Host Name", "name", HostName);
89  host.KeyboardType = UIKeyboardType.ASCIICapable;
90 
91  var port = new EntryElement ("Port", "name", HostPort.ToString ());
92  port.KeyboardType = UIKeyboardType.NumberPad;
93 
94  var sort = new BooleanElement ("Sort Names", SortNames);
95 
96  var root = new RootElement ("Options") {
97  new Section ("Remote Server") { network, host, port },
98  new Section ("Display") { sort }
99  };
100 
101  var dv = new DialogViewController (root, true) { Autorotate = true };
102  dv.ViewDisappearing += delegate {
103  EnableNetwork = network.Value;
104  HostName = host.Value;
105  ushort p;
106  if (UInt16.TryParse (port.Value, out p))
107  HostPort = p;
108  else
109  HostPort = -1;
110  SortNames = sort.Value;
111 
112  var defaults = NSUserDefaults.StandardUserDefaults;
113  defaults.SetBool (EnableNetwork, "network.enabled");
114  defaults.SetString (HostName ?? String.Empty, "network.host.name");
115  defaults.SetInt (HostPort, "network.host.port");
116  defaults.SetBool (SortNames, "display.sort");
117  };
118 
119  return dv;
120  }
121  }
122 }