Exemplo n.º 1
0
        /// <summary>
        /// This method creates an object used to
        /// track changes for future replications.
        /// In this case, a delete trigger is added to a specified table.
        /// Note: If the data-source already has a process for tracking changes, this
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <param name="methodInput">Method input used for the replication object.
        /// This is the name of the table that we need to extract.
        /// methodInput.Input.properties["ObjectName"]
        /// </param>
        /// <returns></returns>
        public MethodResult InitReplicationObject(MethodInput methodInput)
        {
            MethodResult methodResult = null;

            // 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, "InitReplication"))
            {
                //First ensure the change history table exists
                MethodResult initReplicationResult = InitReplication();

                //If the replication table already exist then
                //our work here is done and no other action is required
                if (initReplicationResult.Success)
                {
                    string tableName =
                        GetPropertyValueName("EntityName", methodInput.Input.Properties);
                    string triggerName =
                        string.Format("{0}_Deleted_TRG", tableName);

                    if (CheckForTrigger(triggerName, tableName) == false)
                    {
                        //Use the ConnectorApi provided local data storage to retrieve
                        //and read the sql scripts contents
                        LocalDataStorage localDataStorage    = new LocalDataStorage();
                        string           deleteTriggerString =
                            localDataStorage.ReadData(TriggerFileName);

                        if (string.IsNullOrWhiteSpace(deleteTriggerString))
                        {
                            throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", TriggerFileName));
                        }

                        string query = string.Format(deleteTriggerString, tableName);
                        //Execute the query to create the change history table.
                        _dataAccess.ExecuteNonQuery(query);
                    }

                    //If there were no errors in processing then
                    //just set the Success for the method result to true.
                    methodResult = new MethodResult {
                        Success = true
                    };
                }
                else
                {
                    methodResult = SetErrorMethodResult(ErrorCodes.InitReplication.Number,
                                                        ErrorCodes.InitReplication.Description);
                }
            }

            return(methodResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method defines the process for tracking changes to data.
        /// This particular example shows one way how this operation may work.
        /// Note: A seperate method will create triggers for each table that will fill this table with deletions.
        /// Note: If the data-source already has a process for tracking changes, this
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <returns></returns>
        public MethodResult InitReplication()
        {
            MethodResult methodResult = null;

            // 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, "InitReplication"))
            {
                //First retrieve the object definition of the
                //default table that is used for replication.
                MethodInput objectDefinitionInput = new MethodInput();
                objectDefinitionInput.Input.Properties.Add(
                    "ObjectName", "ScribeChangeHistory");
                MethodResult objectDefinitionResult =
                    GetObjectDefinition(objectDefinitionInput);

                //If the replication table already exist then our work
                //here is done. No other action is required.
                if (objectDefinitionResult.Success == false)
                {
                    //Use the Sribe-provided local data storage
                    //to retrieve and read the sql scripts contents.
                    LocalDataStorage localDataStorage = new LocalDataStorage();
                    string           query            =
                        localDataStorage.ReadData(ChangeHistoryFileName);

                    //Throw an error message if the file was not found
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", ChangeHistoryFileName));
                    }

                    //Execute the query to create the change history table.
                    _dataAccess.ExecuteNonQuery(query);
                }

                //If there were no errors in processing, then
                //set the Success for the method result to true.
                methodResult = new MethodResult {
                    Success = true
                };
            }

            return(methodResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method creates an object used to 
        /// track changes for future replications.
        /// In this case, a delete trigger is added to a specified table. 
        /// Note: If the data-source already has a process for tracking changes, this 
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <param name="methodInput">Method input used for the replication object.
        /// This is the name of the table that we need to extract.
        /// methodInput.Input.properties["ObjectName"]
        /// </param>
        /// <returns></returns>
        public MethodResult InitReplicationObject(MethodInput methodInput)
        {
            MethodResult methodResult = null;

            // 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, "InitReplication"))
            {
                //First ensure the change history table exists
                MethodResult initReplicationResult = InitReplication();

                //If the replication table already exist then
                //our work here is done and no other action is required
                if (initReplicationResult.Success)
                {
                    string tableName =
                         GetPropertyValueName("EntityName", methodInput.Input.Properties);
                    string triggerName =
                        string.Format("{0}_Deleted_TRG", tableName);

                    if (CheckForTrigger(triggerName, tableName) == false)
                    {
                        //Use the ConnectorApi provided local data storage to retrieve
                        //and read the sql scripts contents
                        LocalDataStorage localDataStorage = new LocalDataStorage();
                        string deleteTriggerString =
                            localDataStorage.ReadData(TriggerFileName);

                        if (string.IsNullOrWhiteSpace(deleteTriggerString))
                        {
                            throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", TriggerFileName));
                        }

                        string query = string.Format(deleteTriggerString, tableName);
                        //Execute the query to create the change history table.
                        _dataAccess.ExecuteNonQuery(query);
                    }

                    //If there were no errors in processing then
                    //just set the Success for the method result to true.
                    methodResult = new MethodResult { Success = true };
                }
                else
                {
                    methodResult = SetErrorMethodResult(ErrorCodes.InitReplication.Number,
                                                        ErrorCodes.InitReplication.Description);
                }
            }

            return methodResult;
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method defines the process for tracking changes to data.
        /// This particular example shows one way how this operation may work. 
        /// Note: A seperate method will create triggers for each table that will fill this table with deletions.
        /// Note: If the data-source already has a process for tracking changes, this 
        ///       method will only need to return a positive success in the method result
        /// </summary>
        /// <returns></returns>
        public MethodResult InitReplication()
        {
            MethodResult methodResult = null;

            // 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, "InitReplication"))
            {
                //First retrieve the object definition of the
                //default table that is used for replication.
                MethodInput objectDefinitionInput = new MethodInput();
                objectDefinitionInput.Input.Properties.Add(
                    "ObjectName", "ScribeChangeHistory");
                MethodResult objectDefinitionResult =
                    GetObjectDefinition(objectDefinitionInput);

                //If the replication table already exist then our work
                //here is done. No other action is required.
                if (objectDefinitionResult.Success == false)
                {
                    //Use the Sribe-provided local data storage
                    //to retrieve and read the sql scripts contents.
                    LocalDataStorage localDataStorage = new LocalDataStorage();
                    string query =
                        localDataStorage.ReadData(ChangeHistoryFileName);

                    //Throw an error message if the file was not found
                    if (string.IsNullOrWhiteSpace(query))
                    {
                        throw new InvalidExecuteOperationException(string.Format("Unable to locate file: {0}", ChangeHistoryFileName));
                    }

                    //Execute the query to create the change history table.
                    _dataAccess.ExecuteNonQuery(query);
                }

                //If there were no errors in processing, then
                //set the Success for the method result to true.
                methodResult = new MethodResult { Success = true };
            }

            return methodResult;
        }