diff options
author | Benoit Foucher <benoit@zeroc.com> | 2012-04-25 11:19:13 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2012-04-25 11:19:13 +0200 |
commit | 7e874613ff22bedf988273b51a15ab937f01169f (patch) | |
tree | 115a92a902f80fcc6252c5fac6a957ecc548b82c /cs/test/TestCommon/TestApp.cs | |
parent | Fixed copyrights (diff) | |
download | ice-7e874613ff22bedf988273b51a15ab937f01169f.tar.bz2 ice-7e874613ff22bedf988273b51a15ab937f01169f.tar.xz ice-7e874613ff22bedf988273b51a15ab937f01169f.zip |
Merged Silverlight support
Diffstat (limited to 'cs/test/TestCommon/TestApp.cs')
-rw-r--r-- | cs/test/TestCommon/TestApp.cs | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/cs/test/TestCommon/TestApp.cs b/cs/test/TestCommon/TestApp.cs new file mode 100644 index 00000000000..75e6d8439f1 --- /dev/null +++ b/cs/test/TestCommon/TestApp.cs @@ -0,0 +1,142 @@ +using System;
+
+#if SILVERLIGHT
+using System.Collections.Generic;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+#endif
+
+namespace TestCommon
+{
+ public abstract class TestApp
+ {
+ protected static void test(bool b)
+ {
+ if(!b)
+ {
+ throw new System.Exception();
+ }
+ }
+
+#if !SILVERLIGHT
+ static
+#endif
+ public void Write(string msg)
+ {
+#if SILVERLIGHT
+ Console.Out.Write(msg);
+#else
+ Console.Out.Write(msg);
+#endif
+ }
+
+#if !SILVERLIGHT
+ static
+#endif
+ public void WriteLine(string msg)
+ {
+#if SILVERLIGHT
+ Console.Out.WriteLine(msg);
+#else
+ Console.Out.WriteLine(msg);
+#endif
+ }
+
+#if !SILVERLIGHT
+ static
+#endif
+ public void Flush()
+ {
+ Console.Out.Flush();
+ }
+
+#if SILVERLIGHT
+
+ public abstract void run(Ice.Communicator communicator);
+
+ public virtual Ice.InitializationData
+ initData()
+ {
+ return new Ice.InitializationData();
+ }
+
+ public void main()
+ {
+ int args = Application.Current.Host.Source.OriginalString.IndexOf("?");
+ Dictionary<string, string> properties = new Dictionary<string, string>();
+ if(args > 0 && args + 1 < Application.Current.Host.Source.OriginalString.Length)
+ {
+ string[] props = Application.Current.Host.Source.OriginalString.Substring(args + 1).Split(';');
+ foreach (string prop in props)
+ {
+ int pos = prop.IndexOf('=');
+ if(pos > 0)
+ {
+ properties[prop.Substring(0, pos)] = prop.Substring(pos + 1);
+ }
+ }
+ }
+
+ System.Threading.Thread t = new System.Threading.Thread(() =>
+ {
+ Ice.Communicator communicator = null;
+ try
+ {
+ Ice.InitializationData initializationData = initData();
+ if(initializationData.properties == null)
+ {
+ initializationData.properties = Ice.Util.createProperties();
+ }
+
+ foreach(KeyValuePair<String,String> entry in properties)
+ {
+ if(initializationData.properties.getProperty(entry.Key).Equals(""))
+ {
+ initializationData.properties.setProperty(entry.Key, entry.Value);
+ }
+ }
+
+ communicator = Ice.Util.initialize(initializationData);
+ run(communicator);
+ completed();
+ }
+ catch(System.Exception ex)
+ {
+ failed(ex);
+ }
+ finally
+ {
+ if(communicator != null)
+ {
+ communicator.destroy();
+ }
+ }
+ });
+ t.Start();
+ }
+
+ public void completed()
+ {
+ Deployment.Current.Dispatcher.BeginInvoke(delegate()
+ {
+ Application.Current.MainWindow.Close();
+ });
+ }
+
+ public void failed(System.Exception ex)
+ {
+ System.Environment.ExitCode = 1;
+ WriteLine(Environment.NewLine + "Test Failed:");
+ WriteLine("Exception: " + ex.ToString());
+ completed();
+ }
+#endif
+ }
+}
|