Beispiel #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var host = hostTextBox.Text;
            var port = Convert.ToInt32(hostPortTextBox.Text);

            var connection = new Connection() {HostName = host, Port = port};
            //httpClient.
        }
        public ConnectionViewModel(Connection connection)
            : base()
        {
            this.connection = connection;
            this.Packets = new ObservableCollection<Packet>();

            BindingOperations.EnableCollectionSynchronization(Packets, packetsLock);
        }
        public async Task<ConnectionCreated> Create(CreateConnectionCommand createConnection)
        {
            IDiceConnectionFactory connectionFactory = new DiceConnectionFactory();

            try
            {
                var game = await GamesContext.GetInstance().GetAsync(createConnection.GameId);
                if (game != null)
                {
                    var gameConnection = await game.ConnectionFactory.CreateAsync(new GameConnectionInfo() { HostName = createConnection.HostName, Port = createConnection.Port });
                    var hostedConnection = new HostedConnection(createConnection.HostName, createConnection.Port, gameConnection);
                    gameConnection.GameDataReceived += (sender, e) =>
                    {
                        MessageHubProxy.Invoke("SendMessage", hostedConnection.Id, e.GameData.DataString);
                    };
                    this.ConnectionHost.Add(hostedConnection);
                    var connection = new Connection()
                    {
                        Id = hostedConnection.Id,
                        HostName = createConnection.HostName,
                        Port = createConnection.Port
                    };
                    return new ConnectionCreated(hostedConnection.Id, connection);
                }

                var responseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent(string.Format("Game with id '{0}' was not found.", createConnection.GameId)),
                };
                throw new HttpResponseException(responseMessage);
            }
            catch (Exception ex)
            {
                var responseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                                          {
                                              Content = new StringContent(ex.Message),
                                          };
                throw new HttpResponseException(responseMessage);
            }
        }
Beispiel #4
0
 public ConnectionCreated(Guid id, Connection connection)
 {
     this.ConnectionId = id;
     this.Connection = connection;
     this.Created = DateTime.UtcNow;
 }