예제 #1
0
        /// <summary>
        /// Inserts data trigger.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception>
        public void InsertDataTrigger(ProcessDataTriggerEditDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText = @"
INSERT INTO [dbo].[DataTriggers]
(
     [Guid]
    ,[ProcessId]
    ,[LastModifiedOn]
    ,[Name]
    ,[Notes]
    ,[ProcessToModifySystemName]
    ,[FilterGuid]
    ,[FilterDefinition]
    ,[ModificationType]
    ,[ModificationMapping]
    ,[TriggerType]
    ,[StoredProcedureName]
)
VALUES
(
     @guid
    ,@processId
    ,GETDATE()
    ,@name
    ,@notes
    ,@processToModifySystemName
    ,@filterGuid
    ,@filterDefinition
    ,@modificationType
    ,@modificationMapping
    ,@triggerType
    ,@storedProcedureName
)
SET @id = SCOPE_IDENTITY();";

            using (var cmd = new SqlCommand(CommandText))
            {
                var idParam = cmd.Parameters.Add("@id", SqlDbType.Int);

                idParam.Direction = ParameterDirection.Output;

                cmd.Parameters.AddWithValue("@guid", dto.Guid);
                cmd.Parameters.AddWithValue("@processId", dto.ProcessId);
                cmd.Parameters.AddWithValue("@name", dto.Name);
                cmd.Parameters.AddWithValue("@notes", dto.Notes);
                cmd.Parameters.AddWithValue("@processToModifySystemName", dto.ProcessToModifySystemName);
                cmd.Parameters.AddWithValue("@filterGuid", AdoHelper.NullCheck(dto.FilterGuid));
                cmd.Parameters.AddWithValue("@filterDefinition", AdoHelper.NullCheck(dto.FilterDefinition));
                cmd.Parameters.AddWithValue("@modificationType", dto.ModificationType.ToString());
                cmd.Parameters.AddWithValue("@modificationMapping", AdoHelper.NullCheck(dto.ModificationMapping));
                cmd.Parameters.AddWithValue("@triggerType", dto.TriggerType.ToString());
                cmd.Parameters.AddWithValue("@storedProcedureName", AdoHelper.NullCheck(dto.StoredProcedureName));

                var rowsAffected = Database.Execute(cmd);

                if (rowsAffected == 0)
                {
                    throw new DBConcurrencyException(Resources.StaleDataException);
                }

                dto.Id = (int)idParam.Value;
            }
        }
예제 #2
0
        /// <summary>
        /// Updates data trigger.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception>
        public void UpdateDataTrigger(ProcessDataTriggerEditDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText = @"
UPDATE [dbo].[DataTriggers]
SET
     [Guid] = @guid
    ,[ProcessId] = @processId
    ,[LastModifiedOn] = GETDATE()
    ,[Name] = @name
    ,[Notes] = @notes
    ,[ProcessToModifySystemName] = @processToModifySystemName
    ,[FilterGuid] = @filterGuid
    ,[FilterDefinition] = @filterDefinition
    ,[ModificationType] = @modificationType
    ,[ModificationMapping] = @modificationMapping
    ,[TriggerType] = @triggerType
    ,[StoredProcedureName] = @storedProcedureName
WHERE [Id] = @id;";

            using (var cmd = new SqlCommand(CommandText))
            {
                cmd.Parameters.AddWithValue("@id", dto.Id);
                cmd.Parameters.AddWithValue("@guid", dto.Guid);
                cmd.Parameters.AddWithValue("@processId", dto.ProcessId);
                cmd.Parameters.AddWithValue("@name", dto.Name);
                cmd.Parameters.AddWithValue("@notes", dto.Notes);
                cmd.Parameters.AddWithValue("@processToModifySystemName", dto.ProcessToModifySystemName);
                cmd.Parameters.AddWithValue("@filterGuid", AdoHelper.NullCheck(dto.FilterGuid));
                cmd.Parameters.AddWithValue("@filterDefinition", AdoHelper.NullCheck(dto.FilterDefinition));
                cmd.Parameters.AddWithValue("@modificationType", dto.ModificationType.ToString());
                cmd.Parameters.AddWithValue("@modificationMapping", AdoHelper.NullCheck(dto.ModificationMapping));
                cmd.Parameters.AddWithValue("@triggerType", dto.TriggerType.ToString());
                cmd.Parameters.AddWithValue("@storedProcedureName", AdoHelper.NullCheck(dto.StoredProcedureName));

                var rowsAffected = Database.Execute(cmd);

                if (rowsAffected == 0)
                {
                    throw new DBConcurrencyException(Resources.StaleDataException);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Reads data triggers.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="sr">The reader.</param>
        private static void ReadDataTriggers(ProcessEditDto process, SafeDataReader sr)
        {
            sr.NextResult();

            while (sr.Read())
            {
                var dto = new ProcessDataTriggerEditDto
                {
                    Id = sr.GetInt32(0),
                    Guid = sr.GetGuid(1),
                    Name = sr.GetString(2),
                    Notes = sr.GetString(3),
                    ProcessToModifySystemName = sr.GetString(4),
                    FilterGuid = sr.GetNullableGuid(5),
                    FilterDefinition = sr.GetString(6),
                    ModificationType = (DataTriggerModificationType)Enum.Parse(typeof(DataTriggerModificationType), sr.GetString(7), true),
                    ModificationMapping = sr.GetString(8),
                    TriggerType = sr.GetEnum(9, DataTriggerTypes.Process),
                    StoredProcedureName = sr.GetString(10)
                };

                process.TriggerList.Add(dto);
            }

            ReadDataTriggerMappings(process, sr);
            ReadDataTriggerRules(process, sr);
            ReadDataTriggerStoredProcedureParameters(process, sr);
        }