Exemplo n.º 1
0
        /// <summary>
        /// Perform the Delete operations on the selected table.
        /// This method will filter deletes using the SqlQueryBuilder and the lookup conditions
        /// </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
                    {
                        //use the query builder to parse input conditions
                        SqlQueryBuilder queryBuilder = new SqlQueryBuilder(
                            inputEntity, operationInput.LookupCondition[index],
                            Globals.OperationType.Delete);

                        //Execute the query generated from the operation input.
                        int rowsEffected = _dataAccess.ExecuteNonQuery(queryBuilder.ToString());

                        //Add a the result to the result list.
                        successList.Add(rowsEffected >= 1);
                        objectList.Add(rowsEffected);
                        errors.Add(SetErrorResult(rowsEffected));
                        index++;
                    }
                    catch (Exception exception)
                    {
                        // In the event of an exception do not stop performing
                        // all operations simply 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method determines whether or not an object from the source has changed.
        /// If the object does not exist it will be created.
        /// If the object has changed it will be deleted and the new one will be created.
        /// If no changes are detected then it will be noted and no further action is needed.
        /// </summary>
        /// <param name="methodInput"></param>
        /// <returns></returns>
        public MethodResult CreateOrUpdateObjectForReplication(MethodInput methodInput)
        {
            MethodResult methodResult = new MethodResult();

            // 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, "CreateOrUpdateObjectForReplication"))
            {
                string tableName = GetPropertyValue("Name", methodInput.Input.Properties);
                //get the list of the columns to be created
                List <DataEntity> newColumns =
                    methodInput.Input.Children["RSPropertyDefinitions"];

                //add the default columns to the new ones from the input
                newColumns.AddRange(CreateDefaultColumns());

                //get the definition of the existing table
                MethodResult currentTableDefinition =
                    GetObjectDefinition(new MethodInput
                {
                    Input =
                    {
                        Properties = new EntityProperties
                        {
                            { "ObjectName", tableName }
                        }
                    }
                });

                bool changeDetected = true;

                //check if the table was returned from GetObjectDefinition method
                if (currentTableDefinition != null && currentTableDefinition.Success)
                {
                    //look for any changes in the table schema by
                    //comparing the properties
                    //of the existing object against the those
                    //found in the method input
                    changeDetected = CheckForSchemaChanges(newColumns,
                                                           currentTableDefinition.Return.Children[
                                                               "RSPropertyDefinitions"]);

                    //if a change is decteded drop the table
                    if (changeDetected)
                    {
                        string query = string.Format("DROP TABLE [{0}]", tableName);
                        _dataAccess.ExecuteNonQuery(query);
                    }
                }

                //Ff a change is detected create the table
                if (changeDetected)
                {
                    _dataAccess.CreateTable(tableName, newColumns);
                }

                //Set the method result object
                methodResult = new MethodResult {
                    Success = true, Return = new DataEntity()
                };

                //add a property called 'SchemaChanged' to the return properties
                //this is how ScribeOnline will determine whether or not a replication
                //is required when this method has completed
                //Note: this MUST be labeled 'SchemaChanged'
                methodResult.Return.Properties.Add("SchemaChanged", changeDetected);
            }

            return(methodResult);
        }