Beispiel #1
0
        /// <summary>
        /// Updates process metric.
        /// </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 UpdateProcessMetric(ProcessMetricEditDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
    @"
UPDATE [dbo].[Metrics]
SET
     [LastModifiedOn]               = @p_LastModifiedOn
    ,[GuidId]                       = @p_GuidId
    ,[Name]                         = @p_Name
    ,[Documentation]                = @p_Documentation
    ,[SummaryType]                  = @p_SummaryType
    ,[LockFilter]                   = @p_LockFilter
    ,[SnapshotFrequency]            = @p_SnapshotFrequency
    ,[MetricFieldSystemName]        = @p_MetricFieldSystemName
    ,[GroupFieldOneSystemName]      = @p_GroupFieldOneSystemName
    ,[GroupFieldTwoSystemName]      = @p_GroupFieldTwoSystemName
    ,[GroupFieldThreeSystemName]    = @p_GroupFieldThreeSystemName
    ,[GroupFieldFourSystemName]     = @p_GroupFieldFourSystemName
    ,[FilterGuid]                   = @p_FilterGuid
    ,[OrderByMetricField]           = @p_OrderByMetricField
    ,[OrderByAscending]             = @p_OrderByAscending
    ,[FilterDefinition]             = @p_FilterDefinition
WHERE [Id] = @p_Id;
";
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", dto.LastModifiedOn);
                    command.Parameters.AddWithValue("@p_GuidId", dto.GuidId);
                    command.Parameters.AddWithValue("@p_Name", dto.Name);
                    command.Parameters.AddWithValue("@p_Documentation", dto.Documentation);
                    command.Parameters.AddWithValue("@p_SummaryType", dto.SummaryType);
                    command.Parameters.AddWithValue("@p_LockFilter", dto.LockFilter);
                    command.Parameters.AddWithValue("@p_SnapshotFrequency", dto.SnapshotFrequency);
                    command.Parameters.AddWithValue("@p_MetricFieldSystemName", dto.MetricFieldSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldOneSystemName", dto.GroupFieldOneSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldTwoSystemName", dto.GroupFieldTwoSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldThreeSystemName", dto.GroupFieldThreeSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldFourSystemName", dto.GroupFieldFourSystemName);
                    command.Parameters.AddWithValue("@p_FilterGuid", dto.FilterGuid);
                    command.Parameters.AddWithValue("@p_OrderByMetricField", dto.OrderByMetricField);
                    command.Parameters.AddWithValue("@p_OrderByAscending", dto.OrderByAscending ?? (object)DBNull.Value);
                    command.Parameters.AddWithValue("@p_FilterDefinition", dto.FilterDefinition);

                    if (command.ExecuteNonQuery() == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Inserts process metric.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        public void InsertProcessMetric(ProcessMetricEditDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
    @"
INSERT INTO [dbo].[Metrics]
(
     [ProcessId]
    ,[LastModifiedOn]
    ,[GuidId]
    ,[Name]
    ,[Documentation]
    ,[SummaryType]
    ,[LockFilter]
    ,[SnapshotFrequency]
    ,[MetricFieldSystemName]
    ,[GroupFieldOneSystemName]
    ,[GroupFieldTwoSystemName]
    ,[GroupFieldThreeSystemName]
    ,[GroupFieldFourSystemName]
    ,[FilterGuid]
    ,[OrderByMetricField]
    ,[OrderByAscending]
    ,[FilterDefinition]
)
VALUES
(
     @p_ProcessId
    ,@p_LastModifiedOn
    ,@p_GuidId
    ,@p_Name
    ,@p_Documentation
    ,@p_SummaryType
    ,@p_LockFilter
    ,@p_SnapshotFrequency
    ,@p_MetricFieldSystemName
    ,@p_GroupFieldOneSystemName
    ,@p_GroupFieldTwoSystemName
    ,@p_GroupFieldThreeSystemName
    ,@p_GroupFieldFourSystemName
    ,@p_FilterGuid
    ,@p_OrderByMetricField
    ,@p_OrderByAscending
    ,@p_FilterDefinition
);
SELECT [Id]
FROM [dbo].[Metrics]
WHERE [Id] = SCOPE_IDENTITY()";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_ProcessId", dto.ProcessId);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", dto.LastModifiedOn);
                    command.Parameters.AddWithValue("@p_GuidId", dto.GuidId);
                    command.Parameters.AddWithValue("@p_Name", dto.Name);
                    command.Parameters.AddWithValue("@p_Documentation", dto.Documentation);
                    command.Parameters.AddWithValue("@p_SummaryType", dto.SummaryType);
                    command.Parameters.AddWithValue("@p_LockFilter", dto.LockFilter);
                    command.Parameters.AddWithValue("@p_SnapshotFrequency", dto.SnapshotFrequency);
                    command.Parameters.AddWithValue("@p_MetricFieldSystemName", dto.MetricFieldSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldOneSystemName", dto.GroupFieldOneSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldTwoSystemName", dto.GroupFieldTwoSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldThreeSystemName", dto.GroupFieldThreeSystemName);
                    command.Parameters.AddWithValue("@p_GroupFieldFourSystemName", dto.GroupFieldFourSystemName);
                    command.Parameters.AddWithValue("@p_FilterGuid", dto.FilterGuid);
                    command.Parameters.AddWithValue("@p_OrderByMetricField", dto.OrderByMetricField);
                    command.Parameters.AddWithValue("@p_OrderByAscending", dto.OrderByAscending.HasValue ? (object)dto.OrderByAscending.Value : DBNull.Value);
                    command.Parameters.AddWithValue("@p_FilterDefinition", dto.FilterDefinition);

                    dto.Id = (int)command.ExecuteScalar();
                }
            }
        }