public class AutoCompleteTextBox : TextBoxRound
{
public AutoCompleteTextBox()
{
var allowedStatorTypes = new AutoCompleteStringCollection();
// вставляете свои строки, дополняете конечно логикой для получения тут данных например из базы
var allstate = new[] { "Test", "nTest" }.OrderBy(x => x).Select(x => x).Distinct().ToList();
foreach (var item in allstate)
{
allowedStatorTypes.Add(item);
}
tbInput.AutoCompleteMode = AutoCompleteMode.Suggest;
tbInput.AutoCompleteSource = AutoCompleteSource.CustomSource;
tbInput.AutoCompleteCustomSource = allowedStatorTypes;
}
}
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..");
}
}
}
using System.Collections.Generic;
namespace TreeViewBinding.Code
{
public class TreeSource
{
public TreeSource()
{
Leaves = new List<TreeLeaf>();
}
public List<TreeLeaf> Leaves { get; set; }
/// <summary>
/// Load data stub. In this example use mock data. In real application load data from database or web service
/// </summary>
public void LoadData()
{
var first = new TreeLeaf { Description = "First description", Title = "First" };
var firstSubs = new[]
{
new TreeLeaf(first){Description = "First desc",Title = "First"},
new TreeLeaf(first){Description = "Second desc",Title = "Second"},
new TreeLeaf(first){Description = "Third desc",Title = "Third"}
};
first.Leaves.AddRange(firstSubs);
var second = new TreeLeaf { Description = "Second description", Title = "Second" };
var third = new TreeLeaf { Description = "Third description", Title = "Third" };
Leaves.AddRange(new[]
{
first,
second,
third,
});
}
}
}
using System.Collections.Generic;
namespace TreeViewBinding.Code
{
public class TreeLeaf
{
public TreeLeaf(TreeLeaf parent = null)
{
Leaves = new List<TreeLeaf>();
Parent = parent;
}
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public List<TreeLeaf> Leaves { get; private set; }
public TreeLeaf Parent { get; private set; }
}
}
#region License
// // Разработано: Коротенко Владимиром Николаевичем (Vladimir N. Korotenko)
// // email: koroten@ya.ru
// // skype:vladimir-korotenko
// // https://vkorotenko.ru
// // Создано: 09.05.2020 8:26
#endregion
using System.Collections.Generic;
using System.Windows.Forms;
using TreeViewBinding.Code;
namespace TreeViewBinding
{
public partial class TreeViewBindingForm : Form
{
private TreeSource _treeSource;
private TreeLeaf _currentLeaf;
private TreeNode _node;
public TreeViewBindingForm()
{
InitializeComponent();
_treeSource = new TreeSource();
_treeSource.LoadData();
FillInTree(treeView.Nodes, _treeSource.Leaves);
}
private static void FillInTree(TreeNodeCollection nodes, IEnumerable<TreeLeaf> leafs)
{
foreach (var leaf in leafs)
{
var treeNode = new TreeNode(leaf.Title) {Tag = leaf};
nodes.Add(treeNode);
if (leaf.Leaves.Count > 0) FillInTree(treeNode.Nodes, leaf.Leaves);
}
}
private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Tag is TreeLeaf item)
{
_node = e.Node;
_currentLeaf = item;
titleTextBox.Text = item.Title;
descriptionTexBox.Text = item.Description;
}
}
private void titleTextBox_TextChanged(object sender, System.EventArgs e)
{
if (_node != null)
{
_currentLeaf.Title = _node.Text = titleTextBox.Text;
}
}
private void descriptionTexBox_TextChanged(object sender, System.EventArgs e)
{
if (_node != null)
{
_currentLeaf.Description = descriptionTexBox.Text;
}
}
}
}
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);
}
}
}
}