v3.0.1
v3.0.1
This commit is contained in:
@@ -7,10 +7,36 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
|
||||
<PackageReference Include="Castle.Core" Version="4.4.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.12.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.11.0" />
|
||||
<PackageReference Include="ServiceStack.Redis" Version="5.10.4" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="T4Vue\T4Api.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4Api.vue</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4Vue\T4Api.vue">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4Api.tt</DependentUpon>
|
||||
</None>
|
||||
<None Update="T4Vue\T4Component.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>T4Component.vue</LastGenOutput>
|
||||
</None>
|
||||
<None Update="T4Vue\T4Component.vue">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>T4Component.tt</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -17,33 +17,33 @@ namespace CC.Yi.Common.Cache
|
||||
|
||||
|
||||
|
||||
public bool AddCache<T>(string key, T value, DateTime expDate)
|
||||
public static bool AddCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return CacheWriter.AddCache<T>(key,value,expDate);
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value)
|
||||
public static bool AddCache<T>(string key, T value)
|
||||
{
|
||||
return CacheWriter.AddCache<T>(key, value);
|
||||
}
|
||||
|
||||
public bool RemoveCache(string key)
|
||||
public static bool RemoveCache(string key)
|
||||
{
|
||||
return CacheWriter.RemoveCache(key);
|
||||
}
|
||||
|
||||
public T GetCache<T>(string key)
|
||||
public static T GetCache<T>(string key)
|
||||
{
|
||||
return CacheWriter.GetCache<T>(key);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value, DateTime expDate)
|
||||
public static bool SetCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return CacheWriter.SetCache<T>(key,value,expDate);
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value)
|
||||
{
|
||||
public static bool SetCache<T>(string key, T value)
|
||||
{
|
||||
return CacheWriter.SetCache<T>(key, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,39 +8,92 @@ namespace CC.Yi.Common.Cache
|
||||
public class RedisCache : ICacheWriter
|
||||
{
|
||||
private RedisClient client;
|
||||
private string ip = "49.235.212.122";
|
||||
private int port = 6379;
|
||||
private string pwd = "Qz52013142020.";
|
||||
public RedisCache()
|
||||
{
|
||||
client = new RedisClient("127.0.0.1", 6379, "52013142020.");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
client.Dispose();
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return client.Add<T>(key, value, expDate);
|
||||
try
|
||||
{
|
||||
using (client = new RedisClient(ip, port, pwd))
|
||||
{
|
||||
return client.Add<T>(key, value, expDate);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddCache<T>(string key, T value)
|
||||
{
|
||||
return client.Add<T>(key, value);
|
||||
return client.Add<T>(key, value);
|
||||
}
|
||||
|
||||
public bool RemoveCache(string key)
|
||||
{
|
||||
return client.Remove(key);
|
||||
return client.Remove(key);
|
||||
}
|
||||
|
||||
public T GetCache<T>(string key)
|
||||
{
|
||||
return client.Get<T>(key);
|
||||
try
|
||||
{
|
||||
using (client = new RedisClient(ip, port, pwd))
|
||||
{
|
||||
return client.Get<T>(key);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
object p = new object();
|
||||
return (T)p;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key,T value, DateTime expDate)
|
||||
|
||||
|
||||
public bool SetCache<T>(string key, T value, DateTime expDate)
|
||||
{
|
||||
return client.Set<T>(key, value, expDate);
|
||||
try
|
||||
{
|
||||
using (client = new RedisClient(ip, port, pwd))
|
||||
{
|
||||
return client.Set<T>(key, value, expDate);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetCache<T>(string key, T value)
|
||||
{
|
||||
return client.Set<T>(key, value);
|
||||
try
|
||||
{
|
||||
using (client = new RedisClient(ip, port, pwd))
|
||||
{
|
||||
return client.Set<T>(key, value);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
object p = new object();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
113
CC.Yi/CC.Yi.Common/EmailHelper.cs
Normal file
113
CC.Yi/CC.Yi.Common/EmailHelper.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
public class EmailHelper
|
||||
{
|
||||
public static bool sendMail(string subject, string body, string toMail)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
string fromMail = "454313500@qq.com";
|
||||
string pwdMail = "yvjioburildgbhdf";
|
||||
MailMessage message = new MailMessage();
|
||||
//设置发件人,发件人需要与设置的邮件发送服务器的邮箱一致
|
||||
System.Net.Mail.MailAddress fromAddr = new System.Net.Mail.MailAddress(fromMail, "江西服装学院论坛");
|
||||
message.From = fromAddr;
|
||||
|
||||
//设置收件人,可添加多个,添加方法与下面的一样
|
||||
message.To.Add(toMail);
|
||||
|
||||
|
||||
//设置邮件标题
|
||||
message.Subject = subject;
|
||||
|
||||
//设置邮件内容
|
||||
message.Body = body;
|
||||
|
||||
//设置邮件发送服务器,服务器根据你使用的邮箱而不同,可以到相应的 邮箱管理后台查看,下面是QQ的
|
||||
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.qq.com", 25)
|
||||
;
|
||||
//设置发送人的邮箱账号和密码,POP3/SMTP服务要开启, 密码要是POP3/SMTP等服务的授权码
|
||||
client.Credentials = new System.Net.NetworkCredential(fromMail, pwdMail);//vtirsfsthwuadjfe fhszmpegwoqnecja
|
||||
|
||||
//启用ssl,也就是安全发送
|
||||
client.EnableSsl = true;
|
||||
|
||||
//发送邮件
|
||||
client.Send(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void 接受邮件()
|
||||
{
|
||||
using (TcpClient client = new TcpClient("pop.qq.com", 110))
|
||||
using (NetworkStream n = client.GetStream())
|
||||
{
|
||||
GetEmail.ReadLine(n); // Read the welcome message.
|
||||
GetEmail.SendCommand(n, "USER 1040079213@qq.com");
|
||||
GetEmail.SendCommand(n, "PASS odfaizoqdiupbfgi");
|
||||
GetEmail.SendCommand(n, "LIST"); // Retrieve message IDs
|
||||
List<int> messageIDs = new List<int>();
|
||||
while (true)
|
||||
{
|
||||
string line = GetEmail.ReadLine(n); // e.g., "11876"
|
||||
if (line == ".") break;
|
||||
messageIDs.Add(int.Parse(line.Split(' ')[0])); // Message ID
|
||||
}
|
||||
foreach (int id in messageIDs) // Retrieve each message.
|
||||
{
|
||||
GetEmail.SendCommand(n, "RETR " + id);
|
||||
string randomFile = Guid.NewGuid().ToString() + ".eml";
|
||||
using (StreamWriter writer = File.CreateText(randomFile))
|
||||
while (true)
|
||||
{
|
||||
string line = GetEmail.ReadLine(n); // Read next line of message.
|
||||
if (line == ".") break; // Single dot = end of message.
|
||||
if (line == "..") line = "."; // "Escape out" double dot.
|
||||
writer.WriteLine(line); // Write to output file.
|
||||
}
|
||||
GetEmail.SendCommand(n, "DELE " + id); // Delete message off server.
|
||||
}
|
||||
GetEmail.SendCommand(n, "QUIT");
|
||||
}
|
||||
}
|
||||
}
|
||||
//接受邮件pop
|
||||
public class GetEmail
|
||||
{
|
||||
public static void SendCommand(Stream stream, string line)
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes(line + "\r\n");
|
||||
stream.Write(data, 0, data.Length);
|
||||
string response = ReadLine(stream);
|
||||
if (!response.StartsWith("+OK"))
|
||||
throw new Exception("POP Error: " + response);
|
||||
}
|
||||
public static string ReadLine(Stream s)
|
||||
{
|
||||
List<byte> lineBuffer = new List<byte>();
|
||||
while (true)
|
||||
{
|
||||
int b = s.ReadByte();
|
||||
if (b == 10 || b < 0) break;
|
||||
if (b != 13) lineBuffer.Add((byte)b);
|
||||
}
|
||||
return Encoding.UTF8.GetString(lineBuffer.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
CC.Yi/CC.Yi.Common/Json/DatetimeJsonConverter.cs
Normal file
26
CC.Yi/CC.Yi.Common/Json/DatetimeJsonConverter.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CC.Yi.Common.Json
|
||||
{
|
||||
public class DatetimeJsonConverter: JsonConverter<DateTime>
|
||||
{
|
||||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
if (DateTime.TryParse(reader.GetString(), out DateTime date))
|
||||
return date;
|
||||
}
|
||||
return reader.GetDateTime();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
}
|
||||
}
|
||||
24
CC.Yi/CC.Yi.Common/Json/DefaultJsonOptions.cs
Normal file
24
CC.Yi/CC.Yi.Common/Json/DefaultJsonOptions.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CC.Yi.Common.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// https://blog.csdn.net/sD7O95O/article/details/103797885
|
||||
/// </summary>
|
||||
public class DefaultJsonOptions
|
||||
{
|
||||
public static JsonSerializerOptions Get()
|
||||
{
|
||||
var options = new JsonSerializerOptions();
|
||||
//options.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
|
||||
options.IgnoreNullValues = true;//排除所有属性值为 null 属性
|
||||
//// 自定义名称策略
|
||||
//options.PropertyNamingPolicy = new LowerCaseNamingPolicy();
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
CC.Yi/CC.Yi.Common/Json/EnumJsonConverter.cs
Normal file
38
CC.Yi/CC.Yi.Common/Json/EnumJsonConverter.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace CC.Yi.Common.Json
|
||||
{
|
||||
public class EnumJsonConverter : JsonConverter<Enum>
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert)
|
||||
{
|
||||
return typeToConvert.IsEnum;
|
||||
}
|
||||
//未实现
|
||||
public override Enum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
int num;
|
||||
reader.TryGetInt32(out num);
|
||||
return (Enum)Enum.Parse(typeToConvert,num.ToString());
|
||||
}
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
string str = reader.GetString();
|
||||
return (Enum)Enum.Parse(typeToConvert, str);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Enum value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
16
CC.Yi/CC.Yi.Common/Json/LowerCaseNamingPolicy.cs
Normal file
16
CC.Yi/CC.Yi.Common/Json/LowerCaseNamingPolicy.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CC.Yi.Common.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义名称策略
|
||||
/// </summary>
|
||||
public class LowerCaseNamingPolicy : JsonNamingPolicy
|
||||
{
|
||||
public override string ConvertName(string name) => name.ToLower();
|
||||
}
|
||||
|
||||
}
|
||||
27
CC.Yi/CC.Yi.Common/Json/TimeSpanJsonConverter.cs
Normal file
27
CC.Yi/CC.Yi.Common/Json/TimeSpanJsonConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CC.Yi.Common.Json
|
||||
{
|
||||
public class TimeSpanJsonConverter : JsonConverter<TimeSpan>
|
||||
{
|
||||
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
|
||||
//if (TimeSpan.TryParse(reader.GetString(), out TimeSpan date))
|
||||
// return date;
|
||||
|
||||
TimeSpan.TryParse(reader.GetString(), out TimeSpan date);
|
||||
return date;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
|
||||
{
|
||||
// writer.WriteStringValue(value.ToString("HH:mm:ss"));
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
33
CC.Yi/CC.Yi.Common/LinqHelper.cs
Normal file
33
CC.Yi/CC.Yi.Common/LinqHelper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
public static class LinqHelper
|
||||
{
|
||||
//T是列表类型,S是排序的属性
|
||||
public static IQueryable GetPageEntities<T,S>(IQueryable<T> myData, int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda=null, Expression<Func<T, S>> orderByLambda=null, bool isAsc=false)
|
||||
{
|
||||
total = myData.Where(whereLambda).Count();
|
||||
if (isAsc)
|
||||
{
|
||||
var pageData = myData.Where(whereLambda)
|
||||
.OrderBy<T,S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).AsQueryable();
|
||||
return pageData;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pageData = myData.Where(whereLambda)
|
||||
.OrderByDescending<T, S>(orderByLambda)
|
||||
.Skip(pageSize * (pageIndex - 1))
|
||||
.Take(pageSize).AsQueryable();
|
||||
return pageData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
99
CC.Yi/CC.Yi.Common/RandomHelper.cs
Normal file
99
CC.Yi/CC.Yi.Common/RandomHelper.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
public class RandomHelper
|
||||
{
|
||||
public static string replaceBianLiang(string content)
|
||||
{
|
||||
content = content.Replace("{当前时间}", DateTime.Now.TimeOfDay.ToString());
|
||||
string[] bianliang = new string[] { "{随机字母}", "{随机数字}", "{随机汉字}" };
|
||||
Regex r;
|
||||
int count;
|
||||
string readstr = "";
|
||||
foreach (string str in bianliang)
|
||||
{
|
||||
count = (content.Length - content.Replace(str, "").Length) / str.Length;
|
||||
if (str == "{随机汉字}") readstr = RandChina(count);
|
||||
if (str == "{随机数字}") readstr = GenerateCheckCodeNum(count);
|
||||
if (str == "{随机字母}") readstr = GenerateRandomLetter(count);
|
||||
if (count > readstr.Length) count = readstr.Length;
|
||||
r = new Regex(str.Replace("{", "\\{").Replace("}", "\\}"));
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
content = r.Replace(content, readstr.Substring(i, 1), 1);
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 随机生成字母
|
||||
/// </summary>
|
||||
/// <param name="Length"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateRandomLetter(int Length)
|
||||
{
|
||||
char[] Pattern = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
|
||||
string result = "";
|
||||
int n = Pattern.Length;
|
||||
Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
|
||||
for (int i = 0; i < Length; i++)
|
||||
{
|
||||
int rnd = random.Next(0, n);
|
||||
result += Pattern[rnd];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 随机生成数字
|
||||
/// </summary>
|
||||
/// <param name="codeCount"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateCheckCodeNum(int codeCount)
|
||||
{
|
||||
int rep = 0;
|
||||
string str = string.Empty;
|
||||
long num2 = DateTime.Now.Ticks + rep;
|
||||
rep++;
|
||||
Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep)));
|
||||
for (int i = 0; i < codeCount; i++)
|
||||
{
|
||||
int num = random.Next();
|
||||
str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 此函数为生成指定数目的汉字
|
||||
/// </summary>
|
||||
/// <param name="charLen">汉字数目</param>
|
||||
/// <returns>所有汉字</returns>
|
||||
public static string RandChina(int charLen)
|
||||
{
|
||||
int area, code;//汉字由区位和码位组成(都为0-94,其中区位16-55为一级汉字区,56-87为二级汉字区,1-9为特殊字符区)
|
||||
StringBuilder strtem = new StringBuilder();
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < charLen; i++)
|
||||
{
|
||||
area = rand.Next(16, 88);
|
||||
if (area == 55)//第55区只有89个字符
|
||||
{
|
||||
code = rand.Next(1, 90);
|
||||
}
|
||||
else
|
||||
{
|
||||
code = rand.Next(1, 94);
|
||||
}
|
||||
strtem.Append(Encoding.GetEncoding("GB2312").GetString(new byte[] { Convert.ToByte(area + 160), Convert.ToByte(code + 160) }));
|
||||
}
|
||||
return strtem.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
58
CC.Yi/CC.Yi.Common/T4Vue/T4Api.tt
Normal file
58
CC.Yi/CC.Yi.Common/T4Vue/T4Api.tt
Normal file
@@ -0,0 +1,58 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".vue" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
List<string> ModelData=new List<string>();
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Vue.txt");
|
||||
string p;
|
||||
while((p =sr.ReadLine())!=null)
|
||||
{
|
||||
ModelData.Add(p);
|
||||
}
|
||||
sr.Close();
|
||||
string Model= ModelData[0];
|
||||
string BModel=Model.Substring(0,1).ToUpper()+Model.Substring(1);
|
||||
string[] Data=ModelData[1].Split(',');
|
||||
string[] Name=ModelData[2].Split(',');
|
||||
string[] Default=ModelData[3].Split(',');
|
||||
#>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
import myaxios from '@/utils/myaxios'
|
||||
export default {
|
||||
get<#=BModel#>s() {
|
||||
return myaxios({
|
||||
url: '/<#=BModel#>/get<#=BModel#>s',
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
add<#=BModel#>(<#=Model#>) {
|
||||
return myaxios({
|
||||
url: '/<#=BModel#>/add<#=BModel#>',
|
||||
method: 'post',
|
||||
data: <#=Model#>
|
||||
})
|
||||
},
|
||||
update<#=BModel#>(<#=BModel#>) {
|
||||
return myaxios({
|
||||
url: '/<#=BModel#>/Update<#=BModel#>',
|
||||
method: 'post',
|
||||
data: <#=BModel#>
|
||||
})
|
||||
},
|
||||
del<#=BModel#>List(Ids) {
|
||||
return myaxios({
|
||||
url: '/<#=BModel#>/Del<#=BModel#>List',
|
||||
method: 'post',
|
||||
data: Ids
|
||||
})
|
||||
},
|
||||
}
|
||||
*/
|
||||
35
CC.Yi/CC.Yi.Common/T4Vue/T4Api.vue
Normal file
35
CC.Yi/CC.Yi.Common/T4Vue/T4Api.vue
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
import myaxios from '@/utils/myaxios'
|
||||
export default {
|
||||
getStudents() {
|
||||
return myaxios({
|
||||
url: '/Student/getStudents',
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
addStudent(student) {
|
||||
return myaxios({
|
||||
url: '/Student/addStudent',
|
||||
method: 'post',
|
||||
data: student
|
||||
})
|
||||
},
|
||||
updateStudent(Student) {
|
||||
return myaxios({
|
||||
url: '/Student/UpdateStudent',
|
||||
method: 'post',
|
||||
data: Student
|
||||
})
|
||||
},
|
||||
delStudentList(Ids) {
|
||||
return myaxios({
|
||||
url: '/Student/DelStudentList',
|
||||
method: 'post',
|
||||
data: Ids
|
||||
})
|
||||
},
|
||||
}
|
||||
*/
|
||||
279
CC.Yi/CC.Yi.Common/T4Vue/T4Component.tt
Normal file
279
CC.Yi/CC.Yi.Common/T4Vue/T4Component.tt
Normal file
@@ -0,0 +1,279 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ output extension=".vue" #>
|
||||
<#
|
||||
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
|
||||
List<string> ModelData=new List<string>();
|
||||
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Vue.txt");
|
||||
string p;
|
||||
while((p =sr.ReadLine())!=null)
|
||||
{
|
||||
ModelData.Add(p);
|
||||
}
|
||||
sr.Close();
|
||||
string Model= ModelData[0];
|
||||
string BModel=Model.Substring(0,1).ToUpper()+Model.Substring(1);
|
||||
string[] Data=ModelData[1].Split(',');
|
||||
string[] Name=ModelData[2].Split(',');
|
||||
string[] Default=ModelData[3].Split(',');
|
||||
#>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
<template>
|
||||
<v-card>
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="desserts"
|
||||
sort-by="calories"
|
||||
class="elevation-1"
|
||||
item-key="id"
|
||||
show-select
|
||||
v-model="selected"
|
||||
:search="search"
|
||||
>
|
||||
<template v-slot:top>
|
||||
<!-- 搜索框 -->
|
||||
<v-toolbar flat>
|
||||
<v-spacer></v-spacer>
|
||||
<v-text-field
|
||||
v-model="search"
|
||||
append-icon="mdi-magnify"
|
||||
label="搜索"
|
||||
single-line
|
||||
hide-details
|
||||
class="mx-4"
|
||||
></v-text-field>
|
||||
|
||||
<!-- 添加提示框 -->
|
||||
<v-dialog v-model="dialog" max-width="500px">
|
||||
<template v-slot:activator="{ on, attrs }">
|
||||
<v-btn
|
||||
color="primary"
|
||||
dark
|
||||
class="mb-2 mx-2"
|
||||
v-bind="attrs"
|
||||
v-on="on"
|
||||
>
|
||||
添加新项
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ formTitle }}</span>
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<v-container>
|
||||
<!-- 【1】这里设置对应的编辑框名 -->
|
||||
<v-row>
|
||||
|
||||
<#
|
||||
for(int i=0;i<Data.Length;i++)
|
||||
{
|
||||
#>
|
||||
<v-col cols="12" sm="6" md="4">
|
||||
<v-text-field
|
||||
v-model="editedItem.<#=Data[i]#>"
|
||||
label="<#=Name[i]#>"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<#
|
||||
}
|
||||
#>
|
||||
|
||||
|
||||
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="close"> 取消 </v-btn>
|
||||
<v-btn color="blue darken-1" text @click="save"> 保存 </v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
|
||||
<v-btn color="red" dark class="mb-2" @click="deleteItem(null)">
|
||||
删除所选
|
||||
</v-btn>
|
||||
|
||||
<!-- 删除提示框 -->
|
||||
<v-dialog v-model="dialogDelete" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="headline"
|
||||
>你确定要删除此条记录吗?</v-card-title
|
||||
>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="closeDelete"
|
||||
>取消</v-btn
|
||||
>
|
||||
<v-btn color="blue darken-1" text @click="deleteItemConfirm"
|
||||
>确定</v-btn
|
||||
>
|
||||
<v-spacer></v-spacer>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-toolbar>
|
||||
</template>
|
||||
|
||||
<!-- 表格中的删除和修改 -->
|
||||
<template v-slot:item.actions="{ item }">
|
||||
<v-icon small class="mr-2" @click="editItem(item)"> mdi-pencil </v-icon>
|
||||
<v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
|
||||
</template>
|
||||
|
||||
<!-- 初始化 -->
|
||||
<template v-slot:no-data>
|
||||
<v-btn color="primary" @click="initialize"> 刷新 </v-btn>
|
||||
</template>
|
||||
</v-data-table>
|
||||
|
||||
</v-card>
|
||||
</template>
|
||||
<script>
|
||||
//【2】这里设置对应的API
|
||||
import <#=Model#>Api from "@/api/<#=Model#>Api";
|
||||
export default {
|
||||
data: () => ({
|
||||
page: 1,
|
||||
selected: [],
|
||||
search: "",
|
||||
dialog: false,
|
||||
dialogDelete: false,
|
||||
//【3】这里设置对应的模型字段
|
||||
headers: [
|
||||
{
|
||||
text: "编号",
|
||||
align: "start",
|
||||
value: "id",
|
||||
},
|
||||
|
||||
<#
|
||||
for(int i=0;i<Data.Length;i++)
|
||||
{
|
||||
#>
|
||||
{ text: "<#=Name[i]#>", value: "<#=Data[i]#>", sortable: false },
|
||||
<#
|
||||
}
|
||||
#>
|
||||
|
||||
{ text: "操作", value: "actions", sortable: false },
|
||||
],
|
||||
desserts: [],
|
||||
editedIndex: -1,
|
||||
//【4】这里设置对应的模型默认字段
|
||||
editedItem: {
|
||||
<#
|
||||
for(int i=0;i<Data.Length;i++)
|
||||
{
|
||||
#>
|
||||
<#=Data[i]#>: <#=Default[i]#>,
|
||||
<#
|
||||
}
|
||||
#>
|
||||
},
|
||||
defaultItem: {
|
||||
<#
|
||||
for(int i=0;i<Data.Length;i++)
|
||||
{
|
||||
#>
|
||||
<#=Data[i]#>: <#=Default[i]#>,
|
||||
<#
|
||||
}
|
||||
#>
|
||||
},
|
||||
}),
|
||||
|
||||
computed: {
|
||||
formTitle() {
|
||||
return this.editedIndex === -1 ? "添加数据" : "编辑数据";
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
dialog(val) {
|
||||
val || this.close();
|
||||
},
|
||||
dialogDelete(val) {
|
||||
val || this.closeDelete();
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
this.initialize();
|
||||
},
|
||||
|
||||
methods: {
|
||||
initialize() {
|
||||
//【5】这里获取全部字段的API
|
||||
<#=Model#>Api.get<#=BModel#>s().then((resp) => {
|
||||
const response = resp.data;
|
||||
this.desserts = response;
|
||||
});
|
||||
},
|
||||
|
||||
editItem(item) {
|
||||
this.editedIndex = this.desserts.indexOf(item);
|
||||
this.editedItem = Object.assign({}, item);
|
||||
this.dialog = true;
|
||||
},
|
||||
|
||||
deleteItem(item) {
|
||||
this.editedIndex = this.desserts.indexOf(item);
|
||||
this.editedItem = Object.assign({}, item);
|
||||
this.dialogDelete = true;
|
||||
},
|
||||
|
||||
deleteItemConfirm() {
|
||||
var Ids = [];
|
||||
if (this.editedIndex > -1) {
|
||||
Ids.push(this.editedItem.id);
|
||||
} else {
|
||||
this.selected.forEach(function (item) {
|
||||
Ids.push(item.id);
|
||||
});
|
||||
}
|
||||
//【6】这里多条删除的API
|
||||
<#=Model#>Api.del<#=BModel#>List(Ids).then(() => this.initialize());
|
||||
this.closeDelete();
|
||||
},
|
||||
|
||||
close() {
|
||||
this.dialog = false;
|
||||
this.$nextTick(() => {
|
||||
this.editedItem = Object.assign({}, this.defaultItem);
|
||||
this.editedIndex = -1;
|
||||
});
|
||||
},
|
||||
|
||||
closeDelete() {
|
||||
this.dialogDelete = false;
|
||||
this.$nextTick(() => {
|
||||
this.editedItem = Object.assign({}, this.defaultItem);
|
||||
this.editedIndex = -1;
|
||||
});
|
||||
},
|
||||
|
||||
save() {
|
||||
//【7】这里编辑和添加的API
|
||||
if (this.editedIndex > -1) {
|
||||
<#=Model#>Api.update<#=BModel#>(this.editedItem).then(() => this.initialize());
|
||||
} else {
|
||||
<#=Model#>Api.add<#=BModel#>(this.editedItem).then(() => this.initialize());
|
||||
}
|
||||
this.close();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
*/
|
||||
237
CC.Yi/CC.Yi.Common/T4Vue/T4Component.vue
Normal file
237
CC.Yi/CC.Yi.Common/T4Vue/T4Component.vue
Normal file
@@ -0,0 +1,237 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
<template>
|
||||
<v-card>
|
||||
<v-data-table
|
||||
:headers="headers"
|
||||
:items="desserts"
|
||||
sort-by="calories"
|
||||
class="elevation-1"
|
||||
item-key="id"
|
||||
show-select
|
||||
v-model="selected"
|
||||
:search="search"
|
||||
>
|
||||
<template v-slot:top>
|
||||
<!-- 搜索框 -->
|
||||
<v-toolbar flat>
|
||||
<v-spacer></v-spacer>
|
||||
<v-text-field
|
||||
v-model="search"
|
||||
append-icon="mdi-magnify"
|
||||
label="搜索"
|
||||
single-line
|
||||
hide-details
|
||||
class="mx-4"
|
||||
></v-text-field>
|
||||
|
||||
<!-- 添加提示框 -->
|
||||
<v-dialog v-model="dialog" max-width="500px">
|
||||
<template v-slot:activator="{ on, attrs }">
|
||||
<v-btn
|
||||
color="primary"
|
||||
dark
|
||||
class="mb-2 mx-2"
|
||||
v-bind="attrs"
|
||||
v-on="on"
|
||||
>
|
||||
添加新项
|
||||
</v-btn>
|
||||
</template>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
<span class="headline">{{ formTitle }}</span>
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<v-container>
|
||||
<!-- 【1】这里设置对应的编辑框名 -->
|
||||
<v-row>
|
||||
|
||||
<v-col cols="12" sm="6" md="4">
|
||||
<v-text-field
|
||||
v-model="editedItem.id"
|
||||
label="id"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="12" sm="6" md="4">
|
||||
<v-text-field
|
||||
v-model="editedItem.name"
|
||||
label="姓名"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
|
||||
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="close"> 取消 </v-btn>
|
||||
<v-btn color="blue darken-1" text @click="save"> 保存 </v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
|
||||
<v-btn color="red" dark class="mb-2" @click="deleteItem(null)">
|
||||
删除所选
|
||||
</v-btn>
|
||||
|
||||
<!-- 删除提示框 -->
|
||||
<v-dialog v-model="dialogDelete" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="headline"
|
||||
>你确定要删除此条记录吗?</v-card-title
|
||||
>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="blue darken-1" text @click="closeDelete"
|
||||
>取消</v-btn
|
||||
>
|
||||
<v-btn color="blue darken-1" text @click="deleteItemConfirm"
|
||||
>确定</v-btn
|
||||
>
|
||||
<v-spacer></v-spacer>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-toolbar>
|
||||
</template>
|
||||
|
||||
<!-- 表格中的删除和修改 -->
|
||||
<template v-slot:item.actions="{ item }">
|
||||
<v-icon small class="mr-2" @click="editItem(item)"> mdi-pencil </v-icon>
|
||||
<v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
|
||||
</template>
|
||||
|
||||
<!-- 初始化 -->
|
||||
<template v-slot:no-data>
|
||||
<v-btn color="primary" @click="initialize"> 刷新 </v-btn>
|
||||
</template>
|
||||
</v-data-table>
|
||||
|
||||
</v-card>
|
||||
</template>
|
||||
<script>
|
||||
//【2】这里设置对应的API
|
||||
import studentApi from "@/api/studentApi";
|
||||
export default {
|
||||
data: () => ({
|
||||
page: 1,
|
||||
selected: [],
|
||||
search: "",
|
||||
dialog: false,
|
||||
dialogDelete: false,
|
||||
//【3】这里设置对应的模型字段
|
||||
headers: [
|
||||
{
|
||||
text: "编号",
|
||||
align: "start",
|
||||
value: "id",
|
||||
},
|
||||
|
||||
{ text: "id", value: "id", sortable: false },
|
||||
{ text: "姓名", value: "name", sortable: false },
|
||||
|
||||
{ text: "操作", value: "actions", sortable: false },
|
||||
],
|
||||
desserts: [],
|
||||
editedIndex: -1,
|
||||
//【4】这里设置对应的模型默认字段
|
||||
editedItem: {
|
||||
id: "0",
|
||||
name: "张三",
|
||||
},
|
||||
defaultItem: {
|
||||
id: "0",
|
||||
name: "张三",
|
||||
},
|
||||
}),
|
||||
|
||||
computed: {
|
||||
formTitle() {
|
||||
return this.editedIndex === -1 ? "添加数据" : "编辑数据";
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
dialog(val) {
|
||||
val || this.close();
|
||||
},
|
||||
dialogDelete(val) {
|
||||
val || this.closeDelete();
|
||||
},
|
||||
},
|
||||
|
||||
created() {
|
||||
this.initialize();
|
||||
},
|
||||
|
||||
methods: {
|
||||
initialize() {
|
||||
//【5】这里获取全部字段的API
|
||||
studentApi.getStudents().then((resp) => {
|
||||
const response = resp.data;
|
||||
this.desserts = response;
|
||||
});
|
||||
},
|
||||
|
||||
editItem(item) {
|
||||
this.editedIndex = this.desserts.indexOf(item);
|
||||
this.editedItem = Object.assign({}, item);
|
||||
this.dialog = true;
|
||||
},
|
||||
|
||||
deleteItem(item) {
|
||||
this.editedIndex = this.desserts.indexOf(item);
|
||||
this.editedItem = Object.assign({}, item);
|
||||
this.dialogDelete = true;
|
||||
},
|
||||
|
||||
deleteItemConfirm() {
|
||||
var Ids = [];
|
||||
if (this.editedIndex > -1) {
|
||||
Ids.push(this.editedItem.id);
|
||||
} else {
|
||||
this.selected.forEach(function (item) {
|
||||
Ids.push(item.id);
|
||||
});
|
||||
}
|
||||
//【6】这里多条删除的API
|
||||
studentApi.delStudentList(Ids).then(() => this.initialize());
|
||||
this.closeDelete();
|
||||
},
|
||||
|
||||
close() {
|
||||
this.dialog = false;
|
||||
this.$nextTick(() => {
|
||||
this.editedItem = Object.assign({}, this.defaultItem);
|
||||
this.editedIndex = -1;
|
||||
});
|
||||
},
|
||||
|
||||
closeDelete() {
|
||||
this.dialogDelete = false;
|
||||
this.$nextTick(() => {
|
||||
this.editedItem = Object.assign({}, this.defaultItem);
|
||||
this.editedIndex = -1;
|
||||
});
|
||||
},
|
||||
|
||||
save() {
|
||||
//【7】这里编辑和添加的API
|
||||
if (this.editedIndex > -1) {
|
||||
studentApi.updateStudent(this.editedItem).then(() => this.initialize());
|
||||
} else {
|
||||
studentApi.addStudent(this.editedItem).then(() => this.initialize());
|
||||
}
|
||||
this.close();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
*/
|
||||
59
CC.Yi/CC.Yi.Common/T4Vue/T4Controller.cs
Normal file
59
CC.Yi/CC.Yi.Common/T4Vue/T4Controller.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
//using CC.Yi.Common;
|
||||
//using CC.Yi.IBLL;
|
||||
//using CC.Yi.Model;
|
||||
//using Microsoft.AspNetCore.Authorization;
|
||||
//using Microsoft.AspNetCore.Mvc;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace CC.Yi.API.Controllers
|
||||
//{
|
||||
// [Route("[controller]/[action]")]
|
||||
// [ApiController]
|
||||
// public class PlateController : Controller
|
||||
// {
|
||||
// private IplateBll _plateBll;
|
||||
// private ILogger<PlateController> _logger;
|
||||
// short delFlagNormal = (short)ViewModel.Enum.DelFlagEnum.Normal;
|
||||
// public PlateController(IplateBll plateBll, ILogger<PlateController> logger)
|
||||
// {
|
||||
// _plateBll = plateBll;
|
||||
// _logger = logger;
|
||||
// }
|
||||
|
||||
// [HttpGet]
|
||||
// public async Task<Result> GetPlates()
|
||||
// {
|
||||
// var data =await _plateBll.GetEntities(u=>u.is_delete==delFlagNormal).AsNoTracking().ToListAsync();
|
||||
// return Result.Success().SetData(data);
|
||||
// }
|
||||
|
||||
// [Authorize(Policy = "板块管理")]
|
||||
// [HttpPost]
|
||||
// public Result AddPlate(plate myPlate)
|
||||
// {
|
||||
// _plateBll.Add(myPlate);
|
||||
// return Result.Success();
|
||||
// }
|
||||
|
||||
// [Authorize(Policy = "板块管理")]
|
||||
// [HttpPost]
|
||||
// public Result UpdatePlate(plate myPlate)
|
||||
// {
|
||||
// _plateBll.Update(myPlate);
|
||||
// return Result.Success();
|
||||
// }
|
||||
|
||||
// [Authorize(Policy = "板块管理")]
|
||||
// [HttpPost]
|
||||
// public Result delPlateList(List<int> Ids)
|
||||
// {
|
||||
// _plateBll.DelListByUpdateList(Ids);
|
||||
// return Result.Success();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
13
CC.Yi/CC.Yi.Common/mongodb/model/student.cs
Normal file
13
CC.Yi/CC.Yi.Common/mongodb/model/student.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common.mongodb.model
|
||||
{
|
||||
public class student
|
||||
{
|
||||
public string sname { get; set; }
|
||||
|
||||
public string sex { get; set; }
|
||||
}
|
||||
}
|
||||
29
CC.Yi/CC.Yi.Common/mongodb/mongodbContext.cs
Normal file
29
CC.Yi/CC.Yi.Common/mongodb/mongodbContext.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using CC.Yi.Common.mongodb.model;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common.mongodb
|
||||
{
|
||||
public class mongodbContext
|
||||
{
|
||||
private readonly IMongoDatabase _database = null;
|
||||
public mongodbContext()
|
||||
{
|
||||
//连接服务器名称 mongo的默认端口27017
|
||||
var client = new MongoClient("mongodb://.......:27017");
|
||||
if (client != null)
|
||||
//连接数据库
|
||||
_database = client.GetDatabase("数据库名");
|
||||
}
|
||||
|
||||
public IMongoCollection<student> Province
|
||||
{
|
||||
get
|
||||
{
|
||||
return _database.GetCollection<student>("Province");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
CC.Yi/CC.Yi.Common/settingHelper.cs
Normal file
48
CC.Yi/CC.Yi.Common/settingHelper.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using CC.Yi.Common.Cache;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CC.Yi.Common
|
||||
{
|
||||
public static class settingHelper
|
||||
{
|
||||
public static ICacheWriter CacheWriter { get; set; }
|
||||
|
||||
static settingHelper()
|
||||
{
|
||||
settingHelper.CacheWriter = new RedisCache();
|
||||
}
|
||||
|
||||
public static int commentPage()
|
||||
{
|
||||
return CacheWriter.GetCache<int>("commentPage");
|
||||
}
|
||||
public static int discussPage()
|
||||
{
|
||||
return CacheWriter.GetCache<int>("discussPage");
|
||||
}
|
||||
public static int commentExperience()
|
||||
{
|
||||
return CacheWriter.GetCache<int>("commentExperience");
|
||||
}
|
||||
public static int discussExperience()
|
||||
{
|
||||
return CacheWriter.GetCache<int>("discussExperience");
|
||||
}
|
||||
public static string title()
|
||||
{
|
||||
return CacheWriter.GetCache<string>("title");
|
||||
}
|
||||
|
||||
//配置设置
|
||||
//public static void update(setting data)
|
||||
//{
|
||||
// CacheWriter.SetCache<int>("commentPage", data.commentPage);
|
||||
// CacheWriter.SetCache<int>("discussPage", data.discussPage);
|
||||
// CacheWriter.SetCache<int>("commentExperience", data.commentExperience);
|
||||
// CacheWriter.SetCache<int>("discussExperience", data.discussExperience);
|
||||
// CacheWriter.SetCache<string>("title", data.title);
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user