Ejemplo n.º 1
0
        /// <summary>
        /// Process the column definitions returned from the schema and convert them to use in a property definition
        /// </summary>
        /// <param name="columnDefinition">Data row return the from the database containing the definition of the current column</param>
        /// <returns>Replication Service Property Definition containing the converted column definition</returns>
        private RSPropertyDefinition ProcessColumnDefinition(DataRow columnDefinition)
        {
            //create a new property definition with the initial values in it
            RSPropertyDefinition propertyDefinition = new RSPropertyDefinition();

            //set the name of the property definition to the name of the column
            propertyDefinition.Name = columnDefinition["COLUMN_NAME"].ToString();

            //set whether the property is nullable using the nullable attribute of the column
            propertyDefinition.Nullable = Convert.ToBoolean(columnDefinition["IS_NULLABLE"]);

            //***********IMPORTANT STEP*******************
            //Convert the data type attribute of the column to a generic .Net DataType and
            //set the DataType attribute in the propery definition.
            //Note: The String representation is used ie: "An int is stored as System.Int32"
            propertyDefinition.DataType = DataTypeConverter.OleDbToSystem(columnDefinition["DATA_TYPE"]).ToString();

            //Check if the max length is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["CHARACTER_MAXIMUM_LENGTH"].ToString()) == false)
            {
                propertyDefinition.MaximumLength = Convert.ToInt32(columnDefinition["CHARACTER_MAXIMUM_LENGTH"]);
            }

            //Check if the scale is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["NUMERIC_SCALE"].ToString()) == false)
            {
                propertyDefinition.NumericScale = Convert.ToInt32(columnDefinition["NUMERIC_SCALE"]);
            }

            //Check if the Precision is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["NUMERIC_PRECISION"].ToString()) == false)
            {
                propertyDefinition.NumericPrecision = Convert.ToInt32(columnDefinition["NUMERIC_PRECISION"]);
            }

            //send back the created property definition
            return(propertyDefinition);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process the column definitions returned from the schema and convert them to use in a property definition
        /// </summary>
        /// <param name="columnDefinition">Data row return the from the database containing the definition of the current column</param>
        /// <returns>Replication Service Property Definition containing the converted column definition</returns>
        private RSPropertyDefinition ProcessColumnDefinition(DataRow columnDefinition)
        {
            //create a new property definition with the initial values in it
            RSPropertyDefinition propertyDefinition = new RSPropertyDefinition();

            //set the name of the property definition to the name of the column
            propertyDefinition.Name = columnDefinition["COLUMN_NAME"].ToString();

            //set whether the property is nullable using the nullable attribute of the column
            propertyDefinition.Nullable = Convert.ToBoolean(columnDefinition["IS_NULLABLE"]);

            //***********IMPORTANT STEP*******************
            //Convert the data type attribute of the column to a generic .Net DataType and
            //set the DataType attribute in the propery definition.
            //Note: The String representation is used ie: "An int is stored as System.Int32"
            propertyDefinition.DataType = DataTypeConverter.OleDbToSystem(columnDefinition["DATA_TYPE"]).ToString();

            //Check if the max length is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["CHARACTER_MAXIMUM_LENGTH"].ToString()) == false)
            {
                propertyDefinition.MaximumLength = Convert.ToInt32(columnDefinition["CHARACTER_MAXIMUM_LENGTH"]);
            }

            //Check if the scale is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["NUMERIC_SCALE"].ToString()) == false)
            {
                propertyDefinition.NumericScale = Convert.ToInt32(columnDefinition["NUMERIC_SCALE"]);
            }

            //Check if the Precision is set and add it to the property definition
            if (string.IsNullOrWhiteSpace(columnDefinition["NUMERIC_PRECISION"].ToString()) == false)
            {
                propertyDefinition.NumericPrecision = Convert.ToInt32(columnDefinition["NUMERIC_PRECISION"]);
            }

            //send back the created property definition
            return propertyDefinition;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get a specific Object's definition, this includes any attributes and supporting object properties.
        /// In this case retrieve the table definition along with any columns and the definition of each.
        /// </summary>
        /// <param name="methodInput">Method Input which includes an 'ObjectName'
        /// property to determine the object to retrieve the definition for.</param>
        /// <returns>Method Result which will either include error information or the
        /// Object Definition of the 'ObjectName' specified in the MethodInput properties</returns>
        public MethodResult GetObjectDefinition(MethodInput methodInput)
        {
            //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 allong 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, "GetObjectDefinitionMethod"))
            {
                //get the name of the object in the input properties
                string objectName = GetPropertyValue(
                    "ObjectName", methodInput.Input.Properties);

                //using the meta data access get the definitions
                //for each of the columns in the table
                DataTable tableColumnDefinitions =
                    metadataAccess.GetColumnDefinitions(objectName);

                //using the meta data access get the definition for
                //the table indexes (primary and foreign keys)
                DataTable tableIndexDefinition =
                    metadataAccess.GetTableIndexInformation(objectName);

                //check that both sets of data have been
                //returned from the meta data access layer
                if ((tableColumnDefinitions != null &&
                     tableColumnDefinitions.Rows.Count != 0) &&
                    (tableIndexDefinition != null &&
                     tableIndexDefinition.Rows.Count != 0))
                {
                    //create a new replication service object
                    RSObjectDefinition rsObjectDefinition = new RSObjectDefinition()
                    {
                        Name = objectName,
                        RSPropertyDefinitions = new List <RSPropertyDefinition>()
                    };

                    List <string> tablePrimaryKeys =
                        GetTablePrimaryKeys(rsObjectDefinition.Name, metadataAccess);

                    //parse through each column return from the column definitions and
                    //add a new replication service property definition to the newly created
                    //replication service object definition for each column in the table
                    foreach (DataRow columnDefinition in tableColumnDefinitions.Rows)
                    {
                        //process the column definition and set it
                        //to the resplication service property definition
                        RSPropertyDefinition rsPropertyDefinition =
                            ProcessColumnDefinition(columnDefinition);

                        //check if this is the default last
                        //modified column and set the object property
                        if (rsPropertyDefinition.Name == LastModifiedFieldName)
                        {
                            rsObjectDefinition.ModificationDateFullName =
                                rsPropertyDefinition.Name;
                        }

                        //check if the property is a primary key value
                        rsPropertyDefinition.InPrimaryKey =
                            tablePrimaryKeys.Contains(rsPropertyDefinition.Name);

                        //add the property definition to the object definition
                        rsObjectDefinition.RSPropertyDefinitions.Add(rsPropertyDefinition);
                    }

                    //Convert the replication service object definition to a Data Entity
                    //set the result return value to the replication service object defintion
                    //set the result success to true
                    result = new MethodResult {
                        Success = true, Return = rsObjectDefinition.ToDataEntity()
                    };
                }
                else
                {
                    result = new MethodResult {
                        Success = false, ErrorInfo = new ErrorResult {
                            Description = ErrorCodes.ObjectNotFound.Description, Number = ErrorCodes.ObjectNotFound.Number
                        }
                    };
                }
            }

            //return the method result
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get a specific Object's definition, this includes any attributes and
        /// supporting object properties.
        /// In this case retrieve the table definition along with any columns and
        /// the definition of each.
        /// </summary>
        /// <param name="methodInput">Method Input which includes an 'ObjectName'
        /// property to determine the object to retrieve the definition.</param>
        /// <returns>Method Result, which will either include error information or the
        /// Object Definition of the 'ObjectName' specified in the
        /// MethodInput properties.</returns>
        public MethodResult GetObjectDefinition(MethodInput methodInput)
        {
            //Create a new instance of the method result to fill with
            //meta data information
            MethodResult result = null;

            //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, "GetObjectDefinition"))
            {
                //Get the name of the object in the input properties.
                string objectName =
                    GetPropertyValueName("ObjectName", methodInput.Input.Properties);

                //Use the metadata access to get the
                //definitions for each of the columns in the table.
                DataTable tableColumnDefinitions =
                    metadataAccess.GetColumnDefinitions(objectName);

                //Using the meta data access get the definition for the
                //table indexes (primary and foreign keys)
                DataTable tableIndexDefinition =
                    metadataAccess.GetTableIndexInformation(objectName);

                //Check that both sets of data have been returned
                //from the meta data access layer
                if ((tableColumnDefinitions != null &&
                     tableColumnDefinitions.Rows.Count != 0) &&
                    (tableIndexDefinition != null &&
                     tableIndexDefinition.Rows.Count != 0))
                {
                    //Create a new replication service object
                    RSObjectDefinition rsObjectDefinition = new RSObjectDefinition()
                    {
                        Name = objectName,
                        RSPropertyDefinitions = new List <RSPropertyDefinition>()
                    };

                    //If this is the change history table set the hidden attribute.
                    //Note: this is how to prevent an object from being replicated.
                    rsObjectDefinition.Hidden = objectName == Globals.ChangeHistoryTableName;

                    List <string> tablePrimaryKeys =
                        GetTablePrimaryKeys(rsObjectDefinition.Name, metadataAccess);

                    //Parse each column returned from the column definitions.
                    //For each column, add a new replication service property definition
                    //to the newly created replication service object definition.
                    foreach (DataRow columnDefinition in tableColumnDefinitions.Rows)
                    {
                        //Process the column definition and set it to the
                        //resplication service property definition.
                        RSPropertyDefinition rsPropertyDefinition =
                            ProcessColumnDefinition(columnDefinition);

                        //Check if this is the default last modified column and
                        //set the object property.
                        if (rsPropertyDefinition.Name == LastModifiedFieldName)
                        {
                            rsObjectDefinition.ModificationDateFullName =
                                rsPropertyDefinition.Name;
                        }

                        //Check if the property is a primary key value.
                        rsPropertyDefinition.InPrimaryKey =
                            tablePrimaryKeys.Contains(rsPropertyDefinition.Name);

                        //Add the property definition to the object definition.
                        rsObjectDefinition.RSPropertyDefinitions.Add(rsPropertyDefinition);
                    }

                    //Convert the replication service object definition to a Data Entity.
                    //Set the result return value to the
                    //replication service object definition.
                    //Set the result Success to true.
                    result = new MethodResult
                    {
                        Success = true, Return = rsObjectDefinition.ToDataEntity()
                    };
                }
                else
                {
                    //Set the proper error information in the method result in the
                    //event of a null table or column definitions.
                    result = SetErrorMethodResult(
                        ErrorCodes.NoObjectsFound.Number,
                        ErrorCodes.NoObjectsFound.Description);
                }
            }

            //Return the method result.
            return(result);
        }