当前位置: 首页>>代码示例>>C#>>正文


C# ResponseListener.OnSuccess方法代码示例

本文整理汇总了C#中ConnectSdk.Windows.Service.Capability.Listeners.ResponseListener.OnSuccess方法的典型用法代码示例。如果您正苦于以下问题:C# ResponseListener.OnSuccess方法的具体用法?C# ResponseListener.OnSuccess怎么用?C# ResponseListener.OnSuccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConnectSdk.Windows.Service.Capability.Listeners.ResponseListener的用法示例。


在下文中一共展示了ResponseListener.OnSuccess方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectToWebApp

        public void ConnectToWebApp(WebOsWebAppSession webAppSession, bool joinOnly, ResponseListener connectionListener)
        {
            if (WebAppSessions == null)
                WebAppSessions = new Dictionary<string, WebOsWebAppSession>();

            if (AppToAppIdMappings == null)
                AppToAppIdMappings = new Dictionary<string, string>();

            if (webAppSession == null || webAppSession.LaunchSession == null)
            {
                Util.PostError(connectionListener, new ServiceCommandError(0, "You must provide a valid LaunchSession object"));

                return;
            }

            var tappId = webAppSession.LaunchSession.AppId;

            var tidKey = webAppSession.LaunchSession.SessionType == LaunchSessionType.WebApp ? "webAppId" : "appId";

            if (string.IsNullOrEmpty(tappId))
            {
                Util.PostError(connectionListener, new ServiceCommandError(-1, "You must provide a valid web app session"));

                return;
            }

            var appId = tappId;
            var idKey = tidKey;

            const string uri = "ssap://webapp/connectToApp";
            var payload = new JsonObject();

            try
            {
                payload.Add(idKey, JsonValue.CreateStringValue(appId));

            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {

            }

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var loadEventArgs = loadEventArg as LoadEventArgs;
                    if (loadEventArgs != null)
                    {
                        var jsonObj = (JsonObject)(loadEventArgs.Load.GetPayload());
                        var state = jsonObj.GetNamedString("state");
                        if (!state.Equals("Connected", StringComparison.OrdinalIgnoreCase))
                        {
                            if (joinOnly && state.Equals("WAITING_FOR_APP", StringComparison.OrdinalIgnoreCase))
                            {
                                Util.PostError(connectionListener,
                                    new ServiceCommandError(0, "Web app is not currently running"));
                            }
                            return;
                        }
                        var fullAppId = jsonObj.GetNamedString("appId");
                        if (!string.IsNullOrEmpty(fullAppId))
                        {
                            if (webAppSession.LaunchSession.SessionType == LaunchSessionType.WebApp && !AppToAppIdMappings.ContainsKey(fullAppId))
                                AppToAppIdMappings.Add(fullAppId, appId);
                            webAppSession.SetFullAppId(fullAppId);
                        }
                    }
                    if (connectionListener != null)
                        connectionListener.OnSuccess(loadEventArg);
                },
                serviceCommandError =>
                {
                    webAppSession.DisconnectFromWebApp();
                    var appChannelDidClose = false;
                    if (serviceCommandError != null && serviceCommandError.GetPayload() != null)
                        appChannelDidClose = serviceCommandError.GetPayload().ToString().Contains("app channel closed");

                    if (appChannelDidClose)
                    {
                        if (webAppSession.WebAppSessionListener != null)
                        {
                            webAppSession.WebAppSessionListener.OnWebAppSessionDisconnect(webAppSession);
                        }
                    }
                    else
                    {
                        Util.PostError(connectionListener, serviceCommandError);

                    }
                }
            );

            webAppSession.AppToAppSubscription = new UrlServiceSubscription(this, uri, payload, true, responseListener);;
            webAppSession.AppToAppSubscription.Subscribe();

            ////todo: this is a workaround! Normally the subscribed event should arrive sooner but now we suppose that the existing subscription was successfull
            //UrlServiceSubscription v;
            //if (subscriptions.ContainsKey(uri))
//.........这里部分代码省略.........
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:101,代码来源:WebOsTvService.cs

示例2: GetSystemInfo

        public void GetSystemInfo(ResponseListener listener)
        {
            const string uri = "ssap://api/getServiceList";

            var responseListener = new ResponseListener
                (
                loadEventArg =>
                {
                    var loadEventArgs = loadEventArg as LoadEventArgs;
                    if (loadEventArgs == null) return;
                    var jsonObj = (JsonObject) (loadEventArgs.Load.GetPayload());
                    if (jsonObj.ContainsKey("features"))
                    {
                        listener.OnSuccess(new ServiceCommandError(0, jsonObj.GetNamedArray("features")));
                    }
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
                );

            var request = new ServiceCommand(this, uri, null, responseListener);
            request.Send();
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:22,代码来源:WebOsTvService.cs

示例3: UnPinWebApp

        public void UnPinWebApp(string webAppId, ResponseListener listener)
        {
            if (string.IsNullOrEmpty(webAppId))
            {
                if (listener != null)
                {
                    listener.OnError(new ServiceCommandError(-1, "You must provide a valid web app id"));
                }
                return;
            }

            const string uri = "ssap://webapp/removePinnedWebApp";
            var payload = new JsonObject();

            try
            {
                payload.Add("webAppId", JsonValue.CreateStringValue(webAppId));
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {

            }

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var loadEventArgs = loadEventArg as LoadEventArgs;
                    if (loadEventArgs == null) return;
                    var jsonObj = (JsonObject)(loadEventArgs.Load.GetPayload());
                    if (jsonObj.ContainsKey("pairingType"))
                    {
                        NotifyPairingRequired();
                    }
                    else
                    {
                        listener.OnSuccess(loadEventArg);
                    }
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
            );

            ServiceCommand request = new UrlServiceSubscription(this, uri, payload, true, responseListener);
            request.Send();
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:46,代码来源:WebOsTvService.cs

示例4: CloseWebApp

        public void CloseWebApp(LaunchSession launchSession, ResponseListener listener)
        {
            if (launchSession == null || launchSession.AppId == null || launchSession.AppId.Length == 0)
            {
                Util.PostError(listener, new ServiceCommandError(0, null));
                return;
            }

            var webAppSession = WebAppSessions.ContainsKey(launchSession.AppId) ? WebAppSessions[launchSession.AppId] : null;

            if (webAppSession != null && webAppSession.IsConnected())
            {
                var serviceCommand = new JsonObject();
                var closeCommand = new JsonObject();

                try
                {
                    serviceCommand.Add("type", JsonValue.CreateStringValue("close"));

                    closeCommand.Add("contentType", JsonValue.CreateStringValue("connectsdk.serviceCommand"));
                    closeCommand.Add("serviceCommand", serviceCommand);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                var responseListener = new ResponseListener
                (
                    loadEventArg =>
                    {
                        webAppSession.DisconnectFromWebApp();

                        if (listener != null)
                            listener.OnSuccess(loadEventArg);
                    },
                    serviceCommandError =>
                    {
                        webAppSession.DisconnectFromWebApp();

                        if (listener != null)
                            listener.OnError(serviceCommandError);
                    }
                );

                webAppSession.SendMessage(closeCommand, responseListener);
            }
            else
            {
                //if (webAppSession != null)
                //    webAppSession.DisconnectFromWebApp();

                const string uri = "ssap://webapp/closeWebApp";
                var payload = new JsonObject();

                try
                {
                    if (launchSession.AppId != null)
                        payload.Add("webAppId", JsonValue.CreateStringValue(launchSession.AppId));
                    if (launchSession.SessionId != null)
                        payload.Add("sessionId", JsonValue.CreateStringValue(launchSession.SessionId));
                }
                catch (Exception e)
                {
                    throw e;
                }

                var request = new ServiceCommand(this, uri, payload, listener);
                request.Send();
            }
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:71,代码来源:WebOsTvService.cs

示例5: PostSuccess

 public static void PostSuccess(ResponseListener listener, object obj)
 {
     if (listener == null)
         return;
     listener.OnSuccess(obj);
 }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:6,代码来源:Util.cs

示例6: IsWebAppPinned

        public ServiceCommand IsWebAppPinned(bool isSubscription, string webAppId, ResponseListener listener)
        {
            if (string.IsNullOrEmpty(webAppId))
            {
                if (listener != null)
                {
                    listener.OnError(new ServiceCommandError(-1, "You must provide a valid web app id"));
                }
                return null;
            }

            const string uri = "ssap://webapp/isWebAppPinned";
            var payload = new JsonObject();

            try
            {
                payload.Add("webAppId", JsonValue.CreateStringValue(webAppId));
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {

            }

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var loadEventArgs = loadEventArg as LoadEventArgs;
                    if (loadEventArgs == null) return;
                    var jsonObj = (JsonObject)(loadEventArgs.Load.GetPayload());

                    var status = jsonObj.GetNamedBoolean("pinned");

                    if (listener != null)
                        listener.OnSuccess(status);
                },
                serviceCommandError => Util.PostError(listener, serviceCommandError)
            );

            var request = isSubscription ? new UrlServiceSubscription(this, uri, payload, true, responseListener) : new ServiceCommand(this, uri, payload, responseListener);

            request.Send();
            return request;
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:45,代码来源:WebOsTvService.cs

示例7: Connect

        private void Connect(bool joinOnly, ResponseListener connectionListener)
        {
            if (Socket != null && Socket.State == State.Connecting)
            {
                if (connectionListener != null)
                    connectionListener.OnError(new ServiceCommandError(0,
                        "You have a connection request pending,  please wait until it has finished"));
                return;
            }

            if (IsConnected())
            {
                if (connectionListener != null)
                    connectionListener.OnSuccess(null);
                return;
            }

            MConnectionListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var finalConnectionListener = new ResponseListener
                    (
                        loadEventArg2 =>
                        {
                            Connected = true;

                            if (connectionListener != null)
                                connectionListener.OnSuccess(loadEventArg2);
                        },
                        serviceCommandError =>
                        {
                            DisconnectFromWebApp();

                            if (connectionListener != null)
                                connectionListener.OnError(serviceCommandError);
                        }
                    );

                    Service.ConnectToWebApp(this, joinOnly, finalConnectionListener);
                },
                serviceCommandError =>
                {
                    if (Socket != null)
                        DisconnectFromWebApp();

                    if (connectionListener != null)
                    {
                        if (serviceCommandError == null)
                            serviceCommandError = new ServiceCommandError(0, "Unknown error connecting to web app");

                        connectionListener.OnError(serviceCommandError);
                    }
                }
            );

            if (Socket != null)
            {
                if (Socket.IsConnected())
                    MConnectionListener.OnSuccess(null);
                else
                    Socket.Connect();
            }
            else
            {
                //var uri = WebOstvServiceSocketClient.GetUri(Service);
                //Socket = new WebOstvServiceSocketClient(Service, uri);
                //Socket.Listener = mSocketListener;
                //Socket.Connect();

                var uri = WebOstvServiceSocketClient.GetUri(Service);
                if (WebOstvServiceSocketClient.SocketCache.ContainsKey(uri.ToString()))
                {
                    Socket = WebOstvServiceSocketClient.SocketCache[uri.ToString()];
                    if (mSocketListener != null)
                    {
                        Socket.Listener = mSocketListener;
                    }
                    if (Socket.IsConnected())
                        MConnectionListener.OnSuccess(null);
                    else
                    {
                        Socket.Connect();
                    }
                    //MConnectionListener.OnSuccess(null);
                }
                else
                {
                    Socket = new WebOstvServiceSocketClient(Service, uri)
                    {
                        Listener = mSocketListener
                    };
                    Socket.Connect();
                    WebOstvServiceSocketClient.SocketCache.Add(uri.ToString(), Socket);
                }
            }
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:97,代码来源:WebOsWebAppSession.cs

示例8: SendP2PMessage

        private void SendP2PMessage(Object message, ResponseListener listener)
        {
            var payload = new JsonObject();

            try
            {
                payload.Add("type", JsonValue.CreateStringValue("p2p"));
                payload.Add("to", JsonValue.CreateStringValue(GetFullAppId()));
                if (message is JsonObject)
                    //todo: check if this is the fix
                    payload.Add("payload", (message as JsonObject));
                else
                    payload.Add("payload", JsonValue.CreateStringValue(message.ToString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (IsConnected())
            {
                Socket.SendMessage(payload, null);

                if (listener != null)
                    listener.OnSuccess(null);
            }
            else
            {
                var connectListener = new ResponseListener
                (
                loadEventArg => SendP2PMessage(message, listener),
                serviceCommandError =>
                {
                    if (listener != null)
                        listener.OnError(serviceCommandError);
                }
                );

                Connect(connectListener);
            }
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:41,代码来源:WebOsWebAppSession.cs

示例9: GetPosition

        public override void GetPosition(ResponseListener listener)
        {
            var requestIdNumber = GetNextId();
            var requestId = String.Format("req{0}", requestIdNumber);

            JsonObject message = null;
            try
            {
                message = new JsonObject {{"contentType", JsonValue.CreateStringValue(NamespaceKey + "mediaCommand")}};
                var mediaCommandObject = new JsonObject
                {
                    {"type", JsonValue.CreateStringValue("getPosition")},
                    {"requestId", JsonValue.CreateStringValue(requestId)}
                };
                message.Add("mediaCommand", mediaCommandObject);
            }
            catch (Exception)
            {
                if (listener != null)
                    listener.OnError(new ServiceCommandError(0, null));
            }

            var commandResponseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    try
                    {
                        var position = ((loadEventArg as LoadEventArgs).Load.GetPayload() as JsonObject).GetNamedNumber("position");

                        if (listener != null)
                            listener.OnSuccess(position * 1000);
                    }
                    catch (Exception)
                    {
                        if (listener != null) listener.OnError(new ServiceCommandError(0, null));
                    }
                },
                serviceCommandError =>
                {
                    if (listener != null)
                        listener.OnError(serviceCommandError);
                }
            );

            var command = new ServiceCommand(null, null, null, commandResponseListener);
            mActiveCommands.TryAdd(requestId, command);

            var messageResponseListener = new ResponseListener
            (
                loadEventArg =>
                {

                },
                serviceCommandError =>
                {
                    if (listener != null)
                        listener.OnError(serviceCommandError);
                }
            );

            SendMessage(message, messageResponseListener);
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:63,代码来源:WebOsWebAppSession.cs

示例10: GetPosition

        public void GetPosition(ResponseListener listener)
        {
            var responseListener = new ResponseListener
            (
            loadEventArg =>
            {
                var s = LoadEventArgs.GetValue<string>(loadEventArg);
                var strDuration = Util.ParseData(s, "RelTime");

                var d = DateTime.ParseExact(strDuration, "HH:mm:ss", CultureInfo.InvariantCulture);
                var dmin = DateTime.ParseExact("00:00:00", "HH:mm:ss", CultureInfo.InvariantCulture);
                var longValue = d.Subtract(dmin).TotalMilliseconds;

                if (listener != null)
                {
                    listener.OnSuccess(longValue);
                }
            },
            serviceCommandError =>
            {
                if (listener != null)
                {
                    listener.OnError(serviceCommandError);
                }
            }
            );

            GetPositionInfo(responseListener);
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:29,代码来源:DlnaService.cs

示例11: GetProtocolInfo

        // ReSharper disable once UnusedMember.Local
        private void GetProtocolInfo(ResponseListener listener)
        {
            const string method = "GetProtocolInfo";
            const string instanceId = "0";

            var payload = GetMethodBody(AV_TRANSPORT_URN, instanceId, method, null);

            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    if (listener != null)
                    {
                        listener.OnSuccess(loadEventArg);
                    }
                },
                serviceCommandError =>
                {
                    if (listener != null)
                    {
                        listener.OnError(serviceCommandError);
                    }
                }
            );

            var request = new ServiceCommand(this, method, payload, responseListener);
            request.Send();
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:29,代码来源:DlnaService.cs

示例12: GetPositionInfo

        private void GetPositionInfo(ResponseListener listener)
        {
            const string method = "GetPositionInfo";
            const string instanceId = "0";

            string payload = GetMethodBody(AV_TRANSPORT_URN, instanceId, method, null);

            var responseListener = new ResponseListener
            (
            loadEventArg =>
            {
                if (listener != null)
                {
                    var s = LoadEventArgs.GetValue<string>(loadEventArg);

                    listener.OnSuccess(s);
                }
            },
            serviceCommandError =>
            {
                if (listener != null)
                    listener.OnError(serviceCommandError);
            }
            );

            var request = new ServiceCommand(this, method, payload, responseListener);
            request.Send();
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:28,代码来源:DlnaService.cs

示例13: VolumeUp

        public void VolumeUp(ResponseListener listener)
        {
            var responseListener = new ResponseListener
            (
                loadEventArg =>
                {
                    var volume = (float)loadEventArg;
                    if (volume >= 1.0)
                    {
                        if (listener != null)
                        {
                            listener.OnSuccess(loadEventArg);
                        }
                    }
                    else
                    {
                        var newVolume = (float)(volume + 0.01);

                        if (newVolume > 1.0)
                            newVolume = (float)1.0;

                        SetVolume(newVolume, listener);

                        Util.PostSuccess(listener, null);
                    }
                },
                serviceCommandError =>
                {
                    if (listener != null)
                        listener.OnError(serviceCommandError);
                }
            );

            GetVolume(responseListener);
        }
开发者ID:DmitrySigaev,项目名称:Connect-SDK-Windows,代码行数:35,代码来源:DlnaService.cs


注:本文中的ConnectSdk.Windows.Service.Capability.Listeners.ResponseListener.OnSuccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。