本文整理汇总了C#中IServer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# IServer.Start方法的具体用法?C# IServer.Start怎么用?C# IServer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServer
的用法示例。
在下文中一共展示了IServer.Start方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
// validate settings and fill in any defaults
if (string.IsNullOrEmpty(Settings.BasePath))
Settings.BasePath = Environment.CurrentDirectory;
var handler = CreateHandlerCore();
_server = CreateServerCore(handler);
_server.Start();
}
示例2: Run
public void Run(string[] args, IServer server, IClient client)
{
try
{
TypeApp typeApp = (args[0] == "-s") ? TypeApp.Server : (args[0] == "-c") ? TypeApp.Client : TypeApp.None;
IPAddress ipAdress;
IPEndPoint ipEndPoint;
switch (typeApp)
{
case TypeApp.Client:
ipAdress = IPAddress.Parse(args[1]);
ipEndPoint = new IPEndPoint(ipAdress, int.Parse(args[2]));
client.ipEndPoint = ipEndPoint;
client.Start();
break;
case TypeApp.Server:
ipAdress = IPAddress.Any;
ipEndPoint = new IPEndPoint(ipAdress, int.Parse(args[1]));
server.ipEndPoint = ipEndPoint;
server.Start();
Console.ReadKey(true);
server.Stop();
break;
case TypeApp.None:
throw new Exception("Не указан тип приложения (-c или -s)");
}
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("Неверные параметры");
}
catch (Exception e)
{
Console.WriteLine("Ошибка: {0}", e.Message);
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
}
示例3: Start
public void Start(CommandLineArguments args)
{
_args = null;
if (_view != null)
{
_view.ClearError();
}
try
{
ServiceFactory.Rules.ValidateArgs(args);
}
catch (CassiniException ex)
{
if (_view != null)
{
_view.SetError(ex.Field, ex.Message);
return;
}
throw;
}
if (string.IsNullOrEmpty(args.ApplicationPath) || !Directory.Exists(args.ApplicationPath))
{
if (_view != null)
{
_view.SetError(ErrorField.ApplicationPath, "Invalid Application Path");
return;
}
throw new CassiniException("Invalid Application Path", ErrorField.ApplicationPath);
}
// prepare arguments
IPAddress ip = ServiceFactory.Rules.ParseIP(args.IPMode, args.IPv6, args.IPAddress);
if (_view != null)
{
_view.IPAddress = ip.ToString();
}
ushort port = args.Port;
if (args.PortMode == PortMode.FirstAvailable)
{
port = ServiceFactory.Rules.GetAvailablePort(args.PortRangeStart, args.PortRangeEnd, ip, true);
}
if (_view != null)
{
_view.Port = port;
}
if (_view != null)
{
_view.HostName = args.HostName;
}
_server = ServiceFactory.CreateServer(new ServerArguments
{
Port = port,
VirtualPath = args.VirtualPath,
ApplicationPath = args.ApplicationPath,
IPAddress = ip,
Hostname = args.HostName,
TimeOut = args.TimeOut
});
WireServerEvents();
if (args.AddHost)
{
ServiceFactory.Rules.AddHostEntry(_server.IPAddress.ToString(), _server.HostName);
}
try
{
_server.Start();
_args = args;
if (_view != null)
{
_view.RootUrl = _server.RootUrl;
_view.RunState = RunState.Running;
}
}
catch (Exception ex)
{
if (_view != null)
{
_view.SetError(ErrorField.None, ex.Message);
}
Stop();
}
}
示例4: StartDummyApplication
private static void StartDummyApplication(IServer server)
{
server.Start(new DummyApplication(context => TaskUtilities.CompletedTask));
}
示例5: ServerOnPerformRestartServer
private static void ServerOnPerformRestartServer(IServer server)
{
// TODO
server.Stop();
Console.WriteLine("Waiting 5 seconds before restarting");
System.Threading.Thread.Sleep(5000);
server.Start();
}