[{"server":null,"owner":null,"id":"9bee3a68-3dd2-4387-8bb3-361e8a88ac2e","params":{"result":{"value":null,"datetime":1560419179,"status":null,"version":0},"hash":{"value":"iEvQPpB7DEy7Vd11NgBSuQ==","datetime":1560516918,"status":null,"version":0},"enabled":{"value":true,"datetime":1560419179,"status":null,"version":0},"error_text":{"value":null,"datetime":1560419179,"status":null,"version":0},"type":{"value":"EgsObjectUpdated","datetime":1560506670,"status":null,"version":0},"settings":{"value":"{\"source_type\":\"LowCurrentSensor\",\"source_guids\":[],\"source_states\":[\"alarm_*\"],\"link_type\":\"Provoker_link\",\"link_same_side\":false,\"target_type\":\"ObservablePoint\",\"target_guids\":[],\"target_command\":\"observe\"}","datetime":1560420671,"status":null,"version":0},"state":{"value":"ok.normal","datetime":1560419179,"status":null,"version":0},"script":{"value":"# имя: 'Responsive commander 2'\r\n# описание: команда по событию\r\n# тип триггера: 'EgsObjectUpdated'\r\n# создан: 2017.10.23 14:22:07, Сельченков Н.Ю.\r\n# изменен: '2019.06.14 16.55.16', Сельченков Н.Ю.\r\n# подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Responsive_commander_2\r\n\r\nuse System.Random\r\n\r\nuse typedef\r\n`\r\n    <root>\r\n        <param name=\"source_type\" type=\"text\"/>\r\n        <param name=\"source_guids\" type=\"list\"/>\r\n        <param name=\"source_states\" type=\"list\"/>\r\n        <param name=\"link_type\" type=\"text\"/>\r\n        <param name=\"link_same_side\" type=\"bool\"/>\r\n        <param name=\"target_type\" type=\"text\"/>\r\n        <param name=\"target_guids\" type=\"list\"/>\r\n        <param name=\"target_command\" type=\"text\"/>\r\n    </root>\r\n` as Settings\r\n\r\nconst settings = Settings(trigger.settings)\r\n\r\nuse (\"acuario2.types.\" + settings.source_type) as SourceType from acuario2.types\r\nuse (\"acuario2.types.\" + settings.target_type) as TargetType from acuario2.types\r\nuse (\"acuario2.types.\" + (if settings.link_type isnt empty then settings.link_type else \"Link\")) as LinkType from acuario2.types\r\n\r\nuse (\"acuario2.client.\" + settings.source_type) as SourceTypeImpl from acuario2.types\r\nconst stateTypeName = (SourceTypeImpl as Type).GetProperty(\"state\").PropertyType.Name\r\nuse (\"acuario2.types.\"..stateTypeName) as StateType from acuario2.types\r\nconst stateNames = Enum.GetNames(StateType as Type)\r\nconst validStateMask(mask as string) = from stateNames any it like mask\r\nassert(settings.source_states isnt empty, \"no source state mask specified\")\r\nassert(from settings.source_states all it is validStateMask, \"invalid source state mask\")\r\n\r\nuse (\"acuario2.client.\" + settings.target_type) as TargetTypeImpl from acuario2.types\r\nconst targetTypeName = (TargetTypeImpl as Type).GetProperty(\"command\").PropertyType.Name\r\nuse (\"acuario2.types.\"..targetTypeName) as CommandType from acuario2.types\r\nconst commandValue = CommandType(eval settings.target_command)\r\n\r\nconst source_items = from settings.source_guids select graph[Guid(it)] of type SourceType to array\r\nconst target_items = from settings.target_guids select graph[Guid(it)] of type TargetType to array\r\n\r\nlet allowed_state(state as string) = from settings.source_states any state like it\r\n\r\nlet allowed_source_item(item as SourceType) = (source_items is empty) or (item in source_items)\r\nlet allowed_target_item(item as TargetType) = (target_items is empty) or (item in target_items)\r\n\r\nlet get_opposite_items(pin as Pin) = from pin.Links where it is LinkType select pin[it].Owner to array\r\nlet linked_to(item as Item, items as Item[]) = from item.Pins select many get_opposite_items(it) any it is in items\r\nlet get_same_side_items(pin as Pin) = \r\n    let opposite_items = get_opposite_items(pin)\r\n    from graph.Values of type TargetType \r\n        where it is linked_to opposite_items\r\n        to array\r\nend    \r\n\r\nif (\"state\" in changes) and (@object[\"state\"].Text is allowed_state) then\r\n    let item = @object as SourceType\r\n    if (item isnt null) and (item is allowed_source_item) then\r\n        let targets =  \r\n            if LinkType == Link then from graph.Values of type TargetType\r\n            else if settings.link_same_side then from item.Pins select many get_same_side_items(it)\r\n            else from item.Pins select many get_opposite_items(it) of type TargetType \r\n        from targets \r\n            where it is allowed_target_item\r\n            do it[\"command\"].Set(settings.target_command, null, DateTime.UtcNow) now\r\n    end\r\nend\r\n\r\n","datetime":1560516916,"status":null,"version":0},"name":{"value":"Responsive commander 2","datetime":1560419179,"status":null,"version":0}},"entity":"item","operation":"create"}]