コード例 #1
0
        public void ToDictionary_Works()
        {
            var dict = new StartSessionRequest()
            {
                HostID     = "hostId",
                SystemBUID = "systemBuid",
            }.ToDictionary();

            Assert.Collection(
                dict,
                (k) =>
            {
                Assert.Equal("Label", k.Key);
                Assert.Equal("Kaponata.iOS", k.Value.ToObject());
            },
                (k) =>
            {
                Assert.Equal("ProtocolVersion", k.Key);
                Assert.Equal("2", k.Value.ToObject());
            },
                (k) =>
            {
                Assert.Equal("HostID", k.Key);
                Assert.Equal("hostId", k.Value.ToObject());
            },
                (k) =>
            {
                Assert.Equal("SystemBUID", k.Key);
                Assert.Equal("systemBuid", k.Value.ToObject());
            });
        }
コード例 #2
0
        /// <summary>
        /// Async factory method for constructing a new Session, creating a new session to QLDB on construction.
        /// </summary>
        ///
        /// <param name="ledgerName">The name of the ledger to create a session to.</param>
        /// <param name="sessionClient">The low-level session used for communication with QLDB.</param>
        /// <param name="logger">The logger to inject any logging framework.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>A newly created <see cref="Session"/>.</returns>
        internal static async Task <Session> StartSessionAsync(
            string ledgerName,
            IAmazonQLDBSession sessionClient,
            ILogger logger,
            CancellationToken cancellationToken)
        {
            var startSessionRequest = new StartSessionRequest
            {
                LedgerName = ledgerName,
            };
            var request = new SendCommandRequest
            {
                StartSession = startSessionRequest,
            };

            logger.LogDebug("Sending start session request: {}", request);
            var response = await sessionClient.SendCommandAsync(request, cancellationToken);

            return(new Session(
                       ledgerName,
                       sessionClient,
                       response.StartSession.SessionToken,
                       response.ResponseMetadata.RequestId,
                       logger));
        }
コード例 #3
0
        public async void StartSession()
        {
            try
            {
                var session = _applicationState.GetSession();
                if (session.GetId() == null)
                {
                    var sessionId = await CrunchyrollSessionHandler.GetSessionId();

                    session.SetId(sessionId);
                }



                var req      = new StartSessionRequest(_clientInformation, session.GetAuth(), null);
                var response = await RunSessionless(req, _clientInformation);

                var data = response.ResponseElement.Element("data");

                session.SetId(data.Element("session_id").Value);
            }
            catch (Exception exc)
            {
            }
        }
コード例 #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 {
                ModelSchemaMetadata = metaData,
                ModelSchemaId       = modelSchemaId
            };
            StartSessionResponse response = Post <StartSessionResponse>(StartSessionMethodName, request,
                                                                        DefaultTimeoutSec);

            return(response.SessionId);
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        /// Initializes Transnavi client, obtains session ID
        /// </summary>
        /// <returns></returns>
        public bool Init()
        {
            var startReq = new StartSessionRequest(_requestId);

            try
            {
                var response = (StartSessionResponse)GetResponse(startReq, typeof(StartSessionResponse));
                _sessionId     = response.Result.SessionId;
                _isInitialized = true;
            }
            catch (Exception)
            {
                _isInitialized = false;
                throw;
            }
            return(_isInitialized);
        }
コード例 #7
0
        public CommonApiResponse Start([FromBody] StartSessionRequest request, [FromServices] SessionManagerService sessionManager)
        {
            var merchant = (Merchant)HttpContext.Items["Merchant"];

            var session = sessionManager.Create(merchant, new SessionCreateRequest
            {
                Amount           = request.Amount,
                Currency         = request.Currency,
                FormKey          = request.FormKey,
                FormLanguage     = request.FormLanguage,
                OrderDescription = request.OrderDescription,
                OrderId          = request.OrderId,
                SessionType      = request.SessionType
            });

            return(new StartSessionResponse {
                SessionId = session.ExternalId
            });
        }
コード例 #8
0
ファイル: Session.cs プロジェクト: R-maan/workflow
        /// <summary>
        /// Factory method for constructing a new Session, creating a new session to QLDB on construction.
        /// </summary>
        ///
        /// <param name="ledgerName">The name of the ledger to create a session to.</param>
        /// <param name="sessionClient">The low-level session used for communication with QLDB.</param>
        /// <param name="logger">The logger to inject any logging framework.</param>
        ///
        /// <returns>A newly created <see cref="Session"/>.</returns>
        internal static Session StartSession(string ledgerName, AmazonQLDBSessionClient sessionClient, ILogger logger)
        {
            var startSessionRequest = new StartSessionRequest
            {
                LedgerName = ledgerName,
            };
            var request = new SendCommandRequest
            {
                StartSession = startSessionRequest,
            };

            logger.LogDebug("Sending start session request: {}", request);
            var response = sessionClient.SendCommandAsync(request).GetAwaiter().GetResult();

            return(new Session(
                       ledgerName,
                       sessionClient,
                       response.StartSession.SessionToken,
                       response.ResponseMetadata.RequestId,
                       logger));
        }
コード例 #9
0
ファイル: SessionRegistry.cs プロジェクト: Kaioru/Edelstein
        public async Task <StartSessionResponse> Start(StartSessionRequest request)
        {
            var source = new CancellationTokenSource();
            var result = SessionRegistryResult.Ok;

            source.CancelAfter(SessionLockTimeoutDuration);

            var session = request.Session;
            var @lock   = await _locker.AcquireAsync(session.Account.ToString(), cancellationToken : source.Token);

            if (@lock != null)
            {
                var timeout = DateTime.UtcNow.Add(SessionTimeoutDuration);

                if (await _sessionAccountCache.ExistsAsync(request.Session.Account.ToString()))
                {
                    result = SessionRegistryResult.FailedAlreadyStarted;
                }

                if (result == SessionRegistryResult.Ok)
                {
                    await _sessionAccountCache.SetAsync(session.Account.ToString(), session, timeout);

                    if (session.Character.HasValue)
                    {
                        await _sessionCharacterCache.SetAsync(session.Character.Value.ToString(), session, timeout);
                    }
                }

                await @lock.ReleaseAsync();
            }
            else
            {
                result = SessionRegistryResult.FailedTimeout;
            }

            return(new StartSessionResponse {
                Result = result
            });
        }
コード例 #10
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());
        }
コード例 #11
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());
        }
コード例 #12
0
        private void ClientProc()
        {
            var address = "net.tcp://" + ServerAddr + "/RemoteDesktop";

            try
            {
                var uri = new Uri(address);
                //NetTcpSecurity security = new NetTcpSecurity
                //{
                //    Mode = SecurityMode.Transport,
                //    Transport = new TcpTransportSecurity
                //    {
                //        ClientCredentialType = TcpClientCredentialType.Windows,
                //        ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign,
                //    },
                //};

                NetTcpSecurity security = new NetTcpSecurity
                {
                    Mode = SecurityMode.None,
                };

                var binding = new NetTcpBinding
                {
                    ReceiveTimeout = TimeSpan.MaxValue,//TimeSpan.FromSeconds(10),
                    SendTimeout    = TimeSpan.FromSeconds(10),
                    Security       = security,
                };


                factory = new ChannelFactory <IRemoteDesktopService>(binding, new EndpointAddress(uri));
                var channel = factory.CreateChannel();

                try
                {
                    this.ClientId = RngProvider.GetRandomNumber().ToString();

                    var connectReq = new RemoteDesktopRequest
                    {
                        SenderId = ClientId,
                    };

                    var connectionResponse = channel.Connect(connectReq);
                    if (!connectionResponse.IsSuccess)
                    {
                        logger.Error("connectionResponse " + connectionResponse.FaultCode);
                        return;
                    }

                    this.ServerId   = connectionResponse.ServerId;
                    this.ServerName = connectionResponse.HostName;

                    var screens       = connectionResponse.Screens;
                    var primaryScreen = screens.FirstOrDefault(s => s.IsPrimary);

                    var startRequest = new StartSessionRequest
                    {
                        SenderId = this.ClientId,

                        SrcRect              = primaryScreen.Bounds,
                        DestAddr             = "", //"192.168.1.135",//localAddr.Address.ToString(), //localAddr.ToString(),
                        DestPort             = 1234,
                        DstSize              = new Size(1920, 1080),
                        EnableInputSimulator = true,
                    };


                    var startResponse = channel.Start(startRequest);
                    if (!startResponse.IsSuccess)
                    {
                        logger.Error("startResponse " + startResponse.FaultCode);
                        return;
                    }

                    var inputPars = new VideoEncoderSettings
                    {
                        Resolution = startRequest.DstSize,
                        //Width = startRequest.DstSize.Width,
                        //Height = startRequest.DstSize.Height,

                        //Width = 640,//2560,
                        //Height = 480,//1440,
                        FrameRate = 30,
                    };

                    var outputPars = new VideoEncoderSettings
                    {
                        //Width = 640,//2560,
                        //Height = 480,//1440,
                        //Width = startRequest.DstSize.Width,
                        //Height = startRequest.DstSize.Height,

                        Resolution = startRequest.DstSize,
                        FrameRate  = 30,
                    };
                    var transport = TransportMode.Udp;

                    var networkPars = new NetworkSettings
                    {
                        LocalAddr     = ServerAddr,
                        LocalPort     = 1234,
                        TransportMode = transport,
                    };

                    this.Play(inputPars, outputPars, networkPars);

                    InputManager = new InputManager();

                    InputManager.Start(ServerAddr, 8888);
                    running = true;

                    State = ClientState.Connected;

                    OnStateChanged(State);

                    while (running)
                    {
                        channel.PostMessage("Ping", null);


                        syncEvent.WaitOne(1000);

                        //InternalCommand command = null;
                        //do
                        //{
                        //    command = DequeueCommand();
                        //    if (command != null)
                        //    {
                        //        ProcessCommand(command);
                        //    }

                        //} while (command != null);
                    }
                }
                finally
                {
                    running = false;

                    State = ClientState.Disconnected;
                    OnStateChanged(State);

                    try
                    {
                        var c = (IClientChannel)channel;
                        if (c.State != CommunicationState.Faulted)
                        {
                            c.Close();
                        }
                        else
                        {
                            c.Abort();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);


                State = ClientState.Faulted;
                OnStateChanged(State);

                Close();
            }
        }