示例#1
0
        static void Main(string[] args)
        {
            ActiveModules = new List <IModule>();
            //Instantiate and throw away a Reddit instance so the static constructor won't interfere with the WebAgent later.
            new Reddit();
            var conn = new DirtBagConnection();
            var sub  = ConfigurationManager.AppSettings["Subreddit"];

            conn.InitializeConnection(new[] { sub });
            Initialize();
            string baseAddresses = System.Configuration.ConfigurationManager.AppSettings["ApiListeningUrls"];

            baseAddresses += "," + string.Join(",", args);
            if (!string.IsNullOrWhiteSpace(baseAddresses))
            {
                var opts = new StartOptions();
                foreach (string address in baseAddresses.Split(','))
                {
                    if (!string.IsNullOrWhiteSpace(address))
                    {
                        opts.Urls.Add(address);
                    }
                }

                _app = WebApp.Start <Startup>(opts);
            }

            WaitHandle.WaitOne(); //Go the f**k to sleep
        }
示例#2
0
        public async Task <IEnumerable <Models.BannedEntity> > GetBannedChannels(string subredditName)
        {
            string query = @"
select be.Id, sub.SubName, be.EntityString, be.EntityType as 'Type', be.BannedBy, be.BanReason, be.BanDate, be.ThingID
from BannedEntities be
inner join Subreddits sub on sub.ID = be.SubredditID
where sub.SubName like @subredditName AND be.EntityType = 1
;";

            using (var conn = DirtBagConnection.GetConn()) {
                return(await conn.QueryAsync <Models.BannedEntity>(query, new { subredditName }));
            }
        }
示例#3
0
        public async Task LogNewBannedEntities(IEnumerable <Models.BannedEntity> entities)
        {
            string query = @"
insert into BannedEntities (SubredditID,EntityString,EntityType,BannedBy, BanReason, BanDate, ThingID)
select sub.ID,@EntityString,@Type,@BannedBy,@BanReason,@BanDate,@ThingID from Subreddits sub where sub.SubName like @SubName
;";

            using (var conn = DirtBagConnection.GetConn()) {
                await conn.ExecuteAsync(query, entities);

                return;
            }
        }
示例#4
0
 public void InitDatabase()
 {
     //Database is denormalized due to the impractical constraints of ensuring users and channels are loaded before
     //loading a post or a removal for a user. Normalizing as it is right now may actually reduce performance
     //and would certainly introduce more issues than it is probably worth unless more info is tacked on to some of the
     //categories later on.
     using (var con = DirtBagConnection.GetConn()) {
         bool useLocalDB = DirtBagConnection.UseLocalDB;
         var  initTables = "" +
                           (useLocalDB ?
                            "CREATE TABLE IF NOT EXISTS " :
                            "if not exists( select * from sys.tables t join sys.schemas s on ( t.schema_id = s.schema_id ) where s.name = SCHEMA_NAME() and t.name = 'UserPosts' ) Create table "
                           ) +
                           "[UserPosts]([PostID] INTEGER NOT NULL PRIMARY KEY " + (useLocalDB ? "AUTOINCREMENT" : "IDENTITY") + ", " +
                           //"[UserID] INTEGER NOT NULL, " +
                           "[UserName] nvarchar(50), " +
                           "[ThingID] varchar(10), " +
                           "[Link] nvarchar(200), " +
                           "[PostTime] DATETIME, " +
                           "[ChannelID] varchar(100), " +
                           "[ChannelName] nvarchar(200), " +
                           "[Subreddit] Nvarchar(100) ); " +
                           "" +
                           (useLocalDB ?
                            "CREATE TABLE IF NOT EXISTS " :
                            "if not exists( select * from sys.tables t join sys.schemas s on ( t.schema_id = s.schema_id ) where s.name = SCHEMA_NAME() and t.name = 'PostRemovals' ) Create table "
                           ) +
                           "[PostRemovals]([RemovalID] INTEGER NOT NULL PRIMARY KEY " + (useLocalDB ? "AUTOINCREMENT" : "IDENTITY") + ", " +
                           "[TimeStamp] DATETIME, " +
                           "[PostID] INTEGER NOT NULL, " +
                           "[ModName] NVARCHAR(50), " +
                           "[Reason] NVARCHAR(200) ); " +
                           "" +
                           //"CREATE TABLE IF NOT EXISTS [Channels]( " +
                           //"[ChannelID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                           //"[Identifier] VARCHAR(100) NOT NULL, " +
                           //"[Name] varchar(200) NOT NULL ); " +
                           "" +
                           //"CREATE TABLE IF NOT EXISTS [Users]( " +
                           //"[UserID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                           //"[UserName] VARCHAR(50) ); " +
                           "";
         con.Execute(initTables);
     }
 }
示例#5
0
        public async Task <bool> UpdateBanReason(int id, string subredditName, string modName, string banReason)
        {
            string query = @"
update be
SET be.BanReason = @banReason
OUTPUT GETUTCDATE() as 'HistTimestamp', 'U' as 'HistAction', @modName as 'HistUser', INSERTED.SubredditID, INSERTED.EntityString, INSERTED.EntityType, INSERTED.BannedBy, INSERTED.BanReason, INSERTED.BanDate, INSERTED.ThingID INTO BannedEntities_History
FROM BannedEntities be
inner join Subreddits sub on sub.ID = be.SubredditID
where sub.SubName like @subredditName AND be.id = @id
";

            using (var conn = DirtBagConnection.GetConn()) {
                var results = await conn.ExecuteAsync(query, new { id, subredditName, modName, banReason });

                if (results == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
示例#6
0
        public async Task <string> RemoveBannedEntity(int id, string subredditName, string modName)
        {
            string query = @"
delete be
output GETUTCDATE() as 'HistTimestamp', 'D' as 'HistAction', @modName as 'HistUser', DELETED.SubredditID, DELETED.EntityString, DELETED.EntityType, DELETED.BannedBy, DELETED.BanReason, DELETED.BanDate, DELETED.ThingID INTO BannedEntities_History
output DELETED.EntityString, DELETED.EntityType
from BannedEntities be
inner join Subreddits sub on sub.ID = be.SubredditID
where sub.SubName like @subredditName
AND be.Id = @id
;";

            using (var conn = DirtBagConnection.GetConn()) {
                dynamic results = (await conn.QueryAsync <dynamic>(query, new { id, subredditName, @modName })).FirstOrDefault();
                if (results.EntityType == 2)
                {
                    return(results.EntityString);
                }
                return("");
            }
        }