private void ShowLinks(FavoriteLinkCollection links) { foreach (FavoriteLink link in links) { Console.WriteLine(link.Title + " : " + link.Url); } }
public void Test401_LinqTest() { domain.SaveFavoriteLink(_profileId1, "http://abclink.com", "ABC Link"); domain.SaveFavoriteLink(_profileId1, "http://deflink.com", "DEF Link"); domain.SaveFavoriteLink(_profileId1, "http://ghilink.com", "GHI Link"); FavoriteLinkCollection links = domain.GetLatest20FavoriteLinkCollection(_profileId1); FavoriteLinkCollection filteredLinks1 = LinqHelper.GetFilteredLinks(links, "abc"); Assert.IsTrue(filteredLinks1.Count == 1, "There should be just 1 result"); Console.WriteLine("ABC Link:"); foreach (FavoriteLink favoriteLink in filteredLinks1) { Console.WriteLine(favoriteLink.Url); } FavoriteLinkCollection filteredLinks2 = LinqHelper.GetFilteredLinks(links, "link.com"); Assert.IsTrue(filteredLinks2.Count == 3, "There should be just 3 results"); Console.WriteLine("All Links:"); foreach (FavoriteLink favoriteLink in filteredLinks2) { Console.WriteLine(favoriteLink.Url); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (!String.IsNullOrEmpty(Url)) { Profile profile = Utility.GetProfile(); FavoriteLinkCollection lc = Utility.Domain.GetFavoriteLinkCollectionByUrl(profile.ProfileID, Url); // set the controls if a Favorite Link match is found if (lc.Count > 0) { updateRow.Visible = true; Chapter07.Domain.FavoriteLink lm = lc[0]; hdnOldFavoriteLinkId.Value = lc[0].ID.ToString(); tbTitle.Text = lm.Title; tbTags.Text = lm.Tags; tbNote.Text = lm.Note; if (lm.Rating > 0) { rblRating.SelectedValue = lm.Rating.ToString(); } cbKeeper.Checked = lm.Keeper; } } List <BaseValidator> validators = Utility.GetValidators(Controls); foreach (BaseValidator validator in validators) { validator.ValidationGroup = ValidationGroup; } ValidationSummary1.ValidationGroup = ValidationGroup; } }
private void AddToFavoriteLinkCollection(FavoriteLinkCollection collection, IDataReader dr) { while (dr.Read()) { FavoriteLink fl = new FavoriteLink(dr); collection.Add(fl); } }
public FavoriteLinkCollection GetFavoriteLinkCollectionByUrl(long profileId, string url) { DataSet ds = GetFavoriteLinkByUrl(profileId, url); FavoriteLinkCollection collection = new FavoriteLinkCollection(); AddToFavoriteLinkCollection(collection, ds); return(collection); }
public FavoriteLinkCollection GetFavoriteLinkCollectionByTag(long profileId, string token) { DataSet ds = GetFavoriteLinksByTag(profileId, token); FavoriteLinkCollection collection = new FavoriteLinkCollection(); AddToFavoriteLinkCollection(collection, ds); return(collection); }
public FavoriteLinkCollection GetLatest20FavoriteLinkCollection(long profileId) { DataSet ds = GetLatest20FavoriteLinksByProfileID(profileId); FavoriteLinkCollection collection = new FavoriteLinkCollection(); AddToFavoriteLinkCollection(collection, ds); return(collection); }
public FavoriteLinkDataContract[] GetRecentFavoriteLinkCollection( long profileId, int startDaysBack, int endDaysBack) { Trace.WriteLine("GetRecentFavoriteLinkCollection"); FavoriteLinkDomain domain = new FavoriteLinkDomain(); FavoriteLinkCollection favoriteLinks = domain.GetRecentFavoriteLinkCollection(profileId, startDaysBack, endDaysBack); return(GetFavoriteLinksArray(favoriteLinks)); }
public FavoriteLinkCollection GetRecentFavoriteLinkCollection( long profileId, int startDaysBack, int endDaysBack) { DataSet ds = GetRecentFavoriteLinksByProfileID(profileId, startDaysBack, endDaysBack); FavoriteLinkCollection collection = new FavoriteLinkCollection(); AddToFavoriteLinkCollection(collection, ds); return(collection); }
public void Test304_GetRecentFavoriteLinks() { domain.SaveFavoriteLink(_profileId1, "http://testlink1.com", "Test Link 1"); domain.SaveFavoriteLink(_profileId1, "http://testlink2.com", "Test Link 2"); domain.SaveFavoriteLink(_profileId1, "http://testlink3.com", "Test Link 3"); FavoriteLinkCollection collection = domain.GetRecentFavoriteLinkCollection(_profileId1, 3, 0); Assert.IsTrue(collection.Count > 0, "Recent FavoriteLinkCollection must have items"); ShowLinks(collection); }
public FavoriteLinkDataContract[] GetLatest20FavoriteLinkCollection( long profileId) { Trace.WriteLine("GetLatest20FavoriteLinkCollection"); FavoriteLinkDomain domain = new FavoriteLinkDomain(); FavoriteLinkCollection favoriteLinks = domain.GetLatest20FavoriteLinkCollection(profileId); return(GetFavoriteLinksArray(favoriteLinks)); }
public FavoriteLinkDataContract[] GetFavoriteLinkCollectionByTag( long profileId, string token) { Trace.WriteLine("GetFavoriteLinkCollectionByTag"); FavoriteLinkDomain domain = new FavoriteLinkDomain(); FavoriteLinkCollection favoriteLinks = domain.GetFavoriteLinkCollectionByTag(profileId, token); return(GetFavoriteLinksArray(favoriteLinks)); }
public FavoriteLinkDataContract[] GetFavoriteLinkCollectionByUrl( long profileId, string url) { Trace.WriteLine("GetFavoriteLinkCollectionByUrl"); FavoriteLinkDomain domain = new FavoriteLinkDomain(); FavoriteLinkCollection favoriteLinks = domain.GetFavoriteLinkCollectionByUrl(profileId, url); return(GetFavoriteLinksArray(favoriteLinks)); }
public void Test305_GetFavoriteLinksByTag() { long favoriteLinkId = domain.SaveFavoriteLink(_profileId1, "http://testlink1.com", "Test Link 1"); domain.SaveLinkTag(favoriteLinkId, "token1"); FavoriteLinkCollection collection = domain.GetFavoriteLinkCollectionByTag(_profileId1, "token1"); Assert.IsTrue(collection.Count > 0, "FavoriteLinkCollection by tag must have items"); ShowLinks(collection); }
private void AddToFavoriteLinkCollection(FavoriteLinkCollection collection, DataSet ds) { if (ds.Tables.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { FavoriteLink fl = new FavoriteLink(row); collection.Add(fl); } } }
public static List <String> GetUrls(FavoriteLinkCollection linksIn) { List <String> urlsOut = new List <String>(); var urls = from l in linksIn select l.Url; foreach (String url in urls) { urlsOut.Add(url); } return(urlsOut); }
public static FavoriteLinkCollection GetFilteredLinks( FavoriteLinkCollection linksIn, string str) { FavoriteLinkCollection linksOut = new FavoriteLinkCollection(); var selectedLinks = from l in linksIn where l.Url.Contains(str) select l; foreach (FavoriteLink favoriteLink in selectedLinks) { linksOut.Add(favoriteLink); } return(linksOut); }
public void Test402_LinqTest() { domain.SaveFavoriteLink(_profileId1, "http://abclink.com", "ABC Link"); domain.SaveFavoriteLink(_profileId1, "http://deflink.com", "DEF Link"); domain.SaveFavoriteLink(_profileId1, "http://ghilink.com", "GHI Link"); FavoriteLinkCollection links = domain.GetLatest20FavoriteLinkCollection(_profileId1); List <String> urls = LinqHelper.GetUrls(links); Assert.IsTrue(urls.Count == 3, "There should be just 3 results"); Console.WriteLine("Urls:"); foreach (String url in urls) { Console.WriteLine(url); } }
public void Test202_SaveMultipleLinks() { domain.SaveFavoriteLink(_profileId1, "http://testlink1.com", "Test Link 1"); domain.SaveFavoriteLink(_profileId1, "http://testlink2.com", "Test Link 2"); domain.SaveFavoriteLink(_profileId1, "http://testlink3.com", "Test Link 3"); domain.SaveFavoriteLink(_profileId1, "http://testlink4.com", "Test Link 4"); FavoriteLinkCollection collection1 = domain.GetFavoriteLinkCollection(_profileId1); Assert.IsTrue(collection1.Count == 4, "Profile 1 should have 4 links: " + collection1.Count); domain.SaveFavoriteLink(_profileId2, "http://testlink1.com", "Test Link 1"); domain.SaveFavoriteLink(_profileId2, "http://testlink2.com", "Test Link 2 (alternate)"); FavoriteLinkCollection collection2 = domain.GetFavoriteLinkCollection(_profileId2); Assert.IsTrue(collection2.Count == 2, "Profile 2 should have 2 links: " + collection2.Count); }
private FavoriteLinkDataContract[] GetFavoriteLinksArray( FavoriteLinkCollection favoriteLinks) { List <FavoriteLinkDataContract> links = new List <FavoriteLinkDataContract>(); foreach (FavoriteLink favoriteLink in favoriteLinks) { FavoriteLinkDataContract linkDataContract = new FavoriteLinkDataContract(); linkDataContract.Title = favoriteLink.Title; linkDataContract.Url = favoriteLink.Url; linkDataContract.Keeper = favoriteLink.Keeper; linkDataContract.Rating = favoriteLink.Rating; linkDataContract.Note = favoriteLink.Note; links.Add(linkDataContract); } return(links.ToArray()); }
public void Test301_GetFavoriteLinks() { domain.SaveFavoriteLink(_profileId1, "http://testlink1.com", "Test Link 1"); domain.SaveFavoriteLink(_profileId1, "http://testlink2.com", "Test Link 2"); domain.SaveFavoriteLink(_profileId1, "http://testlink3.com", "Test Link 3"); FavoriteLinkCollection collection1 = domain.GetFavoriteLinkCollection(_profileId1); Assert.IsTrue(collection1.Count > 0, "FavoriteLinkCollection 1 must have items"); ShowLinks(collection1); domain.SaveFavoriteLink(_profileId2, "http://testlink1.com", "Test Link 1"); domain.SaveFavoriteLink(_profileId2, "http://testlink2.com", "Test Link 2"); domain.SaveFavoriteLink(_profileId2, "http://testlink3.com", "Test Link 3"); FavoriteLinkCollection collection2 = domain.GetFavoriteLinkCollection(_profileId2); Assert.IsTrue(collection2.Count > 0, "FavoriteLinkCollection 2 must have items"); ShowLinks(collection2); }
public FavoriteLinkCollection GetFavoriteLinkCollection2(long profileId) { FavoriteLinkCollection collection = new FavoriteLinkCollection(); try { using (DbCommand dbCmd = db.GetStoredProcCommand("chpt07_GetFavoriteLinksByProfileID")) { db.AddInParameter(dbCmd, "@ProfileID", DbType.Int64, profileId); IDataReader dr = db.ExecuteReader(dbCmd); AddToFavoriteLinkCollection(collection, dr); } } catch (Exception ex) { throw GetException("Error in GetFavoriteLinksByProfileID", ex); } //return the results return(collection); }
public long SaveFavoriteLink(long profileId, string url, string title, long oldFavoriteLinkId) { // load existing FavoriteLink bool keeper = true; int rating = 1; string tags = String.Empty; string note = String.Empty; FavoriteLinkCollection lc = GetFavoriteLinkCollectionByUrl(profileId, url); if (lc.Count > 0) { FavoriteLink fl = lc[0]; keeper = fl.Keeper; rating = fl.Rating; tags = fl.Tags; note = fl.Note; } return(SaveFavoriteLink(profileId, url, title, keeper, rating, note, tags, DefaultDate, DefaultDate, oldFavoriteLinkId)); }
public void Test350_LoadTest() { if (!_enableLoadTesting) { return; } String titleFormat = "Link {0}"; String urlFormat = "http://testurl/{0}.html"; TimeKeeper timeKeeper = new TimeKeeper(); int maxLinks = 1000; double totalReflectionCastingTime = 0; double totalDirectCastingTime = 0; Console.WriteLine(String.Format("Starting test with {0} links", maxLinks)); for (int i = 1; i <= maxLinks; i++) { string title = String.Format(titleFormat, i); string url = String.Format(urlFormat, i); domain.SaveFavoriteLink(_profileId1, title, url, true, 3, "A link", "loadtest", -1); } DataSet ds = domain.GetFavoriteLinksByProfileID(_profileId1); FavoriteLink.SelectedCastingMode = CastingMode.ReflectionCasting; timeKeeper.Start(); FavoriteLinkCollection collection1 = new FavoriteLinkCollection(); foreach (DataRow row in ds.Tables[0].Rows) { FavoriteLink link = domain.Convert(row); collection1.Add(link); } timeKeeper.Stop(); totalReflectionCastingTime += timeKeeper.Duration; timeKeeper.Reset(); FavoriteLink.SelectedCastingMode = CastingMode.DirectCasting; timeKeeper.Start(); FavoriteLinkCollection collection2 = new FavoriteLinkCollection(); foreach (DataRow row in ds.Tables[0].Rows) { FavoriteLink link = domain.Convert(row); collection2.Add(link); } timeKeeper.Stop(); totalDirectCastingTime += timeKeeper.Duration; timeKeeper.Reset(); Console.WriteLine(String.Format("Max Links: {0}", maxLinks)); double avgReflectionTime = totalReflectionCastingTime / maxLinks * 1000; double avgDirectTime = totalDirectCastingTime / maxLinks * 1000; Console.WriteLine(String.Format("Avg Reflection Casting Time: {0} ms", avgReflectionTime)); Console.WriteLine(String.Format("Avg Direct Casting Time: {0} ms", avgDirectTime)); domain.PurgeProfile(_profileId1); _profileId1 = domain.GetFavoriteLinkProfileID(_userId1); }
private void RunSetAndGetLoadTesting() { if (!_enableLoadTesting) { return; } String titleFormat = "Link {0}"; String urlFormat = "http://testurl/{0}.html"; TimeKeeper timeKeeper = new TimeKeeper(); int maxLinks = 5; int totalTestRuns = 20; int currentRun = 1; double totalSaveTime = 0; double totalGetDataSetTime = 0; double totalGetDataReaderTime = 0; while (currentRun <= totalTestRuns) { Console.WriteLine(String.Format("Starting test run {0} of {1} with {2} links", currentRun, totalTestRuns, maxLinks)); // pause for a moment to settle I/O Thread.Sleep(100); timeKeeper.Start(); for (int i = 1; i <= maxLinks; i++) { string title = String.Format(titleFormat, i); string url = String.Format(urlFormat, i); domain.SaveFavoriteLink(_profileId1, title, url, true, 3, "A link", "loadtest", -1); } timeKeeper.Stop(); totalSaveTime += timeKeeper.Duration; timeKeeper.Reset(); // pause for a moment to settle I/O Thread.Sleep(500); timeKeeper.Start(); FavoriteLinkCollection collection2 = domain.GetFavoriteLinkCollection2(_profileId1); timeKeeper.Stop(); totalGetDataReaderTime += timeKeeper.Duration; timeKeeper.Reset(); // pause for a moment to settle I/O Thread.Sleep(500); timeKeeper.Start(); FavoriteLinkCollection collection = domain.GetFavoriteLinkCollection(_profileId1); timeKeeper.Stop(); totalGetDataSetTime += timeKeeper.Duration; timeKeeper.Reset(); domain.PurgeProfile(_profileId1); _profileId1 = domain.GetFavoriteLinkProfileID(_userId1); // pause for a moment to settle I/O Thread.Sleep(500); currentRun++; } Console.WriteLine(String.Format("Max Links: {0}", maxLinks)); double avgSaveTime = totalSaveTime / totalTestRuns / maxLinks * 1000; double avgGetDataSetTime = totalGetDataSetTime / totalTestRuns / maxLinks * 1000; double avgGetDataReaderTime = totalGetDataReaderTime / totalTestRuns / maxLinks * 1000; Console.WriteLine(String.Format("Avg Save Time: {0} ms", avgSaveTime)); Console.WriteLine(String.Format("Avg Get DataSet Time: {0} ms", avgGetDataSetTime)); Console.WriteLine(String.Format("Avg Get IDataReader Time: {0} ms", avgGetDataReaderTime)); }