예제 #1
0
    public TinyHttpd Start()
    {
      this.server.Start();

      this.server.BeginAcceptTcpClient(ar =>
      {
        var client = ((TcpListener)ar.AsyncState).EndAcceptTcpClient(ar);
        var request = client.GetStream();

        var bClient = new BufferedClient(request, client.ReceiveBufferSize);
        bClient.OnRequest += message =>
        {
          if (this.OnRequest is MulticastDelegate)
          {
            var response = this.OnRequest(this.Encoding.GetString(message));
            var byteResponse = this.Encoding.GetBytes(response);
            bClient.Stream.Write(byteResponse, 0, byteResponse.Length);
          }

          if (this.OnRequestRaw is MulticastDelegate)
          {
            var responseHeadersAndMessage = this.OnRequestRaw(message);
            bClient.Stream.Write(responseHeadersAndMessage, 0, responseHeadersAndMessage.Length);
          }
        };
        bClient.StartRead();

        this.Start();
      }, this.server);

      return this;
    }
예제 #2
0
        IGeoNamesClient GetClient()
        {
            string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Path.Combine(AppContext.BaseDirectory))
                                .AddJsonFile("appsettings.json", optional: false)
                                .AddJsonFile($"appsettings.{environmentName}.json", optional: true)
                                .AddEnvironmentVariables()
                                .Build();

            var connectionString = configuration["ConnectionStrings:GeoNamesCacheStore"];
            var geoNamesUsername = configuration["AppSettings:GeoNamesUserName"];
            var client           = new BufferedClient(connectionString, geoNamesUsername);

            return(client);
        }