diff --git a/电子展板/App.xaml.cs b/电子展板/App.xaml.cs index fab1b46..e2485ac 100644 --- a/电子展板/App.xaml.cs +++ b/电子展板/App.xaml.cs @@ -1,4 +1,6 @@ -using HandyControl.Collections; + + +using HandyControl.Collections; using System; using System.Configuration; using System.Data; @@ -16,7 +18,7 @@ namespace 电子展板 { public App() { - + } } diff --git a/电子展板/FodyWeavers.xml b/电子展板/FodyWeavers.xml index 1a07c56..3ffc8fe 100644 --- a/电子展板/FodyWeavers.xml +++ b/电子展板/FodyWeavers.xml @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/电子展板/Utility/Web/WithExtensionMultipartFormDataStreamProvider.cs b/电子展板/Utility/Web/WithExtensionMultipartFormDataStreamProvider.cs index 39d0da9..95ab7f3 100644 --- a/电子展板/Utility/Web/WithExtensionMultipartFormDataStreamProvider.cs +++ b/电子展板/Utility/Web/WithExtensionMultipartFormDataStreamProvider.cs @@ -1,4 +1,5 @@ -using System; +#if !Nancy +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -34,3 +35,4 @@ namespace 电子展板.Utility.Web } } +#endif \ No newline at end of file diff --git a/电子展板/WebModule/ApplicationBootstrapper.cs b/电子展板/WebModule/ApplicationBootstrapper.cs index 17058b5..6127d65 100644 --- a/电子展板/WebModule/ApplicationBootstrapper.cs +++ b/电子展板/WebModule/ApplicationBootstrapper.cs @@ -1,4 +1,5 @@ -using Nancy; +#if Nancy +using Nancy; using Nancy.Bootstrapper; using Nancy.Configuration; using Nancy.Conventions; @@ -51,5 +52,5 @@ namespace 电子展板.WebModule pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Methods", "*")); } } - } +#endif \ No newline at end of file diff --git a/电子展板/WebModule/HomeModule.cs b/电子展板/WebModule/HomeModule.cs index edd87e0..abe4e55 100644 --- a/电子展板/WebModule/HomeModule.cs +++ b/电子展板/WebModule/HomeModule.cs @@ -1,4 +1,5 @@ -using Nancy; +#if Nancy +using Nancy; using Nancy.ModelBinding; using Nancy.Swagger; using Nancy.Swagger.Annotations.Attributes; @@ -6,15 +7,11 @@ using Swagger.ObjectModel; using System; using System.Collections.Generic; using System.IO; -using System.IO.Pipes; using System.Linq; using System.Reflection; using 电子展板.Base; using 电子展板.Models; using 电子展板.Utility; -using 电子展板.Utility.Core; -using 电子展板.Utility.Extension; -using 电子展板.Utility.Logs; using 电子展板.Utility.Other; namespace 电子展板.WebModule @@ -120,11 +117,11 @@ namespace 电子展板.WebModule [Route(Tags = new[] { "上传图片" })] private object UploadImage([RouteParam(ParamIn = ParameterIn.Form, Name = "file", Description = "图片文件", ParamType = typeof(SwaggerFile), Required = true)] HttpFile file) { - string uploadPath = MyEnvironment.Root("/Upload/"); - if (!Directory.Exists(uploadPath)) - { - Directory.CreateDirectory(uploadPath); - } + //string uploadPath = MyEnvironment.Root("/Upload/"); + //if (!Directory.Exists(uploadPath)) + //{ + // Directory.CreateDirectory(uploadPath); + //} string ext = Path.GetExtension(file.Name); string fileName = UUID.StrSnowId + ext; @@ -178,3 +175,4 @@ namespace 电子展板.WebModule } } } +#endif \ No newline at end of file diff --git a/电子展板/WebModule/IndexController.cs b/电子展板/WebModule/IndexController.cs index 65cb7a2..d4741b3 100644 --- a/电子展板/WebModule/IndexController.cs +++ b/电子展板/WebModule/IndexController.cs @@ -1,4 +1,5 @@ -using System; +#if !Nancy +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; @@ -180,3 +181,4 @@ namespace 电子展板.WebModule } } } +#endif \ No newline at end of file diff --git a/电子展板/WebServer.cs b/电子展板/WebServer.cs index d16bbd4..a499d47 100644 --- a/电子展板/WebServer.cs +++ b/电子展板/WebServer.cs @@ -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(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(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 /// /// Web启动类 /// @@ -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; } + + /// + /// By default, only read/write props are shown, this + /// prop allows read only props to be shown. + /// + 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) + { + } + + /// + /// Ignore this property when generating swagger model. + /// + public bool Ignore { get; set; } + } +} +#endif \ No newline at end of file diff --git a/电子展板/电子展板.csproj b/电子展板/电子展板.csproj index 5e80763..03db732 100644 --- a/电子展板/电子展板.csproj +++ b/电子展板/电子展板.csproj @@ -8,6 +8,10 @@ favicon.ico app.manifest + + + $(DefineConstants);Nancy + @@ -17,37 +21,53 @@ PreserveNewest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - +