Exemplo n.º 1
0
        public static IDelayDecorator Get(string username, CommandHandler command)
        {
            var userDecorator = UserDecorator.Get(username, command, true);
            var globalDecorator = GlobalDecorator.Get(command);

            if (HybridInstances.ContainsKey(command))
            {
                if (HybridInstances[command].ContainsKey(username))
                    return HybridInstances[command][username];

                var hybridDecorator = new HybridDecorator(userDecorator, globalDecorator);

                HybridInstances[command].AddOrUpdate(username, hybridDecorator, (k, v) => hybridDecorator);

                return hybridDecorator;
            }

            var decorator = new HybridDecorator(userDecorator, globalDecorator);
            var hybrid = new ConcurrentDictionary<string, HybridDecorator>();
            hybrid.AddOrUpdate(username, decorator, (k, v) => decorator);

            HybridInstances.AddOrUpdate(command, hybrid, (k, v) => hybrid);

            return decorator;
        }
Exemplo n.º 2
0
        public static bool TryGet(string command, out CommandHandler handler)
        {
            if (IsExistCommand(command))
            {
                handler = CommandList.Single(t => t.Name.Equals(command, StringComparison.InvariantCultureIgnoreCase));
                return true;
            }

            handler = null;
            return false;
        }