Example #1
0
 public void Initialize()
 {
     if (!AwfulWebRequest.CanAuthenticate)
     {
         using (var dao = new AwfulProfileDAO())
         {
             var profile = dao.GetProfileByUsername(StaticParameters.TEST_USERNAME);
             if (profile != null)
             {
                 AwfulWebRequest.SetCookieJar(profile.GetTokensAsCookies());
             }
         }
     }
 }
 public void Initialize()
 {
     if (this.pmService == null) { this.pmService = AwfulServiceManager.PrivateMessageService; }
     if (!AwfulWebRequest.CanAuthenticate)
     {
         using (var dao = new AwfulProfileDAO())
         {
             var profile = dao.GetProfileByUsername(StaticParameters.TEST_USERNAME);
             if (profile != null)
             {
                 AwfulWebRequest.SetCookieJar(profile.GetTokensAsCookies());
             }
         }
     }
 }
 public void Starting()
 {
     // Load up the current profile if it exists //
     using (var dao = new AwfulProfileDAO())
     {
         var currentProfile = dao.GetProfileByID(this._settings.CurrentProfileID);
         // set cookie jar
         if (currentProfile != null)
         {
             List<Cookie> cookies = new List<Cookie>();
             var tokens = currentProfile.Tokens;
             foreach (var token in tokens) { cookies.Add(token.AsCookie()); }
             AwfulWebRequest.SetCookieJar(cookies);
         }
     }
 }
        private void AwfulAuthenticateByBrowser_LoginSuccessful(object sender, Event.ProfileChangedEventArgs e)
        {
            // update AwfulWebRequest Cookie jar
            AwfulWebRequest.SetCookieJar(e.Cookies);

            // save profile to database, along with authentication tokens
            using (var dao = new AwfulProfileDAO())
            {
                var updatedProfile = dao.SaveAuthenticationCookiesToProfile(e.Value, e.Cookies);
                if (updatedProfile == null)
                {
                    updatedProfile = dao.CreateProfile(e.Value.Username, e.Value.Password, e.Cookies);
                    if (updatedProfile != null) { this._settings.CurrentProfileID = updatedProfile.ID; }
                    else { this._settings.CurrentProfileID = NONE; }
                }
            }
        }
Example #5
0
        public void Starting()
        {
            using (var db = AwfulDataContext.CreateDataContext(TEST_FILENAME))
            {
                if (db.DatabaseExists()) { db.DeleteDatabase(); }
                db.CreateDatabase();
            }

            using (var db = new AwfulDataContext())
            {
                if (!db.DatabaseExists())
                {
                    db.CreateDatabase();
                    var dao = new AwfulProfileDAO(db);
                    dao.CreateProfile(StaticParameters.TEST_USERNAME, StaticParameters.TEST_PASSWORD, new List<Cookie>());
                }
            }
        }
Example #6
0
        public void Started()
        {
            var dao = new AwfulProfileDAO();

            var testProfile = dao.GetProfileByUsername(StaticParameters.TEST_USERNAME);
            if (testProfile != null)
            {
                AwfulWebRequest.SetCookieJar(testProfile.GetTokensAsCookies());
                if (!AwfulWebRequest.CanAuthenticate)
                {
                    AwfulAuthenticateByBrowser.LoginSuccessful += (o, a) =>
                        {
                            dao.SaveAuthenticationCookiesToProfile(testProfile, a.Cookies);
                            dao.Dispose();
                        };
                }
            }

            TestContext = AwfulDataContext.CreateDataContext(TEST_FILENAME);
        }
        public void TestCreateProfile()
        {
            using (var dao = new AwfulProfileDAO(AwfulTestService.TestContext))
            {
                List<Cookie> cookies = new List<Cookie>();
                cookies.Add(new Cookie("cookie1", "value1"));
                cookies.Add(new Cookie("cookie2", "value2"));
                var profile = dao.CreateProfile("username", "password", cookies);

                // ensure profile was created
                Assert.IsNotNull(profile);
                Assert.AreEqual("username", profile.Username);
                Assert.AreEqual("password", profile.Password);
                Assert.IsTrue(profile.Tokens.Count == 2);

                // ensure profile was persisted
                var profileInDatabase = AwfulTestService.TestContext.Profiles
                    .Where(p => p.Username == "username").SingleOrDefault();

                Assert.IsNotNull(profileInDatabase);
                Assert.IsTrue(profileInDatabase.Tokens.Count == 2);
            }
        }
 public void TestUpdateUsername()
 {
     using (var dao = new AwfulProfileDAO(AwfulTestService.TestContext))
     {
         var profile = dao.RenameProfile(Profile1, "changed");
         Assert.IsNotNull(profile);
         Assert.AreEqual(profile.ID, Profile1.ID);
         Assert.AreEqual("changed", profile.Username);
         Assert.AreEqual(profile.Username, Profile1.Username);
     }
 }
Example #9
0
 public void UpdateUserBookmarksAsync(AwfulProfile user, bool refresh, Action<AwfulProfile> result)
 {
     // check database first
     var bookmarks = new List<AwfulThreadBookmark>();
     if (!refresh)
     {
         user = this.GetProfileByUsername(user.Username);
         bookmarks.AddRange(user.ThreadBookmarks);
     }
     if (bookmarks.IsNullOrEmpty())
     {
         // fetch from web
         AwfulForumPage cp = new AwfulControlPanel().GetBookmarks();
         cp.RefreshAsync(cpRefreshed =>
             {
                 using (var dao = new AwfulProfileDAO())
                 {
                     var profile = dao.SaveBookmarksToProfile(user, cpRefreshed.Threads);
                     if (profile == null)
                     {
                         // if we're here, then there's a database issue, but the show must go on
                         using (var dao2 = new AwfulProfileDAO())
                         {
                             user = dao2.GetProfileByUsername(user.Username);
                             user.AddRangeToBookmarks(cpRefreshed.Threads);
                             result(user);
                         }
                     }
                     else { result(profile); }
                 }
             });
     }
     else
     {
         result(user);
     }
 }