Ejemplo n.º 1
0
 /// <summary>
 /// 重新加载数据
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="query">查询信息</param>
 internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
 {
     foreach (valueType value in SqlTable.Select(ref connection, ref query))
     {
         insert(value);
     }
 }
Ejemplo n.º 2
0
        public static TwitchCommand[] GetAll(TwitchConnection connection)
        {
            List <object[]> results = _table.Select(null, null, "ChannelUserId=?a AND BotUserId=?b",
                                                    new object[] { connection.channel.user.id, connection.bot.user.id }, null, 0);

            if (results != null)
            {
                TwitchCommand[] commands = new TwitchCommand[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    commands[i] = new SqlTwitchCommand(
                        results[i][0].FromSql <uint>(),
                        connection,
                        results[i][3].FromSql <string>(),
                        results[i][4].FromSql <string>(),
                        results[i][5].FromSql <bool>(),
                        TimeSpan.FromSeconds(results[i][6].FromSql <int>()),
                        results[i][7].FromSql <string>());
                }

                return(commands);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重新加载数据
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="query">查询信息</param>
        internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
        {
            LeftArray <valueType> array = SqlTable.Select(ref connection, ref query);

            array.RemoveNot(isValue);
            reset(array);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 重新加载数据
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="query">查询信息</param>
 internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
 {
     foreach (valueType value in SqlTable.Select(ref connection, ref query))
     {
         setMemberCacheAndValue(value);
         dictionary[GetKey(value)] = value;
     }
 }
        public static SqlTwitchUserInChannel GetMostRecent(TwitchChannel channel)
        {
            try {
                object[] results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "CreatedAt Desc");
                if (results != null && results.Length > 0)
                {
                    return(FromSql(channel, results));
                }
                else
                {
                    return(null);
                }
            } catch (Exception e) {
                Log.exception(e);

                return(null);
            }
        }
Ejemplo n.º 6
0
        internal static SqlTwitchUser FromName(string username)
        {
            try {
                object[] values = _table.Select(null, null, "Name=?a", new object[] { username }, null);
                if (values != null && values.Length > 0)
                {
                    return(new SqlTwitchUser(values[0].FromSql <uint>(), values[1].FromSql <string>(),
                                             values[2].FromSql <DateTime>(), values[3].FromSql <string>(), values[4].FromSql <string>()));
                }
                else
                {
                    return(null);
                }
            } catch (Exception e) {
                Log.exception(e);

                return(null);
            }
        }
Ejemplo n.º 7
0
        public static SqlTwitchAlert FromGuid(string value)
        {
            object[] results = _table.Select(null, null, "AlertGuid=?a", new object[] { value }, null);
            if (results != null && results.Length > 0)
            {
                return(new SqlTwitchAlert(new SqlTwitchConnection(new SqlTwitchBot(new SqlTwitchUser(results[0].FromSql <uint>())),
                                                                  new SqlTwitchChannel(new SqlTwitchUser(results[1].FromSql <uint>()))),
                                          results[2].FromSql <string>(),
                                          results[3].FromSql <DateTime>()));
            }

            return(null);
        }
Ejemplo n.º 8
0
        public static TwitchChannel[] GetAllLiveFollowers(TwitchChannel channel)
        {
            string where = "twitch_followers.ChannelUserId=?a and IsLive=?b";
            string join = "join twitch_followers on twitch_followers.UserId=twitch_channels.UserId";

            object[] vars = new object[] { channel.user.id, true };

            List <object[]> results = _table.Select(join, null, where, vars, null, 0);

            if (results != null)
            {
                TwitchChannel[] channels = new TwitchChannel[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    channels[i] = FromSql(results[i]);
                }

                return(channels);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        public static TwitchUserPoints[] GetTopUsersForChannel(TwitchChannel channel, uint count)
        {
            List <object[]> results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "Points Desc", count);

            if (results != null && results.Count > 0)
            {
                TwitchUserPoints[] points = new TwitchUserPoints[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    points[i] = new SqlTwitchUserPoints(new SqlTwitchUser((uint)results[i][0]), channel, (ulong)results[i][2], (DateTime)results[i][3]);
                }

                return(points);
            }

            return(null);
        }
Ejemplo n.º 10
0
        public static TwitchChannelPointScale[] ForChannel(TwitchChannel channel)
        {
            List <object[]> results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "UnitValue", 0);

            if (results != null && results.Count > 0)
            {
                TwitchChannelPointScale[] points = new TwitchChannelPointScale[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    points[i] = new SqlTwitchChannelPointScale(channel, results[i][1].FromSql <ulong>(), results[i][2].FromSql <string>(), results[i][3].FromSql <string>());
                }

                return(points);
            }

            return(null);
        }
        public static SqlTwitchConnection[] GetAllAutoConnectingConnections(TwitchBot bot)
        {
            List <object[]> results = _table.Select(null, null, "BotUserId=?a and AutoConnectToChat=?b", new object[] { bot.user.id, true }, null, 0);

            if (results != null && results.Count > 0)
            {
                SqlTwitchConnection[] connections = new SqlTwitchConnection[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    connections[i] = new SqlTwitchConnection(bot, new SqlTwitchChannel(new SqlTwitchUser((uint)results[i][1])), (ulong)results[i][2] != 0);
                }

                return(connections);
            }

            return(null);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 重新加载数据
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="query">查询信息</param>
        internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
        {
            LeftArray <valueType> array = SqlTable.Select(ref connection, ref query);
            int maxIdentity             = array.maxKey(value => GetKey(value), 0);

            if (memberGroup == 0)
            {
                SqlTable.Identity64 = maxIdentity + baseIdentity;
            }
            int length = maxIdentity >= IdentityArray.ArraySize ? 1 << ((uint)maxIdentity).bits() : IdentityArray.ArraySize;
            IdentityArray <valueType> newValues = new IdentityArray <valueType>(length);

            Pointer.Size newCounts = Unmanaged.GetSize64(length * sizeof(int), true);
            try
            {
                int *intCounts = newCounts.Int;
                foreach (valueType value in array)
                {
                    setMemberCacheAndValue(value);
                    int identity = GetKey(value);
                    newValues[identity] = value;
                    intCounts[identity] = 1;
                }
                for (int step = 2; step != length; step <<= 1)
                {
                    for (int index = step, countStep = step >> 1; index != length; index += step)
                    {
                        intCounts[index] += intCounts[index - countStep];
                    }
                }
                Unmanaged.Free(ref counts);
                this.Array = newValues;
                counts     = newCounts;
                size       = length;
                Count      = array.Length;
                newCounts.Null();
            }
            catch (Exception error)
            {
                SqlTable.Log.add(AutoCSer.Log.LogType.Error, error);
            }
            finally { Unmanaged.Free(ref newCounts); }
        }
Ejemplo n.º 13
0
        public static TwitchBot[] GetAll()
        {
            List <object[]> results = _table.Select(null, null, null, null, null, 0);

            if (results != null)
            {
                TwitchBot[] bots = new TwitchBot[results.Count];
                for (int i = 0; i < results.Count; i++)
                {
                    bots[i] = new SqlTwitchBot(new SqlTwitchUser(results[i][0].FromSql <uint>()), results[i][1].FromSql <string>());
                }

                return(bots);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 重新加载数据
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="query">查询信息</param>
 internal override void Reset(ref DbConnection connection, ref SelectQuery <modelType> query)
 {
     reset(SqlTable.Select(ref connection, ref query));
 }