Пример #1
0
        public void Dispose()
        {
            //if (isStarted) Stop();

            try {
                messageListener?.Dispose();
            }
            catch (Exception error) {
                Log.Error("Failed to dispose TCP message listener!", error);
            }

            try {
                Sessions?.Dispose();
            }
            catch (Exception error) {
                Log.Error("Failed to dispose session manager!", error);
            }

            try {
                receiver?.Dispose();
                receiver = null;
            }
            catch (Exception error) {
                Log.Error("Failed to dispose HTTP receiver!", error);
            }
        }
Пример #2
0
        /// <summary>
        ///     调用
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static Task CallTask(HttpContext context)
        {
            if (!string.Equals(context.Request.Method, "OPTIONS", StringComparison.OrdinalIgnoreCase))
            {
                return(HttpProtocol.CrosOption(context.Response));
            }
            HttpProtocol.CrosCall(context.Response);
            var uri = context.Request.GetUri();

            if (uri.AbsolutePath == "/")
            {
                //response.Redirect("/index.html");
                return(context.Response.WriteAsync("Wecome MessageMVC,Lucky every day!", Encoding.UTF8));
            }
            HttpProtocol.FormatResponse(context.Request, context.Response);
            return(HttpReceiver.OutCall(context));
            //if (context.Request.Headers.TryGetValue("User-Agent", out var agent) &&
            //    agent.Count == 1 && agent[0] == MessageRouteOption.AgentName)
            //{
            //    return InnerCall(context);
            //}
            //else
            //{
            //    return OutCall(context);
            //}
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        public void Dispose()
        {
            //if (isStarted) Stop();

            messageListener?.Dispose();
            Sessions?.Dispose();
            receiver?.Dispose();
            receiver = null;
        }
Пример #6
0
 private void StopReceiver()
 {
     try {
         receiver?.Dispose();
         receiver = null;
     }
     catch (Exception error) {
         Log.Error("Failed to stop HTTP Receiver!", error);
     }
 }
Пример #7
0
        public void Dispose()
        {
            if (isStarted)
            {
                Stop();
            }

            Queue?.Dispose();
            Sessions?.Dispose();
            receiver?.Dispose();
            receiver = null;
        }
Пример #8
0
        private static Agent CreateMinderTestAgent(string url, bool useLogging, Transformer transformerConfig)
        {
            var receiver = new HttpReceiver();

            receiver.Configure(new[] { new Setting("Url", url), new Setting("UseLogging", useLogging.ToString()) });

            return(new Agent(
                       new AgentConfig(name: "Minder Submit/Receive Agent"),
                       receiver,
                       transformerConfig,
                       new MinderExceptionHandler(),
                       (CreateMinderHappyFlow(), CreateReceiveUnhappyFlow())));
        }
Пример #9
0
        public void Abort()
        {
            Queue.Abort();
            Sessions.Abort();

            try {
                receiver?.Dispose();
                receiver = null;
            }
            catch (Exception error) {
                Log.Error("Failed to stop HTTP Receiver!", error);
            }
        }
Пример #10
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);
            }
        }
Пример #11
0
        public void Abort()
        {
            Log.Debug("Server abort started...");

            Queue.Abort();
            Sessions.Abort();

            try {
                receiver?.Dispose();
                receiver = null;
            }
            catch (Exception error) {
                Log.Error("Failed to stop HTTP Receiver!", error);
            }
        }
Пример #12
0
        public void Stop()
        {
            Log.Debug("Stopping Server...");

            Queue.Stop();
            Sessions.Stop();

            try {
                receiver?.Dispose();
                receiver = null;
            }
            catch (Exception error) {
                Log.Error("Failed to stop HTTP Receiver!", error);
            }

            Log.Info("Server stopped.");
        }
Пример #13
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);
            }
        }
Пример #14
0
        public override HttpResponseMessage Execute()
        {
            var reciever = HttpReceiver.GetReceiver().SetToken(Application.Current.Properties[Constants.ValidatedUserToken].ToString());

            return(reciever.Get(endpoint));
        }
Пример #15
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);
        }
Пример #16
0
 public void Dispose()
 {
     receiver?.Dispose();
     receiver = null;
 }