Exemplo n.º 1
0
        public async stt::Task CallFunctionResourceNamesAsync()
        {
            moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient> mockGrpcClient = new moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            CallFunctionRequest request = new CallFunctionRequest
            {
                CloudFunctionName = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
                Data = "data387f778d",
            };
            CallFunctionResponse expectedResponse = new CallFunctionResponse
            {
                ExecutionId = "execution_id7e78fb21",
                Result      = "result1784a8b4",
                Error       = "error0e105ecb",
            };

            mockGrpcClient.Setup(x => x.CallFunctionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <CallFunctionResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CloudFunctionsServiceClient client = new CloudFunctionsServiceClientImpl(mockGrpcClient.Object, null);
            CallFunctionResponse        responseCallSettings = await client.CallFunctionAsync(request.CloudFunctionName, request.Data, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            CallFunctionResponse responseCancellationToken = await client.CallFunctionAsync(request.CloudFunctionName, request.Data, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 2
0
 /// <summary>Snippet for CallFunction</summary>
 public void CallFunctionResourceNames()
 {
     // Snippet: CallFunction(CloudFunctionName, string, CallSettings)
     // Create client
     CloudFunctionsServiceClient cloudFunctionsServiceClient = CloudFunctionsServiceClient.Create();
     // Initialize request argument(s)
     CloudFunctionName name = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]");
     string            data = "";
     // Make the request
     CallFunctionResponse response = cloudFunctionsServiceClient.CallFunction(name, data);
     // End snippet
 }
Exemplo n.º 3
0
 /// <summary>Snippet for CallFunction</summary>
 public void CallFunction()
 {
     // Snippet: CallFunction(string, string, CallSettings)
     // Create client
     CloudFunctionsServiceClient cloudFunctionsServiceClient = CloudFunctionsServiceClient.Create();
     // Initialize request argument(s)
     string name = "projects/[PROJECT]/locations/[LOCATION]/functions/[FUNCTION]";
     string data = "";
     // Make the request
     CallFunctionResponse response = cloudFunctionsServiceClient.CallFunction(name, data);
     // End snippet
 }
Exemplo n.º 4
0
        /// <summary>Snippet for CallFunctionAsync</summary>
        public async Task CallFunctionResourceNamesAsync()
        {
            // Snippet: CallFunctionAsync(CloudFunctionName, string, CallSettings)
            // Additional: CallFunctionAsync(CloudFunctionName, string, CancellationToken)
            // Create client
            CloudFunctionsServiceClient cloudFunctionsServiceClient = await CloudFunctionsServiceClient.CreateAsync();

            // Initialize request argument(s)
            CloudFunctionName name = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]");
            string            data = "";
            // Make the request
            CallFunctionResponse response = await cloudFunctionsServiceClient.CallFunctionAsync(name, data);

            // End snippet
        }
Exemplo n.º 5
0
        /// <summary>Snippet for CallFunctionAsync</summary>
        public async Task CallFunctionAsync()
        {
            // Snippet: CallFunctionAsync(string, string, CallSettings)
            // Additional: CallFunctionAsync(string, string, CancellationToken)
            // Create client
            CloudFunctionsServiceClient cloudFunctionsServiceClient = await CloudFunctionsServiceClient.CreateAsync();

            // Initialize request argument(s)
            string name = "projects/[PROJECT]/locations/[LOCATION]/functions/[FUNCTION]";
            string data = "";
            // Make the request
            CallFunctionResponse response = await cloudFunctionsServiceClient.CallFunctionAsync(name, data);

            // End snippet
        }
Exemplo n.º 6
0
 /// <summary>Snippet for CallFunction</summary>
 public void CallFunctionRequestObject()
 {
     // Snippet: CallFunction(CallFunctionRequest, CallSettings)
     // Create client
     CloudFunctionsServiceClient cloudFunctionsServiceClient = CloudFunctionsServiceClient.Create();
     // Initialize request argument(s)
     CallFunctionRequest request = new CallFunctionRequest
     {
         CloudFunctionName = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
         Data = "",
     };
     // Make the request
     CallFunctionResponse response = cloudFunctionsServiceClient.CallFunction(request);
     // End snippet
 }
Exemplo n.º 7
0
        /// <summary>Snippet for CallFunctionAsync</summary>
        public async Task CallFunctionRequestObjectAsync()
        {
            // Snippet: CallFunctionAsync(CallFunctionRequest, CallSettings)
            // Additional: CallFunctionAsync(CallFunctionRequest, CancellationToken)
            // Create client
            CloudFunctionsServiceClient cloudFunctionsServiceClient = await CloudFunctionsServiceClient.CreateAsync();

            // Initialize request argument(s)
            CallFunctionRequest request = new CallFunctionRequest
            {
                CloudFunctionName = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
                Data = "",
            };
            // Make the request
            CallFunctionResponse response = await cloudFunctionsServiceClient.CallFunctionAsync(request);

            // End snippet
        }
Exemplo n.º 8
0
        public void CallFunctionResourceNames()
        {
            moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient> mockGrpcClient = new moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            CallFunctionRequest request = new CallFunctionRequest
            {
                CloudFunctionName = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
                Data = "data387f778d",
            };
            CallFunctionResponse expectedResponse = new CallFunctionResponse
            {
                ExecutionId = "execution_id7e78fb21",
                Result      = "result1784a8b4",
                Error       = "error0e105ecb",
            };

            mockGrpcClient.Setup(x => x.CallFunction(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CloudFunctionsServiceClient client   = new CloudFunctionsServiceClientImpl(mockGrpcClient.Object, null);
            CallFunctionResponse        response = client.CallFunction(request.CloudFunctionName, request.Data);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 9
0
        // Handling incoming messages
        private void Ws_OnMessage(object sender, MessageEventArgs e)
        {
            if (e.Data != String.Empty)
            {
                string msg = "<empty message>";

                // Response for handshake
                if (e.Data.Contains("register_0"))
                {
                    RegisterResponse rr = JsonConvert.DeserializeObject <RegisterResponse>(e.Data);
                    msg = "Handshake successful." + Environment.NewLine + rr.ToString();

                    SubscribeWebsocketEvents();
                }
                else if (e.Data.Contains("newPair"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);

                    if (cfr.Payload.ReturnValue && cfr.Type == "response")
                    {
                        msg = "Pairing request acknowledged.";
                    }
                    else if (!cfr.Payload.ReturnValue && cfr.Type == "response")
                    {
                        msg = "Pairing request unsuccessful.";
                    }
                    else if (cfr.Type == "registered")
                    {
                        RegisterResponse rr = JsonConvert.DeserializeObject <RegisterResponse>(e.Data);

                        if (String.IsNullOrEmpty(selectedDevice.ApiKey))
                        {
                            selectedDevice.ApiKey = rr.Payload.client_key;
                        }

                        SaveDeviceList();
                        SubscribeWebsocketEvents();
                    }
                }
                // Response for audio status request
                else if (e.Data.Contains("volume_sub"))
                {
                    AudioStatusResponse asr = JsonConvert.DeserializeObject <AudioStatusResponse>(e.Data);
                    msg = "Audio status received." + Environment.NewLine + asr.ToString();

                    // Displaying the volume level
                    string txt = asr.Payload.Volume + "/" + asr.Payload.VolumeMax;

                    btVol.Invoke(new Action(() => { btVol.Text = txt; }));

                    // Setting the speaker icon on mute button
                    if (asr.Payload.Mute)
                    {
                        btnMute.Invoke(new Action(() => { btnMute.Image = Resources.Speaker_off; }));
                        Global._isMuted = true;
                    }
                    else
                    {
                        btnMute.Invoke(new Action(() => { btnMute.Image = Resources.Speaker_on; }));
                        Global._isMuted = false;
                    }
                }
                // Response for volume up request
                else if (e.Data.Contains("volumeup_1"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);

                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Volume up acknowledged.";
                    }
                    else
                    {
                        msg = "Volume up request rejected.";
                    }
                }
                // Response for volume down request
                else if (e.Data.Contains("volumedown_1"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Volume down acknowledged.";
                    }
                    else
                    {
                        msg = "Volume down request rejected.";
                    }
                }
                // Response for toggle mute request
                else if (e.Data.Contains("toggle_mute"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Toggle mute acknowledged.";
                    }
                    else
                    {
                        msg = "Toggle mute request rejected.";
                    }
                }
                // Response for current channel info request
                else if (e.Data.Contains("channel_sub"))
                {
                    ci = JsonConvert.DeserializeObject <ChannelInfo>(e.Data);

                    // Displaying the current channel
                    string chan = String.Format("({0}) {1}", ci.Payload.ChannelNumber, ci.Payload.ChannelName);
                    btVol.Invoke(new Action(() => { btChan.Text = chan; }));
                    msg = "Current channel info arrived.";
                }
                // Response for channel up/down request
                else if (e.Data.Contains("channelup_1") || e.Data.Contains("channeldown_1"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        GetCurrentChannel();
                        msg = cfr.Id == "channelup_1" ? "Channel up success." : "Channel down success.";
                    }
                }
                // Response for get channels list request
                else if (e.Data.Contains("getchannels_1"))
                {
                    clr = JsonConvert.DeserializeObject <ChannelListResponse>(e.Data);

                    if (clr.Payload.ReturnValue == true)
                    {
                        // Opening the channel list window
                        chWindow = new ChannelListWindow
                        {
                            channels = clr.Payload.ChannelList
                        };
                        chWindow.ci = ci;
                        chWindow.ShowDialog();
                        msg = "Channel list request succeeded.";
                    }
                    else
                    {
                        msg = "Channel list request unsuccessful.";
                    }
                }
                else if (e.Data.Contains("get_inputlist"))
                {
                    if (e.Data.Contains("\"returnValue\":true"))
                    {
                        Input response = new Input();
                        response = JsonConvert.DeserializeObject <Input>(e.Data);

                        inputWindow = new InputListWindow
                        {
                            InputList = response.Payload.Devices
                        };
                        inputWindow.ShowDialog();
                    }
                }
                // Response for displaying toast message on the screen request
                else if (e.Data.Contains("toast_1"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Toast message request succeeded.";
                    }
                    else
                    {
                        msg = "Toast message request rejected.";
                    }
                }
                else if (e.Data.Contains("openchannel_1"))
                {
                    // Missing response from WebOs!!!
                    //CallFunctionResponse cfr = JsonConvert.DeserializeObject<CallFunctionResponse>(e.Data);
                    //if (cfr.Payload.returnValue)
                    //{
                    //    msg = "Open channel request succeeded.";
                    //}
                    //else
                    //{
                    //    msg = "Open channel request rejected.";
                    //}
                }
                else if (e.Data.Contains("youtube_open"))
                {
                    AppSession.LaunchAppResponse yr = JsonConvert.DeserializeObject <AppSession.LaunchAppResponse>(e.Data);
                    if (yr.Payload.ReturnValue)
                    {
                        msg = "Youtube open video request succeeded.";
                        (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).ClearUrlField();
                        (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).sessionId = yr.Payload.SessionId;
                        appSession.SessionId = yr.Payload.SessionId;
                    }
                    else
                    {
                        msg = "Youtube open video request rejected.";
                    }
                }
                else if (e.Data.Contains("youtube_close"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);

                    if (cfr.Payload.ReturnValue == true)
                    {
                        msg = "Youtube app close request succeeded.";
                        youtubeWindow.Invoke(new Action(() => { youtubeWindow.Close(); }));
                        youtubeWindow = null;
                    }
                    else
                    {
                        msg = "Youtube app close request rejected." + Environment.NewLine + e.Data;
                    }
                }
                else if (e.Data.Contains("ForeGroundAppInfo"))
                {
                    AppSession.AppInfoResponse yr = JsonConvert.DeserializeObject <AppSession.AppInfoResponse>(e.Data);
                    if (yr.Payload.ReturnValue)
                    {
                        msg = "Foreground app info request succeeded.";
                        switch (yr.Payload.AppId)
                        {
                        case "youtube.leanback.v4":
                            (Application.OpenForms["YoutubeWindow"] as YoutubeWindow).youtubeInfo = yr;
                            break;

                        case "com.webos.app.livetv":
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        msg = "Foreground app info request rejected.";
                    }
                }
                else if (e.Data.Contains("play_01"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Play button request succeeded.";
                    }
                    else
                    {
                        msg = "Play button request rejected.";
                    }
                }
                else if (e.Data.Contains("pause"))
                {
                    CallFunctionResponse cfr = JsonConvert.DeserializeObject <CallFunctionResponse>(e.Data);
                    if (cfr.Payload.ReturnValue)
                    {
                        msg = "Pause button request succeeded.";
                    }
                    else
                    {
                        msg = "Pause button request rejected.";
                    }
                }
                else if (e.Data.Contains("getchannelprograminfo_1"))
                {
                    channelProgramInfo = JsonConvert.DeserializeObject <ChannelProgramInfo>(e.Data);

                    if (channelProgramInfo.Payload.ReturnValue)
                    {
                        // Opening the program info list window
                        progInfoWindow = new ProgramInfoWindow
                        {
                            ChanProginfo = channelProgramInfo
                        };
                        progInfoWindow.ShowDialog();

                        msg = "Channel program info request succeeded.";
                    }
                    else
                    {
                        msg = "Channel program info request rejected.";
                    }
                }
                else
                {
                    msg = e.Data;
                }

                DisplayMessage(msg);
            }
        }