Exemple #1
0
        private void StartReceiver()
        {
            var httpConfig = agent.AgentConfiguration.Value.Http;

            var httpPrefix = $"http://{httpConfig.Host}:{httpConfig.Port}/";

            if (!string.IsNullOrEmpty(httpConfig.Path))
            {
                httpPrefix = NetPath.Combine(httpPrefix, httpConfig.Path);
            }

            if (!httpPrefix.EndsWith("/"))
            {
                httpPrefix += "/";
            }

            receiver = new HttpReceiver(Context);
            receiver.Routes.Scan(Assembly.GetExecutingAssembly());
            receiver.AddPrefix(httpPrefix);

            try {
                receiver.Start();

                Log.Debug($"HTTP Server listening at {httpPrefix}");
            }
            catch (Exception error) {
                Log.Error("Failed to start HTTP Receiver!", error);
            }
        }
Exemple #2
0
        private void StartHttpServer()
        {
            var enableSecurity = ServerConfiguration.Value.Security?.Enabled ?? false;
            var http           = ServerConfiguration.Value.Http;

            var contentDir = new ContentDirectory {
                DirectoryPath = Configuration.HttpContentDirectory,
                UrlPath       = "/Content/",
            };

            var sharedContentDir = new ContentDirectory {
                DirectoryPath = Configuration.HttpSharedContentDirectory,
                UrlPath       = "/SharedContent/",
            };

            var context = new HttpReceiverContext {
                ListenerPath       = http.Path,
                ContentDirectories =
                {
                    contentDir,
                    sharedContentDir,
                },
            };

            if (enableSecurity)
            {
                var ldapAuth = new LdapAuthorization();

                context.SecurityMgr = new ServerHttpSecurity {
                    Authorization = ldapAuth,
                };
            }

            context.Views.AddFolderFromExternal(Configuration.HttpViewDirectory);

            var httpPrefix = $"http://{http.Host}:{http.Port}/";

            if (!string.IsNullOrEmpty(http.Path))
            {
                httpPrefix = NetPath.Combine(httpPrefix, http.Path);
            }

            if (!httpPrefix.EndsWith("/"))
            {
                httpPrefix += "/";
            }

            receiver = new HttpReceiver(context);
            receiver.Routes.Scan(Assembly.GetExecutingAssembly());
            receiver.AddPrefix(httpPrefix);

            try {
                receiver.Start();

                Log.Debug($"HTTP Server listening at {httpPrefix}");
            }
            catch (Exception error) {
                Log.Error("Failed to start HTTP Receiver!", error);
            }
        }
Exemple #3
0
        private void StartHttpServer()
        {
            var contentDir = new ContentDirectory {
                DirectoryPath = Configuration.HttpContentDirectory,
                UrlPath       = "/Content/",
            };

            var sharedContentDir = new ContentDirectory {
                DirectoryPath = Configuration.HttpSharedContentDirectory,
                UrlPath       = "/SharedContent/",
            };

            var context = new HttpReceiverContext {
                SecurityMgr        = new AgentHttpSecurity(),
                ListenerPath       = Definition.Http.Path,
                ContentDirectories =
                {
                    contentDir,
                    sharedContentDir,
                },
            };

            context.Views.AddFolderFromExternal(Configuration.HttpViewDirectory);

            var httpPrefix = $"http://{Definition.Http.Host}:{Definition.Http.Port}/";

            if (!string.IsNullOrEmpty(Definition.Http.Path))
            {
                httpPrefix = NetPath.Combine(httpPrefix, Definition.Http.Path);
            }

            if (!httpPrefix.EndsWith("/"))
            {
                httpPrefix += "/";
            }

            receiver = new HttpReceiver(context);
            receiver.Routes.Scan(Assembly.GetExecutingAssembly());
            receiver.AddPrefix(httpPrefix);

            try {
                receiver.Start();

                Log.Info($"HTTP Server listening at {httpPrefix}");
            }
            catch (Exception error) {
                Log.Error("Failed to start HTTP Receiver!", error);
            }
        }
Exemple #4
0
        private static bool StartReceiver(HttpReceiverContext context)
        {
            Console.ResetColor();
            Console.WriteLine("Starting Http Server...");
            Console.WriteLine("Listening at http://*/piServer");

            receiver = new HttpReceiver(context);
            receiver.AddPrefix("http://*:80/piServer/");

            try {
                receiver.Routes.Scan(Assembly.GetExecutingAssembly());

                receiver.Start();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("  Http Server started successfully.");
                return(true);
            }
            catch (Exception error) {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"  Failed to start Http Server! {error}");
                return(false);
            }
        }