Beispiel #1
0
        /// <summary>
        /// The insert data trigger field mapping.
        /// </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 InsertDataTriggerFieldMapping(DataTriggerFieldMappingEditDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText = @"
INSERT INTO [dbo].[DataTriggerFieldMappings]
(
     [Guid]
    ,[DataTriggerId]
    ,[LastModifiedOn]
    ,[DestinationFieldSystemName]
    ,[ModificationType]
    ,[SourceDataProcessName]
    ,[SourceDataFilterGuid]
    ,[SourceDataFilterDefinition]
    ,[Expression]
)
VALUES
(
     @guid
    ,@dataTriggerId
    ,GETDATE()
    ,@destinationFieldSystemName
    ,@modificationType
    ,@sourceDataProcessName
    ,@sourceDataFilterGuid
    ,@sourceDataFilterDefinition
    ,@expression
)
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("@dataTriggerId", dto.DataTriggerId);
                cmd.Parameters.AddWithValue("@destinationFieldSystemName", dto.DestinationFieldSystemName);
                cmd.Parameters.AddWithValue("@modificationType", dto.ModificationType.ToString());
                cmd.Parameters.AddWithValue("@sourceDataProcessName", dto.SourceDataProcessName);
                cmd.Parameters.AddWithValue("@sourceDataFilterGuid", AdoHelper.NullCheck(dto.SourceDataFilterGuid));
                cmd.Parameters.AddWithValue("@sourceDataFilterDefinition", dto.SourceDataFilterDefinition);
                cmd.Parameters.AddWithValue("@expression", dto.Expression);

                var rowsAffected = Database.Execute(cmd);

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

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

            const string CommandText = @"
UPDATE [dbo].[DataTriggerFieldMappings]
SET
     [Guid] = @guid
    ,[DataTriggerId] = @dataTriggerId
    ,[LastModifiedOn] = GETDATE()
    ,[DestinationFieldSystemName] = @destinationFieldSystemName
    ,[ModificationType] = @modificationType
    ,[SourceDataProcessName] = @sourceDataProcessName
    ,[SourceDataFilterGuid] = @sourceDataFilterGuid
    ,[SourceDataFilterDefinition] = @sourceDataFilterDefinition
    ,[Expression] = @expression
WHERE [Id] = @id;";

            using (var cmd = new SqlCommand(CommandText))
            {
                cmd.Parameters.AddWithValue("@id", dto.Id);
                cmd.Parameters.AddWithValue("@guid", dto.Guid);
                cmd.Parameters.AddWithValue("@dataTriggerId", dto.DataTriggerId);
                cmd.Parameters.AddWithValue("@destinationFieldSystemName", dto.DestinationFieldSystemName);
                cmd.Parameters.AddWithValue("@modificationType", dto.ModificationType.ToString());
                cmd.Parameters.AddWithValue("@sourceDataProcessName", dto.SourceDataProcessName);
                cmd.Parameters.AddWithValue("@sourceDataFilterGuid", AdoHelper.NullCheck(dto.SourceDataFilterGuid));
                cmd.Parameters.AddWithValue("@sourceDataFilterDefinition", dto.SourceDataFilterDefinition);
                cmd.Parameters.AddWithValue("@expression", dto.Expression);

                var rowsAffected = Database.Execute(cmd);

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

            int? triggerId = null;
            ProcessDataTriggerEditDto trigger = null;

            while (sr.Read())
            {
                var mappingDto = new DataTriggerFieldMappingEditDto
                {
                    Id = sr.GetInt32(0),
                    Guid = sr.GetGuid(1),
                    DataTriggerId = sr.GetInt32(2),
                    DestinationFieldSystemName = sr.GetString(3),
                    DestinationFieldDisplayName = sr.GetString(4),
                    ModificationType =
                        (DataTriggerModificationType)
                        Enum.Parse(typeof(DataTriggerModificationType), sr.GetString(5), true),
                    Expression = sr.GetString(6),
                    SourceDataProcessName = sr.GetString(7),
                    SourceDataFilterGuid = sr.GetNullableGuid(8),
                    SourceDataFilterDefinition = sr.GetString(9)
                };

                if (mappingDto.DataTriggerId != triggerId)
                {
                    trigger = process.TriggerList.First(t => t.Id == mappingDto.DataTriggerId);
                    triggerId = mappingDto.DataTriggerId;
                }

                trigger.FieldMappingList.Add(mappingDto);
            }

            ReadDataTriggerFieldMappingDataSources(process, sr);
        }