简化使用
This commit is contained in:
@@ -1,80 +1,80 @@
|
||||
using System;
|
||||
using Nancy.Swagger.Annotations.Attributes;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using 电子展板.Base;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置类
|
||||
/// </summary>
|
||||
[SwaggerClassComment("配置项")]
|
||||
[Model("配置项")]
|
||||
public class MyConfig : ModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
[Comment("时间")]
|
||||
[SwaggerComment("时间", true)]
|
||||
[ModelProperty(Description = "时间", Required = true)]
|
||||
public string Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间字体大小
|
||||
/// </summary>
|
||||
[Comment("时间字体大小")]
|
||||
[SwaggerComment("时间字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "时间字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int TimeSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 负责人
|
||||
/// </summary>
|
||||
[Comment("负责人")]
|
||||
[SwaggerComment("负责人", true)]
|
||||
[ModelProperty(Description = "负责人", Required = true)]
|
||||
public string Charger { get; set; }
|
||||
/// <summary>
|
||||
/// 负责人字体大小
|
||||
/// </summary>
|
||||
[Comment("负责人字体大小")]
|
||||
[SwaggerComment("负责人字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "负责人字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int ChargerSize { get; set; }
|
||||
/// <summary>
|
||||
/// 风险等级
|
||||
/// </summary>
|
||||
[Comment("风险等级")]
|
||||
[SwaggerComment("风险等级", true)]
|
||||
[ModelProperty(Description = "风险等级", Required = true)]
|
||||
public string RiskLevel { get; set; }
|
||||
/// <summary>
|
||||
/// 风险等级字体大小
|
||||
/// </summary>
|
||||
[Comment("风险等级字体大小")]
|
||||
[SwaggerComment("风险等级字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "风险等级字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int RiskLevelSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工作内容
|
||||
/// </summary>
|
||||
[Comment("工作内容")]
|
||||
[SwaggerComment("工作内容", true)]
|
||||
[ModelProperty(Description = "工作内容", Required = true)]
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 工作内容字体大小
|
||||
/// </summary>
|
||||
[Comment("工作内容字体大小")]
|
||||
[SwaggerComment("工作内容字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "工作内容字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int ContentSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 危险点
|
||||
/// </summary>
|
||||
[Comment("危险点")]
|
||||
[SwaggerComment("危险点", true)]
|
||||
[ModelProperty(Description = "危险点", Required = true)]
|
||||
public string DangerPoint { get; set; }
|
||||
/// <summary>
|
||||
/// 危险点
|
||||
/// </summary>
|
||||
[Comment("危险点字体大小")]
|
||||
[SwaggerComment("危险点字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "危险点字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int DangerPointSize { get; set; }
|
||||
|
||||
|
||||
@@ -82,40 +82,41 @@ namespace 电子展板.Models
|
||||
/// 重点措施
|
||||
/// </summary>
|
||||
[Comment("重点措施")]
|
||||
[SwaggerComment("重点措施", true)]
|
||||
[ModelProperty(Description = "重点措施", Required = true)]
|
||||
public string Measures { get; set; }
|
||||
|
||||
[Comment("重点措施字体大小")]
|
||||
[ModelProperty(Description = "重点措施字体大小", Required = true)]
|
||||
public int MeasuresSize { get; set; }
|
||||
|
||||
[Comment("党员1图片路径")]
|
||||
[SwaggerComment("党员1图片路径", true)]
|
||||
[ModelProperty(Description = "党员1图片路径", Required = true)]
|
||||
public string CPCMember1Path { get; set; }
|
||||
[Comment("党员1姓名")]
|
||||
[SwaggerComment("党员1姓名", true)]
|
||||
[ModelProperty(Description = "党员1姓名", Required = true)]
|
||||
public string CPCMember1Name { get; set; }
|
||||
[Comment("党员2图片路径")]
|
||||
[SwaggerComment("党员2图片路径", true)]
|
||||
[ModelProperty(Description = "党员2图片路径", Required = true)]
|
||||
public string CPCMember2Path { get; set; }
|
||||
[Comment("党员2姓名")]
|
||||
[SwaggerComment("党员2姓名", true)]
|
||||
[ModelProperty(Description = "党员2姓名", Required = true)]
|
||||
public string CPCMember2Name { get; set; }
|
||||
[Comment("党员3图片路径")]
|
||||
[SwaggerComment("党员3图片路径", true)]
|
||||
[ModelProperty(Description = "党员3图片路径", Required = true)]
|
||||
public string CPCMember3Path { get; set; }
|
||||
|
||||
[Comment("党员3姓名")]
|
||||
[SwaggerComment("党员3姓名", true)]
|
||||
[ModelProperty(Description = "党员3姓名", Required = true)]
|
||||
public string CPCMember3Name { get; set; }
|
||||
[Comment("党员4图片路径")]
|
||||
[SwaggerComment("党员4图片路径", true)]
|
||||
[ModelProperty(Description = "党员4图片路径", Required = true)]
|
||||
public string CPCMember4Path { get; set; }
|
||||
[Comment("党员4姓名")]
|
||||
[SwaggerComment("党员4姓名", true)]
|
||||
[ModelProperty(Description = "党员4姓名", Required = true)]
|
||||
public string CPCMember4Name { get; set; }
|
||||
|
||||
[Comment("党员字体大小")]
|
||||
[SwaggerComment("党员字体大小", true, 15, 60)]
|
||||
[ModelProperty(Description = "党员字体大小", Required = true, Minimum = 15, Maximum = 60)]
|
||||
public int CPCMemberSize { get; set; }
|
||||
/// <summary>
|
||||
/// 转换成JSON字符串
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using System;
|
||||
using Nancy.Swagger.Annotations.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.Models
|
||||
{
|
||||
[SwaggerClassComment("返回数据")]
|
||||
public class RetValue
|
||||
[Model("返回数据")]
|
||||
public class RetValue<T>
|
||||
{
|
||||
[SwaggerComment("返回状态")]
|
||||
[ModelProperty("返回状态")]
|
||||
public int state { get; set; }
|
||||
[SwaggerComment("返回消息")]
|
||||
[ModelProperty("返回消息")]
|
||||
public string message { get; set; }
|
||||
[SwaggerComment("返回数据")]
|
||||
public object data { get; set; }
|
||||
|
||||
[ModelProperty("返回数据")]
|
||||
public T data { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 电子展板.Utility
|
||||
{
|
||||
public class ContentTypeUtils
|
||||
{
|
||||
public static string GetContentType(string fileName)
|
||||
{
|
||||
return System.Web.MimeMapping.GetMimeMapping(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 电子展板.Utility.Swagger
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class SwaggerClassCommentAttribute : Attribute
|
||||
{
|
||||
public string Comment { get; set; }
|
||||
public SwaggerClassCommentAttribute(string comment)
|
||||
{
|
||||
Comment = comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 电子展板.Utility.Swagger
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class SwaggerCommentAttribute : Attribute
|
||||
{
|
||||
public string Comment { get; set; }
|
||||
public bool? IsRequired { get; set; }
|
||||
|
||||
public long? Min { get; set; }
|
||||
public long? Max { get; set; }
|
||||
public SwaggerCommentAttribute()
|
||||
{
|
||||
Comment = "";
|
||||
}
|
||||
public SwaggerCommentAttribute(string comment)
|
||||
{
|
||||
Comment = comment;
|
||||
}
|
||||
public SwaggerCommentAttribute(string comment, bool isRequired)
|
||||
{
|
||||
Comment = comment;
|
||||
IsRequired = isRequired;
|
||||
}
|
||||
public SwaggerCommentAttribute(string comment, bool isRequired, long min, long max)
|
||||
{
|
||||
Comment = comment;
|
||||
IsRequired = isRequired;
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using Nancy.Swagger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 电子展板.Utility.Swagger
|
||||
{
|
||||
public static class SwaggerModelDataUtils
|
||||
{
|
||||
public static SwaggerModelData GetModelData<T>()
|
||||
{
|
||||
return SwaggerModelData.ForType<T>(with =>
|
||||
{
|
||||
Type type = typeof(T);
|
||||
SwaggerClassCommentAttribute classComment = type.GetCustomAttribute<SwaggerClassCommentAttribute>();
|
||||
with.Description(classComment != null ? classComment.Comment : type.Name);
|
||||
PropertyInfo[] propertyInfos = typeof(T).GetProperties();
|
||||
foreach (PropertyInfo propertyInfo in propertyInfos)
|
||||
{
|
||||
SwaggerModelPropertyData ss = with.Data.Properties.Where(x => x.Name == propertyInfo.Name).FirstOrDefault();
|
||||
SwaggerCommentAttribute attribute = propertyInfo.GetCustomAttribute<SwaggerCommentAttribute>();
|
||||
if (attribute == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(attribute.Comment))
|
||||
ss.Description = attribute.Comment;
|
||||
if (attribute.IsRequired != null)
|
||||
ss.Required = attribute.IsRequired.Value;
|
||||
if (attribute.Min != null)
|
||||
ss.Minimum = attribute.Min.Value;
|
||||
if (attribute.Max != null)
|
||||
ss.Maximum = attribute.Max.Value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using Nancy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace 电子展板.Utility.Swagger
|
||||
{
|
||||
public class SwaggerModule : NancyModule
|
||||
{
|
||||
public SwaggerModule()
|
||||
{
|
||||
//全局静态资源
|
||||
Get("/swagger", RedirectToIndex);
|
||||
Get("/swagger/index.html", Index);
|
||||
Get("/swagger/{name*}", StaticResource);
|
||||
}
|
||||
|
||||
private object RedirectToIndex(dynamic dynamic)
|
||||
{
|
||||
return Response.AsRedirect("/swagger/index.html");
|
||||
}
|
||||
|
||||
private object Index(dynamic dynamic)
|
||||
{
|
||||
var url = $"{Request.Url.BasePath}/api-docs";
|
||||
string packUri = $"pack://application:,,,/Assets/SwaggerUI/index.html";
|
||||
string contentType = System.Web.MimeMapping.GetMimeMapping(packUri);
|
||||
byte[] bytes = null;
|
||||
using (var stream = System.Windows.Application.GetResourceStream(new Uri(packUri, UriKind.RelativeOrAbsolute)).Stream)
|
||||
{
|
||||
bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, bytes.Length);
|
||||
}
|
||||
string html = Encoding.UTF8.GetString(bytes);
|
||||
html = html.Replace("@url", url);
|
||||
return Response.AsText(html, contentType);
|
||||
}
|
||||
|
||||
private object StaticResource(dynamic dynamic)
|
||||
{
|
||||
string name = dynamic.name;
|
||||
return Resouce(name);
|
||||
}
|
||||
|
||||
private object Resouce(string resourcePath)
|
||||
{
|
||||
if (resourcePath == "")
|
||||
resourcePath = "index.html";
|
||||
string packUri = $"pack://application:,,,/Assets/SwaggerUI/{resourcePath}";
|
||||
string contentType = System.Web.MimeMapping.GetMimeMapping(packUri);
|
||||
return Response.FromStream(System.Windows.Application.GetResourceStream(new Uri(packUri, UriKind.RelativeOrAbsolute)).Stream, contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Conventions;
|
||||
using Nancy.Swagger.Annotations;
|
||||
using Nancy.Swagger.Services;
|
||||
using Nancy.TinyIoc;
|
||||
using Swagger.ObjectModel;
|
||||
@@ -18,6 +19,8 @@ namespace 电子展板.WebModule
|
||||
Url = "https://www.cnblogs.com/zjwno1"
|
||||
}, "http://www.cnblogs.com/zjwno1");
|
||||
base.ApplicationStartup(container, pipelines);
|
||||
//仅显示有特性的接口
|
||||
SwaggerAnnotationsConfig.ShowOnlyAnnotatedRoutes = true;
|
||||
}
|
||||
|
||||
protected override void ConfigureConventions(NancyConventions nancyConventions)
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
using Nancy.Metadata.Modules;
|
||||
using Nancy.Swagger;
|
||||
using Swagger.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using 电子展板.Models;
|
||||
using 电子展板.Utility.Core;
|
||||
|
||||
namespace 电子展板.WebModule
|
||||
{
|
||||
public class HomeMetadataModule : MetadataModule<PathItem>
|
||||
{
|
||||
public HomeMetadataModule(ISwaggerModelCatalog modelCatalog)
|
||||
{
|
||||
//添加模型
|
||||
modelCatalog.AddModels(typeof(MyConfig));
|
||||
Describe["getConfig"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("getConfig");
|
||||
//设置tag
|
||||
op.Tag("getConfig");
|
||||
//备注
|
||||
op.Summary("获得当前配置");
|
||||
//参数配置
|
||||
//op.BodyParameter(p =>
|
||||
// p.Description("配置项")
|
||||
// .Name("Config")
|
||||
// .Schema<MyConfig>()
|
||||
//);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
//.Example("application/json", JsonHelper.ToJson(GlobalVariable.Config))
|
||||
.Schema<MyConfig>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Describe["uploadImage"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("uploadImage");
|
||||
//设置tag
|
||||
op.Tag("uploadImage");
|
||||
//备注
|
||||
op.Summary("上传照片");
|
||||
//文件上传
|
||||
op.ConsumeMimeType("multipart/form-data");
|
||||
//参数配置
|
||||
op.Parameter(p =>
|
||||
p.In(ParameterIn.Form)
|
||||
.Name("file")//参数名
|
||||
.Type("file")//文件类型
|
||||
.Description("上传文件")
|
||||
.IsRequired()
|
||||
);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
.Example("application/json", new RetValue { state = 1, message = "上传成功", data = "/upload/123.png" }.ToJson())
|
||||
.Schema<RetValue>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Describe["save"] = description => description.AsSwagger(
|
||||
with => with.Operation(
|
||||
op =>
|
||||
{
|
||||
//设置操作id
|
||||
op.OperationId("save");
|
||||
//设置tag
|
||||
op.Tag("save");
|
||||
//备注
|
||||
op.Summary("保存配置");
|
||||
//参数配置
|
||||
op.BodyParameter(p =>
|
||||
p.Description("配置项")
|
||||
.Name("Config")
|
||||
.Schema<MyConfig>()
|
||||
);
|
||||
//返回值配置
|
||||
op.Response(r =>
|
||||
r.Description("返回数据")
|
||||
.Example("application/json", new RetValue { state = 1, message = "保存成功" }.ToJson())
|
||||
.Schema<RetValue>()
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using Nancy;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Swagger;
|
||||
using Nancy.Swagger.Annotations.Attributes;
|
||||
using Swagger.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -19,8 +22,14 @@ namespace 电子展板.WebModule
|
||||
{
|
||||
public class HomeModule : NancyModule
|
||||
{
|
||||
public HomeModule()
|
||||
public HomeModule(ISwaggerModelCatalog modelCatalog)
|
||||
{
|
||||
|
||||
//涉及到哪些Model
|
||||
modelCatalog.AddModel<MyConfig>();
|
||||
modelCatalog.AddModel<RetValue<string>>();
|
||||
|
||||
|
||||
//默认页面
|
||||
Get("", Index);
|
||||
Get("/", Index);
|
||||
@@ -33,26 +42,51 @@ namespace 电子展板.WebModule
|
||||
//获得上传的文件
|
||||
Get("/upload/{id}", GetUploadFiles);
|
||||
//上传图片
|
||||
Post("/uploadImage", UploadImage, null, "uploadImage");
|
||||
Post("/uploadImage", dynamic =>
|
||||
{
|
||||
IEnumerable<HttpFile> files = Request.Files;
|
||||
if (files == null || files.Count() == 0)
|
||||
return UploadImage(null);
|
||||
return UploadImage(files.FirstOrDefault());
|
||||
}, null, "uploadImage");
|
||||
//保存配置
|
||||
Post("/save", SaveConfig, null, "save");
|
||||
}
|
||||
//默认页面
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 默认页面
|
||||
/// </summary>
|
||||
/// <param name="dynamic"></param>
|
||||
/// <returns></returns>
|
||||
private object Index(dynamic dynamic)
|
||||
{
|
||||
return Resouce("Views/Index.html");
|
||||
}
|
||||
//全局静态资源
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 全局静态资源
|
||||
/// </summary>
|
||||
/// <param name="dynamic"></param>
|
||||
/// <returns></returns>
|
||||
private object StaticResource(dynamic dynamic)
|
||||
{
|
||||
string name = dynamic.name;
|
||||
return Resouce(name);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获得配置
|
||||
/// </summary>
|
||||
/// <param name="dynamic"></param>
|
||||
/// <returns></returns>
|
||||
[Route("getConfig")]//Name
|
||||
[Route(HttpMethod.Get, "/getConfig")]//Method And Path
|
||||
[Route(Summary = "获得配置数据")]
|
||||
[SwaggerResponse(HttpStatusCode.OK, typeof(MyConfig))]
|
||||
[Route(Tags = new[] { "获得配置数据" })]
|
||||
private object GetConfig(dynamic dynamic)
|
||||
{
|
||||
//保留JSON KEY首字母大写,这里就不用 Response.AsJson();
|
||||
@@ -70,7 +104,7 @@ namespace 电子展板.WebModule
|
||||
private object GetUploadFiles(dynamic dynamic)
|
||||
{
|
||||
string id = dynamic.id;
|
||||
string contentType = System.Web.MimeMapping.GetMimeMapping(id);
|
||||
string contentType = MimeTypes.GetMimeType(id);
|
||||
return Response.AsFile(MyEnvironment.Root("/Upload/" + id), contentType);
|
||||
}
|
||||
|
||||
@@ -79,29 +113,36 @@ namespace 电子展板.WebModule
|
||||
/// </summary>
|
||||
/// <param name="dynamic"></param>
|
||||
/// <returns></returns>
|
||||
private object UploadImage(dynamic dynamic)
|
||||
[Route("uploadImage")]//Name
|
||||
[Route(HttpMethod.Post, "/uploadImage")]//Method And Path
|
||||
[Route(Summary = "上传图片")]
|
||||
[SwaggerResponse(HttpStatusCode.OK, typeof(RetValue<string>))]
|
||||
[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);
|
||||
}
|
||||
List<string> filePathList = new List<string>();
|
||||
foreach (var file in Request.Files)
|
||||
|
||||
string ext = Path.GetExtension(file.Name);
|
||||
string fileName = UUID.StrSnowId + ext;
|
||||
var filePath = uploadPath + fileName;
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
string ext = Path.GetExtension(file.Name);
|
||||
string fileName = UUID.StrSnowId + ext;
|
||||
var filePath = uploadPath + fileName;
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
file.Value.CopyTo(fileStream);
|
||||
}
|
||||
filePathList.Add($"/Upload/{fileName}");
|
||||
file.Value.CopyTo(fileStream);
|
||||
}
|
||||
RetValue result = new RetValue { state = 1, message = "上传成功", data = filePathList.GetStrArray() };
|
||||
RetValue<string> result = new RetValue<string> { state = 1, message = "上传成功", data = $"/upload/{fileName}" };
|
||||
return Response.AsJson(result);
|
||||
}
|
||||
|
||||
|
||||
[Route("save")]//Name
|
||||
[Route(HttpMethod.Post, "/save")]//Method And Path
|
||||
[Route(Summary = "保存配置")]
|
||||
[SwaggerResponse(HttpStatusCode.OK, typeof(RetValue<string>))]
|
||||
[Route(Tags = new[] { "保存配置" })]
|
||||
private object SaveConfig(dynamic dynamic)
|
||||
{
|
||||
MyConfig config = this.Bind<MyConfig>();
|
||||
@@ -119,13 +160,13 @@ namespace 电子展板.WebModule
|
||||
GlobalVariable.SaveConfig();
|
||||
//保存并修改界面
|
||||
EventBus.Instance.Publish("save", "");
|
||||
RetValue result = new RetValue { state = 1, message = "保存成功" };
|
||||
RetValue<string> result = new RetValue<string> { state = 1, message = "保存成功" };
|
||||
return Response.AsJson(result);
|
||||
}
|
||||
private object Resouce(string resourcePath)
|
||||
{
|
||||
string packUri = $"pack://application:,,,/Assets/{resourcePath}";
|
||||
string contentType = System.Web.MimeMapping.GetMimeMapping(packUri);
|
||||
string contentType = MimeTypes.GetMimeType(packUri);
|
||||
return Response.FromStream(System.Windows.Application.GetResourceStream(new Uri(packUri, UriKind.RelativeOrAbsolute)).Stream, contentType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using Nancy.Swagger;
|
||||
using Nancy.Swagger.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using 电子展板.Models;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.WebModule.ModelMetadata
|
||||
{
|
||||
public class MyConfigModelDataProvider : ISwaggerModelDataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用自定义特性注解完成配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SwaggerModelData GetModelData()
|
||||
{
|
||||
return SwaggerModelDataUtils.GetModelData<MyConfig>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Nancy.Swagger;
|
||||
using Nancy.Swagger.Services;
|
||||
using 电子展板.Models;
|
||||
using 电子展板.Utility.Swagger;
|
||||
|
||||
namespace 电子展板.WebModule.ModelMetadata
|
||||
{
|
||||
public class RetValueDataProvider : ISwaggerModelDataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用自定义特性注解完成配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SwaggerModelData GetModelData()
|
||||
{
|
||||
return SwaggerModelDataUtils.GetModelData<RetValue>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,6 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>-->
|
||||
<PackageReference Include="HandyControl" Version="3.5.1" />
|
||||
<PackageReference Include="Nancy.Swagger.Alyce" Version="2.2.76" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -35,9 +31,12 @@
|
||||
<!-- 日志框架 -->
|
||||
<PackageReference Include="NLog" Version="6.0.2" />
|
||||
<!-- WEB 自宿主 -->
|
||||
<Reference Include="System.Web" />
|
||||
<PackageReference Include="Nancy" Version="2.0.0" />
|
||||
<PackageReference Include="ZJW.NancySwagger" Version="2.0.0" />
|
||||
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0" />
|
||||
<!-- 界面UI-->
|
||||
<PackageReference Include="HandyControl" Version="3.5.1" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Upload\0.jpg">
|
||||
|
||||
Reference in New Issue
Block a user