Example #1
0
        void Setup(string commandParam, string commandEventParam, string commandReleaseEventParam)
        {
            if (string.IsNullOrWhiteSpace(commandParam))
            {
                if (!string.IsNullOrWhiteSpace(commandEventParam))
                {
                    Log.Write(LogLevel.Warning, "Command event '" + commandEventParam + "' has no associated command in SimpleHotkey.cs");
                }
                if (!string.IsNullOrWhiteSpace(commandReleaseEventParam))
                {
                    Log.Write(LogLevel.Warning, "Command release event '" + commandReleaseEventParam + "' has no associated command in SimpleHotkey.cs");
                }
                return;
            }

            string[]    commands = commandParam.Trim().Split(',');
            CommandFlag combo    = 0;

            foreach (string command in commands)
            {
                CommandFlag flag = flagFromString(command);
                if (flag == CommandFlag.Invalid)
                {
                    continue;
                }
                combo |= flag;

                Subscribe += (Client client) =>
                {
                    client.SubscribeToCommand(command, CommandAction.All, (CommandData data) =>
                    {
                        OnCommand(data);
                    },
                                              (canceledData) => { });
                };
            }
            if (combo == 0)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(commandEventParam))
            {
                CommandEvents.Add(combo, commandEventParam);
            }

            if (!string.IsNullOrWhiteSpace(commandReleaseEventParam))
            {
                CommandReleaseEvents.Add(combo, commandReleaseEventParam);
            }
        }
Example #2
0
        void OnCommand(CommandData data)
        {
            if (!Enabled)
            {
                return;
            }

            CommandFlag currentHotkey = flagFromString(data.Command);

            if (currentHotkey == CommandFlag.Invalid)
            {
                return;
            }

            if (data.Action == CommandAction.Pressed)
            {
                if ((currentHotkey & HeldKeys[data.SessionId]) == 0x0)
                {
                    string sendEvents;
                    if (CommandEvents.TryGetValue(currentHotkey, out sendEvents))
                    {
                        SimpleData sd = new SimpleData(this);
                        sd.SourceObjectId = ObjectPrivate.ObjectId;
                        sd.AgentInfo      = ScenePrivate.FindAgent(data.SessionId)?.AgentInfo;
                        sd.ObjectId       = (sd.AgentInfo != null) ? sd.AgentInfo.ObjectId : ObjectId.Invalid;
                        SendToAll(sendEvents, sd);
                    }

                    HeldKeys[data.SessionId] |= currentHotkey;
                }
            }
            else if (data.Action == CommandAction.Released)
            {
                if ((currentHotkey & HeldKeys[data.SessionId]) != 0x0)
                {
                    string sendEvents;
                    if (CommandReleaseEvents.TryGetValue(currentHotkey, out sendEvents))
                    {
                        SimpleData sd = new SimpleData(this);
                        sd.SourceObjectId = ObjectPrivate.ObjectId;
                        sd.AgentInfo      = ScenePrivate.FindAgent(data.SessionId)?.AgentInfo;
                        sd.ObjectId       = (sd.AgentInfo != null) ? sd.AgentInfo.ObjectId : ObjectId.Invalid;
                        SendToAll(sendEvents, sd);
                    }

                    HeldKeys[data.SessionId] &= ~currentHotkey;
                }
            }
        }
        public void AddCommand <CmdClass>()
        {
            IEnumerable <Attribute> attributes = typeof(CmdClass).GetCustomAttributes();

            if (attributes.Any(t => t is CommandFlag))
            {
                CommandFlag flag = attributes.First(t => t is CommandFlag) as CommandFlag;
                if (!appCenter.CommandDict.ContainsKey(flag.CommandType))
                {
                    appCenter.CommandDict.Add(flag.CommandType, typeof(CmdClass));
                }
                else
                {
                    appCenter.CommandDict[flag.CommandType] = typeof(CmdClass);
                }
            }
        }
 /// <summary>
 ///     初始化命令
 /// </summary>
 public void InitCommandList()
 {
     Type[] commandList = Assembly.GetExecutingAssembly().GetTypes()
                          .Where(t => typeof(P2PCommand).IsAssignableFrom(t) && !t.IsAbstract)
                          .ToArray();
     foreach (Type type in commandList)
     {
         IEnumerable <Attribute> attributes = type.GetCustomAttributes();
         if (!attributes.Any(t => t is CommandFlag))
         {
             continue;
         }
         CommandFlag flag = attributes.First(t => t is CommandFlag) as CommandFlag;
         if (!Global.CommandDict.ContainsKey(flag.CommandType))
         {
             Global.CommandDict.Add(flag.CommandType, type);
         }
     }
 }
Example #5
0
        protected virtual bool HasFlag(CommandFlag commandFlag)
        {
            var folderOutcome = CommandLineArgs.Get(commandFlag.Flags);

            return(folderOutcome);
        }
Example #6
0
        public IParseFlags AddFlag(CommandFlag commandFlag)
        {
            toParse.Add(commandFlag);

            return(this);
        }
Example #7
0
 public Button(CommandID command, CommandID group, int priority, CommandID icon, CommandType type, CommandFlag flags, string text)
 {
     this.command  = command;
     this.group    = group;
     this.priority = priority;
     if (icon == null)
     {
         this.icon = Util.NoIcon;
     }
     else
     {
         this.icon = icon;
     }
     this.commandType = type;
     this.flags       = flags;
     if (string.IsNullOrEmpty(text))
     {
         this.text = Properties.Resources.CTC_LabelUnknown;
     }
     else
     {
         this.text = text;
     }
 }