# имя: 'Responsive media exporter 2' # описание: экспортирование видео ролика по событию # тип триггера: 'EgsObjectUpdated' # создан: 2017.11.02 11.33.11, Сельченков Н.Ю. # изменен: '2018.04.26 14.33.30', Сельченков Н.Ю. # подробности: https://redmine.integra-s.com:11000/projects/eilyacuario/wiki/Responsive_media_exporter_2 use System.Uri use System.Threading.Tasks.Task use System.Text.RegularExpressions.Regex use System.Collections.Generic.Dictionary(string, object) as Dictionary use System.Collections.Generic.List(Task) as TaskList use acuario2.types.VideoCamera from acuario2.types use acuario2.types.LogicLink from acuario2.types use acuario2.types.Position from acuario2.types use acuario2.types.Space from acuario2.types use integravideo.client.Iv7Server from IntegraVideo7Client ###################################################### use typedef ` http://localhost:1986/axis2/services/Iv7Server ` as Settings const settings = Settings(trigger.settings) use ("acuario2.types." + settings.source_type) as SourceType from acuario2.types use ("acuario2.client." + settings.source_type) as SourceTypeImpl from acuario2.types const stateTypeName = (SourceTypeImpl as Type).GetProperty("state").PropertyType.Name use ("acuario2.types."..stateTypeName) as StateType from acuario2.types const stateNames = Enum.GetNames(StateType as Type) const validStateMask(mask as string) = from stateNames any it like mask assert(settings.source_states isnt empty, "no source state mask specified") assert(from settings.source_states all it is validStateMask, "invalid source state mask") const source_items = from settings.source_guids select graph[Guid(it)] of type SourceType to array const uri = Uri(settings.url) use new { code = 0, user_code = 0, result = null as Dictionary[] } as CallMethod2Result ###################################################### let iv7 = null as Iv7Server let сall_method2(name as string, json as string) = #print(name, json) json = iv7.CallMethod2(name, json, "") print json let res = CallMethod2Result(json) if (res.code is 0) and (res.user_code is 0) then res.result end let start_export_media { id = "", @from = "", @to = "", path = "" } = let result = сall_method2("media:export_media", string(it)) if result isnt null then (result[0] as Dictionary)["unic"] as string end let get_param_from_urls(obj as VideoCamera, pattern as string) = let regex = Regex(pattern) from obj.url select regex.Match(it) where Success select Groups[1].Value first end let get_key2(obj as VideoCamera) = get_param_from_urls(obj, "key2=(.+)[&|;]?") let export_media(camera as VideoCamera, duration as TimeSpan, path as string) = let datetime_format = "yyyy.MM.dd HH:mm:ss" let half_duration = TimeSpan(duration.Ticks / 2) let since = (DateTime.Now - half_duration).ToString(datetime_format) let until = (DateTime.Now + half_duration).ToString(datetime_format) let id = get_key2(camera) print("exporting video delayed for", duration) await Task.Delay(duration) let unic = start_export_media { id = id, @from = since, @to = until, path = path } print("exporting video started", unic, camera) end ###################################################### let allowed_state(state as string) = (settings.source_states isnt empty) and (from settings.source_states any state like it) let allowed_source_item(item as SourceType) = (source_items is empty) or (item in source_items) if ("state" in changes) and (@object["state"].Text is allowed_state) then let item = @object as SourceType if (item isnt null) and (item is allowed_source_item) then iv7 = Iv7Server() iv7.Url = string(uri) let targets = VideoCamera[](0) if settings.logic_link then targets = from item.GetItemsLinkedBy(LogicLink) of type VideoCamera union targets to array if settings.same_space then targets = from item.GetItemsLinkedBy(Position) of type Space select many GetItemsLinkedBy(Position) of type VideoCamera union targets to array from targets do async export_media(it, TimeSpan(settings.media_duration), string(settings.media_path)) now end end