# имя: 'Responsive commander 3' # описание: команда по событию # тип триггера: 'EgsObjectUpdated' # создан: 2017.10.23 14:22:07, Сельченков Н.Ю. # изменен: '2019.06.14 16.59.30', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Responsive_commander_3 use System.Random use System.Linq.Expressions.Expression use acuario2.dynamic.DynamicExpression use typedef ` ` as Settings const settings = Settings(trigger.settings) use ("acuario2.types." + settings.source_type) as SourceType from acuario2.types use ("acuario2.types." + settings.target_type) as TargetType from acuario2.types use ("acuario2.types." + (if settings.link_type isnt empty then settings.link_type else "Link")) as LinkType from acuario2.types const delegate = DynamicExpression.TryParseLambda(new [ Expression.Parameter(SourceType as Type) ], bool, settings.source_condition, null).Compile() const triggered(item as SourceType) = delegate.DynamicInvoke(new [item]) as bool use ("acuario2.client." + settings.target_type) as TargetTypeImpl from acuario2.types const targetTypeName = (TargetTypeImpl as Type).GetProperty("command").PropertyType.Name use ("acuario2.types."..targetTypeName) as CommandType from acuario2.types const commandValue = CommandType(eval settings.target_command) const source_items = from settings.source_guids select graph[Guid(it)] of type SourceType to array const target_items = from settings.target_guids select graph[Guid(it)] of type TargetType to array let allowed_source_item(item as SourceType) = (source_items is empty) or (item in source_items) let allowed_target_item(item as TargetType) = (target_items is empty) or (item in target_items) let get_opposite_items(pin as Pin) = from pin.Links where it is LinkType select pin[it].Owner to array let linked_to(item as Item, items as Item[]) = from item.Pins select many get_opposite_items(it) any it is in items let get_same_side_items(pin as Pin) = let opposite_items = get_opposite_items(pin) from graph.Values of type TargetType where it is linked_to opposite_items to array end let item = @object as SourceType if (item isnt null) and (item is allowed_source_item) and (item is triggered) then let targets = if LinkType == Link then from graph.Values of type TargetType else if settings.link_same_side then from item.Pins select many get_same_side_items(it) else from item.Pins select many get_opposite_items(it) of type TargetType from targets where it is allowed_target_item do it["command"].Set(settings.target_command, null, DateTime.UtcNow) now end