/// <summary>
        /// 获取模块配置xml
        /// </summary>
        /// <returns></returns>
        public static string GetModelConfigXml()
        {
            string pathFlag = "\\";

            if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
            {
                pathFlag = "/";
            }
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            string modelConfigPath = WebConfigHelper.GetAppSettingValue("ModelConfig");

            if (string.IsNullOrEmpty(modelConfigPath))                                 //没有配置实体配置
            {
                modelConfigPath = string.Format("Config{0}modelConfig.xml", pathFlag); //取默认配置
            }
            modelConfigPath = basePath + modelConfigPath;
            if (!System.IO.File.Exists(modelConfigPath)) //文件不存在
            {
                return(string.Empty);
            }
            return(modelConfigPath);
        }
Example #2
0
        /// <summary>
        /// 获取网站架构Url
        /// </summary>
        /// <returns></returns>
        public static string GetBaseUrl()
        {
            try
            {
                return(ApplicationObject.CurrentOneHttpContext.Request.Url.Scheme + "://" + ApplicationObject.CurrentOneHttpContext.Request.Url.Authority + ApplicationObject.CurrentOneHttpContext.Request.ApplicationPath.TrimEnd('/') + '/');
            }
            catch { }
            string webHost = WebConfigHelper.GetAppSettingValue("WebHost");

            return(webHost);
        }
Example #3
0
        /// <summary>
        /// 获取首页URL
        /// </summary>
        /// <returns></returns>
        public static string GetIndexUrl()
        {
            string defaultController = WebConfigHelper.GetAppSettingValue("DefaultController");
            string defaultAction     = WebConfigHelper.GetAppSettingValue("DefaultAction");

            if (!string.IsNullOrEmpty(defaultController) && !string.IsNullOrEmpty(defaultAction))
            {
                return(string.Format("/{0}/{1}.html", defaultController, defaultAction));
            }
            return("/Page/Main.html");
        }
Example #4
0
        /// <summary>
        /// 获取网站架构Url
        /// </summary>
        /// <returns></returns>
        public static string GetBaseUrl()
        {
            try
            {
                return(ApplicationObject.CurrentOneHttpContext.Request.Scheme + "://" + ApplicationObject.CurrentOneHttpContext.Request.Host.Value + '/');
            }
            catch { }
            string webHost = WebConfigHelper.GetAppSettingValue("WebHost");

            return(webHost);
        }
        /// <summary>
        /// 获取模块表名,支持跨库
        /// </summary>
        /// <param name="modelType">实体类型对象</param>
        /// <param name="currTempDblinkArgs">当前连接对象,默认为本地连接</param>
        /// <returns></returns>
        public static string GetModuleTableName(Type modelType, DbLinkArgs currTempDblinkArgs = null)
        {
            string dbType = string.Empty;
            //额外配置的连接字符串
            string connString = GetModelConnString(modelType, out dbType);

            if (string.IsNullOrWhiteSpace(dbType))
            {
                dbType = "0";
            }
            DatabaseType dbTypeEnum = DatabaseType.MsSqlServer;

            try
            {
                dbTypeEnum = (DatabaseType)Enum.Parse(typeof(DatabaseType), dbType);
            }
            catch { }
            //额外数据库连接对象
            DbLinkArgs dblinkArgs = GetDbLinkArgs(connString, dbTypeEnum);

            if (dblinkArgs != null)
            {
                //本地连接字符串
                string currConnString = WebConfigHelper.GetConnectionString("DbReadConnString");
                string currDbTypeStr  = WebConfigHelper.GetAppSettingValue("DbType");
                if (string.IsNullOrEmpty(currDbTypeStr))
                {
                    currDbTypeStr = "0";
                }
                DatabaseType currDbType = DatabaseType.MsSqlServer;
                try
                {
                    currDbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), currDbTypeStr);
                }
                catch { }
                //本地连接对象
                DbLinkArgs currDblinkArgs = currTempDblinkArgs != null ? currTempDblinkArgs : GetDbLinkArgs(currConnString, currDbType);
                if (dblinkArgs.DataSource == currDblinkArgs.DataSource || dblinkArgs.DataSource == "." || dblinkArgs.DataSource == "(local)") //服务器相同或本地服务器
                {
                    if (dblinkArgs.DbName != currDblinkArgs.DbName)                                                                           //跨库不跨服务器
                    {
                        return(string.Format("[{0}].[dbo].[{1}]", dblinkArgs.DbName, modelType.Name));
                    }
                }
                else //跨服务器
                {
                    return(string.Format("[{0}].[{1}].[dbo].[{2}]", dblinkArgs.DataSource, dblinkArgs.DbName, modelType.Name));
                }
            }
            return(modelType.Name);
        }
        /// <summary>
        /// 获取实体连接字符串
        /// </summary>
        /// <param name="modelType">实体类型对象</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="read">读写分离标识,是否读数据库,为否则取写数据库</param>
        /// <param name="export">是否为导出</param>
        /// <returns></returns>
        public static string GetModelConnString(Type modelType, out string dbType, bool read = true, bool export = false)
        {
            dbType = string.Empty;
            if (null == modelType)
            {
                return(string.Empty);
            }
            string tempConnStr     = string.Empty;
            string modelConfigPath = GetModelConfigXml();
            string node            = GetModelNode(modelType);

            if (!string.IsNullOrEmpty(node)) //有配置节点
            {
                tempConnStr = XmlHelper.Read(modelConfigPath, node, export ? "exportConnString" : (read ? "readConnString" : "writeConnString"));
                if ((!read || export) && string.IsNullOrEmpty(tempConnStr))
                {
                    tempConnStr = XmlHelper.Read(modelConfigPath, node, "readConnString");
                }
                dbType = XmlHelper.Read(modelConfigPath, node, "dbType");
                if (string.IsNullOrEmpty(tempConnStr) && modelType.BaseType != null)
                {
                    tempConnStr = GetModelConnString(modelType.BaseType, out dbType, read, export);
                    if (string.IsNullOrEmpty(tempConnStr) && modelType.BaseType.BaseType != null)
                    {
                        tempConnStr = GetModelConnString(modelType.BaseType.BaseType, out dbType, read, export);
                    }
                }
            }
            if (string.IsNullOrEmpty(tempConnStr)) //节点配置中没有配置连接字符串时
            {
                string readConnStr  = export ? WebConfigHelper.GetConnectionString("exportConnString") : WebConfigHelper.GetConnectionString("DbReadConnString");
                string writeConnStr = WebConfigHelper.GetConnectionString("DbWriteConnString");
                if (!read) //写
                {
                    if (!string.IsNullOrEmpty(writeConnStr))
                    {
                        return(writeConnStr);
                    }
                    return(readConnStr);
                }
                else //读
                {
                    return(readConnStr);
                }
            }
            return(tempConnStr);
        }
        /// <summary>
        /// 获取模块配置xml
        /// </summary>
        /// <returns></returns>
        public static string GetModelConfigXml()
        {
            string pathFlag        = System.IO.Path.DirectorySeparatorChar.ToString();
            string basePath        = WebHelper.MapPath("/") + pathFlag;
            string modelConfigPath = WebConfigHelper.GetAppSettingValue("ModelConfig");

            if (string.IsNullOrEmpty(modelConfigPath))                                 //没有配置实体配置
            {
                modelConfigPath = string.Format("Config{0}modelConfig.xml", pathFlag); //取默认配置
            }
            modelConfigPath = basePath + modelConfigPath;
            if (!System.IO.File.Exists(modelConfigPath)) //文件不存在
            {
                return(string.Empty);
            }
            return(modelConfigPath);
        }
        /// <summary>
        /// 获取实体连接字符串
        /// </summary>
        /// <param name="modelType">实体类型对象</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="read">读写分离标识,是否读数据库,为否则取写数据库</param>
        /// <param name="export">是否为导出</param>
        /// <returns></returns>
        public static string GetModelConnStr(Type modelType, out DatabaseType dbType, bool read = true, bool export = false)
        {
            string dbTypeStr = string.Empty;
            string connStr   = GetModelConnString(modelType, out dbTypeStr, read, export);

            dbType = DatabaseType.MsSqlServer;
            try
            {
                if (string.IsNullOrEmpty(dbTypeStr))
                {
                    dbTypeStr = WebConfigHelper.GetAppSettingValue("DbType");
                }
                dbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), dbTypeStr);
            }
            catch { }
            return(connStr);
        }
        /// <summary>
        /// 模块数据库是否是跨服务器
        /// </summary>
        /// <param name="modelType">实体类型</param>
        /// <returns></returns>
        public static bool IsCrossServer(Type modelType)
        {
            string dbType = string.Empty;
            //额外配置的连接字符串
            string connString = GetModelConnString(modelType, out dbType);

            if (string.IsNullOrWhiteSpace(dbType))
            {
                dbType = "0";
            }
            DatabaseType dbTypeEnum = DatabaseType.MsSqlServer;

            try
            {
                dbTypeEnum = (DatabaseType)Enum.Parse(typeof(DatabaseType), dbType);
            }
            catch { }
            //额外数据库连接对象
            DbLinkArgs dblinkArgs = GetDbLinkArgs(connString, dbTypeEnum);

            if (dblinkArgs != null)
            {
                //本地连接字符串
                string currConnString = WebConfigHelper.GetConnectionString("DbReadConnString");
                string currDbTypeStr  = WebConfigHelper.GetAppSettingValue("DbType");
                if (string.IsNullOrEmpty(currDbTypeStr))
                {
                    currDbTypeStr = "0";
                }
                DatabaseType currDbType = DatabaseType.MsSqlServer;
                try
                {
                    currDbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), currDbTypeStr);
                }
                catch { }
                //本地连接对象
                DbLinkArgs currDblinkArgs = GetDbLinkArgs(currConnString, currDbType);
                if (dblinkArgs.DataSource != currDblinkArgs.DataSource) //服务器不相同
                {
                    return(true);
                }
            }
            return(false);
        }
Example #10
0
        /// <summary>
        /// 获取JS的修改时间
        /// </summary>
        /// <param name="jsPath">JS的URL路径</param>
        /// <returns></returns>
        public static string GetJsModifyTimeStr(string jsPath)
        {
            if (string.IsNullOrEmpty(jsPath))
            {
                return(string.Empty);
            }
            string tempPath = jsPath;

            try
            {
                if (tempPath.StartsWith("/"))
                {
                    tempPath = tempPath.Substring(1, tempPath.Length - 1);
                }
            }
            catch
            {
                return(string.Empty);
            }
            bool   isLinux  = WebConfigHelper.GetAppSettingValue("IsLinux") == "true";
            string filePath = Globals.GetWebDir();

            if (isLinux)
            {
                filePath += jsPath;
            }
            else
            {
                filePath += jsPath.Replace("/", "\\");
            }
            if (!System.IO.File.Exists(filePath)) //js不存在
            {
                return(string.Empty);
            }
            try
            {
                FileInfo fi = new FileInfo(filePath);
                string   r  = fi.LastWriteTime.ToString("yyMMddHHmmss");
                return(r);
            }
            catch { }
            return(string.Empty);
        }
        /// <summary>
        /// 获取本地数据库连接对象
        /// </summary>
        /// <returns></returns>
        public static DbLinkArgs GetLocalDbLinkArgs()
        {
            string currConnString = WebConfigHelper.GetConnectionString("DbReadConnString");
            string currDbTypeStr  = WebConfigHelper.GetAppSettingValue("DbType");

            if (string.IsNullOrEmpty(currDbTypeStr))
            {
                currDbTypeStr = "0";
            }
            DatabaseType currDbType = DatabaseType.MsSqlServer;

            try
            {
                currDbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), currDbTypeStr);
            }
            catch { }
            //本地连接对象
            DbLinkArgs currDblinkArgs = GetDbLinkArgs(currConnString, currDbType);

            return(currDblinkArgs);
        }
Example #12
0
 /// <summary>
 /// 设置网站信息
 /// </summary>
 /// <param name="name">系统名称</param>
 /// <param name="logo">系统LOGO</param>
 /// <param name="copyright">版权信息</param>
 /// <returns>返回异常信息</returns>
 public static string SetCurrWebInfo(string name, string logo, string copyright)
 {
     try
     {
         string pathFlag = "\\";
         if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
         {
             pathFlag = "/";
         }
         string basePath = AppDomain.CurrentDomain.BaseDirectory;
         if (!basePath.EndsWith(pathFlag))
         {
             basePath += pathFlag;
         }
         string webConfigPath = string.Format("{0}Config{1}webConfig.xml", basePath, pathFlag);
         if (!System.IO.File.Exists(webConfigPath)) //文件不存在
         {
             StringBuilder sb = new StringBuilder();
             sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
             sb.Append("<web>");
             sb.AppendFormat("<name>{0}</name>", name);
             sb.AppendFormat("<logo>{0}</logo>", logo);
             sb.AppendFormat("<copyright>{0}</copyright>", copyright);
             sb.Append("</web>");
             System.IO.StreamWriter sw = new System.IO.StreamWriter(webConfigPath, false, Encoding.UTF8);
             sw.Write(sb.ToString());
             sw.Close();
             return(string.Empty);
         }
         XmlHelper.Update(webConfigPath, "/web/name", name);
         XmlHelper.Update(webConfigPath, "/web/logo", logo);
         XmlHelper.Update(webConfigPath, "/web/copyright", copyright);
         return(string.Empty);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Example #13
0
        /// <summary>
        /// 获取配置文件
        /// </summary>
        /// <param name="configName">配置文件名,带文件扩展名</param>
        /// <returns></returns>
        public static string GetConfigFilePath(string configName)
        {
            string pathFlag = "\\";

            if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
            {
                pathFlag = "/";
            }
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            string xmlPath = basePath + string.Format("Config{0}{1}", pathFlag, configName);

            if (!System.IO.File.Exists(xmlPath)) //文件不存在
            {
                return(string.Empty);
            }
            return(xmlPath);
        }
Example #14
0
        /// <summary>
        /// 获取Bin目录,包含反斜杠
        /// </summary>
        /// <returns></returns>
        public static string GetBinPath()
        {
            string pathFlag = "\\";

            if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
            {
                pathFlag = "/";
            }
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            if (!basePath.Contains("bin"))
            {
                basePath += "bin";
            }
            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            return(basePath);
        }
Example #15
0
        /// <summary>
        /// 获取Web路径
        /// </summary>
        /// <returns></returns>
        public static string GetWebDir()
        {
            string pathFlag = "\\";

            if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
            {
                pathFlag = "/";
            }
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (basePath.EndsWith(pathFlag))
            {
                basePath = basePath.Substring(0, basePath.Length - 1);
            }
            if (basePath.EndsWith("bin"))
            {
                basePath = basePath.Substring(0, basePath.Length - 3);
            }
            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            return(basePath);
        }
Example #16
0
        /// <summary>
        /// 获取当前网站系统名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrWebName()
        {
            string pathFlag = "\\";

            if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true")
            {
                pathFlag = "/";
            }
            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith(pathFlag))
            {
                basePath += pathFlag;
            }
            string webConfigPath = string.Format("{0}Config{1}webConfig.xml", basePath, pathFlag);

            if (!System.IO.File.Exists(webConfigPath)) //文件不存在
            {
                return(string.Empty);
            }
            string name = XmlHelper.Read(webConfigPath, "/web/name");

            return(name);
        }