📄 galleryadmin.cs
字号:
Owners.Text = gallery.Owners;
IsActive.Items.FindByValue( gallery.IsActive.ToString() ).Selected = true;
IsSearchable.Items.FindByValue( gallery.IsSearchable.ToString() ).Selected = true;
// Select all of the DisplayExifProperties items
for(int i = 0 ; i < gallery.DisplayExifProperties.Length ; i++)
ExifTypes.Items.FindByValue( ((int)gallery.DisplayExifProperties[i]).ToString() ).Selected = true;
// Plug in the values for various gallery settings
CategoryListingColumns.Text = gallery.CategoryListingColumns.ToString();
CategoryListingRows.Text = gallery.CategoryListingRows.ToString();
PictureListingColumns.Text = gallery.PictureListingColumns.ToString();
PictureListingRows.Text = gallery.PictureListingRows.ToString();
PicturesSortBy.SelectedSortByValue = gallery.ThreadSortBy;
EnableComments.Items.FindByValue( gallery.EnableComments.ToString() ).Selected = true;
ModerateComments.Items.FindByValue( gallery.ModerateComments.ToString() ).Selected = true;
EnableRatings.Items.FindByValue( gallery.EnableRatings.ToString() ).Selected = true;
EnableExif.Items.FindByValue( gallery.EnableExif.ToString() ).Selected = true;
EnableOrderPrints.Items.FindByValue( gallery.EnableOrderPrints.ToString() ).Selected = true;
ThumbnailX.Text = gallery.ThumbnailX.ToString();
ThumbnailY.Text = gallery.ThumbnailY.ToString();
ThumbnailQuality.Text = gallery.ThumbnailQuality.ToString();
ThumbnailBrightness.Text = gallery.ThumbnailBrightness.ToString();
SecondaryThumbnailX.Text = gallery.SecondaryThumbnailX.ToString();
SecondaryThumbnailY.Text = gallery.SecondaryThumbnailY.ToString();
SecondaryThumbnailQuality.Text = gallery.SecondaryThumbnailQuality.ToString();
PictureDetailsX.Text = gallery.PictureDetailsX.ToString();
PictureDetailsY.Text = gallery.PictureDetailsY.ToString();
PictureDetailsQuality.Text = gallery.PictureDetailsQuality.ToString();
SlideshowX.Text = gallery.SlideshowX.ToString();
SlideshowY.Text = gallery.SlideshowY.ToString();
SlideshowQuality.Text = gallery.SlideshowQuality.ToString();
// Calculate the current cache size
CalculateCacheSize();
// Set some resource labels
Save.Text = ResourceManager.GetString("Save");
Delete.Text = ResourceManager.GetString("Delete");
ThumbnailRebuild.Text = ResourceManager.GetString("GalleryAdmin_Rebuild");
SecondaryThumbnailRebuild.Text = ResourceManager.GetString("GalleryAdmin_Rebuild");
CleanCache.Text = ResourceManager.GetString("GalleryAdmin_CleanCache");
CleanCache.ToolTip = ResourceManager.GetString("GalleryAdmin_CleanCache_Detail");
ClearCache.Text = ResourceManager.GetString("GalleryAdmin_ClearCache");
ClearCache.ToolTip = ResourceManager.GetString("GalleryAdmin_ClearCache_Detail");
// If rebuilding thumbnails is disabled, hide the buttons
if(Jobs.Instance().IsJobEnabled("RebuildThumbnailsJob") == false)
{
ThumbnailRebuild.Visible = false;
SecondaryThumbnailRebuild.Visible = false;
}
// Populate the themes
PopulateThemes();
string theme = string.Format("{0}@{1}", gallery.Theme, gallery.SecondaryCSS).ToLower().Trim();
ListItem liTheme = Themes.Items.FindByValue(theme);
if(liTheme != null)
liTheme.Selected = true;
CustomCSS.Text = gallery.CSSOverride;
}
private void Save_Click(Object sender, EventArgs e)
{
// Get the current gallery settings
Gallery gallery = GetGallery();
// If the ApplicationKey was changed, we need to rename a few things... but only if the user is an admin
if(CSContext.Current.User.IsGalleryAdministrator)
{
string formattedKey = null;
Globals.ValidateApplicationKey(ApplicationKeyLabel.Text, out formattedKey);
if(gallery.ApplicationKey != formattedKey)
{
string oldPath = Globals.GetSiteUrls().Locations["galleries"] + gallery.ApplicationKey;
string newPath = Globals.GetSiteUrls().Locations["galleries"] + formattedKey;
WebDirectory.Move(oldPath, newPath);
gallery.ApplicationKey = formattedKey;
}
}
// Plug in the values from the form
gallery.Name = Name.Text;
gallery.Owners = Owners.Text;
gallery.Description = Description.Text;
gallery.IsActive = Boolean.Parse( IsActive.SelectedValue );
gallery.IsSearchable = Boolean.Parse( IsSearchable.SelectedValue );
// Apply all of the feature settings
gallery.CategoryListingColumns = int.Parse(CategoryListingColumns.Text);
gallery.CategoryListingRows = int.Parse(CategoryListingRows.Text);
gallery.PictureListingColumns = int.Parse(PictureListingColumns.Text);
gallery.PictureListingRows = int.Parse(PictureListingRows.Text);
gallery.ThreadSortBy = PicturesSortBy.SelectedSortByValue;
gallery.EnableComments = Boolean.Parse( EnableComments.SelectedValue );
gallery.ModerateComments = Boolean.Parse( ModerateComments.SelectedValue );
gallery.EnableRatings = Boolean.Parse( EnableRatings.SelectedValue );
gallery.EnableExif = Boolean.Parse( EnableExif.SelectedValue );
gallery.EnableOrderPrints = Boolean.Parse( EnableOrderPrints.SelectedValue );
// Get all of the values that are checked
ArrayList properties = new ArrayList();
foreach(ListItem item in ExifTypes.Items)
if(item.Selected == true)
properties.Add((ExifProperty)int.Parse(item.Value));
gallery.DisplayExifProperties = (ExifProperty[])properties.ToArray(typeof(ExifProperty));
gallery.ThumbnailX = int.Parse(ThumbnailX.Text);
gallery.ThumbnailY = int.Parse(ThumbnailY.Text);
gallery.ThumbnailQuality = int.Parse(ThumbnailQuality.Text);
gallery.ThumbnailBrightness = int.Parse(ThumbnailBrightness.Text);
gallery.SecondaryThumbnailX = int.Parse(SecondaryThumbnailX.Text);
gallery.SecondaryThumbnailY = int.Parse(SecondaryThumbnailY.Text);
gallery.SecondaryThumbnailQuality = int.Parse(SecondaryThumbnailQuality.Text);
gallery.PictureDetailsX = int.Parse(PictureDetailsX.Text);
gallery.PictureDetailsY = int.Parse(PictureDetailsY.Text);
gallery.PictureDetailsQuality = int.Parse(PictureDetailsQuality.Text);
gallery.SlideshowX = int.Parse(SlideshowX.Text);
gallery.SlideshowY = int.Parse(SlideshowY.Text);
gallery.SlideshowQuality = int.Parse(SlideshowQuality.Text);
// Themes
string[] theme = Themes.SelectedValue.Split('@');
gallery.Theme = theme[0];
if(theme.Length > 1)
gallery.SecondaryCSS = theme[1];
else
gallery.SecondaryCSS = null;
gallery.CSSOverride = CustomCSS.Text;
// Some basic settings we should always have...
gallery.EnableAutoDelete = false; // Don't auto delete picutres
gallery.EnablePostStatistics = false; // Don't let comments count towards post count
// Make sure the page is valid
if(Page.IsValid)
{
// Update it
Galleries.UpdateGallery(gallery);
if(CSContext.Current.Url != null)
Globals.RedirectSiteUrl();
else
CSContext.Current.Context.Response.Redirect( GalleryUrls.Instance().Admin_ManageGalleries, true );
}
}
private void Delete_Click(Object sender, EventArgs e)
{
if(CSContext.Current.User.IsGalleryAdministrator)
{
// Delete it
WebDirectory.Delete(Globals.GetSiteUrls().Locations["galleries"] + Galleries.GetGallery(SectionID).ApplicationKey);
Galleries.DeleteGallery(SectionID);
if(!Globals.RedirectSiteUrl())
CSContext.Current.Context.Response.Redirect( GalleryUrls.Instance().Admin_ManageGalleries, true );
}
else
throw new CSException( CSExceptionType.AdministrationAccessDenied );
}
private void CalculateCacheSize()
{
// Calculate the current cache size
FileInfo[] files = (new DirectoryInfo(Picture.CacheDirectory())).GetFiles(CSContext.Current.SiteSettings.SettingsID + "." + SectionID + ".*");
long count = 0;
foreach(FileInfo file in files)
count += file.Length;
count = count / 1024;
CacheSize.Text = count.ToString() + "kb";
}
private void ThumbnailRebuild_Click(object sender, EventArgs e)
{
Gallery gallery = GetGallery();
Hashtable pictures = GalleryDataProvider.Instance().GetAllPictures(gallery.SectionID);
Queue queue = CSCache.Get("RebuildItems") as Queue;
GalleryConfiguration.Instance().CalculateFileSystemStorageLocation();
// The queue doesn't exist, so create it
if(queue == null)
{
queue = Queue.Synchronized(new Queue());
CSCache.Max("RebuildItems", queue);
}
// Loop the pictures and create the queue items
foreach(int key in pictures.Keys)
{
Picture picture = pictures[key] as Picture;
GalleryImageSettings settings = new GalleryImageSettings(gallery.ThumbnailX, gallery.ThumbnailY, gallery.ThumbnailQuality, true, false, false);
settings.Brightness = gallery.ThumbnailBrightness;
string filename = Picture.CacheFilename(gallery.SectionID, picture.PostID, GalleryImageType.Thumbnail, settings.Width, settings.Height);
// Remove the file in advance, so if anyone browses it will regenerate it then and skip it in the job
File.Delete(filename);
// Create the item and queue it
RebuildItem item = new RebuildItem(gallery, picture, filename, settings);
queue.Enqueue(item);
}
// Show a message that they have been queued.
Literal message = (Literal)FindControl("Message");
message.Text = "<span style='color: green'>" + string.Format(ResourceManager.GetString("GalleryAdmin_RebuildQueue"), pictures.Count) + " </span>";
message.Visible = true;
}
private void SecondaryThumbnailRebuild_Click(object sender, EventArgs e)
{
Gallery gallery = GetGallery();
Hashtable pictures = GalleryDataProvider.Instance().GetAllPictures(gallery.SectionID);
Queue queue = CSCache.Get("RebuildItems") as Queue;
GalleryConfiguration.Instance().CalculateFileSystemStorageLocation();
// The queue doesn't exist, so create it
if(queue == null)
{
queue = Queue.Synchronized(new Queue());
CSCache.Max("RebuildItems", queue);
}
// Loop the pictures and create the queue items
foreach(int key in pictures.Keys)
{
Picture picture = pictures[key] as Picture;
GalleryImageSettings settings = new GalleryImageSettings(gallery.SecondaryThumbnailX, gallery.SecondaryThumbnailY, gallery.SecondaryThumbnailQuality, true, false, false);
string filename = Picture.CacheFilename(gallery.SectionID, picture.PostID, GalleryImageType.SecondaryThumbnail, settings.Width, settings.Height);
// Remove the file in advance, so if anyone browses it will regenerate it then and skip it in the job
File.Delete(filename);
// Create the item and queue it
RebuildItem item = new RebuildItem(gallery, picture, filename, settings);
queue.Enqueue(item);
}
// Show a message that they have been queued.
Literal message = (Literal)FindControl("Message");
message.Text = "<span style='color: green'>" + string.Format(ResourceManager.GetString("GalleryAdmin_RebuildQueue"), pictures.Count) + " </span>";
message.Visible = true;
}
private void CleanCache_Click(object sender, EventArgs e)
{
Gallery gallery = GetGallery();
// Delete all of the files except those which might be thumbnails or large thumbnails
FileInfo[] files = (new DirectoryInfo(Picture.CacheDirectory())).GetFiles(CSContext.Current.SiteSettings.SettingsID + "." + gallery.SectionID + ".*");
foreach(FileInfo file in files)
{
string filename = file.Name.Replace(CSContext.Current.SiteSettings.SettingsID + "." + gallery.SectionID + ".", "").Replace(file.Extension, "");
string[] parts = filename.Split('.', 'x'); // 0 = AppKey, 1 = type of widthxheight
if( (parts[1] != "thumb") && (parts[1] != "secondarythumb") )
file.Delete();
}
CalculateCacheSize();
}
private void ClearCache_Click(object sender, EventArgs e)
{
Gallery gallery = GetGallery();
// Delete all of the files
FileInfo[] files = (new DirectoryInfo(Picture.CacheDirectory())).GetFiles(CSContext.Current.SiteSettings.SettingsID + "." + gallery.SectionID + ".*");
foreach(FileInfo file in files)
file.Delete();
CalculateCacheSize();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -