Пример #1
0
        /// <summary>
        /// Creates and registers a command for a command client</summary>
        /// <param name="def">Command definition</param>
        /// <param name="client">Command client</param>
        /// <returns>ICommandItem for command</returns>
        public ICommandItem RegisterCommand(CommandDef def, ICommandClient client)
        {
            Requires.NotNull(client, "client");

            // Problem - what about same command tag registered in several places with different shortcuts
            // submenus etc?
            ICommandItem command;

            if (!m_commandsLookup.TryGetValue(def.CommandTag, out command))
            {
                if (!CommandIsUnique(def.MenuTag, def.CommandTag))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}",
                                  def.CommandTag, def.GroupTag, def.MenuTag, def.Text));
                }

                command = new CommandItem(def, CanDoCommand, CommandExecuted);
                m_commands.Add(command);
                m_commands.Sort(new CommandComparer());
                m_commandsLookup.Add(command.CommandTag, command);
                int index = m_commands.IndexOf(command);
                CommandAdded.Raise <ItemInsertedEventArgs <ICommandItem> >(this, new ItemInsertedEventArgs <ICommandItem>(index, command));
            }

            m_commandClients.Add(def.CommandTag, client);

            return(command);
        }
Пример #2
0
        public void AddOuterCommand(Int32 identity, Byte[][] message)
        {
            var commandInfo = CommandCodec.DecodeCommandInit(identity, message);

            commandInfo.MessageWrapper = CreateWrapper($"c_{commandInfo.Name}{commandInfo.Node}_msg",
                                                       commandInfo.RequestDescription,
                                                       $"c_{commandInfo.Name}{commandInfo.Node}_repl",
                                                       commandInfo.ReplyDescription);

            m_outerCommands.Add((commandInfo.Node, commandInfo.Name), commandInfo);
            CommandAdded?.Invoke(this, commandInfo);

            IMessageCreator CreateWrapper(String msgName, IList <MessagePartDescription> msgDesc,
                                          String repName, IList <MessagePartDescription> replDesc)
            {
                var msg = (msgDesc is null) ?
                          typeof(MockMessage) :
                          (msgDesc[0].Type == MessageValueType.Raw) ?
                          typeof(RawMessage) :
                          MessageTypeCreator.Instance.CreateMessageType(msgName, msgDesc);
                var repl = (replDesc is null) ?
                           typeof(MockMessage) :
                           (replDesc[0].Type == MessageValueType.Raw) ?
                           typeof(RawMessage) :
                           MessageTypeCreator.Instance.CreateMessageType(repName, replDesc);

                return((IMessageCreator)Activator.CreateInstance(
                           typeof(MessageCreator <,>).MakeGenericType(msg, repl)));
            }
        }
Пример #3
0
 public void Add(TCommand command)
 {
     if (CommandAdded != null)
     {
         CommandAdded.Invoke(command);
     }
 }
Пример #4
0
        public IVariable <T> RegisterVariable <T>(ProxyVariableInfo <T> info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            if (CheckForCommandExistence <IVariable <T> >(info.Name, out var existingCommand))
            {
                return(existingCommand);
            }

            var expression = info.Expression;

            if (!(expression.Body is MemberExpression memberAccess))
            {
                throw new ArgumentException("Invalid Expression. Expression should consist of a property or field access only", nameof(expression));
            }

            var instance = Expression.Lambda <Func <object> >(memberAccess.Expression).Compile()();

            if (instance == null)
            {
                throw new ArgumentException("Cannot register a variable on a null object", nameof(expression));
            }

            var memberInfo = memberAccess.Member;

            //Reject write-only properties
            if (memberInfo is PropertyInfo prop)
            {
                var getter = prop.GetGetMethod(true);

                if (getter == null)
                {
                    throw new ArgumentException($"The property {prop.Name} of type {prop.DeclaringType.FullName} has no get accessor", nameof(expression));
                }

                if (!getter.IsPublic)
                {
                    throw new ArgumentException($"The property {prop.Name} of type {prop.DeclaringType.FullName} has a non-public get accessor", nameof(expression));
                }
            }

            var typeProxy = info._typeProxy ?? _commandSystem.GetTypeProxy <T>();

            var variable = new ProxyVariable <T>(this, info.Name, info.Flags, info.HelpInfo, instance, memberInfo, info._isReadOnly, typeProxy, info.CreateChangeHandlerList(), info.Tag);

            _commands.Add(variable.Name, variable);

            CommandAdded?.Invoke(variable);

            return(variable);
        }
Пример #5
0
        public override void AddCommand(string cmd, string format, string description, ConfigFlags flags, CommandCallback callback, object data = null)
        {
            if (Commands.ContainsKey(cmd))
            {
                Debug.Warning("console", $"Command {cmd} already exist");
                return;
            }

            var command = new ConsoleCommand(cmd, format, description, flags, data);

            command.Executed += callback;
            Commands.Add(cmd, command);
            CommandAdded?.Invoke(command);
        }
Пример #6
0
        public async Task AddCommandAsync(ICommandModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            await HubContext.Clients.All.ReceiveCommand(command);

            if (CommandAdded != null)
            {
                CommandAdded.Invoke(this, new CommandEventArgs(command));
            }
        }
Пример #7
0
        public ICommand RegisterCommand(CommandInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            if (CheckForCommandExistence <ICommand>(info.Name, out var existingCommand))
            {
                return(existingCommand);
            }

            var command = new Command(this, info.Name, info.Executors, info.Flags, info.HelpInfo, info.Tag);

            _commands.Add(command.Name, command);

            CommandAdded?.Invoke(command);

            return(command);
        }
Пример #8
0
        public IVariable <T> RegisterVariable <T>(VirtualVariableInfo <T> info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            if (CheckForCommandExistence <IVariable <T> >(info.Name, out var existingCommand))
            {
                return(existingCommand);
            }

            var typeProxy = info._typeProxy ?? _commandSystem.GetTypeProxy <T>();

            var variable = new VirtualVariable <T>(this, info.Name, info.Value, info._isReadOnly ?? false, info.Flags, info.HelpInfo, typeProxy, info.CreateChangeHandlerList(), info.Tag);

            _commands.Add(variable.Name, variable);

            CommandAdded?.Invoke(variable);

            return(variable);
        }
 private void OnCommandAdded(object sender, EditorCommand editorCommand)
 {
     CommandAdded?.Invoke(this, editorCommand);
 }
Пример #10
0
 //------------------
 private void FireCommandAddedEvent(OwlCommand c)
 {
     CommandAdded?.Invoke(this, c);
     FireQueueChangedEvent();
 }
Пример #11
0
 public void AddCommand(OuterCommand commandInfo)
 {
     Commands.Add(commandInfo.Name, commandInfo);
     CommandAdded?.Invoke(this, new CommandAddedEventArgs(commandInfo));
 }