CodeGenerator icon indicating copy to clipboard operation
CodeGenerator copied to clipboard

TODO List

Open yuanrui opened this issue 7 years ago • 2 comments

  1. I18N.
  2. Select part of template file to generate.
  3. Remove dependency dll, integration mono t4
  4. Support MySql.
  5. Add template:LayUI, Vue etc.
  6. Complete documentation.

yuanrui avatar Oct 22 '18 01:10 yuanrui

Where can I find "DbContextFactory" and "AjaxMessage", Tks

Lanneret1999 avatar Sep 07 '24 02:09 Lanneret1999

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);
        }
    }
}

yuanrui avatar Nov 01 '24 03:11 yuanrui