~ubuntu-branches/ubuntu/karmic/ndesk-dbus/karmic

« back to all changes in this revision

Viewing changes to examples/TestExceptions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-10-16 11:52:32 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071016115232-fe3ejbyws97q4rf2
Tags: 0.6.0-1
* New upstream release.
* debian/control:
  + Update build dependencies.
* debian/rules:
  + Update for new upstream build system.
  + Call dh_clifixperms instead of manual find magic.
  + Bump clilibs to >= 0.6.0.
* debian/watch:
  + Update location.
* patches/01_pkg-config-library-path.dpatch:
  + Fix library path in the pkg-config file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2006 Alp Toker <alp@atoker.com>
2
 
// This software is made available under the MIT License
3
 
// See COPYING for details
4
 
 
5
 
using System;
6
 
using System.Collections.Generic;
7
 
using NDesk.DBus;
8
 
using org.freedesktop.DBus;
9
 
 
10
 
public class ManagedDBusTestExceptions
11
 
{
12
 
        public static void Main ()
13
 
        {
14
 
                Bus bus = Bus.Session;
15
 
 
16
 
                string myNameReq = "org.ndesk.testexceptions";
17
 
                ObjectPath myOpath = new ObjectPath ("/org/ndesk/testexceptions");
18
 
 
19
 
                DemoObject demo;
20
 
 
21
 
                if (bus.NameHasOwner (myNameReq)) {
22
 
                        demo = bus.GetObject<DemoObject> (myNameReq, myOpath);
23
 
                } else {
24
 
                        demo = new DemoObject ();
25
 
                        bus.Register (myNameReq, myOpath, demo);
26
 
 
27
 
                        RequestNameReply nameReply = bus.RequestName (myNameReq, NameFlag.None);
28
 
                        Console.WriteLine ("RequestNameReply: " + nameReply);
29
 
 
30
 
                        while (true)
31
 
                                bus.Iterate ();
32
 
                }
33
 
 
34
 
                Console.WriteLine ();
35
 
                //org.freedesktop.DBus.Error.InvalidArgs: Requested bus name "" is not valid
36
 
                try {
37
 
                        bus.RequestName ("");
38
 
                } catch (Exception e) {
39
 
                        Console.WriteLine (e);
40
 
                }
41
 
 
42
 
                //TODO: make this work as expected (what is expected?)
43
 
                Console.WriteLine ();
44
 
                try {
45
 
                        demo.ThrowSomeException ();
46
 
                } catch (Exception e) {
47
 
                        Console.WriteLine (e);
48
 
                }
49
 
 
50
 
                Console.WriteLine ();
51
 
                try {
52
 
                        demo.ThrowSomeExceptionNoRet ();
53
 
                } catch (Exception e) {
54
 
                        Console.WriteLine (e);
55
 
                }
56
 
                //handle the thrown exception
57
 
                //conn.Iterate ();
58
 
 
59
 
                Console.WriteLine ();
60
 
                try {
61
 
                        demo.HandleVariant (null);
62
 
                } catch (Exception e) {
63
 
                        Console.WriteLine (e);
64
 
                }
65
 
 
66
 
                Console.WriteLine ();
67
 
                try {
68
 
                        demo.HandleString (null);
69
 
                } catch (Exception e) {
70
 
                        Console.WriteLine (e);
71
 
                }
72
 
 
73
 
                Console.WriteLine ();
74
 
                try {
75
 
                        demo.HandleArray (null);
76
 
                } catch (Exception e) {
77
 
                        Console.WriteLine (e);
78
 
                }
79
 
        }
80
 
}
81
 
 
82
 
[Interface ("org.ndesk.testexceptions")]
83
 
public class DemoObject : MarshalByRefObject
84
 
{
85
 
        public int ThrowSomeException ()
86
 
        {
87
 
                Console.WriteLine ("Asked to throw some Exception");
88
 
 
89
 
                throw new Exception ("Some Exception");
90
 
        }
91
 
 
92
 
        public void ThrowSomeExceptionNoRet ()
93
 
        {
94
 
                Console.WriteLine ("Asked to throw some Exception NoRet");
95
 
 
96
 
                throw new Exception ("Some Exception NoRet");
97
 
        }
98
 
 
99
 
        public void HandleVariant (object o)
100
 
        {
101
 
                Console.WriteLine (o);
102
 
        }
103
 
 
104
 
        public void HandleString (string str)
105
 
        {
106
 
                Console.WriteLine (str);
107
 
        }
108
 
 
109
 
        public void HandleArray (byte[] arr)
110
 
        {
111
 
                Console.WriteLine (arr);
112
 
        }
113
 
}