private void ProcessCommand(IStudioCommand command, IStudioCommandScope scope) { var handlers = TryGetHandlers(command); if (handlers == null) { return; } var scopeHandlers = handlers.TryGetValue(scope) ?? (command.CanRouteToGlobalScope ? handlers.TryGetValue(_globalScope) : null); if (scopeHandlers == null) { return; } var guiAsyncActions = new List <Tuple <CommandTuple, IStudioCommand> >(); foreach (var tuple in scopeHandlers.CachedValues) { if (!tuple.Item3) { ProcessCommand(tuple, command); } else { guiAsyncActions.Add(Tuple.Create(tuple, command)); } } if (!guiAsyncActions.IsEmpty()) { GuiDispatcher.GlobalDispatcher.AddAction(() => guiAsyncActions.ForEach(t => ProcessCommand(t.Item1, t.Item2))); } }
void IStudioCommandService.Process(object sender, IStudioCommand command, bool isSyncProcess) { if (TryGetHandlers(command) == null) { return; } var scope = sender is IStudioCommandScope ? _globalScope : GetScope(sender); if (scope == _undefinedScope) { return; } if (isSyncProcess) { if (Thread.CurrentThread != GuiDispatcher.GlobalDispatcher.Dispatcher.Thread) { throw new ArgumentException(LocalizedStrings.Str3596); } ProcessCommand(command, scope); return; } _queue.Enqueue(Tuple.Create(command, scope)); }
private static void ProcessCommand(CommandTuple tuple, IStudioCommand command) { try { tuple.Item1(command); } catch (Exception ex) { ex.LogError(); } }
bool IStudioCommandService.CanProcess(object sender, IStudioCommand command) { var handlers = TryGetHandlers(command); if (handlers == null) { return(false); } var scope = sender is IStudioCommandScope ? _globalScope : GetScope(sender); if (scope == _undefinedScope) { return(false); } var scopeHandlers = handlers.TryGetValue(scope) ?? (command.CanRouteToGlobalScope ? handlers.TryGetValue(_globalScope) : null); return(scopeHandlers != null && scopeHandlers.CachedValues.All(tuple => tuple.Item2 == null || tuple.Item2(command))); }
public static bool CanProcess(this IStudioCommand command, object sender) { return(ConfigManager.GetService <IStudioCommandService>().CanProcess(sender, command)); }
public static void SyncProcess(this IStudioCommand command, object sender) { ConfigManager.GetService <IStudioCommandService>().Process(sender, command); }
public static void Process(this IStudioCommand command, object sender, bool isSyncProcess = false) { ConfigManager.GetService <IStudioCommandService>().Process(sender, command, isSyncProcess); }
private Dictionary <IStudioCommandScope, CachedSynchronizedDictionary <object, CommandTuple> > TryGetHandlers(IStudioCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } var commandType = command.GetType(); var handlers = _handlers.TryGetValue(commandType); if (handlers != null) { return(handlers); } var baseType = _handlers.Keys.FirstOrDefault(commandType.IsSubclassOf); return(baseType != null ? _handlers.TryGetValue(baseType) : null); }
public void Process(object sender, IStudioCommand command, bool isSyncProcess = true) { }
public bool CanProcess(object sender, IStudioCommand command) { return(true); }