コード例 #1
0
        public static void ExecuteBot(int id)
        {
            var ctx = new RedditRSSEntities();

            ExecuteBotInternal(ctx, id);
            ctx.SaveChanges();
        }
コード例 #2
0
ファイル: BotList.ascx.cs プロジェクト: DrLeh/reddit-rss-bot
        protected void gvBots_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var id  = int.Parse((string)e.CommandArgument);
            var ctx = new RedditRSSEntities();

            if (e.CommandName == "StartBot")
            {
                var bot = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                if (bot != null)
                {
                    bot.StatusTypeID = 2;
                }
                ctx.SaveChanges();
            }
            else if (e.CommandName == "StopBot")
            {
                var bot = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                if (bot != null)
                {
                    bot.StatusTypeID = 3;
                }
                ctx.SaveChanges();
            }
            else if (e.CommandName == "DeleteBot")
            {
                var botToRemove = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                ctx.RedditRSSBotDatas.Remove(botToRemove);
                ctx.SaveChanges();
            }
            gvBots.DataBind();
        }
コード例 #3
0
        protected void btnAddFeed_Click(object sender, EventArgs e)
        {
            var feed      = tbFeedUrl.Text;
            var subreddit = tbSubReddit.Text;
            var interval  = int.Parse(tbInterval.Text);

            var ctx            = new RedditRSSEntities();
            var selectedUserID = int.Parse(ddlUsers.SelectedValue);
            var user           = ctx.RedditUsers.Where(x => x.ID == selectedUserID).FirstOrDefault();
            var botData        = new RedditRSSBotData()
            {
                FeedUrl    = feed,
                Subreddit  = subreddit,
                RedditUser = user,
                Interval   = interval
            };

            ctx.RedditRSSBotDatas.Add(botData);
            ctx.SaveChanges();

            var manager = RedditRSSBotManager.Instance;

            manager.AddBot(botData.CreateBot());
            ucBotList.DataBind();
        }
コード例 #4
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            var username        = tbUsername.Text;
            var password        = tbPassword.Text;
            var passwordConfirm = tbPasswordConfirm.Text;

            if (username == null && password == null && passwordConfirm == null)
            {
                lblMessage.Text = "All fields are required";
            }
            else if (password != passwordConfirm)
            {
                lblMessage.Text = "Password Fields don't match!";
            }
            else
            {
                var ctx     = new RedditRSSEntities();
                var appUser = new AppUser();
                appUser.Username = username;
                appUser.Password = password;
                appUser.HashPassword();
                ctx.AppUsers.Add(appUser);
                ctx.SaveChanges();
                Session[AppConstants.SessionKeys.LOGGED_IN_USER_ID]   = appUser.ID;
                Session[AppConstants.SessionKeys.LOGGED_IN_USER_NAME] = appUser.Username;
                Response.Redirect("~/");
            }
        }
コード例 #5
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var  returnUrl  = Request.QueryString["returnUrl"];
            bool loginValid = false;
            var  userName   = tbUsername.Text;
            var  pw         = tbPassword.Text;
            var  ctx        = new RedditRSSEntities();
            var  appUser    = ctx.AppUsers.Where(x => x.Username == userName).FirstOrDefault();

            if (appUser != null)
            {
                var validPW = CryptUtil.ValidatePassword(pw, appUser.HashedPassword);
                if (validPW)
                {
                    loginValid = true;
                    Session[AppConstants.SessionKeys.LOGGED_IN_USER_ID]   = appUser.ID;
                    Session[AppConstants.SessionKeys.LOGGED_IN_USER_NAME] = appUser.Username;
                }
            }
            if (!loginValid)
            {
                lblMessage.Text = "Login invalid. Please check the username and password";
            }
            else
            {
                Response.Redirect("~/" + (returnUrl == null ? "": returnUrl));
            }
        }
コード例 #6
0
        public IQueryable <RedditUser> ddlUsers_GetData()
        {
            var ctx = new RedditRSSEntities();

            if (UserLoggedIn)
            {
                return(ctx.RedditUsers.Where(x => x.AppUserID == CurrentUserID).AsQueryable());
            }
            return(null);
        }
コード例 #7
0
        public static void ExecuteAllRunningBots()
        {
            var ctx      = new RedditRSSEntities();
            var botDatas = ctx.RedditRSSBotDatas.Where(x => x.StatusTypeID == 2).Select(x => x.ID);

            foreach (var botDataID in botDatas)
            {
                ExecuteBotInternal(ctx, botDataID);
            }
            ctx.SaveChanges();
        }
コード例 #8
0
        private static void ExecuteBotInternal(RedditRSSEntities ctx, int id)
        {
            var botData = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();

            if (botData != null)
            {
                var bot            = new RedditRSSBot(botData);
                var newSubmissions = bot.CheckAndSubmitNews();
                newSubmissions.ToList().ForEach(x => ctx.RedditSubmissions.Add(x));
            }
        }
コード例 #9
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var user = new RedditUser();

            user.Username  = tbUsername.Text;
            user.Password  = tbPassword.Text;
            user.AppUserID = CurrentUserID;
            var ctx = new RedditRSSEntities();

            ctx.RedditUsers.Add(user);
            ctx.SaveChanges();
            gvUsers.DataBind();
        }
コード例 #10
0
ファイル: Manage.aspx.cs プロジェクト: DrLeh/reddit-rss-bot
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            var userID      = (int)CurrentUserID;
            var ctx         = new RedditRSSEntities();
            var appUser     = ctx.AppUsers.Where(x => x.ID == userID).FirstOrDefault();
            var redditUsers = ctx.RedditUsers.Where(x => x.AppUserID == userID).ToList();
            var bots        = ctx.RedditRSSBotDatas.Where(x => redditUsers.Any(y => x.RedditUserID == y.ID)).ToList();

            bots.ForEach(x => ctx.RedditRSSBotDatas.Remove(x));
            redditUsers.ForEach(x => ctx.RedditUsers.Remove(x));
            ctx.AppUsers.Remove(appUser);
            ctx.SaveChanges();
            Response.Redirect("~/");
        }
コード例 #11
0
        protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteUser")
            {
                var id       = int.Parse((string)e.CommandArgument);
                var ctx      = new RedditRSSEntities();
                var user     = ctx.RedditUsers.Where(x => x.ID == id).FirstOrDefault();
                var botDatas = ctx.RedditRSSBotDatas.Where(x => x.RedditUserID == id).ToList();

                var botsToRemove = ctx.RedditRSSBotDatas.Where(x => x.RedditUserID == id).ToList();

                botDatas.ForEach(x => ctx.RedditRSSBotDatas.Remove(x));
                ctx.RedditUsers.Remove(user);
                ctx.SaveChanges();
                gvUsers.DataBind();
            }
        }
コード例 #12
0
ファイル: BotList.ascx.cs プロジェクト: DrLeh/reddit-rss-bot
        public IQueryable <RedditRSSBotData> gvBots_GetData()
        {
            var ctx     = new RedditRSSEntities();
            var results = new List <RedditRSSBotData>().AsQueryable();

            if (this.DisplayMode == BotListDisplayMode.SingleUser)
            {
                results = ctx.RedditRSSBotDatas.Where(x => x.RedditUser.AppUserID == (int)CurrentUserID);
            }
            else if (DisplayMode == BotListDisplayMode.All)
            {
                results = ctx.RedditRSSBotDatas;
            }
            else if (DisplayMode == BotListDisplayMode.CurrentlyRunning)
            {
                results = ctx.RedditRSSBotDatas.Where(x => x.StatusTypeID == 2);
            }
            return(results);
        }
コード例 #13
0
        private List <RedditUser> GetRedditUsers()
        {
            var ctx = new RedditRSSEntities();

            return(ctx.RedditUsers.ToList());
        }