⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pictureoptions.aspx.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;
using CommunityServer.Galleries.Controls;
using Telligent.CommunityServer.MetadataExtractor.Exif;
using Telligent.CommunityServer.MetadataExtractor.Jpeg;
using Image = System.Web.UI.WebControls.Image;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;
using Script = CommunityServer.Controls.Script;

namespace CommunityServer.ControlPanel.Galleries.Options
{
	/// <summary>
	/// Summary description for PictureOptionsPage.
	/// </summary>
	public class PictureOptionsPage : BaseGalleryPage
	{

		#region Child Controls

		protected Controls.ResourceControl Resourcecontrol1;
		protected MPContent DescriptionRegion;
		protected Script GalleryAdminScript;
		protected ResourceControl Resourcecontrol2;
		protected Literal CacheMessage;
		protected Literal ImportCount;
		protected IButton SaveButton;
		protected IButton ImportButton;
		protected MPContent TaskRegion;
		protected MPContainer MPContainer;
		protected YesNoRadioButtonList ynEnableExif;
		protected TextBox WatermarkText, WatermarkMinImageY, WatermarkMinImageX;
		protected ListBox ExifTypes;
		protected DropDownList ImageWatermarkPosition, ImageWatermarkType;
		protected Literal CacheSize;
		protected LinkButton ThumbnailRebuild, SecondaryThumbnailRebuild, CleanCache, ClearCache;
		protected HtmlAnchor ThumbnailPreview, SecondaryThumbnailPreview, PictureDetailsPreview, SlideshowPreview;
		protected HtmlInputFile WatermarkData;
		protected Image imgWatermark;
		protected ParentCategoryDropDown ImportCategoryID;
        protected StatusMessage ImportStatus;

		protected ImageSettings ThumbnailSettings,SecondaryThumbnailSettings, PictureDetailsSettings, SlideshowSettings, MaxSettings;

		#endregion

	    private void Page_Load(object sender, EventArgs e)
		{
			ThumbnailPreview.Attributes.Add("onclick", "TogglePreview('" + ThumbnailSettings.ImageXClientID + "', '" + ThumbnailSettings.ImageYClientID + "', '" + ThumbnailPreview.ClientID + "');");
			SecondaryThumbnailPreview.Attributes.Add("onclick", "TogglePreview('" + SecondaryThumbnailSettings.ImageXClientID + "', '" + SecondaryThumbnailSettings.ImageYClientID + "', '" + SecondaryThumbnailPreview.ClientID + "');");
			PictureDetailsPreview.Attributes.Add("onclick", "TogglePreview('" + PictureDetailsSettings.ImageXClientID + "', '" + PictureDetailsSettings.ImageYClientID + "', '" + PictureDetailsPreview.ClientID + "');");
			SlideshowPreview.Attributes.Add("onclick", "TogglePreview('" + SlideshowSettings.ImageXClientID + "', '" + SlideshowSettings.ImageYClientID + "', '" + SlideshowPreview.ClientID + "');");
			
			WatermarkData.Attributes.Add("onchange","__doPostBack('" + WatermarkData.ClientID + "','');") ;
			ConfigurateWatermarkImage();

			if(!IsPostBack)
            {
				// Add a list of all the different EXIF properties
                ProcessMetadataDirectory(new CSExifDirectory());
                ProcessMetadataDirectory(new CSJpegDirectory());

				foreach(string s in Enum.GetNames(typeof(WatermarkPosition)))
					ImageWatermarkPosition.Items.Add(new ListItem(ResourceManager.GetString("CP_Photos_PictureOptions_WatermarkPosition_" + s) , s)) ;

				foreach(string s in Enum.GetNames(typeof(WatermarkType)))
					ImageWatermarkType.Items.Add(new ListItem(ResourceManager.GetString("CP_Photos_PictureOptions_WatermarkType_" + s), s)) ;

				ListItem li = ImageWatermarkType.Items.FindByValue(CurrentGallery.WatermarkType.ToString()) ;
				if(li != null)
					li.Selected = true;

				li = ImageWatermarkPosition.Items.FindByValue(CurrentGallery.WatermarkPosition.ToString());
				if(li != null)
					li.Selected = true;
			
				WatermarkText.Text = CurrentGallery.WatermarkText.ToString();
				WatermarkMinImageX.Text = CurrentGallery.WatermarkMinWidth.ToString();
				WatermarkMinImageY.Text = CurrentGallery.WatermarkMinHeight.ToString();

				ynEnableExif.Items.FindByValue( CurrentGallery.EnableExif.ToString() ).Selected = true;
				
                // Select all of the DisplayExifProperties items
                for (int i = 0; i < CurrentGallery.DisplayExifProperties.Length; i++)
                {
                    ListItem item = ExifTypes.Items.FindByValue(CurrentGallery.DisplayExifProperties[i]);
                    if (item != null)
                        item.Selected = true;
                }

				ThumbnailSettings.SetFormFields(CurrentGallery.GetThumbnailSettings()) ;

				SecondaryThumbnailSettings.SetFormFields(CurrentGallery.GetSecondaryThumbnailSettings()) ;
				
				PictureDetailsSettings.SetFormFields(CurrentGallery.GetPictureDetailsSettings()) ;
				
				SlideshowSettings.SetFormFields(CurrentGallery.GetSlideshowSettings()) ;

				MaxSettings.SetFormFields(CurrentGallery.GetMaxSettings());

				// Calculate the current cache size
				CalculateCacheSize();

				CalculateImportCount();

				ImportCategoryID.SectionID = CurrentGallery.SectionID;
				ImportCategoryID.DataBind();

				ThumbnailRebuild.Text = Components.ResourceManager.GetString("CP_Photos_PictureOptions_Rebuild");
				SecondaryThumbnailRebuild.Text = Components.ResourceManager.GetString("CP_Photos_PictureOptions_Rebuild");
				CleanCache.Text = Components.ResourceManager.GetString("CP_Photos_PictureOptions_CleanCache");
				CleanCache.ToolTip = Components.ResourceManager.GetString("CP_Photos_PictureOptions_CleanCache_Help");
				ClearCache.Text = Components.ResourceManager.GetString("CP_Photos_PictureOptions_ClearCache");
				ClearCache.ToolTip = Components.ResourceManager.GetString("CP_Photos_PictureOptions_ClearCache_Help");

				// If rebuilding thumbnails is disabled, hide the buttons
				if(Jobs.Instance().IsJobEnabled("RebuildThumbnailsJob") == false)
				{
					ThumbnailRebuild.Visible = false;
					SecondaryThumbnailRebuild.Visible = false;
				}



            }
			else
			{
				//check to see if our quick add has data
				if((WatermarkData != null) && (WatermarkData.PostedFile != null) && (WatermarkData.PostedFile.ContentLength > 0))
					QuickAddWatermarkData();
				else
					CacheMessage.Visible = false;

			}
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
			this.SaveButton.Click += new EventHandler(SaveButton_Click);
			AddClickEvents();
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new EventHandler(this.Page_Load);

		}
		#endregion

        private void ProcessMetadataDirectory(ICSMetadataDirectory directory)
        {
            Hashtable tags = directory.GetTags();
            foreach (int key in tags.Keys)
                ExifTypes.Items.Add(new ListItem(tags[key] as string, directory.DirectoryName() + ":" + key.ToString()));
        }

        interface ICSMetadataDirectory { Hashtable GetTags(); string DirectoryName(); }
        internal class CSExifDirectory : ExifDirectory, ICSMetadataDirectory { public Hashtable GetTags() { return tagNameMap as Hashtable; } public string DirectoryName() { return typeof(ExifDirectory).FullName; } }
        internal class CSJpegDirectory : JpegDirectory, ICSMetadataDirectory { public Hashtable GetTags() { return tagNameMap as Hashtable; } public string DirectoryName() { return typeof(JpegDirectory).FullName; } }

		private void QuickAddWatermarkData()
		{
			if (!ValidateWatermarkContentType(WatermarkData.PostedFile.ContentType))
			{
				CacheMessage.Text = "<span style='color: red'>" + string.Format(Components.ResourceManager.GetString("CP_Photos_PictureOptions_WatermarkInvalidMineType"), WatermarkData.PostedFile.ContentType) + "</span>";
				CacheMessage.Visible = true;
			}
			else
			{
				GalleryConfiguration.Instance().CacheSettings.LegacyClearStorage(CurrentGallery.SectionID) ;
				GalleryConfiguration.Instance().CacheSettings.DeleteSectionFromDisk(CurrentGallery.SectionID) ;
				
				string filename = GalleryConfiguration.Instance().CacheSettings.GetLocalWatermarkFileName(CurrentGallery.SectionID);
				if(File.Exists(filename))
					File.Delete(filename);

				WatermarkData.PostedFile.SaveAs(filename);
				this.ConfigurateWatermarkImage();
				
				CacheMessage.Text = "<span style='color: green'>" + Components.ResourceManager.GetString("CP_Photos_PictureOptions_WatermarkClearWarning") + "</span>";
				CacheMessage.Visible = true;

				CalculateCacheSize();
			}

		}

		private bool ValidateWatermarkContentType(string contentType)
		{
			switch(contentType)
			{
				case "image/bmp":
				case "image/jpeg":
				case "image/pjpeg":
				case "image/gif":
				case "image/png":
                case "image/x-png":
					return true;

				default:
					return false;
			}
			
		}

		private void ConfigurateWatermarkImage()
		{
			string filename = GalleryConfiguration.Instance().CacheSettings.GetLocalWatermarkFileName(CurrentGallery.SectionID);
			if(File.Exists(filename))
			{
				imgWatermark.ImageUrl = GalleryUrls.Instance().ViewWatermark(CurrentGallery.ApplicationKey);
				imgWatermark.Height	= 100;
			}
			else
			{
				imgWatermark.ImageUrl = "../../../utility/images/1x1.gif";
				imgWatermark.Height	= 100;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -