/// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlDatabaseTrigger"/> class.
        /// </summary>
        /// <param name="name">A trigger name.</param>
        /// <param name="definition">The definition of the trigger.</param>
        /// <param name="queryTiming">A trigger query timing.</param>
        /// <param name="events">Table events that cause the trigger to fire.</param>
        /// <param name="isEnabled">If <see langword="true"/>, determines that the trigger is currently enabled.</param>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>. Alternatively if <paramref name="definition"/> is <c>null</c>, empty or whitespace.</exception>
        /// <exception cref="ArgumentException"><paramref name="queryTiming"/> or <paramref name="events"/> is an invalid enum or has invalid values.</exception>
        public PostgreSqlDatabaseTrigger(Identifier name, string definition, TriggerQueryTiming queryTiming, TriggerEvent events, bool isEnabled)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (definition.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(definition));
            }
            if (!queryTiming.IsValid())
            {
                throw new ArgumentException($"The { nameof(TriggerQueryTiming) } provided must be a valid enum.", nameof(queryTiming));
            }
            if (!events.IsValid())
            {
                throw new ArgumentException($"The { nameof(TriggerEvent) } provided must be a valid enum.", nameof(events));
            }
            if (events == TriggerEvent.None)
            {
                throw new ArgumentException("Invalid trigger event flags given. Must include at least one event, e.g. INSERT, DELETE, UPDATE.", nameof(events));
            }

            Name         = name.LocalName;
            Definition   = definition;
            QueryTiming  = queryTiming;
            TriggerEvent = events;
            IsEnabled    = isEnabled;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParsedTriggerData"/> class.
        /// </summary>
        /// <param name="queryTiming">A query timing.</param>
        /// <param name="events">Trigger events.</param>
        /// <exception cref="ArgumentException"><paramref name="queryTiming"/> or <paramref name="events"/> are invalid enum values.</exception>
        public ParsedTriggerData(TriggerQueryTiming queryTiming, TriggerEvent events)
        {
            if (!queryTiming.IsValid())
            {
                throw new ArgumentException($"The { nameof(TriggerQueryTiming) } provided must be a valid enum.", nameof(queryTiming));
            }
            if (!events.IsValid())
            {
                throw new ArgumentException($"The { nameof(TriggerEvent) } provided must be a valid enum.", nameof(events));
            }

            Timing = queryTiming;
            Event  = events;
        }