Beispiel #1
0
        /// <summary>
        /// Gets the event by ID.
        /// </summary>
        public override Event GetEventByID(long eventID)
        {
            try
            {
                stopwatch.Restart();
                conn.Open();

                string sql = queryBuilder.SelectEventQuery +
                             "WHERE event_id = @eventID AND @startTime <= time_stamp AND time_stamp < @endTime";

                DateTime      eventTime = ScadaUtils.RetrieveTimeFromID(eventID); // accurate to seconds
                NpgsqlCommand cmd       = new NpgsqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("eventID", eventID);
                cmd.Parameters.AddWithValue("startTime", eventTime);
                cmd.Parameters.AddWithValue("endTime", eventTime.AddSeconds(1.0));
                Event ev = null;

                using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                {
                    if (reader.Read())
                    {
                        ev = ReadEvent(reader);
                    }
                }

                stopwatch.Stop();
                arcLog?.WriteAction(ServerPhrases.ReadingEventCompleted, stopwatch.ElapsedMilliseconds);
                return(ev);
            }
            finally
            {
                conn.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the event by ID.
        /// </summary>
        public override Event GetEventByID(long eventID)
        {
            stopwatch.Restart();
            EventTable eventTable = GetEventTable(ScadaUtils.RetrieveTimeFromID(eventID));
            Event      ev         = eventTable.GetEventByID(eventID);

            stopwatch.Stop();
            arcLog?.WriteAction(ServerPhrases.ReadingEventCompleted, stopwatch.ElapsedMilliseconds);
            return(ev);
        }
Beispiel #3
0
        /// <summary>
        /// Acknowledges the event.
        /// </summary>
        public override void AckEvent(long eventID, DateTime timestamp, int userID)
        {
            EventTable eventTable = GetEventTable(ScadaUtils.RetrieveTimeFromID(eventID));
            Event      ev         = eventTable.GetEventByID(eventID);

            if (ev != null)
            {
                stopwatch.Restart();
                ev.Ack          = true;
                ev.AckTimestamp = timestamp;
                ev.AckUserID    = userID;

                adapter.FileName = eventTable.FileName;
                adapter.WriteEventAck(ev);
                eventTable.FileAge = File.GetLastWriteTimeUtc(eventTable.FileName);

                stopwatch.Stop();
                arcLog?.WriteAction(ServerPhrases.AckEventCompleted, stopwatch.ElapsedMilliseconds);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Acknowledges the event.
        /// </summary>
        public override void AckEvent(EventAck eventAck)
        {
            try
            {
                stopwatch.Restart();
                conn.Open();

                string sql = $"UPDATE {queryBuilder.EventTable} " +
                             "SET ack = true, ack_timestamp = @ackTimestamp, ack_user_id = @ackUserID " +
                             "WHERE event_id = @eventID AND @startTime <= time_stamp AND time_stamp < @endTime";

                DateTime      eventTime = ScadaUtils.RetrieveTimeFromID(eventAck.EventID);
                NpgsqlCommand cmd       = new NpgsqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("ackTimestamp", eventAck.Timestamp);
                cmd.Parameters.AddWithValue("ackUserID", eventAck.UserID);
                cmd.Parameters.AddWithValue("eventID", eventAck.EventID);
                cmd.Parameters.AddWithValue("startTime", eventTime);
                cmd.Parameters.AddWithValue("endTime", eventTime.AddSeconds(1.0));
                int rowsAffected = cmd.ExecuteNonQuery();
                stopwatch.Stop();

                if (rowsAffected > 0)
                {
                    arcLog?.WriteAction(ServerPhrases.AckEventCompleted, eventAck.EventID,
                                        stopwatch.ElapsedMilliseconds);
                }
                else
                {
                    arcLog?.WriteAction(ServerPhrases.AckEventNotFound, eventAck.EventID);
                }
            }
            finally
            {
                conn.Close();
            }
        }