91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

NFinal 學習筆記 03--代碼生成器

發布時間:2020-07-05 06:16:24 來源:網絡 閱讀:482 作者:xiaolu6t6t 欄目:編程語言

NFinal代碼生成器與其他的代碼生成器不太一樣,只需要運行模塊下的WebComplier.aspx即可生成最終的web層代碼。包括數據庫的操作,Router類,

調試文件等。附上一段代碼與大家分享

using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using NFinal.Compile;

//防止.net 2.0下類自動引入Linq命名空間報錯.
namespace System.Linq
{
    delegate void None();
}
namespace NFinal
{
    public class Frame
    {
        public static string appRoot;
        public static string AssemblyTitle;
       
        public static List<NFinal.DB.ConnectionString> ConnectionStrings = new List<NFinal.DB.ConnectionString>();

        public Frame(string appRoot)
        {
            Frame.appRoot = appRoot;
            string[] fileNames = Directory.GetFiles(appRoot, "*.csproj");
            if (fileNames.Length > 0)
            {
                AssemblyTitle = Path.GetFileNameWithoutExtension(fileNames[0]);
            }
            else
            {
                string temp;
                temp = appRoot.Trim('\\');
                AssemblyTitle = temp.Substring(temp.LastIndexOf('\\') + 1);
            }
        }

        /// <summary>
        /// 把基于網站根目錄的絕對路徑改為相對路徑
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string MapPath(string url)
        {
            return appRoot + url.Trim('/').Replace('/', '\\');
        }

        public void GetDB()
        {
            //獲取WebConfig中的連接字符串信息
            string configFileName = appRoot + "Web.config";
            if (File.Exists(configFileName))
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(configFileName);
                System.Xml.XmlNode root = doc.DocumentElement.SelectSingleNode("/configuration");
                System.Xml.XmlNodeList nodeList = root.SelectNodes("connectionStrings/add[@connectionString]");
                Frame.ConnectionStrings.Clear();
                if (nodeList.Count > 0)
                {
                    System.Xml.XmlElement ele = null;
                    foreach (System.Xml.XmlNode node in nodeList)
                    {
                        ele = node as System.Xml.XmlElement;
                        var connectionString = new NFinal.DB.ConnectionString();
                        connectionString.name = ele.Attributes["name"].Value;
                        connectionString.value = ele.Attributes["connectionString"].Value;
                        connectionString.provider = ele.Attributes["providerName"].Value;
              
                        if (connectionString.provider.ToLower().IndexOf("mysql") > -1)
                        {
                            connectionString.type = NFinal.DB.DBType.MySql;
                        }
                        else if (connectionString.provider.ToLower().IndexOf("sqlclient") > -1)
                        {
                            connectionString.type = NFinal.DB.DBType.SqlServer;
                        }
                        else if (connectionString.provider.ToLower().IndexOf("sqlite") > -1)
                        {
                            connectionString.type = NFinal.DB.DBType.Sqlite;
                        }
                        else if (connectionString.provider.ToLower().IndexOf("oracle") > -1)
                        {
                            connectionString.type = NFinal.DB.DBType.Oracle;
                        }
                        else
                        {
                            connectionString.type = NFinal.DB.DBType.Unknown;
                        }
                        Frame.ConnectionStrings.Add(connectionString);
                    }
                }
            }
            //讀取數據庫信息
            NFinal.DB.Coding.DataUtility dataUtility = null;
            if (Frame.ConnectionStrings.Count > 0)
            {
                NFinal.DB.ConnectionString conStr;
                NFinal.DB.Coding.DB.DbStore.Clear();
                for (int i = 0; i < Frame.ConnectionStrings.Count; i++)
                {
                    conStr = Frame.ConnectionStrings[i];
                    if (conStr.type == NFinal.DB.DBType.MySql)
                    {
                        dataUtility = new NFinal.DB.Coding.MySQLDataUtility(conStr.value);
                        dataUtility.GetAllTables(dataUtility.con.Database);
                        NFinal.DB.Coding.DB.DbStore.Add(conStr.name, dataUtility);
                    }
                    else if (conStr.type == NFinal.DB.DBType.Sqlite)
                    {
                        dataUtility = new NFinal.DB.Coding.SQLiteDataUtility(conStr.value);
                        dataUtility.GetAllTables(dataUtility.con.Database);
                        NFinal.DB.Coding.DB.DbStore.Add(conStr.name, dataUtility);
                    }
                    else if (conStr.type == NFinal.DB.DBType.SqlServer)
                    {
                        dataUtility = new NFinal.DB.Coding.SQLDataUtility(conStr.value);
                        dataUtility.GetAllTables(dataUtility.con.Database);
                        NFinal.DB.Coding.DB.DbStore.Add(conStr.name, dataUtility);
                    }
                    else if (conStr.type == NFinal.DB.DBType.Oracle)
                    {
#if NET2
#else
                        dataUtility = new NFinal.DB.Coding.OracleDataUtility(conStr.value);
                        dataUtility.GetAllTables(dataUtility.con.Database);
                        NFinal.DB.Coding.DB.DbStore.Add(conStr.name, dataUtility);
#endif
                    }
                }
            }
        }

        /// <summary>
        /// 創建主路由
        /// </summary>
        /// <param name="apps"></param>
        public void CreateMain(string[] apps)
        {
            VTemplate.Engine.TemplateDocument doc = null;
            doc=new VTemplate.Engine.TemplateDocument(MapPath("NFinal/Template/Main.tpl"), System.Text.Encoding.UTF8);
            doc.SetValue("project", NFinal.Frame.AssemblyTitle);
            doc.SetValue("apps", apps);
            doc.SetValue("ControllerSuffix", "Controller");
            doc.RenderTo(MapPath("NFinal/Main.cs"), System.Text.Encoding.UTF8);
        }

        /// <summary>
        /// 獲取所有的應用模塊
        /// </summary>
        /// <returns></returns>
        public string[] GetApps()
        {
            string webConfigFileName= MapPath("/Web.config");
            XmlDocument doc = new XmlDocument();
            doc.Load(webConfigFileName);
            XmlNode appsNode = doc.DocumentElement.SelectSingleNode("appSettings/add[@key='Apps']");
            string[] Apps = null;

            if (appsNode != null && appsNode.Attributes.Count > 0 && appsNode.Attributes["value"] != null)
            {
                Apps = appsNode.Attributes["value"].Value.Split(',');
            }
            else
            {
                Apps =new string[] {"App"};
            }
            return Apps;
        }
        
    }

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

开封市| 高尔夫| 西畴县| 龙南县| 上林县| 内乡县| 灌云县| 商城县| 大余县| 扎兰屯市| 宜兰县| 三江| 武鸣县| 九台市| 巴楚县| 桂阳县| 泾源县| 襄樊市| 榆社县| 孝昌县| 德阳市| 成武县| 河池市| 杂多县| 嵊泗县| 驻马店市| 玛曲县| 伽师县| 科技| 大港区| 隆德县| 抚宁县| 洛浦县| 措美县| 平塘县| 泸州市| 长乐市| 兴化市| 磐石市| 南乐县| 乐安县|