/// <summary> /// 创建机构人员组对象 /// </summary> /// <param name="type">需要创建的对象类型</param> /// <returns></returns> public IOguObject CreateObject(SchemaType type) { OguBaseImpl oBase = null; switch (type) { case SchemaType.Users: oBase = new OguUserImpl(); break; case SchemaType.Organizations: oBase = new OguOrganizationImpl(); break; case SchemaType.OrganizationsInRole: oBase = new OguOrganizationInRoleImpl(); break; case SchemaType.Groups: oBase = new OguGroupImpl(); break; default: throw new InvalidOperationException(string.Format(Resource.InvalidObjectTypeCreation, type.ToString())); } return(oBase); }
public static List <T> BuildObjectsFromTable <T>(DataTable table, IOrganization parent) where T : IOguObject { List <T> list = new List <T>(); foreach (DataRow row in table.Rows) { SchemaType type; if (row.Table.Columns.Contains("OBJECTCLASS")) { type = (SchemaType)Enum.Parse(typeof(SchemaType), row["OBJECTCLASS"].ToString(), true); if (type == SchemaType.Organizations) { if (row.Table.Columns.Contains("ACCESS_LEVEL") || (parent != null && parent is IOrganizationInRole)) { type = SchemaType.OrganizationsInRole; } } } else { type = OguObjectHelper.GetSchemaTypeFromInterface <T>(); } IOguObject baseObject = OguPermissionSettings.GetConfig().OguObjectFactory.CreateObject(type); if (baseObject is OguBaseImpl) { OguBaseImpl oBase = (OguBaseImpl)baseObject; oBase.InitProperties(row); if (oBase is IOrganizationInRole && (parent != null && parent is IOrganizationInRole)) { ((OguOrganizationInRoleImpl)oBase).AccessLevel = ((IOrganizationInRole)parent).AccessLevel; } } list.Add((T)(baseObject as object)); } return(list); }