Ejemplo n.º 1
0
        public static void ScheduleDelete <TEntity>(this IEntitySession session, IQueryable query,
                                                    CommandSchedule schedule = CommandSchedule.TransactionEnd)
        {
            var entSession = (EntitySession)session;

            entSession.ScheduleLinqNonQuery <TEntity>(query, LinqOperation.Delete, schedule);
        }
Ejemplo n.º 2
0
        public void ScheduleLinqNonQuery <TEntity>(IQueryable baseQuery, LinqOperation op,
                                                   CommandSchedule schedule = CommandSchedule.TransactionEnd)
        {
            Util.Check(baseQuery is EntityQuery, "query parameter should an EntityQuery.");
            var model     = Context.App.Model;
            var targetEnt = model.GetEntityInfo(typeof(TEntity));

            Util.Check(targetEnt != null, "Generic parameter {0} is not an entity registered in the Model.", typeof(TEntity));
            var command = LinqCommandFactory.CreateLinqNonQuery(this, baseQuery.Expression, op, targetEnt);

            switch (schedule)
            {
            case CommandSchedule.TransactionStart:
                ScheduledCommandsAtStart = ScheduledCommandsAtStart ?? new List <LinqCommand>();
                ScheduledCommandsAtStart.Add(command);
                break;

            case CommandSchedule.TransactionEnd:
                ScheduledCommandsAtEnd = ScheduledCommandsAtEnd ?? new List <LinqCommand>();
                ScheduledCommandsAtEnd.Add(command);
                break;
            }
        }
Ejemplo n.º 3
0
        public static void ScheduleNonQuery <TEntity>(this IEntitySession session,
                                                      IQueryable query, LinqCommandType commandType,
                                                      CommandSchedule schedule = CommandSchedule.TransactionEnd)
        {
            var entQuery = query as EntityQuery;
            var model    = session.Context.App.Model;

            Util.Check(entQuery != null, "query parameter should an EntityQuery.");
            var prov      = entQuery.Provider as EntityQueryProvider;
            var targetEnt = model.GetEntityInfo(typeof(TEntity));

            Util.Check(targetEnt != null, "Generic parameter {0} is not an entity registered in the Model.", typeof(TEntity));
            var command = new LinqCommand(entQuery, commandType, LinqCommandKind.DynamicSql, targetEnt);

            LinqCommandAnalyzer.Analyze(model, command);
            command.EvaluateLocalValues((EntitySession)session);
            var scheduledCommand = new ScheduledLinqCommand()
            {
                Command = command, Schedule = schedule
            };
            var entSession = (EntitySession)session;

            entSession.ScheduledCommands.Add(scheduledCommand);
        }
Ejemplo n.º 4
0
 private void ExecuteScheduledCommands(DataConnection conn, EntitySession session, CommandSchedule schedule)
 {
     if (session.ScheduledCommands.Count == 0)
     return;
       foreach (var cmd in session.ScheduledCommands)
     if (cmd.Schedule == schedule) {
       ExecuteLinqNonQuery(cmd.Command, session, conn);
     }
 }
Ejemplo n.º 5
0
        public async Task MessageReceivedAsync(SocketMessage discordMessage)
        {
            if (!(discordMessage is SocketUserMessage message))
            {
                return;
            }

            //Still ignore messages from the bot to avoid recursive commands
            if (message.Author.Id == Client.CurrentUser.Id)
            {
                return;
            }

            /*
             * if (ConfigManager.LastConfig.IgnoreBotInput)
             * {
             *  if (message.Author.IsBot || message.Author.IsWebhook)
             *  {
             *      return;
             *  }
             * }
             * else
             * {
             * }
             */

            ulong guildId = 0;

            if (message.Channel is IGuildChannel gChannel)
            {
                guildId = gChannel.GuildId;
            }

            var _ = Task.Run(async() =>
            {
                var context = new ShardedCommandContext(Client, message);
                var argPos  = 0;

                if (guildId != 0)
                {
                    //Check that the message was from a server and try to use a custom set prefix if available.
                    using (var db = new Database())
                    {
                        var comp   = db.Competitions.FirstOrDefault(x => x.GuildId == guildId);
                        var prefix = comp?.Prefix ?? Program.Prefix;
                        if (!message.HasStringPrefix(prefix, ref argPos, StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (!message.HasMentionPrefix(context.Client.CurrentUser, ref argPos))
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    //If the bot is in developer mode or dms use regular prefix or dev override prefix
                    if (!message.HasStringPrefix(Program.Prefix, ref argPos, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!message.HasMentionPrefix(context.Client.CurrentUser, ref argPos))
                        {
                            return;
                        }
                        return;
                    }
                }

                //NOTE: Since guildId is 0 for dms, they have their own command queue.
                if (!CommandScheduler.ContainsKey(guildId))
                {
                    CommandScheduler[guildId] = new CommandSchedule
                    {
                        GuildId = guildId
                    };
                }

                CommandScheduler[guildId].AddTask(context, argPos);
            });
        }
Ejemplo n.º 6
0
 public static void ScheduleDelete <TEntity>(this IEntitySession session, IQueryable query,
                                             CommandSchedule schedule = CommandSchedule.TransactionEnd)
 {
     ScheduleNonQuery <TEntity>(session, query, LinqCommandType.Delete, schedule);
 }
Ejemplo n.º 7
0
 private void ExecuteScheduledCommands(DataConnection conn, EntitySession session, CommandSchedule schedule)
 {
     if (session.ScheduledCommands.Count == 0)
     {
         return;
     }
     foreach (var cmd in session.ScheduledCommands)
     {
         if (cmd.Schedule == schedule)
         {
             ExecuteLinqNonQuery(cmd.Command, session, conn);
         }
     }
 }