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); } }
/// <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); //} }
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); } }
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); } }
public void Dispose() { //if (isStarted) Stop(); messageListener?.Dispose(); Sessions?.Dispose(); receiver?.Dispose(); receiver = null; }
private void StopReceiver() { try { receiver?.Dispose(); receiver = null; } catch (Exception error) { Log.Error("Failed to stop HTTP Receiver!", error); } }
public void Dispose() { if (isStarted) { Stop(); } Queue?.Dispose(); Sessions?.Dispose(); receiver?.Dispose(); receiver = null; }
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()))); }
public void Abort() { Queue.Abort(); Sessions.Abort(); try { receiver?.Dispose(); receiver = null; } catch (Exception error) { Log.Error("Failed to stop HTTP Receiver!", error); } }
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); } }
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); } }
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."); }
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); } }
public override HttpResponseMessage Execute() { var reciever = HttpReceiver.GetReceiver().SetToken(Application.Current.Properties[Constants.ValidatedUserToken].ToString()); return(reciever.Get(endpoint)); }
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); }
public void Dispose() { receiver?.Dispose(); receiver = null; }