Exemplo n.º 1
0
        private async void Result_AboutAnnounced(object sender, AboutListener.AboutAnnouncedEventArgs e)
        {
            Log.WriteLine($"\tFrom bus :{e.BusName}");
            Log.WriteLine($"\tAbout version {e.Version}");
            Log.WriteLine($"\tSessionPort {e.Port}");
            Log.WriteLine($"\tObjectDescription:");
            foreach (var path in e.ObjectDescription.Paths)
            {
                Log.WriteLine($"\t\t{path}");
                var interfaces = e.ObjectDescription.GetInterfaces(path);
                foreach (var i in interfaces)
                {
                    Log.WriteLine($"\t\t\t" + i);
                }
            }
            Log.WriteLine($"\tAboutData:");
            PrintAboutData(e.AboutData, null, 2);
            Log.WriteLine("*********************************************************************************");

            var session = new Session(TrafficType.Messages, false, Proximity.Any, Transport.Any);

            clientBus.EnableConcurrentCallbacks();
            var sessionId = clientBus.JoinSession(e.BusName, e.Port, null, session);

            if (sessionId != 0)
            {
                var aboutProxy = new AboutProxy(clientBus, e.BusName, sessionId);
                Log.WriteLine("*********************************************************************************");
                Log.WriteLine("AboutProxy.GetObjectDescription:");

                var aod2 = aboutProxy.ObjectDescription;
                foreach (var path in aod2.Paths)
                {
                    Log.WriteLine($"\t\t{path}");
                    foreach (var i in aod2.GetInterfaces(path))
                    {
                        Log.WriteLine($"\t\t\t{i}");
                    }
                }
                Log.WriteLine("*********************************************************************************");
                Log.WriteLine("AboutProxy.GetAboutData: (Default Language)");
                using (
                    var aboutData = aboutProxy.GetAboutData("en"))
                {
                    PrintAboutData(aboutData, "en", 1);
                    var langs = aboutData.SupportedLanguages;
                    if (langs.Length > 1)
                    {
                        var dlang = aboutData.DefaultLanguage;
                        foreach (var lang in langs)
                        {
                            if (lang == dlang)
                            {
                                continue;
                            }
                            using (var data = aboutProxy.GetAboutData(lang))
                            {
                                PrintAboutData(data, lang, 1);
                            }
                        }
                    }
                }
                Log.WriteLine("*********************************************************************************");
                Log.WriteLine($"AboutProxy.GetVersion {aboutProxy.Version}");
                Log.WriteLine("*********************************************************************************");
                string[] paths       = e.ObjectDescription.GetInterfacePaths(INTERFACE_NAME);
                var      proxyObject = new ProxyBusObject(clientBus, e.BusName, paths[0], session);
                proxyObject.IntrospectRemoteObject();
                var arg = new MsgArg("ECHO Echo echo...\n");
                //var replyMsg = proxyObject.MethodCall(clientBus, INTERFACE_NAME, "Echo", arg, 1, TimeSpan.FromMilliseconds(25000));
                var replyMsg = await proxyObject.MethodCallAsync(serviceBus, INTERFACE_NAME, "Echo", arg, 1, TimeSpan.FromMilliseconds(25000));

                //
                var msg = replyMsg.GetArgument(0);
                Log.WriteLine($"Echo method reply: {ArgValueToString(msg)}");
            }
            Log.WriteLine("*********************************************************************************");
        }