Skip to content

Commit 0b51efc

Browse files
author
liuliang
committed
11
1 parent c70f8d7 commit 0b51efc

File tree

514 files changed

+185850
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

514 files changed

+185850
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Web.Models;
8+
using Tibos.Service;
9+
using Tibos.Common;
10+
using Microsoft.AspNetCore.Http;
11+
using System.Security.Cryptography;
12+
using System.Text;
13+
using Microsoft.AspNetCore.Hosting;
14+
using System.IO;
15+
using System.Collections;
16+
using Tibos.Web.Models;
17+
18+
namespace Web.Controllers
19+
{
20+
public class HomeController : Controller
21+
{
22+
private IHostingEnvironment hostingEnv;
23+
private IViewRenderService _viewRenderService;
24+
public HomeController(IHostingEnvironment env, IViewRenderService viewSendeRenderService)
25+
{
26+
_viewRenderService = viewSendeRenderService;
27+
hostingEnv = env;
28+
}
29+
public IActionResult Index()
30+
{
31+
ViewData["GUID"] = Guid.NewGuid();
32+
return View();
33+
}
34+
public IActionResult Login()
35+
{
36+
return View();
37+
}
38+
39+
public IActionResult About()
40+
{
41+
return View();
42+
}
43+
44+
public IActionResult Home()
45+
{
46+
return View();
47+
}
48+
public IActionResult Api()
49+
{
50+
return View();
51+
}
52+
53+
public IActionResult Api2()
54+
{
55+
return View();
56+
}
57+
58+
public IActionResult Test()
59+
{
60+
return View();
61+
}
62+
63+
public IActionResult Html()
64+
{
65+
return View();
66+
}
67+
68+
List<Wiki> list_wiki = new List<Wiki>();
69+
70+
public IActionResult Wiki()
71+
{
72+
list_wiki = new List<Wiki>();
73+
list_wiki.Add(new Controllers.Wiki() { title = "Web区域", content = "测试,测试,测试", ClientType = "IOS", id = 1 });
74+
list_wiki.Add(new Controllers.Wiki() { title = "IOS区域", content = "测试,测试,测试", ClientType = "Android", id = 2 });
75+
list_wiki.Add(new Controllers.Wiki() { title = "Android区域", content = "测试,测试,测试", ClientType = "Web", id = 3 });
76+
ViewData["list_wiki"] = list_wiki;
77+
return View();
78+
}
79+
80+
[HttpPost]
81+
public JsonResult GetSubWiki(int id)
82+
{
83+
list_wiki = new List<Wiki>();
84+
var res = "<pre class=\"prettyprint lang-cs\">public JsonResult GetWikiList(int limit = 10, int offset = 1)</ pre ><br /> 测试,测试";
85+
86+
list_wiki.Add(new Controllers.Wiki() { title = "怎么调用API?", content = res, ClientType = "IOS", id = 1 });
87+
list_wiki.Add(new Controllers.Wiki() { title = "注册", content = "测试,测试,测试", ClientType = "Android", id = 2 });
88+
list_wiki.Add(new Controllers.Wiki() { title = "登录", content = "测试,测试,测试", ClientType = "Web", id = 3 });
89+
return Json(list_wiki);
90+
}
91+
92+
public IActionResult UpImg()
93+
{
94+
return View();
95+
}
96+
[HttpGet]
97+
public ActionResult GetAuthCode()
98+
{
99+
string pic_code = "";
100+
byte[] b = new VerifyCode().GetVerifyCode(ref pic_code);
101+
HttpContext.Session.SetString("pic_code", pic_code);//存入session
102+
return File(b, @"image/Gif");
103+
}
104+
105+
[HttpPost]
106+
public JsonResult Login(string user_name, string password, string code, string returnUrl)
107+
{
108+
Json json = new Tibos.Common.Json();
109+
string pic_code = HttpContext.Session.GetString("pic_code");
110+
using (var md5 = MD5.Create())
111+
{
112+
var res = md5.ComputeHash(Encoding.UTF8.GetBytes(code.ToLower()));
113+
code = BitConverter.ToString(res);
114+
}
115+
if (pic_code != code)
116+
{
117+
json.status = -1;
118+
json.msg = "验证码不正确";
119+
}
120+
121+
if (!String.IsNullOrEmpty(returnUrl))
122+
{
123+
json.returnUrl = returnUrl;
124+
}
125+
else
126+
{
127+
json.returnUrl = "/home/index";
128+
}
129+
return Json(json);
130+
}
131+
132+
public IActionResult Error()
133+
{
134+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
135+
}
136+
137+
138+
139+
public async Task<IActionResult> KKK()
140+
{
141+
var result = await _viewRenderService.RenderToStringAsync("Home/index", "");
142+
await WriteViewAsync(result);
143+
return Content(result);
144+
}
145+
146+
147+
148+
149+
public async Task<IActionResult> UeditorUpload()
150+
{
151+
var files = Request.Form.Files;
152+
string callback = Request.Query["callback"];
153+
string editorId = Request.Query["editorid"];
154+
if (files != null && files.Count > 0)
155+
{
156+
var file = files[0];
157+
string contentPath = hostingEnv.WebRootPath;
158+
string fileDir = Path.Combine(contentPath, "upload");
159+
if (!Directory.Exists(fileDir))
160+
{
161+
Directory.CreateDirectory(fileDir);
162+
}
163+
string fileExt = Path.GetExtension(file.FileName);
164+
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileExt;
165+
string filePath = Path.Combine(fileDir, newFileName);
166+
using (FileStream fs = new FileStream(filePath, FileMode.Create))
167+
{
168+
await file.CopyToAsync(fs);
169+
}
170+
var fileInfo = getUploadInfo("../../../upload/" + newFileName, file.FileName,
171+
Path.GetFileName(filePath), file.Length, fileExt);
172+
string json = BuildJson(fileInfo);
173+
174+
Response.ContentType = "text/html";
175+
if (callback != null)
176+
{
177+
await Response.WriteAsync(String.Format("<script>{0}(JSON.parse(\"{1}\"));</script>", callback, json));
178+
}
179+
else
180+
{
181+
await Response.WriteAsync(json);
182+
}
183+
return View();
184+
}
185+
return NoContent();
186+
}
187+
private string BuildJson(Hashtable info)
188+
{
189+
List<string> fields = new List<string>();
190+
string[] keys = new string[] { "originalName", "name", "url", "size", "state", "type" };
191+
for (int i = 0; i < keys.Length; i++)
192+
{
193+
fields.Add(String.Format("\"{0}\": \"{1}\"", keys[i], info[keys[i]]));
194+
}
195+
return "{" + String.Join(",", fields) + "}";
196+
}
197+
/**
198+
* 获取上传信息
199+
* @return Hashtable
200+
*/
201+
private Hashtable getUploadInfo(string URL, string originalName, string name, long size, string type, string state = "SUCCESS")
202+
{
203+
Hashtable infoList = new Hashtable();
204+
205+
infoList.Add("state", state);
206+
infoList.Add("url", URL);
207+
infoList.Add("originalName", originalName);
208+
infoList.Add("name", Path.GetFileName(URL));
209+
infoList.Add("size", size);
210+
infoList.Add("type", Path.GetExtension(originalName));
211+
212+
return infoList;
213+
}
214+
215+
216+
217+
218+
219+
/// <summary>
220+
/// 将视图写入文件
221+
/// </summary>
222+
/// <param name="info">路由信息</param>
223+
/// <returns></returns>
224+
public async Task WriteViewAsync(string html)
225+
{
226+
//创建文件流
227+
FileStream myfs = new FileStream(@"E:\GitProject\nh.core\Tibos.Web\temp\aaa.html", FileMode.Create);
228+
//打开方式
229+
//1:Create 用指定的名称创建一个新文件,如果文件已经存在则改写旧文件
230+
//2:CreateNew 创建一个文件,如果文件存在会发生异常,提示文件已经存在
231+
//3:Open 打开一个文件 指定的文件必须存在,否则会发生异常
232+
//4:OpenOrCreate 打开一个文件,如果文件不存在则用指定的名称新建一个文件并打开它.
233+
//5:Append 打开现有文件,并在文件尾部追加内容.
234+
235+
//创建写入器
236+
StreamWriter mySw = new StreamWriter(myfs);//将文件流给写入器
237+
//将录入的内容写入文件
238+
mySw.Write(html);
239+
//关闭写入器
240+
mySw.Close();
241+
//关闭文件流
242+
myfs.Close();
243+
}
244+
245+
246+
247+
}
248+
public class Wiki
249+
{
250+
251+
public int id { get; set; }
252+
public string title { get; set; }
253+
254+
public string ClientType { get; set; }
255+
256+
public string content { get; set; }
257+
}
258+
259+
260+
261+
262+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.Filters;
4+
using Microsoft.Extensions.Caching.Memory;
5+
using Microsoft.Extensions.Logging;
6+
using Newtonsoft.Json;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Globalization;
10+
using System.Linq;
11+
using System.Threading.Tasks;
12+
using Tibos.Common;
13+
using Tibos.Service.Contract;
14+
15+
namespace Tibos.Web.Filters
16+
{
17+
public class ActionFilterAttribute : Attribute, IActionFilter
18+
{
19+
20+
21+
public void OnActionExecuting(ActionExecutingContext context)
22+
{
23+
24+
}
25+
public void OnActionExecuted(ActionExecutedContext context)
26+
{
27+
28+
}
29+
}
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.AspNetCore.Mvc.Filters;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Tibos.Web.Filters
9+
{
10+
public class ExceptionFilterAttribute: IFilterMetadata
11+
{
12+
private readonly ILogger<ExceptionFilterAttribute> logger;
13+
14+
public ExceptionFilterAttribute(ILoggerFactory loggerFactory)
15+
{
16+
logger = loggerFactory.CreateLogger<ExceptionFilterAttribute>();
17+
}
18+
19+
public void OnException(ExceptionContext context)
20+
{
21+
logger.LogError("Exception Execute! Message:" + context.Exception.Message);
22+
context.ExceptionHandled = true;
23+
}
24+
}
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Castle.Core.Logging;
2+
using Microsoft.AspNetCore.Mvc.Filters;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace Tibos.Web.Filters
10+
{
11+
public class ResourceFilterAttribute : Attribute, IResourceFilter
12+
{
13+
private readonly ILogger<ResourceFilterAttribute> logger;
14+
15+
public ResourceFilterAttribute(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
16+
{
17+
logger = loggerFactory.CreateLogger<ResourceFilterAttribute>();
18+
}
19+
20+
public void OnResourceExecuted(ResourceExecutedContext context)
21+
{
22+
23+
}
24+
25+
public void OnResourceExecuting(ResourceExecutingContext context)
26+
{
27+
28+
}
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.AspNetCore.Mvc.Filters;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Tibos.Web.Filters
9+
{
10+
public class ResultFilterAttribute : Attribute, IResultFilter
11+
{
12+
private readonly ILogger<ResultFilterAttribute> logger;
13+
14+
public ResultFilterAttribute(ILoggerFactory loggerFactory)
15+
{
16+
logger = loggerFactory.CreateLogger<ResultFilterAttribute>();
17+
}
18+
19+
public void OnResultExecuted(ResultExecutedContext context)
20+
{
21+
22+
}
23+
24+
public void OnResultExecuting(ResultExecutingContext context)
25+
{
26+
27+
}
28+
}
29+
}

Tibos.Web/Models/ErrorViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Web.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

0 commit comments

Comments
 (0)