/// <summary>
        /// Run the client stress op which stresses the bus attachment in a client type
        /// configuration which find the well-known service name and calls the 'cat'
        /// method
        /// </summary>
        /// <param name="isMultipoint">True if operation uses multipoint sessions</param>
        private void RunClient(bool isMultipoint)
        {
            try
            {
                ClientBusListener clientBusListener = new ClientBusListener(this.busAtt, this, this.foundName);
                this.busAtt.FindAdvertisedName(ServiceName);
                this.DebugPrint("Looking for WKN : " + ServiceName);

                this.foundName.WaitOne(12000);

                SessionOpts optsIn = new SessionOpts(
                            TrafficType.TRAFFIC_MESSAGES,
                            isMultipoint,
                            ProximityType.PROXIMITY_ANY,
                            TransportMaskType.TRANSPORT_ANY);
                SessionOpts[] optsOut = new SessionOpts[1];
                Task<JoinSessionResult> joinTask = this.busAtt.JoinSessionAsync(
                            this.DiscoveredName,
                            ServicePort,
                            (SessionListener)clientBusListener,
                            optsIn,
                            optsOut,
                            null).AsTask<JoinSessionResult>();
                joinTask.Wait();
                JoinSessionResult joinResult = joinTask.Result;
                QStatus status = joinResult.Status;

                ProxyBusObject proxyBusObj = null;
                if (QStatus.ER_OK == status)
                {
                    this.DebugPrint("JoinSession with " + this.DiscoveredName + " was successful (sessionId=" + joinResult.SessionId + ")");
                    proxyBusObj = new ProxyBusObject(this.busAtt, this.DiscoveredName, ServicePath, joinResult.SessionId);
                    Task<IntrospectRemoteObjectResult> introTask = proxyBusObj.IntrospectRemoteObjectAsync(null).AsTask<IntrospectRemoteObjectResult>();
                    introTask.Wait();
                    IntrospectRemoteObjectResult introResult = introTask.Result;
                    status = introResult.Status;

                    if (QStatus.ER_OK == status)
                    {
                        this.DebugPrint("Introspection of the service was successfull");
                        MsgArg hello = new MsgArg("s", new object[] { "Hello " });
                        MsgArg world = new MsgArg("s", new object[] { "World!" });
                        InterfaceMember catMethod = proxyBusObj.GetInterface(InterfaceName).GetMethod("cat");
                        byte flags = (byte)0;
                        Task<MethodCallResult> catTask = proxyBusObj.MethodCallAsync(catMethod, new MsgArg[] { hello, world }, null, 5000, flags).AsTask<MethodCallResult>();
                        catTask.Wait();
                        MethodCallResult catResult = catTask.Result;
                        if (catResult.Message.Type == AllJoynMessageType.MESSAGE_METHOD_RET)
                        {
                            this.DebugPrint(this.DiscoveredName + ".cat ( path=" + ServicePath + ") returned \"" + catResult.Message.GetArg(0).Value.ToString() + "\"");
                        }
                        else
                        {
                            this.DebugPrint("Method call on " + this.DiscoveredName + ".cat failed (ReturnType=" + catResult.Message.Type.ToString() + ")");
                        }
                    }
                    else
                    {
                        this.DebugPrint("Introspection was unsuccessful: " + status.ToString());
                    }
                }
                else
                {
                    this.DebugPrint("Join Session was unsuccessful: " + status.ToString());
                }

                this.busAtt.CancelFindAdvertisedName(ServiceName);
                this.busAtt.UnregisterBusListener(clientBusListener);
                this.DebugPrint("Successfully unraveled the client operation");
            }
            catch (ArgumentNullException ex)
            {
                this.DebugPrint(">>>> TIMEOUT, Client could not find WKN >>>>");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Client Execution Error >>>> " + errMsg);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Run the client stress op which stresses the bus attachment in a client type
        /// configuration which find the well-known service name and calls the 'cat'
        /// method
        /// </summary>
        /// <param name="isMultipoint">True if operation uses multipoint sessions</param>
        private void RunClient(bool isMultipoint)
        {
            try
            {
                ClientBusListener clientBusListener = new ClientBusListener(this.busAtt, this, this.foundName);
                this.busAtt.FindAdvertisedName(ServiceName);
                this.DebugPrint("Looking for WKN : " + ServiceName);

                this.foundName.WaitOne(12000);

                SessionOpts optsIn = new SessionOpts(
                    TrafficType.TRAFFIC_MESSAGES,
                    isMultipoint,
                    ProximityType.PROXIMITY_ANY,
                    TransportMaskType.TRANSPORT_ANY);
                SessionOpts[]            optsOut  = new SessionOpts[1];
                Task <JoinSessionResult> joinTask = this.busAtt.JoinSessionAsync(
                    this.DiscoveredName,
                    ServicePort,
                    (SessionListener)clientBusListener,
                    optsIn,
                    optsOut,
                    null).AsTask <JoinSessionResult>();
                joinTask.Wait();
                JoinSessionResult joinResult = joinTask.Result;
                QStatus           status     = joinResult.Status;

                ProxyBusObject proxyBusObj = null;
                if (QStatus.ER_OK == status)
                {
                    this.DebugPrint("JoinSession with " + this.DiscoveredName + " was successful (sessionId=" + joinResult.SessionId + ")");
                    proxyBusObj = new ProxyBusObject(this.busAtt, this.DiscoveredName, ServicePath, joinResult.SessionId);
                    Task <IntrospectRemoteObjectResult> introTask = proxyBusObj.IntrospectRemoteObjectAsync(null).AsTask <IntrospectRemoteObjectResult>();
                    introTask.Wait();
                    IntrospectRemoteObjectResult introResult = introTask.Result;
                    status = introResult.Status;

                    if (QStatus.ER_OK == status)
                    {
                        this.DebugPrint("Introspection of the service was successfull");
                        MsgArg                  hello     = new MsgArg("s", new object[] { "Hello " });
                        MsgArg                  world     = new MsgArg("s", new object[] { "World!" });
                        InterfaceMember         catMethod = proxyBusObj.GetInterface(InterfaceName).GetMethod("cat");
                        byte                    flags     = (byte)0;
                        Task <MethodCallResult> catTask   = proxyBusObj.MethodCallAsync(catMethod, new MsgArg[] { hello, world }, null, 5000, flags).AsTask <MethodCallResult>();
                        catTask.Wait();
                        MethodCallResult catResult = catTask.Result;
                        if (catResult.Message.Type == AllJoynMessageType.MESSAGE_METHOD_RET)
                        {
                            this.DebugPrint(this.DiscoveredName + ".cat ( path=" + ServicePath + ") returned \"" + catResult.Message.GetArg(0).Value.ToString() + "\"");
                        }
                        else
                        {
                            this.DebugPrint("Method call on " + this.DiscoveredName + ".cat failed (ReturnType=" + catResult.Message.Type.ToString() + ")");
                        }
                    }
                    else
                    {
                        this.DebugPrint("Introspection was unsuccessful: " + status.ToString());
                    }
                }
                else
                {
                    this.DebugPrint("Join Session was unsuccessful: " + status.ToString());
                }

                this.busAtt.CancelFindAdvertisedName(ServiceName);
                this.busAtt.UnregisterBusListener(clientBusListener);
                this.DebugPrint("Successfully unraveled the client operation");
            }
            catch (ArgumentNullException ex)
            {
                this.DebugPrint(">>>> TIMEOUT, Client could not find WKN >>>>");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Client Execution Error >>>> " + errMsg);
            }
        }