[{"server":null,"owner":null,"id":"2352ce48-8609-4994-a3a2-14f852cdfad2","params":{"result":{"value":null,"datetime":1560517037,"status":null,"version":0},"hash":{"value":"nQhSngfnqeqZif6Rj5/Z5Q==","datetime":1560517171,"status":null,"version":0},"enabled":{"value":true,"datetime":1560517037,"status":null,"version":0},"error_text":{"value":null,"datetime":1560517105,"status":null,"version":0},"type":{"value":"EgsObjectUpdated","datetime":1560517038,"status":null,"version":0},"settings":{"value":"{\"source_type\":\"LowCurrentSensor\",\"source_guids\":[],\"source_states\":[\"error_*\",\"alarm_*\"],\"link_type\":\"\",\"link_same_side\":false,\"target_type\":\"ObservablePoint\",\"target_guids\":[],\"target_command\":\"observe\",\"source_condition\":\"state is \\\"alarm_alarm\\\"\"}","datetime":1560517104,"status":null,"version":0},"state":{"value":"ok.normal","datetime":1560517105,"status":null,"version":0},"script":{"value":"# имя: 'Responsive commander 3'\r\n# описание: команда по событию\r\n# тип триггера: 'EgsObjectUpdated'\r\n# создан: 2017.10.23 14:22:07, Сельченков Н.Ю.\r\n# изменен: '2019.06.14 16.59.30', Сельченков Н.Ю.\r\n# подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Responsive_commander_3\r\n\r\nuse System.Random\r\nuse System.Linq.Expressions.Expression\r\nuse acuario2.dynamic.DynamicExpression\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_condition\" type=\"text\"/>\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\nconst delegate = DynamicExpression.TryParseLambda(new [ Expression.Parameter(SourceType as Type) ], bool, settings.source_condition, null).Compile()\r\nconst triggered(item as SourceType) = delegate.DynamicInvoke(new [item]) as bool\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_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\nlet item = @object as SourceType\r\nif (item isnt null) and (item is allowed_source_item) and (item is triggered) 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\nend\r\n\r\n","datetime":1560517170,"status":null,"version":0},"name":{"value":"Responsive commander 3","datetime":1560517037,"status":null,"version":0}},"entity":"item","operation":"create"}]