Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
        private static int Main(string[] args)
        {
            Console.ResetColor();
            Console.WriteLine("Connecting Pin Manager...");

            if (Board.Current.IsRaspberryPi)
            {
                try {
                    PinMgr.Connect();

                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("  Pin Manager connected.");
                }
                catch (Exception error) {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"  Failed to connect Pin Manager! {error}");
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"  No Raspberry Pi device detected.");
            }

            Console.ResetColor();
            Console.WriteLine("Starting Http Server...");

            var prefix   = ConfigurationManager.AppSettings["http.prefix"];
            var root     = ConfigurationManager.AppSettings["http.root"];
            var receiver = new HttpReceiver(prefix, root);

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

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

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Http Server is running. Press any key to stop...");
            Console.WriteLine();
            Console.ReadKey(true);

            Console.ResetColor();
            Console.WriteLine();
            Console.WriteLine("Stopping Http Server...");

            try {
                receiver.Dispose();

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("  Http Server stopped.");
            }
            catch (Exception error) {
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"  Error while stopping Http Server! {error}");
            }

            Console.ResetColor();
            Console.WriteLine("Closing Pin Manager...");

            try {
                PinMgr.Dispose();

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("  Pin Manager disconnected.");
            }
            catch (Exception error) {
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"  Error while disconnecting Pin Manager! {error}");
            }

            Console.ResetColor();
            return(0);
        }