CodeGenerator
CodeGenerator copied to clipboard
TODO List
- I18N.
- Select part of template file to generate.
- Remove dependency dll, integration mono t4
- Support MySql.
- Add template:LayUI, Vue etc.
- Complete documentation.
Where can I find "DbContextFactory" and "AjaxMessage", Tks
Where can I find "DbContextFactory" and "AjaxMessage", Tks
@Lanneret1999 Refer to these source code.
LocalContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
namespace Banana.Github.Share
{
public class LocalContext
{
public static readonly LocalContext Current = new LocalContext();
private LocalContext()
{
}
public Object this[Object key]
{
get
{
if (HttpContext.Current != null)
{
return HttpContext.Current.Items[key];
}
else
{
LocalDataStoreSlot slot = Thread.GetNamedDataSlot(key.ToString());
return Thread.GetData(slot);
}
}
set
{
if (HttpContext.Current != null)
{
HttpContext.Current.Items[key] = value;
}
else
{
LocalDataStoreSlot slot = Thread.GetNamedDataSlot(key.ToString());
Thread.SetData(slot, value);
}
}
}
}
}
DbContextFactory.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
namespace Banana.Github.Share
{
public class DbContextFactory
{
const string DB_CTX_KEY = "EF_CTX_DATA";;
const string CONNECTION_NAME = "DefaultConnectionString";
public static DbContext Create()
{
var ctx = LocalContext.Current[DB_CTX_KEY] as DbContext;
if (ctx == null)
{
ctx = new YourDbContext(); //TODO: need replace, Object type is EF Db context
LocalContext.Current[DB_CTX_KEY] = ctx;
}
return ctx;
}
public static void Dispose()
{
var ctx = LocalContext.Current[DB_CTX_KEY] as DbContext;
if (ctx == null)
{
return;
}
((IDisposable)ctx).Dispose();
}
}
}
AjaxMessage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Banana.Github.Share
{
internal struct AjaxShowType
{
public const string None = "";
public const string Error = "error";
public const string Question = "question";
public const string Info = "info";
public const string Warning = "warning";
public const string Success = "success";
}
public class AjaxMessage
{
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 显示类型
/// </summary>
public string ShowType { get; protected set; }
/// <summary>
/// 是否成功
/// </summary>
public bool IsSuccess
{
get
{
return ShowType == AjaxShowType.Success;
}
}
public AjaxMessage()
{
ShowType = AjaxShowType.Info;
}
public AjaxMessage(string title, string content)
{
Title = title;
Content = content;
ShowType = AjaxShowType.Info;
}
/// <summary>
/// 提示信息
/// </summary>
/// <param name="title">显示标题</param>
/// <param name="content">显示类型</param>
/// <param name="showType">显示类型</param>
public AjaxMessage(string title, string content, string showType)
{
Title = title;
Content = content;
ShowType = showType;
}
public static AjaxMessage Success(string title, string content)
{
return new AjaxMessage(title, content, AjaxShowType.Success);
}
public static AjaxMessage Info(string title, string content)
{
return new AjaxMessage(title, content, AjaxShowType.Info);
}
public static AjaxMessage Question(string title, string content)
{
return new AjaxMessage(title, content, AjaxShowType.Question);
}
public static AjaxMessage Warning(string title, string content)
{
return new AjaxMessage(title, content, AjaxShowType.Warning);
}
public static AjaxMessage Error(string title, string content)
{
return new AjaxMessage(title, content, AjaxShowType.Error);
}
}
public class AjaxMessage<T> : AjaxMessage
{
public T Data { get; set; }
public AjaxMessage(string title, string content, string showType, T data)
{
Title = title;
Content = content;
ShowType = showType;
Data = data;
}
public static AjaxMessage Success(string title, string content, T data)
{
return new AjaxMessage<T>(title, content, AjaxShowType.Success, data);
}
public static AjaxMessage Info(string title, string content, T data)
{
return new AjaxMessage<T>(title, content, AjaxShowType.Info, data);
}
public static AjaxMessage Question(string title, string content, T data)
{
return new AjaxMessage<T>(title, content, AjaxShowType.Question, data);
}
public static AjaxMessage Warning(string title, string content, T data)
{
return new AjaxMessage<T>(title, content, AjaxShowType.Warning, data);
}
public static AjaxMessage Error(string title, string content, T data)
{
return new AjaxMessage<T>(title, content, AjaxShowType.Error, data);
}
}
}