Skip to content

Instantly share code, notes, and snippets.

@ayende
Created February 6, 2016 21:50
Show Gist options
  • Save ayende/989682910c8312629473 to your computer and use it in GitHub Desktop.
Save ayende/989682910c8312629473 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Raven.Server
{
public class Program
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
app.Run(async context =>
{
await
context.Response.WriteAsync(
$"'{context.Request.Method}' '{context.Request.Path}' '{context.Request.QueryString}'");
});
}
public static int Main(string[] args)
{
var configBuilder = new ConfigurationBuilder()
.Add(new MemoryConfigurationProvider(new Dictionary<string, string>
{
["server.urls"] = "http://localhost:8080"
}));
if (args != null)
{
configBuilder.AddCommandLine(args);
}
var config = configBuilder.Build();
IHostingEngine application = new WebHostBuilder(config)
.UseStartup<Program>()
.UseServer("Microsoft.AspNet.Server.Kestrel")
.Build();
IApplication app = null;
try
{
app = application.Start();
Console.WriteLine("Server started, listening to requests...");
Console.WriteLine();
var httpClient = new HttpClient();
var msg = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/replication/topology");
Console.WriteLine(httpClient.SendAsync(msg).Result.Content.ReadAsStringAsync().Result);
msg = new HttpRequestMessage(HttpMethod.Put, "http://localhost:8080/admin/databases/CanSaveAndLoad")
{
Headers = { TransferEncodingChunked = true },
Content = new ByteArrayContent(new byte[146]),
};
Console.WriteLine(httpClient.SendAsync(msg).Result.Content.ReadAsStringAsync().Result);
msg = new HttpRequestMessage(HttpMethod.Get,
"http://localhost:8080/databases/CanSaveAndLoad/docs?&id=Raven%2FHilo%2Fusers&id=Raven%2FServerPrefixForHilo");
Console.WriteLine(httpClient.SendAsync(msg).Result.Content.ReadAsStringAsync().Result);
return 0;
}
finally
{
app?.Dispose();
}
}
}
}
{
"version": "4.0.0-*",
"description": "Raven.Server is the database server for RavenDB",
"authors": [ "Hibernating Rhinos" ],
"tags": [ "database", "nosql", "doc db" ],
"projectUrl": "https://ravendb.net",
"compile": [ "**/*.cs", "../CommonAssemblyInfo.cs" ],
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
},
"commands": {
"ConsoleApp7": "ConsoleApp7"
},
"frameworks": {
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"System.Net.Http": "4.0.1-beta-23516",
"System.Net.Http.WinHttpHandler": "4.0.0-beta-23516",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment