Example #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            StartSessionResponse response = new StartSessionResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("SessionId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.SessionId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StreamUrl", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.StreamUrl = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TokenValue", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.TokenValue = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #2
0
        /// <summary>
        /// Asynchronously starts a service on the device, and returns a <see cref="Stream"/> which represents a connection
        /// to the remote service.
        /// </summary>
        /// <param name="serviceName">
        /// The name of the lockdown service to start.
        /// </param>
        /// <param name="startSession">
        /// A value indicating whether to start a session before starting the service. This is required for most services;
        /// with some exceptions (such as the unsecured notification service).
        /// </param>
        /// <param name="cancellationToken">
        /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the asynchronous operation. This task returns a <see cref="Stream"/>
        /// which represents a connection to the remote service when completed.
        /// </returns>
        protected async Task <PropertyListProtocol> StartServiceAsync(string serviceName, bool startSession, CancellationToken cancellationToken)
        {
            ServiceDescriptor service;

            await using (var lockdown = await this.factory.CreateAsync(cancellationToken))
            {
                StartSessionResponse session = null;

                if (startSession)
                {
                    session = await lockdown.StartSessionAsync(this.Context.PairingRecord, cancellationToken).ConfigureAwait(false);
                }

                service = await lockdown.StartServiceAsync(serviceName, cancellationToken).ConfigureAwait(false);

                if (session != null)
                {
                    await lockdown.StopSessionAsync(session.SessionID, cancellationToken).ConfigureAwait(false);
                }
            }

            var serviceStream = await this.Muxer.ConnectAsync(this.Context.Device, service.Port, cancellationToken);

            var protocol = this.propertyListProtocolFactory.Create(serviceStream, ownsStream: true, this.Logger);

            if (service.EnableServiceSSL)
            {
                await protocol.EnableSslAsync(this.Context.PairingRecord, cancellationToken).ConfigureAwait(false);
            }

            return(protocol);
        }
Example #3
0
        /// <summary>
        /// Starts new train session.
        /// </summary>
        /// <param name="metaData">Meta data of the model's input and output.</param>
        /// <param name="modelSchemaId">ML model schema identifier.</param>
        /// <returns>
        /// The identifier of the started session.
        /// </returns>
        public Guid StartTrainSession(string metaData, Guid modelSchemaId)
        {
            var request = new StartSessionRequest {
                ModelSchemaMetadata = metaData,
                ModelSchemaId       = modelSchemaId
            };
            StartSessionResponse response = Post <StartSessionResponse>(StartSessionMethodName, request,
                                                                        DefaultTimeoutSec);

            return(response.SessionId);
        }
Example #4
0
        /// <summary>
        /// Starts new train session.
        /// </summary>
        /// <param name="metaData">Meta data of the model's input and output.</param>
        /// <param name="modelSchemaId">ML model schema identifier.</param>
        /// <returns>
        /// The identifier of the started session.
        /// </returns>
        public Guid StartTrainSession(string metaData, Guid modelSchemaId)
        {
            var request = new StartSessionRequest {
                ApiKey = _apiKey,                 // TODO 7.14.1 | Remove api key from request's body
                ModelSchemaMetadata = metaData,
                ModelSchemaId       = modelSchemaId
            };
            StartSessionResponse response = Post <StartSessionResponse>(StartSessionMethodName, request,
                                                                        DefaultTimeoutSec);

            return(response.SessionId);
        }
Example #5
0
        public void FromDictionary_WithError_Works()
        {
            var dict = new NSDictionary();

            dict.Add("Request", "StartSession");
            dict.Add("Error", "SessionInactive");

            var response = new StartSessionResponse();

            response.FromDictionary(dict);

            Assert.Equal("StartSession", response.Request);
            Assert.Equal(LockdownError.SessionInactive, response.Error);
        }
Example #6
0
        public void FromDictionary_Works()
        {
            var dict = new NSDictionary();

            dict.Add("Request", "StartSession");
            dict.Add("SessionID", "abc");

            var response = new StartSessionResponse();

            response.FromDictionary(dict);

            Assert.Equal("StartSession", response.Request);
            Assert.False(response.EnableSessionSSL);
            Assert.Equal("abc", response.SessionID);
            Assert.Null(response.Error);
        }
Example #7
0
        public async Task CreateAsync_Works_Async()
        {
            var pairingRecord   = new PairingRecord();
            var sessionResponse = new StartSessionResponse()
            {
                SessionID = "1234"
            };
            var lockdownClientFactory = new Mock <LockdownClientFactory>(MockBehavior.Strict);
            var muxerClient           = new Mock <MuxerClient>(MockBehavior.Strict);
            var context = new DeviceContext()
            {
                Device = new MuxerDevice(), PairingRecord = pairingRecord
            };

            var lockdownClient = new Mock <LockdownClient>(MockBehavior.Strict);

            lockdownClientFactory
            .Setup(l => l.CreateAsync(default))
Example #8
0
        public async Task <IActionResult> StartASession([FromBody] StartSessionRequest request)
        {
            Guid lobbyId = playerRegistry.GetLobbyIdByPlayerId(request.PlayerId);

            List <ServerSidePlayerOverview> players = playerRegistry.GetAllPlayersInLobby(request.PlayerId);

            StartSessionResponse response = new StartSessionResponse
            {
                Players   = players,
                SessionId = lobbyId,                              //shortcut
                Questions = new List <ServerSideQuestionOverview> //shortcuts
                {
                    new ServerSideQuestionOverview {
                        Text = "What number is NOT a Fibonacci number", Options = new List <String> {
                            "1", "2", "8", "20"
                        }, CorrectOptionIndex = 3, Value = 1000,
                    },
                    new ServerSideQuestionOverview {
                        Text = "What was the name of the supernatural computer in »The hitchhiker's guide to the galaxy«", Options = new List <String> {
                            "Who cares", "Think deep", "Deep Thought", "42"
                        }, CorrectOptionIndex = 2, Value = 2000,
                    },
                    new ServerSideQuestionOverview {
                        Text = "According to Scott Pilgrim, how many vegan law violations can you commit without losing your vegan superpowers?", Options = new List <String> {
                            "4", "3", "2", "1"
                        }, CorrectOptionIndex = 1, Value = 3000,
                    },
                    new ServerSideQuestionOverview {
                        Text = "You know what? (F is for Familiy)", Options = new List <String> {
                            "You know what?", "You know what? You know what?", "You know what? You know what? You know what? ", "You know what? You know what? You know what? You know what?"
                        }, CorrectOptionIndex = 1, Value = 4000,
                    },
                }
            };

            await lobbyHubContext.Clients.Group(lobbyId.ToString()).StartSession(response);

            return(base.NoContent());
        }
Example #9
0
        public async Task <IActionResult> StartSession(StartSessionRequest reqeust)
        {
            IEnumerable <PlayerServerSide> playerInLobby = playerRegistry.GetPlayersInLobby(reqeust.PlayerId);

            List <QuestionResponse> question = new List <QuestionResponse>
            {
                new QuestionResponse {
                    Text = "What number is NOT a Fibonacci number", Options = new List <String> {
                        "1", "2", "8", "20"
                    }, CorrectOptionIndex = 3, Value = 1000,
                },
                new QuestionResponse {
                    Text = "What was the name of the supernatural computer in »The hitchhiker's guide to the galaxy«", Options = new List <String> {
                        "Who cares", "Think deep", "Deep Thought", "42"
                    }, CorrectOptionIndex = 2, Value = 2000,
                },
                new QuestionResponse {
                    Text = "According to Scott Pilgrim, how many vegan law violations can you commit without losing your vegan superpowers?", Options = new List <String> {
                        "4", "3", "2", "1"
                    }, CorrectOptionIndex = 1, Value = 3000,
                },
                new QuestionResponse {
                    Text = "You know what? (F is for Familiy)", Options = new List <String> {
                        "You know what?", "You know what? You know what?", "You know what? You know what? You know what? ", "You know what? You know what? You know what? You know what?"
                    }, CorrectOptionIndex = 1, Value = 4000,
                },
            };

            StartSessionResponse response = new StartSessionResponse
            {
                PlayerInSession = playerInLobby.Select(x => GetPlayerOverview(x)).ToList(),
                Questions       = question
            };

            await lobbyHubContext.Clients.Group(reqeust.LobbyId.ToString()).StartSession(response);

            return(base.NoContent());
        }
Example #10
0
        public void FromDictionary_ValidatesArguments()
        {
            var response = new StartSessionResponse();

            Assert.Throws <ArgumentNullException>(() => response.FromDictionary(null));
        }