Example #1
0
        public void ConfigureServer(IRestServer server)
        {
            server.Prefixes.Add($"http://localhost:{_serverPort}/");

            /* Configure Router Options (if supported by your router implementation) */
            server.Router.Options.SendExceptionMessages = true;
        }
Example #2
0
 /// <summary>
 /// Applies the global headers to the provided response header collection.
 /// </summary>
 /// <param name="server"></param>
 /// <param name="headers"></param>
 public static void ApplyGlobalResponseHeaders(this IRestServer server, WebHeaderCollection headers)
 {
     foreach (var header in server.GlobalResponseHeaders.Where(g => !g.Suppress))
     {
         headers.Add(header.Name, header.Value);
     }
 }
Example #3
0
 internal HttpContext(HttpListenerContext context, IRestServer server)
 {
     Request  = new HttpRequest(context.Request);
     Response = new HttpResponse(context.Response, context.Request.Headers);
     User     = context.User;
     Server   = server;
 }
Example #4
0
 /// <summary>
 /// Starts the server and blocks the calling thread until the server stops listening
 /// </summary>
 public static void Run(this IRestServer server)
 {
     server.Start();
     while (server.IsListening)
     {
     }
 }
Example #5
0
        public static void Start()
        {
            if (restServer != null && restServer.IsListening)
            {
                return;
            }

            try
            {
                restServer = RestServerBuilder.From <Startup>().Build();
                //restServer = RestServerBuilder.UseDefaults().Build();

                //Urls = restServer.Prefixes.ToList();

                restServer.AfterStarting += (s) =>
                {
                    Process.Start("explorer", s.Prefixes.First());
                };

                restServer.AfterStopping += (s) =>
                {
                    Console.WriteLine("Web-Server beendet.");
                };

                //Urls = restServer.Prefixes.ToList();
                restServer.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        public static IRestServer UseCorrelationId(this IRestServer server, string correlationIdFieldName, Func <string> correlactionIdGenerator)
        {
            var mw = new CorrelationId(correlationIdFieldName, correlactionIdGenerator);

            server.OnRequestAsync += mw.EnsureCorrelationIdAsync;
            return(server);
        }
Example #7
0
        public void CloneEventHandlers(IRestServer server)
        {
            if (BeforeStarting != null)
            {
                foreach (var action in BeforeStarting.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.BeforeStarting += action;
                }
            }

            if (AfterStarting != null)
            {
                foreach (var action in AfterStarting.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.AfterStarting += action;
                }
            }

            if (BeforeStopping != null)
            {
                foreach (var action in BeforeStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.BeforeStopping += action;
                }
            }

            if (AfterStopping != null)
            {
                foreach (var action in AfterStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>())
                {
                    server.AfterStopping += action;
                }
            }
        }
Example #8
0
 /// <summary>
 /// Adds a server to the cluster
 /// </summary>
 public void Add(string label, IRestServer server)
 {
     if (_started)
     {
         server.Start();
     }
     _servers.Add(label, server);
 }
Example #9
0
 /// <summary>
 /// Adds a server to the cluster
 /// </summary>
 public void Add(string label, IRestServer server)
 {
     Servers.Add(label, server);
     if (Started)
     {
         OnBeforeStartEach?.Invoke(server);
         server.Start();
         OnAfterStartEach?.Invoke(server);
     }
 }
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            MainKernel.Load<MainModule>();
            MainKernel.Load<QueueItemModule>();
            MainKernel.Load<ClientModule>();

            _restServer = MainKernel.Get<IRestServer>();
            _restServer.Start();

            DisplayRootViewFor<IMainViewModel>();
        }
Example #11
0
        public void ConfigureServer(IRestServer server)
        {
            // The path to your static content
            var folderPath = Path.Combine(Directory.GetCurrentDirectory(), "website");

            // The following line is shorthand for:
            //     server.ContentFolders.Add(new ContentFolder(folderPath));
            server.ContentFolders.Add(folderPath);
            server.UseContentFolders();

            server.Prefixes.Add($"http://localhost:{_serverPort}/");

            /* Configure Router Options (if supported by your router implementation) */
            server.Router.Options.SendExceptionMessages = true;
        }
 public MainApplication(IConfigurationService configurationService,
                        IRecordService recordService,
                        IPlaybackService playbackService,
                        IRestServer restServer,
                        IRestRouter[] routers,
                        IStreamingServer streamingServer,
                        IQueryService[] queryServices)
 {
     _startMode       = configurationService.GetConfiguration().StartMode;
     _recordService   = recordService;
     _playbackService = playbackService;
     _streamingServer = streamingServer;
     _restServer      = restServer;
     _restRouters     = routers;
     _queryServices   = queryServices;
     _currentMode     = ApplicationMode.Waiting;
 }
Example #13
0
        internal HttpContext(HttpListenerContext context, IRestServer server, CancellationToken token)
        {
            Advanced          = context;
            Server            = server;
            CancellationToken = token;

            // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
            var acceptEncoding    = context.Request.Headers.GetValue <string>("Accept-Encoding", string.Empty);
            var identityForbidden = (acceptEncoding.Contains("identity;q=0") || acceptEncoding.Contains("*;q=0"));

            Request  = new HttpRequest(context.Request);
            Response = new HttpResponse(context.Response)
            {
                CompressionProvider    = new CompressionProvider(QualityValues.Parse(acceptEncoding), identityForbidden),
                ContentExpiresDuration = server.Router.Options.ContentExpiresDuration
            };

            server.ApplyGlobalResponseHeaders(Response.Headers);
        }
Example #14
0
 public static IRestServer UseContentFolders(this IRestServer server)
 {
     server.OnRequestAsync += ContentFolders.SendFileIfExistsAsnyc;
     return(server);
 }
Example #15
0
 public static IRestServer UseCorsPolicy(this IRestServer server, ICorsPolicy policy)
 {
     server.OnRequestAsync += policy.ApplyAsync;
     return(server);
 }
Example #16
0
 public static IRestServer UseCorsPolicy(this IRestServer server, IEnumerable <Uri> allowOrigins)
 {
     return(server.UseCorsPolicy(new CorsPolicy(allowOrigins)));
 }
Example #17
0
 public static IRestServer UseCorsPolicy(this IRestServer server, IEnumerable <string> allowOrigins)
 {
     return(server.UseCorsPolicy(allowOrigins.Cast <Uri>().ToList()));
 }
Example #18
0
 public static IRestServer UseCorsPolicy(this IRestServer server, Uri allowOrigin)
 {
     return(server.UseCorsPolicy(new CorsPolicy(allowOrigin)));
 }
Example #19
0
 public static IRestServer UseCorsPolicy(this IRestServer server)
 {
     server.OnRequestAsync += CorsPolicy.CorsWildcardAsync;
     return(server);
 }
Example #20
0
 public static IRestServer SetDefaultLogger(this IRestServer server, ILoggerFactory factory)
 {
     LoggerFactory = factory;
     return(server);
 }
Example #21
0
 /// <summary>
 /// Adds a server to the cluster
 /// </summary>
 /// <param name="server"></param>
 /// <returns>Assigned labled of the server that was addded</returns>
 public string Add(IRestServer server)
 {
     Add(server.ListenerPrefix, server);
     return(server.ListenerPrefix);
 }
Example #22
0
 public void RunInteractiveShell(IRestServer server)
 {
     _server = server;
     InteractiveShell.Start();
 }
Example #23
0
 public static IRestServer UseCorrelationId(this IRestServer server, string correlationIdFieldName)
 {
     return(server.UseCorrelationId(correlationIdFieldName, null));
 }
Example #24
0
 /// <summary>
 /// For use in routes that want to stop the server; starts a new thread and then calls Stop on the server
 /// </summary>
 public static void ThreadSafeStop(this IRestServer server)
 {
     new Thread(server.Stop).Start();
 }
Example #25
0
 public static IRestServer UseCorrelationId(this IRestServer server, Func <string> correlactionIdGenerator)
 {
     return(server.UseCorrelationId(null, correlactionIdGenerator));
 }