Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Easiest way to obtain Current Gallery ID in external project library
daveburke
#1 Posted : Thursday, 2 December 2010 1:04:14 PM(UTC)
daveburke

Rank: Advanced Member

Joined: 12/01/2009(UTC)
Posts: 62
Location: Vermont

Roger,

Don't feel required to strain your brain on this, but to obtain the current gallery object in a Class Project Library with GSP 2.3 I was able to do the following.

Code:

public int CurrentGalleryID
{
get
{
return GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.GalleryId;
}
}


I've spent the morning trying to come up with something elegant but am not happy with an approach using Cache objects. Something like

Code:

Dictionary<int, IAlbum> albumCache = (Dictionary<int, IAlbum>)HelperFunctions.GetCache(CacheItem.Albums);
int _aid = DataHelper.GetIntFromQueryString("aid",1);
foreach (KeyValuePair<int, IAlbum> kvp in albumCache)
{
if (((Album)kvp.Value).Id == _aid)
return ((Album)kvp.Value).GalleryId;
}


I was wondering if you had any advice. If not, I'll come up with something. Thought I'd get your input before investing more time in it.

Thanks much!
Dave
Roger Martin
#2 Posted : Thursday, 2 December 2010 1:19:41 PM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,300
Location: Fort Atkinson, WI

As you know, a gallery ID is no longer isolated to the web app. It is not even tied to a single page or instance of the Gallery control on the page. For instance, one can dynamically assign a gallery ID early in the page life cycle so that the page is capable of showing different galleries to different users.

So, to answer your question, we need to know what gallery you *want* to get, and then we can figure out how to get the gallery ID. Your question implies you will always have an album ID in the query string. Is that true? If so, then loading the album and grabbing the gallery ID from it is the best way. That's how GSP does it when the 'aid' query string is present.
Roger Martin
Creator and Lead Developer of Gallery Server Pro
daveburke
#3 Posted : Thursday, 2 December 2010 1:39:38 PM(UTC)
daveburke

Rank: Advanced Member

Joined: 12/01/2009(UTC)
Posts: 62
Location: Vermont

Roger Martin wrote:
As you know, a gallery ID is no longer isolated to the web app. It is not even tied to a single page or instance of the Gallery control on the page.

That's why it's so beautiful and so difficult to obtain outside of the Gallery Object hierarchy. :)

Roger Martin wrote:

Your question implies you will always have an album ID in the query string.


You're absolutely right. I won't always have an album ID in the query string which makes it a bad plan. I'm looking forward to thoroughly understanding your groups architecture. I'll probably do something based on the unique page or url properties for the current group.

No need to take more of your time on this now. I appreciate your thoughts as always.

Thanks,
Dave
Roger Martin
#4 Posted : Sunday, 5 December 2010 1:34:00 PM(UTC)
Roger Martin

Rank: Administration

Joined: 3/08/2007(UTC)
Posts: 3,300
Location: Fort Atkinson, WI

GSP sometimes finds itself in a situation where no gallery ID is obvious (such as when a new page is created with a gallery control), so it just uses the first one found in the database. That may or may not work for you, depending on your situation.

You can see the exact logic in the GalleryId property of the GalleryPage class.
Roger Martin
Creator and Lead Developer of Gallery Server Pro
Rss Feed  Atom Feed
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.