#if NET20
// NET 20 specific
#endif
<TargetFrameworks>netstandard1.3;netstandard2.1;net45;net46;net472;netcoreapp1;netcoreapp2;netcoreapp3;netcoreapp3.1</TargetFrameworks>
https://github.com/vkorotenko/NAddressParser/blob/... using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace TestTrapCtrlC{
public class Program{
static bool exitSystem = false;
#region Trap application termination
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
private delegate bool EventHandler(CtrlType sig);
static EventHandler _handler;
enum CtrlType {
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private static bool Handler(CtrlType sig) {
Console.WriteLine("Exiting system due to external CTRL-C, or process kill, or shutdown");
//do your cleanup here
Thread.Sleep(5000); //simulate some cleanup delay
Console.WriteLine("Cleanup complete");
//allow main to run off
exitSystem = true;
//shutdown right away so there are no lingering threads
Environment.Exit(-1);
return true;
}
#endregion
static void Main(string[] args) {
// Some biolerplate to react to close window event, CTRL-C, kill, etc
_handler += new EventHandler(Handler);
SetConsoleCtrlHandler(_handler, true);
//start your multi threaded program here
Program p = new Program();
p.Start();
//hold the console so it doesn’t run off the end
while(!exitSystem) {
Thread.Sleep(500);
}
}
public void Start() {
// start a thread and start doing some processing
Console.WriteLine("Thread started, processing..");
}
}
}
#region License
// // Разработано: Коротенко Владимиром Николаевичем (Vladimir N. Korotenko)
// // email: koroten@ya.ru
// // skype:vladimir-korotenko
// // https://vkorotenko.ru
// // Создано: 06.04.2020 16:10
#endregion
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Kvn.CustomControls
{
public class EllipseButton : Button
{
protected override void OnPaint(PaintEventArgs e)
{
var grPath = new GraphicsPath();
grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
Region = new Region(grPath);
base.OnPaint(e);
}
}
}
POST https://you_server_api/api/power
{
"mode": "on"
}
var baseAdress = new Uri(Properties.Settings.Default.BaseUri);
var server = new WebApiServer(baseAdress);
server.Start();
var message = $"Web API Self hosted on {baseAdress} Hit ENTER to exit...";
_logger.Info(message);
System.Console.ReadLine();
server.Stop();
return (int)ScanerStatus.Ok;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace RO.WebScaner.Console
{
/// <summary>
/// Web api server implementation
/// </summary>
public class WebApiServer
{
Logger _logger = LogManager.GetCurrentClassLogger();
Uri _uri;
HttpSelfHostServer _server;
/// <summary>
/// Create instance of Webapi embedd server
/// </summary>
/// <param name="uri">Endpoint address</param>
public WebApiServer(Uri uri)
{
_uri = uri;
}
/// <summary>
/// Start web api server.
/// </summary>
/// Команда для запуска исключения файрвола
/// netsh http add urlacl url=http://+:8000/ user=ZOOPLAZA-PC\developer
/// <remarks>
/// </remarks>
public void Start()
{
_logger.Info("Start WebApi server");
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_uri);
config.EnableCors();
ConfigRoutes(config);
ConfigFormatter(config);
_server = new HttpSelfHostServer(config);
_server.OpenAsync().Wait();
}
/// <summary>
/// Remove xml formatter, maybe in future add binary formatter
/// </summary>
/// <param name="config"></param>
private static void ConfigFormatter(HttpSelfHostConfiguration config)
{
// remove xml
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
/// <summary>
/// Config web api routes
/// </summary>
/// <param name="config"></param>
private static void ConfigRoutes(HttpSelfHostConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
public void Stop() {
_server.CloseAsync().Wait();
_logger.Info("Close WebApi server");
}
}
}
using NLog;
using RO.WebScaner.Console.Models;
using RO.WebScaner.Core;
using RO.WebScaner.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Cors;
namespace RO.WebScaner.Console.Controllers
{
public class ListController : ApiController
{
Logger _logger;
/// <summary>
/// Logger with delay load
/// </summary>
public Logger Logger
{
get
{
if (_logger == null)
{
_logger = LogManager.GetCurrentClassLogger();
}
return _logger;
}
set { _logger = value; }
}
[EnableCors(origins: "*",headers: "*", methods:"*")]
public IHttpActionResult Get()
{
try
{
var model = Worker.List();
return Ok(model);
}
catch(Exception e)
{
Logger.Error(e);
return InternalServerError(e);
}
}
}
}
dotnet watch run
Часто слышу что Windows Server не ломал только ленивый. В связи с этим вопрос, есть ли смысл, для себя, по фану, начинать изучение программирования и создания CMS исключетельно средствами MS технологий, .NET и т.д. и т.п. и насколько чаще в экосистеме MS находятся уязвимости по сравнению с другими платформами, такими как PHP/mySQL и др.