转移.net core 3.1,为.NET 5做准备

This commit is contained in:
ÂëÉñ
2020-10-22 14:59:36 +08:00
parent fd9bca23a7
commit a35d596237
1080 changed files with 175912 additions and 185681 deletions

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
namespace Infrastructure.Utilities
{
/// <summary>
/// 动态属性Bag
/// </summary>
public class DynamicPropertyBag : DynamicObject
{
private Dictionary<string, object> storage = new Dictionary<string, object>();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (storage.ContainsKey(binder.Name))
{
result = storage[binder.Name];
return true;
}
result = null;
return false;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
string key = binder.Name;
if (storage.ContainsKey(key))
storage[key] = value;
else
storage.Add(key, value);
return true;
}
public override string ToString()
{
StringWriter message = new StringWriter();
foreach (var item in storage)
message.WriteLine("{0}:\t{1}", item.Key, item.Value);
return message.ToString();
}
}
}

View File

@@ -0,0 +1,13 @@
using Infrastructure.Extensions.AutofacManager;
using Microsoft.AspNetCore.Http;
namespace Infrastructure.Utilities
{
public static class HttpContext
{
private static IHttpContextAccessor _accessor=AutofacContainerModule.GetService<IHttpContextAccessor>();
public static Microsoft.AspNetCore.Http.HttpContext Current => _accessor.HttpContext;
}
}

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Infrastructure.Utilities
{
public class HttpManager
{
public static Task<string> HttpPostAsync(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> headers = null)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
if (!string.IsNullOrEmpty(contentType))
{
request.ContentType = contentType;
}
if (headers != null)
{
foreach (var header in headers)
request.Headers[header.Key] = header.Value;
}
try
{
byte[] bytes = Encoding.UTF8.GetBytes(postData ?? "");
using (Stream sendStream = request.GetRequestStream())
{
sendStream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
return streamReader.ReadToEndAsync();
}
}
catch (Exception ex)
{
return Task.FromResult(ex.Message);
}
}
public static Task<string> HttpGetAsync(string url, Dictionary<string, string> headers = null)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
if (headers != null)
{
foreach (var header in headers)
request.Headers[header.Key] = header.Value;
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
return streamReader.ReadToEndAsync();
}
}
catch (Exception ex)
{
return Task.FromResult(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,64 @@
using System.IO;
using System.Linq;
using Infrastructure.Extensions;
namespace Infrastructure.Utilities
{
public class ProjectPath
{
/// <summary>
/// 获取web父目录所在位置
/// </summary>
/// <returns></returns>
public static DirectoryInfo GetProjectDirectoryInfo()
{
return GetProjectDirectoryInfo(new DirectoryInfo("".MapPath()), 1);
}
/// <summary>
/// 获取指定结尾的项目名称
/// </summary>
/// <param name="lastIndexOfName"></param>
/// <returns></returns>
public static string GetLastIndexOfDirectoryName(string lastIndexOfName)
{
string projectName = GetProjectDirectoryInfo()?.GetDirectories()
.Where(c => c.Name.LastIndexOf(lastIndexOfName) != -1).Select(x => x.Name).FirstOrDefault();
if (string.IsNullOrEmpty(projectName))
{
projectName = new DirectoryInfo("".MapPath()).GetFiles().Where(x => x.Name.LastIndexOf(lastIndexOfName + ".dll") != -1).FirstOrDefault().Name;
if (!string.IsNullOrEmpty(projectName))
{
projectName = projectName.Replace(".dll", "");
}
}
return projectName;
}
/// <summary>
/// 获取项目所在路径
/// </summary>
/// <param name="directoryInfo"></param>
/// <returns></returns>
private static DirectoryInfo GetProjectDirectoryInfo(DirectoryInfo directoryInfo, int findCount)
{
if (directoryInfo == null)
{
return null;
}
if (directoryInfo.Exists
&& directoryInfo.GetDirectories().Where(x => x.Name.LastIndexOf(".Mvc") != -1).FirstOrDefault() != null)
{
return directoryInfo;
}
if (findCount < 7)
{
findCount++;
DirectoryInfo dir = GetProjectDirectoryInfo(directoryInfo.Parent, findCount);
if (dir != null)
{
return dir;
}
}
return null;
}
}
}

View File

@@ -0,0 +1,59 @@
using Infrastructure.Const;
namespace Infrastructure.Utilities
{
public static class ResponseMsg
{
public static string GetMsg(this ResponseType responseType)
{
string msg;
switch (responseType)
{
case ResponseType.LoginExpiration:
msg = "登陆已过期,请重新登陆"; break;
case ResponseType.TokenExpiration:
msg = "Token已过期,请重新登陆"; break;
case ResponseType.AccountLocked:
msg = "帐号已被锁定"; break;
case ResponseType.LoginSuccess:
msg = "登陆成功"; break;
case ResponseType.ParametersLack:
msg = "参数不完整"; break;
case ResponseType.NoPermissions:
msg = "没有权限操作"; break;
case ResponseType.NoRolePermissions:
msg = "角色没有权限操作"; break;
case ResponseType.ServerError:
msg = "服务器好像出了点问题....."; break;
case ResponseType.LoginError:
msg = "用户名或密码错误"; break;
case ResponseType.SaveSuccess:
msg = "保存成功"; break;
case ResponseType.NoKey:
msg = "没有主键不能编辑"; break;
case ResponseType.NoKeyDel:
msg = "没有主键不能删除"; break;
case ResponseType.KeyError:
msg = "主键不正确或没有传入主键"; break;
case ResponseType.EidtSuccess:
msg = "编辑成功"; break;
case ResponseType.DelSuccess:
msg = "删除成功"; break;
case ResponseType.RegisterSuccess:
msg = "注册成功"; break;
case ResponseType.AuditSuccess:
msg = "审核成功"; break;
case ResponseType.ModifyPwdSuccess:
msg = "密码修改成功"; break;
case ResponseType.OperSuccess:
msg = "操作成功"; break;
case ResponseType.PINError:
msg = "验证码不正确"; break;
default: msg = responseType.ToString(); break;
}
return msg;
}
}
}

View File

@@ -0,0 +1,74 @@
// ***********************************************************************
// Assembly : Infrastructure
// Author : yubaolee
// Created : 06-21-2016
//
// Last Modified By : yubaolee
// Last Modified On : 06-22-2016
// Contact :
// File: UriUtil.cs
// ***********************************************************************
using System;
using System.Collections.Specialized;
using System.Web;
namespace Infrastructure.Utilities
{
/// <summary>
/// URl帮助类
/// </summary>
public class UriUtil
{
/// <summary>
/// 在URL后面追加参数
/// </summary>
/// <param name="url"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string GetAppendedQueryString(string url, string key, string value)
{
if (url.Contains("?"))
{
url = string.Format("{0}&{1}={2}", url, key, value);
}
else
{
url = string.Format("{0}?{1}={2}", url, key, value);
}
return url;
}
public static string RemoveParameter(string url, string key)
{
url = url.ToLower();
key = key.ToLower();
if (!url.Contains(key + "=")) return url;
Uri uri = new Uri(url);
NameValueCollection collection = HttpUtility.ParseQueryString(uri.Query);
if (collection.Count == 0) return url;
var val = collection[key];
string fragmentToRemove = string.Format("{0}={1}",key , val);
String result = url.ToLower().Replace("&" + fragmentToRemove, string.Empty).Replace("?" + fragmentToRemove, string.Empty);
return result;
}
/// <summary>
/// 根据URL的相对地址获取决定路径
/// <para>eg: /Home/About ==>http://192.168.0.1/Home/About</para>
/// </summary>
/// <returns>System.String.</returns>
//public static string GetAbsolutePathForRelativePath(string relativePath)
//{
// HttpRequest Request = HttpContext.Current.Request;
// string returnUrl = string.Format("{0}{1}",Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) , VirtualPathUtility.ToAbsolute(relativePath));
// return returnUrl;
//}
}
}

View File

@@ -0,0 +1,81 @@
using Infrastructure.Const;
namespace Infrastructure.Utilities
{
public class WebResponseContent : Response
{
public WebResponseContent()
{
Code = 200;
Message = "操作成功";
}
public WebResponseContent(bool status)
{
this.Status = status;
}
public bool Status { get; set; }
public object Result { get; set; }
public WebResponseContent OK()
{
this.Status = true;
return this;
}
public static WebResponseContent Instance
{
get { return new WebResponseContent(); }
}
public WebResponseContent OK(string message = null,object data=null)
{
this.Status = true;
this.Message = message;
this.Result = data;
return this;
}
public WebResponseContent OK(ResponseType responseType)
{
return Set(responseType, true);
}
public WebResponseContent Error(string message = null)
{
this.Status = false;
this.Message = message;
return this;
}
public WebResponseContent Error(ResponseType responseType)
{
return Set(responseType, false);
}
public WebResponseContent Set(ResponseType responseType)
{
bool? b = null;
return this.Set(responseType, b);
}
public WebResponseContent Set(ResponseType responseType, bool? status)
{
return this.Set(responseType, null, status);
}
public WebResponseContent Set(ResponseType responseType, string msg)
{
bool? b = null;
return this.Set(responseType, msg, b);
}
public WebResponseContent Set(ResponseType responseType, string msg, bool? status)
{
if (status != null)
{
this.Status = (bool)status;
}
this.Code = (int)responseType;
if (!string.IsNullOrEmpty(msg))
{
Message = msg;
return this;
}
Message = responseType.GetMsg();
return this;
}
}
}