예제 #1
0
        public IEnumerable <PathContainer> GetElementsFromBus(string busName)
        {
            IntrospectableGetter getter = delegate(string path) {
                return(bus.GetObject <Introspectable>(busName, new ObjectPath(path)));
            };

            List <PathContainer> paths = new List <PathContainer>(7);

            ParseIntrospectable(rootPath, getter, paths);

            return((IEnumerable <PathContainer>)paths);
        }
예제 #2
0
        void ParseIntrospectable(string currentPath, IntrospectableGetter getter,
		                                    List<PathContainer> paths)
        {
            Introspectable intr = null;
            string intrData = null;

            try {
                intr = getter(currentPath);
                intrData = intr.Introspect();
            } catch (Exception e) {
                string error = "Managed D-Bus error on path : " + currentPath + Environment.NewLine +
                        "Error : " + e.Message;
                if (DBusError != null) {
                    DBusError(this, new DBusErrorEventArgs(error));
                }
                Console.WriteLine(error);
                return;
            }

            if (dump) {
                Console.WriteLine("On path : " + currentPath);
                Console.WriteLine(intrData ?? "Nothing to be parsed");
                Console.WriteLine();
            }

            if (string.IsNullOrEmpty(intrData))
                return;

            List<Interface> interfaces = null;

            using (XmlTextReader reader = new XmlTextReader(new StringReader(intrData))) {
                reader.XmlResolver = null;
                reader.ReadToFollowing("node");

                while (reader.Read()) {
                    if (reader.NodeType == XmlNodeType.EndElement)
                        continue;

                    if (reader.Name == "interface") {
                        if (interfaces == null)
                            interfaces = new List<Interface>(5);
                        interfaces.Add(MakeInterfaceFromNode(reader.ReadSubtree(), reader["name"]));
                    } else if (reader.Name == "node") {
                        if (reader["name"] != null) {
                            string newPath = JoinPath(currentPath, reader["name"]);
                            ParseIntrospectable(newPath, getter, paths);
                        }
                    }
                }
            }

            if (interfaces != null)
                paths.Add(new PathContainer(currentPath, (IEnumerable<Interface>)interfaces));
        }
예제 #3
0
        void ParseIntrospectable(string currentPath, IntrospectableGetter getter,
                                 List <PathContainer> paths)
        {
            Introspectable intr     = null;
            string         intrData = null;

            try {
                intr     = getter(currentPath);
                intrData = intr.Introspect();
            } catch (Exception e) {
                string error = "Managed D-Bus error on path : " + currentPath + Environment.NewLine +
                               "Error : " + e.Message;
                if (DBusError != null)
                {
                    DBusError(this, new DBusErrorEventArgs(error));
                }
                Console.WriteLine(error);
                return;
            }

            if (dump)
            {
                Console.WriteLine("On path : " + currentPath);
                Console.WriteLine(intrData ?? "Nothing to be parsed");
                Console.WriteLine();
            }

            if (string.IsNullOrEmpty(intrData))
            {
                return;
            }

            List <Interface> interfaces = null;

            using (XmlTextReader reader = new XmlTextReader(new StringReader(intrData))) {
                reader.XmlResolver = null;
                reader.ReadToFollowing("node");

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        continue;
                    }

                    if (reader.Name == "interface")
                    {
                        if (interfaces == null)
                        {
                            interfaces = new List <Interface>(5);
                        }
                        interfaces.Add(MakeInterfaceFromNode(reader.ReadSubtree(), reader["name"]));
                    }
                    else if (reader.Name == "node")
                    {
                        if (reader["name"] != null)
                        {
                            string newPath = JoinPath(currentPath, reader["name"]);
                            ParseIntrospectable(newPath, getter, paths);
                        }
                    }
                }
            }

            if (interfaces != null)
            {
                paths.Add(new PathContainer(currentPath, (IEnumerable <Interface>)interfaces));
            }
        }