/// <summary> /// Retrieve a list of Object Definitions /// TODO: Add examples for GetObjectProperties, and GetPropertyRelations /// </summary> /// <param name="shouldGetProperties">Defines whether or not to get a list of properties associated with each object</param> /// <param name="shouldGetRelations">Defines whether or not to get a list of relations with each object such as foreign keys</param> /// <returns>List of Object Defintions</returns> public IEnumerable <IObjectDefinition> RetrieveObjectDefinitions( bool shouldGetProperties = false, bool shouldGetRelations = false) { //create a new list of object definitions to return the list a tables in List <IObjectDefinition> objectDefinitions = new List <IObjectDefinition>(); using (new LogMethodExecution( Globals.ConnectorName, "GetObjectList")) { //get the list of tables DataTable tableDefinitions = _metadataAccess.GetTableList(); //add each table to the object definition list foreach (DataRow table in tableDefinitions.Rows) { //create a new object defining the name of the table and //description using the information returned from metadata var objectDefinition = new ObjectDefinition { Name = table["TABLE_NAME"].ToString(), FullName = table["TABLE_NAME"].ToString(), Description = GetTableDescription(table["TABLE_NAME"].ToString()) }; //add the newly created object definition to the definition list objectDefinitions.Add(objectDefinition); //Set the hidden attribute to true if this is the change history table. //Note: this is how to set items to not recommended for replication in the UI objectDefinition.Hidden = objectDefinition.Name == Globals.ChangeHistoryTableName; } } //send back the object definition list return(objectDefinitions); }
/// <summary> /// Get the list of 'Object' names or in this case /// table names from the data source /// include the primary key or identifyer in the each of the objects /// </summary> /// <returns>MethodResult to be return in a readable state</returns> public MethodResult GetObjectDefinitionList() { //Create a new instance of the method result to fill with //meta data information MethodResult result = new MethodResult(); // Create a new instance of the metadata access class and pass // the data access instance along with it OleDbMetadataAccess metadataAccess = new OleDbMetadataAccess(_dataAccess); // Use LogMethodExecution to add entry and exit tracing to a method. // When wrapped in a using statement, the exit point // is written during garbage collection. using (new LogMethodExecution( Globals.ConnectorName, "GetObjectDefinitionList")) { //Get a list of indexes for each table DataTable tableList = metadataAccess.GetTableList(); //check that valid data has been return from the schema if (tableList != null && tableList.Rows.Count != 0) { //Create a list of generic Data Entities //***This is a Key piece of the replication process*** //This is where the table list will be stored in a //generic fashion and return in the result. List <DataEntity> dataEntityList = new List <DataEntity>(); //Parse the list of rows that contain the table //information and stuff them into generic data entities. //Add them to the list that will be returned in the result. foreach (DataRow tableRow in tableList.Rows) { var tableName = tableRow["TABLE_NAME"].ToString(); var dataEntity = new DataEntity("Object"); dataEntity.Properties.Add("Name", tableName); dataEntity.Properties.Add( "PrimaryKeyName", PrimaryKeyFieldName); dataEntity.Properties.Add( "Description", GetTableDescription(tableName)); //Check if the table has the ModifiedOn column dataEntity.Properties.Add( "ModificationDateFullName", CheckForLastModifiedColumnName( tableName, metadataAccess) ? LastModifiedFieldName : string.Empty); dataEntity.Properties.Add("Hidden", tableName == Globals.ChangeHistoryTableName); dataEntityList.Add(dataEntity); } //Set the success of the result to true since the //list of entities has been filled. result.Success = true; //Create a new instance of the return result set //with the name of the returned items. result.Return = new DataEntity("ObjectList"); //Add the entity list to the result. result.Return.Properties.Add("Result", dataEntityList); } else { //Set the proper error information in the event that //incorrect schema information is returned from the database. result = SetErrorMethodResult( ErrorCodes.GetObjectList.Number, ErrorCodes.GetObjectList.Description); } } //Return the method result containing the object definition list. return(result); }