Created
October 17, 2016 21:32
-
-
Save Stephen2/1e9b395ab7025026ab1480b3737917ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Fetch - ALL */ | |
private IQueryable<Image> GetAllImages() { | |
//Aaaahh non-multisite, how simple you were | |
if (!SystemManager.CurrentContext.IsMultisiteMode) { | |
return LibrariesManager.GetManager().GetImages(); | |
} | |
return SitefinityQuery.Get<Image>(LibrariesManager.GetManager().Provider) | |
.Where(o => GetLibrariesApplicationNames().Contains(o.ApplicationName)); | |
} | |
/* Fetch - LIVE RECORDS */ | |
IQueryable<Image> GetImages() { | |
return GetAllImages().Where(o => o.Visible && o.Status == ContentLifecycleStatus.Live); | |
} | |
Image GetImage(Guid id) { | |
return GetImages().SingleOrDefault(o => o.Id == id); | |
} | |
/* Provider/Application names */ | |
IEnumerable<string> GetLibrariesApplicationNames() { | |
//Get Provider names via SiteDataSourceLinks | |
var providerNames = GetProviderNames(typeof(LibrariesManager).FullName); | |
//NOW we can't just use these, because the "Default" provider for Sitefinity | |
//Has a different ProviderName from ApplicationName | |
//We could hardcode it, but that's not right, let's look it up in the place Sitefinity sets it. | |
return providerNames.Select(o => LibrariesProviderApplicationName(o)); | |
} | |
string LibrariesProviderApplicationName(string providerName) { | |
return Config.Get<LibrariesConfig>().Providers[providerName].Parameters["applicationName"]; | |
} | |
IEnumerable<string> GetProviderNames(string dataSourceName) { | |
return SystemManager.CurrentContext.CurrentSite.SiteDataSourceLinks | |
.Where(o => o.DataSourceName == dataSourceName) | |
.Select(o => o.ProviderName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment