# имя: 'Event checker 2' # описание: Тех. осмотр, проверка и т.п. # тип триггера: 'EgsScheduled' # создан: 2017.10.27 13.12.06, Сельченков Н.Ю. # изменен: '2018.12.19 14.00.11', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Event_checker_2 use acuario2.types.OnMaintance from acuario2.types use acuario2.types.OnMaintanceStateargs from acuario2.types use acuario2.utils.TextExtension from acuario2.utils use typedef ` ` as Settings const settings = Settings(trigger.settings) use ("acuario2.types." + settings.type) as ItemType from acuario2.types const eventName = TextExtension.LowercaseFirst(settings.event) const EventName = TextExtension.UppercaseFirst(settings.event) const eventPeriod = eventName.."Period" const eventLast = eventName.."Last" const eventPlanned = eventName.."Planned" const EventNeeded = OnMaintanceStateargs(eval EventName.."Needed") const EventExpired = OnMaintanceStateargs(eval EventName.."Expired") const timeout = settings.timeout ?? TimeSpan.Zero let clearStateArg(item, value) = if value is in item.stateargs then item.stateargs = from item.stateargs except value to array let setStateArg(item, value) = if value isnt in item.stateargs then item.stateargs = from item.stateargs union value to array from graph.Values of type OnMaintance where it is ItemType do if stateargs is nil then stateargs = OnMaintanceStateargs[](0) let period = it.(eventPeriod) if period is TimeSpan.Zero then it[eventPeriod].Set(period, Status.invalid, null) else let now = DateTime.UtcNow let last = it.(eventLast) if (last is DateTime.MinValue) or (last > now) then it[eventLast].Set(last, Status.invalid, null) else it.(eventPlanned) = last + period if now > it.(eventPlanned) then setStateArg(it, EventExpired) it[eventLast].Set(last, Status.alarm, null) else if now > it.(eventPlanned) - timeout then setStateArg(it, EventNeeded) else clearStateArg(it, EventExpired); clearStateArg(it, EventNeeded) end end now