internal static ConnObject GetConnObject(string dbConn) { dbConn = string.IsNullOrEmpty(dbConn) ? AppConfig.DB.DefaultConn : dbConn; if (dbConn.EndsWith("_Bak")) { dbConn = dbConn.Replace("_Bak", ""); } if (connDicCache.ContainsKey(dbConn)) { return(connDicCache[dbConn]); } ConnBean cbMaster = GetConnBean(dbConn); if (cbMaster == null) { string errMsg = string.Format("Can't find the connection key '{0}' from web.config or app.config!", dbConn); if (dbConn == AppConfig.DB.DefaultConn) { Error.Throw(errMsg); } else { ConnBean cb = GetConnBean(AppConfig.DB.DefaultConn); if (cb != null) { cbMaster = cb.Clone();//获取默认的值。 } else { Error.Throw(errMsg); } } } ConnObject co = new ConnObject(); co.Master = cbMaster; if (dbConn != null && dbConn.Length < 32 && !dbConn.Trim().Contains(" ")) // 为configKey { ConnBean coBak = GetConnBean(dbConn + "_Bak"); if (coBak != null && coBak.ProviderName == cbMaster.ProviderName) { co.BackUp = coBak; } for (int i = 1; i < 1000; i++) { ConnBean cbSlave = GetConnBean(dbConn + "_Slave" + i); if (cbSlave == null) { break; } cbSlave.IsSlave = true; co.Slave.Add(cbSlave); } } if (!connDicCache.ContainsKey(dbConn) && co.Master.ConfigName == dbConn) // 非一致的,由外面切换后再缓存 { connDicCache.Set(dbConn, co); } return(co); }
private void BuildRss() { object propValue = null; XmlNode cNode = rssDoc.XmlDoc.DocumentElement.ChildNodes[0]; CreateNode(cNode, channel);//Channel处理 XmlNode iNode = null; if (img != null) { iNode = rssDoc.CreateNode("image", string.Empty); cNode.AppendChild(iNode); CreateNode(iNode, img);//Channel-Image处理 } if (channel.Items.Count > 0) { foreach (RssItem item in channel.Items) { iNode = rssDoc.CreateNode("item", string.Empty); cNode.AppendChild(iNode); CreateNode(iNode, item);//Channel-Items处理 } } else if (_MTable != null && mapList.Count > 0) { foreach (MDataRow row in _MTable.Rows) { iNode = rssDoc.CreateNode("item", string.Empty); cNode.AppendChild(iNode); //foreach (RssItemMap item in mapList) RssItemMap item = null; for (int k = 0; k < mapList.Count; k++) { item = mapList[k]; if (item.TableColumnNames.Length > 0) { MDictionary <string, string> dic = new MDictionary <string, string>(item.TableColumnNames.Length, StringComparer.OrdinalIgnoreCase); object[] values = new object[item.TableColumnNames.Length]; for (int i = 0; i < item.TableColumnNames.Length; i++) { string columnName = item.TableColumnNames[i].ToString(); values[i] = row[columnName].Value; dic.Set(columnName, Convert.ToString(values[i])); } if (OnForeach != null) { item.FormatText = OnForeach(item.FormatText, dic, k); } if (string.IsNullOrEmpty(item.FormatText)) { propValue = values[0]; } else { propValue = string.Format(item.FormatText, values); } } //else if (item.TableColumnNames.Length > 0) //{ // propValue = row[item.TableColumnNames[0].ToString()].Value; // if (!string.IsNullOrEmpty(item.FormatText)) // { // propValue = string.Format(item.FormatText, propValue); // } //} else { propValue = item.FormatText; } if (propValue == null || propValue == DBNull.Value) { continue; } if (item.RssItemName == "Description") { propValue = rssDoc.SetCDATA(propValue.ToString()); } rssDoc.CreateNodeTo(iNode, item.RssItemName.Substring(0, 1).ToLower() + item.RssItemName.Substring(1), propValue.ToString()); } } } }
public static MDataColumn GetColumns(Type typeInfo) { string key = "ColumnCache_" + typeInfo.FullName; if (_ColumnCache.ContainsKey(key)) { return(_ColumnCache[key].Clone()); } else { #region 获取列结构 MDataColumn mdc = new MDataColumn(); mdc.TableName = typeInfo.Name; switch (StaticTool.GetSystemType(ref typeInfo)) { case SysType.Base: case SysType.Enum: mdc.Add(typeInfo.Name, DataType.GetSqlType(typeInfo), false); return(mdc); case SysType.Generic: case SysType.Collection: Type[] argTypes; Tool.StaticTool.GetArgumentLength(ref typeInfo, out argTypes); foreach (Type type in argTypes) { mdc.Add(type.Name, DataType.GetSqlType(type), false); } argTypes = null; return(mdc); } List <PropertyInfo> pis = StaticTool.GetPropertyInfo(typeInfo); if (pis.Count > 0) { for (int i = 0; i < pis.Count; i++) { SetStruct(mdc, pis[i], null, i, pis.Count); } } else { List <FieldInfo> fis = StaticTool.GetFieldInfo(typeInfo); if (fis.Count > 0) { for (int i = 0; i < fis.Count; i++) { SetStruct(mdc, null, fis[i], i, fis.Count); } } } object[] tableAttr = typeInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);//看是否设置了表特性,获取表名和表描述 if (tableAttr != null && tableAttr.Length == 1) { DescriptionAttribute attr = tableAttr[0] as DescriptionAttribute; if (attr != null && !string.IsNullOrEmpty(attr.Description)) { mdc.Description = attr.Description; } } pis = null; #endregion if (!_ColumnCache.ContainsKey(key)) { _ColumnCache.Set(key, mdc.Clone()); } return(mdc); } }
public static MDataColumn GetColumns(Type typeInfo) { string key = "ColumnCache:" + typeInfo.FullName; if (columnCache.ContainsKey(key)) { return(columnCache[key].Clone()); } else { #region 获取列结构 MDataColumn mdc = new MDataColumn(); switch (StaticTool.GetSystemType(ref typeInfo)) { case SysType.Base: case SysType.Enum: mdc.Add(typeInfo.Name, DataType.GetSqlType(typeInfo), false); return(mdc); case SysType.Generic: case SysType.Collection: Type[] argTypes; Tool.StaticTool.GetArgumentLength(ref typeInfo, out argTypes); foreach (Type type in argTypes) { mdc.Add(type.Name, DataType.GetSqlType(type), false); } argTypes = null; return(mdc); } PropertyInfo[] pis = StaticTool.GetPropertyInfo(typeInfo); SqlDbType sqlType; for (int i = 0; i < pis.Length; i++) { sqlType = SQL.DataType.GetSqlType(pis[i].PropertyType); mdc.Add(pis[i].Name, sqlType); MCellStruct column = mdc[i]; column.MaxSize = DataType.GetMaxSize(sqlType); if (i == 0) { column.IsPrimaryKey = true; column.IsCanNull = false; if (column.ColumnName.ToLower().Contains("id") && (column.SqlType == System.Data.SqlDbType.Int || column.SqlType == SqlDbType.BigInt)) { column.IsAutoIncrement = true; } } else if (i > pis.Length - 3 && sqlType == SqlDbType.DateTime && pis[i].Name.EndsWith("Time")) { column.DefaultValue = SqlValue.GetDate; } } pis = null; #endregion if (!columnCache.ContainsKey(key)) { columnCache.Set(key, mdc.Clone()); } return(mdc); } }