# имя: 'Proxy item 3' # описание: прокси - заместитель связанного устройства # тип триггера: 'EgsObjectUpdated' # создан: 2018.02.28 17.37.48, Сельченков Н.Ю. # изменен: '2019.04.19 11.51.39', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Proxy_item_3 use Newtonsoft.Json.Linq.JObject as JObject use Newtonsoft.Json.JsonConvert as JsonConvert from Newtonsoft.Json use typedef ` ` as Settings const settings = Settings(trigger.settings) const table = JsonConvert.DeserializeObject(settings.table, JObject) as JObject use ("acuario2.types." + settings.item_type) as ItemType from acuario2.types use ("acuario2.types." + settings.proxy_type) as ProxyType from acuario2.types if @object is Item then let item = @object as ItemType if (item isnt nil) and ("state" in changes) then let source = item["state"] from item.(settings.item_pin).GetOppositeItems() where it is ProxyType do let target = it["state"] let value = from table.Properties() where source.Text like Name select Value try first if value isnt null then target.Set(value, source.Status, source.DateTime) else if source.Text in target.EnumNames then target.Set(source.Text, source.Status, source.DateTime) else switch item.State when "ok" then target.Set("ok_normal", source.Status, source.DateTime) when "error" then target.Set("error_defective", source.Status, source.DateTime) when "alarm" then target.Set("alarm_alarm", source.Status, source.DateTime) when "none" then target.Set("none_unknown", source.Status, source.DateTime) else target.Set("DEFAULT", Status.invalid, source.DateTime) now end let proxy = @object as ProxyType if (proxy isnt nil) and ("command" in changes) then let source = proxy["command"].Old ?? proxy["command"] from proxy.(settings.proxy_pin).GetOppositeItems() where it is ItemType do let target = it["command"] if source.Text in target.EnumNames then target.Set(source.Text, source.Status, source.DateTime) else target.Set("DEFAULT", Status.invalid, source.DateTime) now end end