public List <WonkaRefSource> GetSourceCache() { List <WonkaRefSource> SourceCache = new List <WonkaRefSource>(); XmlSerializer SourceSerializer = new XmlSerializer(typeof(WonkaRefSource)); XmlNodeList SourceNodeList = moXmlDoc.GetElementsByTagName("WonkaRefSource"); foreach (XmlNode SourceNode in SourceNodeList) { WonkaRefSource TempSource = (WonkaRefSource)SourceSerializer.Deserialize(new StringReader(SourceNode.OuterXml)); SourceCache.Add(TempSource); } return(SourceCache); }
public IMetadataRetrievable ImportSource(string psDatabaseTable, IModel poDbContext) { WonkaImportSource NewImportSource = new WonkaImportSource(); HashSet <string> KeyColNames = new HashSet <string>(); IEntityType FoundTable = null; if (!String.IsNullOrEmpty(psDatabaseTable) && (poDbContext != null)) { if (moCachedImports.ContainsKey(psDatabaseTable)) { return(moCachedImports[psDatabaseTable]); } var tables = poDbContext.GetEntityTypes(psDatabaseTable); foreach (var TmpTable in tables) { if (TmpTable.Name == psDatabaseTable) { FoundTable = TmpTable; var KeyCols = TmpTable.GetDeclaredKeys(); foreach (var KeyCol in KeyCols) { KeyColNames.Add(KeyCol.GetName()); } break; } } if (FoundTable == null) { throw new WonkaImportException("ERROR! Table (" + psDatabaseTable + ") was not found in the provided DbContext."); } var columns = from p in FoundTable.GetProperties() select new { colName = p.Name, colType = p.GetColumnType(), maxLength = p.GetMaxLength(), precision = 0, scale = 0, defValue = p.GetDefaultValue() }; /* * var columns = * from meta in poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) * from p in (meta as EntityType).Properties.Where(p => p.DeclaringType.Name == psDatabaseTable) * select new * { * colName = p.Name, * colType = p.TypeUsage.EdmType, * doc = p.Documentation, * maxLength = p.MaxLength, * precision = p.Precision, * scale = p.Scale, * defValue = p.DefaultValue, * props = p.MetadataProperties * }; */ foreach (var TmpCol in columns) { string sTmpColName = TmpCol.colName; WonkaRefAttr TmpWonkaAttr = new WonkaRefAttr(); TmpWonkaAttr.AttrId = GenerateNewAttrId(); TmpWonkaAttr.AttrName = sTmpColName; TmpWonkaAttr.ColName = sTmpColName; TmpWonkaAttr.TabName = psDatabaseTable; TmpWonkaAttr.DefaultValue = Convert.ToString(TmpCol.defValue); // TmpWonkaAttr.Description = (TmpCol.doc != null) ? TmpCol.doc.LongDescription : ""; TmpWonkaAttr.IsDate = IsTypeDate(TmpCol.colType); TmpWonkaAttr.IsNumeric = IsTypeNumeric(TmpCol.colType); TmpWonkaAttr.IsDecimal = IsTypeDecimal(TmpCol.colType); if (TmpWonkaAttr.IsNumeric || TmpWonkaAttr.IsDecimal) { // TmpWonkaAttr.Precision = (int) ((TmpCol.precision != null) ? TmpCol.precision : 0); // TmpWonkaAttr.Scale = (int) ((TmpCol.scale != null) ? TmpCol.scale : 0); TmpWonkaAttr.Precision = TmpCol.precision; TmpWonkaAttr.Scale = TmpCol.scale; } TmpWonkaAttr.MaxLength = (TmpCol.maxLength != null) ? (int)TmpCol.maxLength : 0; TmpWonkaAttr.FieldId = TmpWonkaAttr.AttrId + 1000; TmpWonkaAttr.GroupId = CONST_DEFAULT_GROUP_ID; TmpWonkaAttr.IsAudited = true; TmpWonkaAttr.IsKey = KeyColNames.Contains(TmpWonkaAttr.AttrName); NewImportSource.AddAttribute(TmpWonkaAttr); } if (NewImportSource.GetAttrCache().Count <= 0) { throw new WonkaBizRuleException(0, 0, "ERROR! Could not import the schema because the Reader's field count was zero."); } WonkaRefGroup NewImportGroup = new WonkaRefGroup(); NewImportGroup.GroupId = CONST_DEFAULT_GROUP_ID; NewImportGroup.GroupName = psDatabaseTable; NewImportGroup.KeyTabCols = KeyColNames; NewImportGroup.ProductTabName = psDatabaseTable; NewImportSource.AddGroup(NewImportGroup); WonkaRefSource GuestSource = new WonkaRefSource(); GuestSource.SourceId = 1; GuestSource.SourceName = "Guest"; GuestSource.Status = "Active"; NewImportSource.AddSource(GuestSource); } else { throw new WonkaBizRuleException(0, 0, "ERROR! Could not import the schema for the database table."); } PopulateDefaults(); return(NewImportSource); }
public void AddSource(WonkaRefSource poNewSource) { SourceCollection.Add(poNewSource); }
public IMetadataRetrievable ImportSource(string psDatabaseTable, ObjectContext poDbContext) { WonkaBreImportSource NewImportSource = new WonkaBreImportSource(); HashSet <string> KeyColNames = new HashSet <string>(); if (!String.IsNullOrEmpty(psDatabaseTable) && (poDbContext != null)) { if (moCachedImports.ContainsKey(psDatabaseTable)) { return(moCachedImports[psDatabaseTable]); } var tables = poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType); foreach (var TmpTable in tables) { EntityType TmpEntityType = (EntityType)TmpTable; if (TmpEntityType.Name == psDatabaseTable) { var KeyCols = TmpEntityType.KeyMembers; foreach (var KeyCol in KeyCols) { KeyColNames.Add(KeyCol.Name); } break; } } var columns = from meta in poDbContext.MetadataWorkspace.GetItems(DataSpace.CSpace).Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from p in (meta as EntityType).Properties.Where(p => p.DeclaringType.Name == psDatabaseTable) select new { colName = p.Name, colType = p.TypeUsage.EdmType, doc = p.Documentation, maxLength = p.MaxLength, precision = p.Precision, scale = p.Scale, defValue = p.DefaultValue, props = p.MetadataProperties }; foreach (var TmpCol in columns) { string sTmpColName = TmpCol.colName; var Props = TmpCol.props; WonkaRefAttr TmpWonkaAttr = new WonkaRefAttr(); TmpWonkaAttr.AttrId = GenerateNewAttrId(); TmpWonkaAttr.AttrName = sTmpColName; TmpWonkaAttr.ColName = sTmpColName; TmpWonkaAttr.TabName = psDatabaseTable; TmpWonkaAttr.DefaultValue = Convert.ToString(TmpCol.defValue); TmpWonkaAttr.Description = (TmpCol.doc != null) ? TmpCol.doc.LongDescription : ""; TmpWonkaAttr.IsDate = IsTypeDate(TmpCol.colType); TmpWonkaAttr.IsNumeric = IsTypeNumeric(TmpCol.colType); TmpWonkaAttr.IsDecimal = IsTypeDecimal(TmpCol.colType); if (TmpWonkaAttr.IsNumeric || TmpWonkaAttr.IsDecimal) { TmpWonkaAttr.Precision = (int)((TmpCol.precision != null) ? TmpCol.precision : 0); TmpWonkaAttr.Scale = (int)((TmpCol.scale != null) ? TmpCol.scale : 0); } TmpWonkaAttr.MaxLength = (TmpCol.maxLength != null) ? (int)TmpCol.maxLength : 0; TmpWonkaAttr.FieldId = TmpWonkaAttr.AttrId + 1000; TmpWonkaAttr.GroupId = CONST_DEFAULT_GROUP_ID; TmpWonkaAttr.IsAudited = true; TmpWonkaAttr.IsKey = KeyColNames.Contains(TmpWonkaAttr.AttrName); NewImportSource.AddAttribute(TmpWonkaAttr); } if (NewImportSource.GetAttrCache().Count <= 0) { throw new WonkaBreException(0, 0, "ERROR! Could not import the schema because the Reader's field count was zero."); } WonkaRefGroup NewImportGroup = new WonkaRefGroup(); NewImportGroup.GroupId = CONST_DEFAULT_GROUP_ID; NewImportGroup.GroupName = psDatabaseTable; NewImportGroup.KeyTabCols = KeyColNames; NewImportGroup.ProductTabName = psDatabaseTable; NewImportSource.AddGroup(NewImportGroup); WonkaRefSource GuestSource = new WonkaRefSource(); GuestSource.SourceId = 1; GuestSource.SourceName = "Guest"; GuestSource.Status = "Active"; NewImportSource.AddSource(GuestSource); foreach (WonkaRefAttr TempAttr in NewImportSource.GetAttrCache()) { WonkaRefField NewImportField = new WonkaRefField(); NewImportField.FieldId = TempAttr.FieldId; NewImportField.FieldName = TempAttr.AttrName; NewImportField.Description = TempAttr.Description; NewImportField.GroupId = CONST_DEFAULT_GROUP_ID; NewImportField.DisplayName = TempAttr.AttrName; NewImportField.AttrIds.Add(TempAttr.AttrId); NewImportSource.AddField(NewImportField); WonkaRefSourceField NewImportSrcFld = new WonkaRefSourceField(); NewImportSrcFld.SourceFieldId = 10000 + NewImportField.FieldId; NewImportSrcFld.SourceId = 1; NewImportSrcFld.FieldId = NewImportField.FieldId; NewImportSrcFld.SecurityLevel = CONST_SEC_LEVEL_READ; NewImportSource.AddSourceField(NewImportSrcFld); } } else { throw new WonkaBreException(0, 0, "ERROR! Could not import the schema for the database table."); } PopulateDefaults(); return(NewImportSource); }