本文整理汇总了C#中HttpServer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.Dispose方法的具体用法?C# HttpServer.Dispose怎么用?C# HttpServer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
System.AppDomain.CurrentDomain.UnhandledException += Debug;
var server = new HttpServer(env =>
{
var context = new Microsoft.Owin.OwinContext(env);
var response = context.Response;
response.StatusCode = 200;
response.Headers.Add("Content-Type", new[] { "text/plain" });
response.Headers.Add("Content-Length", new[] { "13" });
response.Headers.Add("Server", new[] { "Fracture" });
response.Write("Hello, world!");
// Complete the Task.
return Task.FromResult<object>(null);
});
server.Start(6667);
Console.WriteLine("Running server on port 6667.");
Console.ReadLine();
server.Dispose();
}
示例2: Main
public static void Main (string[] args)
{
Log.Register (new ConsoleOutEventLog (80));
Log.Information ("Initializing application...");
HttpSocketClient.RegisterHttpProxyUse (false, false); // Don't look for proxies.
Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
{
e.Cancel = true;
executing = false;
};
// Object database setup
DB.BackupConnectionString = "Data Source=controller.db;Version=3;";
DB.BackupProviderName = "Clayster.Library.Data.Providers.SQLiteServer.SQLiteServerProvider";
db = DB.GetDatabaseProxy ("TheController");
// Mail setup
mailSettings = MailSettings.LoadSettings ();
if (mailSettings == null)
{
mailSettings = new MailSettings ();
mailSettings.Host = "Enter mailserver SMTP host name here.";
mailSettings.Port = 25;
mailSettings.Ssl = false;
mailSettings.From = "Enter address of sender here.";
mailSettings.User = "Enter SMTP user account here.";
mailSettings.Password = "Enter SMTP user password here.";
mailSettings.Recipient = "Enter recipient of alarm mails here.";
mailSettings.SaveNew ();
}
SmtpOutbox.Host = mailSettings.Host;
SmtpOutbox.Port = mailSettings.Port;
SmtpOutbox.Ssl = mailSettings.Ssl;
SmtpOutbox.From = mailSettings.From;
SmtpOutbox.User = mailSettings.User;
SmtpOutbox.Password = mailSettings.Password;
SmtpOutbox.OutboxPath = "MailOutbox";
SmtpOutbox.Start (Directory.GetCurrentDirectory ());
// UPnP Interface
upnpServer = new HttpServer (8080, 10, true, true, 1);
Log.Information ("UPnP Server receiving requests on port " + upnpServer.Port.ToString ());
ssdpClient = new SsdpClient (upnpServer, 10, true, true, false, false, false, 30);
stillImageCameras = new Dictionary<string, IUPnPService> ();
subscriptions = new SortedDictionary<DateTime, Subscription> ();
stateVariables = new Dictionary<string, Dictionary<string, string>> ();
events = new UPnPEvents ("/events");
upnpServer.Register (events);
ssdpClient.OnUpdated += NetworkUpdated;
events.OnEventsReceived += EventsReceived;
// Main loop
Log.Information ("Initialization complete. Application started...");
try
{
#if USE_HTTP
MonitorHttp ();
#elif USE_COAP
MonitorCoap ();
#elif USE_MQTT
MonitorMqtt ();
#endif
} catch (Exception ex)
{
Log.Exception (ex);
} finally
{
Log.Information ("Terminating application.");
Log.Flush ();
Log.Terminate ();
SmtpOutbox.Terminate ();
ssdpClient.Dispose ();
upnpServer.Dispose ();
}
}
示例3: Main
//.........这里部分代码省略.........
sumHours += Rec;
nrHours++;
} else
break;
}
Pos = perDay.Count;
while (Pos-- > 0)
{
Record Rec = perDay [Pos];
Timestamp = Rec.Timestamp;
if (Timestamp.Month == CurrentTime.Month && Timestamp.Year == CurrentTime.Year)
{
sumDays += Rec;
nrDays++;
} else
break;
}
// Sampling of new Sensor Values
Timer Timer = new Timer (SampleSensorValues, null, 1000 - DateTime.Now.Millisecond, 1000); // Every second.
// HTTP Interface
HttpServer HttpServer = new HttpServer (80, 10, true, true, 1);
Log.Information ("HTTP Server receiving requests on port " + HttpServer.Port.ToString ());
HttpServer.RegisterAuthenticationMethod (new DigestAuthentication ("The Sensor Realm", GetDigestUserPasswordHash));
HttpServer.RegisterAuthenticationMethod (new SessionAuthentication ());
credentials = LoginCredentials.LoadCredentials ();
if (credentials == null)
{
credentials = new LoginCredentials ();
credentials.UserName = "Admin";
credentials.PasswordHash = CalcHash ("Admin", "Password");
credentials.SaveNew ();
}
HttpServer.Register ("/", HttpGetRoot, HttpPostRoot, false); // Synchronous, no authentication
HttpServer.Register ("/html", HttpGetHtml, false); // Synchronous, no authentication
HttpServer.Register ("/historygraph", HttpGetHistoryGraph, false); // Synchronous, no authentication
HttpServer.Register ("/credentials", HttpGetCredentials, HttpPostCredentials, false); // Synchronous, no authentication
HttpServer.Register ("/xml", HttpGetXml, true); // Synchronous, http authentication
HttpServer.Register ("/json", HttpGetJson, true); // Synchronous, http authentication
HttpServer.Register ("/turtle", HttpGetTurtle, true); // Synchronous, http authentication
HttpServer.Register ("/rdf", HttpGetRdf, true); // Synchronous, http authentication
HttpServer.Register ("/event/xml", HttpGetEventXml, true, false); // Asynchronous, http authentication
HttpServer.Register ("/event/json", HttpGetEventJson, true, false); // Asynchronous, http authentication
HttpServer.Register ("/event/turtle", HttpGetEventTurtle, true, false); // Asynchronous, http authentication
HttpServer.Register ("/event/rdf", HttpGetEventRdf, true, false); // Asynchronous, http authentication
// HTTPS interface
// Certificate must be a valid P12 (PFX) certificate file containing a private key.
// X509Certificate2 Certificate = new X509Certificate2 ("Certificate.pfx", "PASSWORD");
// HttpServer HttpsServer = new HttpServer (443, 10, true, true, 1, true, false, Certificate);
//
// HttpsServer.RegisterAuthenticationMethod (new DigestAuthentication ("The Sensor Realm", GetDigestUserPasswordHash));
// HttpsServer.RegisterAuthenticationMethod (new SessionAuthentication ());
//
// foreach (IHttpServerResource Resource in HttpServer.GetResources())
// HttpsServer.Register (Resource);
//
// Log.Information ("HTTPS Server receiving requests on port " + HttpsServer.Port.ToString ());
// Main loop
Log.Information ("Initialization complete. Application started...");
try
{
while (executionLed.Value)
{
System.Threading.Thread.Sleep (1000);
}
} catch (Exception ex)
{
Log.Exception (ex);
executionLed.Low ();
} finally
{
Log.Information ("Terminating application.");
Log.Flush ();
Log.Terminate ();
Timer.Dispose ();
HttpServer.Dispose ();
//HttpsServer.Dispose ();
executionLed.Dispose ();
measurementLed.Dispose ();
errorLed.Dispose ();
networkLed.Dispose ();
motion.Dispose ();
i2cBus.Dispose ();
}
return 0;
}
示例4: Main
private static void Main(string[] args)
{
Console.WriteLine();
var options = new Options();
try {
Console.TreatControlCAsInput = false;
Console.CancelKeyPress += CancelKeyPressed;
options.Parse(args);
if (options.ShowHelp) {
options.PrintUsage();
return;
}
if (options.ShowVersion) {
ShowVersion();
return;
}
if (options.ShowLicense) {
ShowLicense();
return;
}
if (options.ListViews) {
ListViews();
return;
}
if (options.ListOrders) {
ListOrders();
return;
}
if (options.Directories.Length == 0) {
throw new GetOptException("No directories specified");
}
options.SetupLogging();
using (var icon = new ProgramIcon()) {
var server = new HttpServer(options.Port);
try {
using (var authorizer = new HttpAuthorizer(server)) {
if (options.Ips.Length != 0) {
authorizer.AddMethod(new IPAddressAuthorizer(options.Ips));
}
if (options.Macs.Length != 0) {
authorizer.AddMethod(new MacAuthorizer(options.Macs));
}
if (options.UserAgents.Length != 0) {
authorizer.AddMethod(
new UserAgentAuthorizer(options.UserAgents));
}
Console.Title = "SimpleDLNA - starting ...";
var types = options.Types[0];
foreach (var t in options.Types) {
types = types | t;
server.Logger.InfoFormat("Enabled type {0}", t);
}
var friendlyName = "sdlna";
if (options.Seperate) {
foreach (var d in options.Directories) {
server.Logger.InfoFormat("Mounting FileServer for {0}", d.FullName);
var fs = SetupFileServer(
options, types, new DirectoryInfo[] { d });
friendlyName = fs.FriendlyName;
server.RegisterMediaServer(fs);
server.Logger.NoticeFormat("{0} mounted", d.FullName);
}
}
else {
server.Logger.InfoFormat(
"Mounting FileServer for {0} ({1})",
options.Directories[0], options.Directories.Length);
var fs = SetupFileServer(options, types, options.Directories);
friendlyName = fs.FriendlyName;
server.RegisterMediaServer(fs);
server.Logger.NoticeFormat(
"{0} ({1}) mounted",
options.Directories[0], options.Directories.Length);
}
Console.Title = String.Format("{0} - running ...", friendlyName);
Run(server);
}
}
finally {
server.Dispose();
}
}
}
catch (GetOptException ex) {
Console.Error.WriteLine("Error: {0}\n\n", ex.Message);
options.PrintUsage();
}
#if !DEBUG
catch (Exception ex) {
LogManager.GetLogger(typeof(Program)).Fatal("Failed to run", ex);
}
//.........这里部分代码省略.........