新增按条件选择使用哪种Web框架
This commit is contained in:
@@ -1,56 +1,62 @@
|
||||
using Microsoft.Owin;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using Nancy.Hosting.Self;
|
||||
using Owin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
#if Nancy
|
||||
using Nancy.Hosting.Self;
|
||||
#else
|
||||
using Microsoft.Owin;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using Owin;
|
||||
using System.Web.Http;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using System.Net.Http.Formatting;
|
||||
#endif
|
||||
|
||||
|
||||
namespace 电子展板
|
||||
{
|
||||
|
||||
public class WebServer
|
||||
{
|
||||
private static bool UseNancy = false;
|
||||
|
||||
#if Nancy
|
||||
private static NancyHost _host;
|
||||
#else
|
||||
private static IDisposable host;
|
||||
#endif
|
||||
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (UseNancy)
|
||||
{
|
||||
_host = new NancyHost(new Uri("http://localhost:80"));
|
||||
_host.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
StartOptions startOptions = new StartOptions();
|
||||
startOptions.Urls.Add($"http://*:80/");
|
||||
host = WebApp.Start<Startup>(startOptions);
|
||||
}
|
||||
#if Nancy
|
||||
_host = new NancyHost(new Uri("http://localhost:80"));
|
||||
_host.Start();
|
||||
#else
|
||||
StartOptions startOptions = new StartOptions();
|
||||
startOptions.Urls.Add($"http://*:80/");
|
||||
host = WebApp.Start<Startup>(startOptions);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
#if Nancy
|
||||
if (_host != null)
|
||||
{
|
||||
_host.Stop();
|
||||
_host.Dispose();
|
||||
_host = null;
|
||||
}
|
||||
if (host != null)
|
||||
{
|
||||
host.Dispose();
|
||||
host = null;
|
||||
}
|
||||
#else
|
||||
if (host != null)
|
||||
{
|
||||
host.Dispose();
|
||||
host = null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !Nancy
|
||||
/// <summary>
|
||||
/// Web启动类
|
||||
/// </summary>
|
||||
@@ -117,4 +123,109 @@ namespace 电子展板
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !Nancy
|
||||
namespace Nancy.Swagger.Annotations.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||
public class ModelAttribute : Attribute
|
||||
{
|
||||
public ModelAttribute(string description)
|
||||
{
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// By default, only read/write props are shown, this
|
||||
/// prop allows read only props to be shown.
|
||||
/// </summary>
|
||||
public bool ShowReadOnlyProps { get; set; }
|
||||
}
|
||||
|
||||
public abstract class SwaggerDataTypeAttribute : Attribute
|
||||
{
|
||||
private long? _maximum;
|
||||
private long? _minium;
|
||||
private bool? _required;
|
||||
private bool? _uniqueItems;
|
||||
|
||||
protected SwaggerDataTypeAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string DefaultValue { get; set; }
|
||||
|
||||
public string[] Enum { get; set; }
|
||||
|
||||
public long Maximum
|
||||
{
|
||||
get { return _maximum.GetValueOrDefault(); }
|
||||
set { _maximum = value; }
|
||||
}
|
||||
|
||||
public long Minimum
|
||||
{
|
||||
get { return _minium.GetValueOrDefault(); }
|
||||
set { _minium = value; }
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Required
|
||||
{
|
||||
get { return _required.GetValueOrDefault(); }
|
||||
set { _required = value; }
|
||||
}
|
||||
|
||||
public bool UniqueItems
|
||||
{
|
||||
get { return _uniqueItems.GetValueOrDefault(); }
|
||||
set { _uniqueItems = value; }
|
||||
}
|
||||
|
||||
internal long? GetNullableMaximum()
|
||||
{
|
||||
return _maximum;
|
||||
}
|
||||
|
||||
internal long? GetNullableMinimum()
|
||||
{
|
||||
return _minium;
|
||||
}
|
||||
|
||||
internal bool? GetNullableRequired()
|
||||
{
|
||||
return _required;
|
||||
}
|
||||
|
||||
internal bool? GetNullableUniqueItems()
|
||||
{
|
||||
return _uniqueItems;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
|
||||
public class ModelPropertyAttribute : SwaggerDataTypeAttribute
|
||||
{
|
||||
public ModelPropertyAttribute() : this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ModelPropertyAttribute(string name) : base(name)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ignore this property when generating swagger model.
|
||||
/// </summary>
|
||||
public bool Ignore { get; set; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user