Exemplo n.º 1
0
        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)));
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 private static void ProcessCommand(CommandTuple tuple, IStudioCommand command)
 {
     try
     {
         tuple.Item1(command);
     }
     catch (Exception ex)
     {
         ex.LogError();
     }
 }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
0
 public static bool CanProcess(this IStudioCommand command, object sender)
 {
     return(ConfigManager.GetService <IStudioCommandService>().CanProcess(sender, command));
 }
Exemplo n.º 6
0
 public static void SyncProcess(this IStudioCommand command, object sender)
 {
     ConfigManager.GetService <IStudioCommandService>().Process(sender, command);
 }
Exemplo n.º 7
0
 public static void Process(this IStudioCommand command, object sender, bool isSyncProcess = false)
 {
     ConfigManager.GetService <IStudioCommandService>().Process(sender, command, isSyncProcess);
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 public void Process(object sender, IStudioCommand command, bool isSyncProcess = true)
 {
 }
Exemplo n.º 10
0
 public bool CanProcess(object sender, IStudioCommand command)
 {
     return(true);
 }