예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Perform the Delete operation on the created ScribeChangeHistory 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 operation result
        /// </summary>
        /// <param name="operationInput"></param>
        /// <returns></returns>
        public OperationResult DeleteOperation(OperationInput operationInput)
        {
            OperationResult operationResult = new OperationResult();

            // 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, "Delete"))
            {
                List <bool>        successList = new List <bool>();
                List <int>         objectList  = new List <int>();
                List <ErrorResult> errors      = new List <ErrorResult>();

                int index = 0;
                //Execute each of the inputs individually
                foreach (DataEntity inputEntity in operationInput.Input)
                {
                    try
                    {
                        //Construct the query that will remove any records in the change
                        //history table that were used in a previous syncronization

                        /*Note:
                         * A more enhanced example of query parsing can be found in
                         * SqlQueryBuilder.cs which is part of the Sample RS Target Connector
                         */
                        string query = string.Format("DELETE FROM ScribeChangeHistory {0}",
                                                     ParseComparisionExpression(
                                                         operationInput.LookupCondition[index] as ComparisonExpression));
                        //execute the query to clean the scribe change history table
                        int recordsDeleted = _dataAccess.ExecuteNonQuery(query);
                        //add a new success result
                        successList.Add(true);
                        objectList.Add(recordsDeleted);
                        errors.Add(new ErrorResult());
                        index++;
                    }
                    catch (Exception exception)
                    {
                        //In the event of an exception do not stop performing all operations
                        //simple log each individually
                        successList.Add(false);
                        objectList.Add(0);
                        errors.Add(new ErrorResult
                        {
                            Description = exception.Message, Detail = exception.ToString()
                        });
                    }
                }

                //Add the results from the operations to the operation result object
                operationResult.Success         = successList.ToArray();
                operationResult.ObjectsAffected = objectList.ToArray();
                operationResult.ErrorInfo       = errors.ToArray();
            }

            return(operationResult);
        }