Exemplo n.º 1
0
 public void AddBinding(string command, BindingMessage message)
 {
     if (!bindings.ContainsKey(command))
     {
         bindings.Add(command, message);
     }
 }
Exemplo n.º 2
0
        public static IApplicationBuilder UseCommandBinding(this IApplicationBuilder app)
        {
            var mp             = app.ApplicationServices.GetService(typeof(MessageProcessing)) as MessageProcessing;
            var commandClasses = Assembly.GetExecutingAssembly().ExportedTypes.Where(x => x.IsClass && x.BaseType == typeof(BindingMessage));

            foreach (Type @class in commandClasses)
            {
                var atrs = @class.GetCustomAttributes <BotCommandAttribute>();

                if (atrs.Count() > 0)
                {
                    foreach (var atr in atrs)
                    {
                        BindingMessage msg = Activator.CreateInstance(@class) as BindingMessage;
                        mp.AddBinding(atr.CommandString, msg);
                    }
                }
            }

            return(app);
        }