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

📄 configuration.cs

📁 三层架构的.net源码三层架构的.net源码
💻 CS
📖 第 1 页 / 共 4 页
字号:
			SaveSiteSettings();

			// Return the new ModuleDefID
			return newModuleDef.ModuleDefId;
		}

		//*********************************************************************
		//
		// DeleteModuleDefinition() Method <a name="DeleteModuleDefinition"></a>
		//
		// The DeleteModuleDefinition method deletes the specified module type 
		// definition from the portal.  Each module which is related to the
		// ModuleDefinition is deleted from each tab in the configuration
		// file, and all data relating to each module is deleted from the
		// database.
		//
		// Other relevant sources:
		//    + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
		//	  + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
		//    + <a href="DeleteModule.htm" style="color:green">DeleteModule Stored Procedure</a>
		//
		//*********************************************************************
		public void DeleteModuleDefinition(int defId) 
		{
			// 从HttpContext中获取全局设置对象
			SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];

			//
			// Delete information in the Database relating to each Module being deleted
			//

			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
			SqlCommand myCommand = new SqlCommand("Portal_DeleteModule", myConnection);

			// Mark the Command as a SPROC
			myCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterModuleID = new SqlParameter("@ModuleID", SqlDbType.Int, 4);
			myConnection.Open();

			foreach(SiteConfiguration.ModuleRow moduleRow in siteSettings.Module.Select())
			{
				if(moduleRow.ModuleDefId == defId)
				{
					myCommand.Parameters.Clear();
					parameterModuleID.Value = moduleRow.ModuleId;
					myCommand.Parameters.Add(parameterModuleID);

					// Delete the xml module associated with the ModuleDef
					// in the configuration file
					siteSettings.Module.RemoveModuleRow(moduleRow);

					// Open the database connection and execute the command
					myCommand.ExecuteNonQuery();
				}
			}

			myConnection.Close();

			// Finish removing Module Definition
			siteSettings.ModuleDefinition.RemoveModuleDefinitionRow(siteSettings.ModuleDefinition.FindByModuleDefId(defId));

			// Save the changes 
			SaveSiteSettings();
		}
       
		//*********************************************************************
		//
		// UpdateModuleDefinition() Method <a name="UpdateModuleDefinition"></a>
		//
		// The UpdateModuleDefinition method updates the settings for the 
		// specified module type definition.
		//
		// Other relevant sources:
		//    + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
		//	  + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
		//
		//*********************************************************************
		public void UpdateModuleDefinition(int defId, String name, String desktopSrc, String mobileSrc) 
		{
			// 从HttpContext中获取全局设置对象
			SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];

			// Find the appropriate Module in the Module table and update the properties
			SiteConfiguration.ModuleDefinitionRow modDefRow = siteSettings.ModuleDefinition.FindByModuleDefId(defId);

			modDefRow.FriendlyName = name;
			modDefRow.DesktopSourceFile = desktopSrc;
			modDefRow.MobileSourceFile = mobileSrc;

			// Save the changes 
			SaveSiteSettings();
		}

		//*********************************************************************
		//
		// GetSingleModuleDefinition Method
		//
		// The GetSingleModuleDefinition method returns a ModuleDefinitionRow
		// object containing details about a specific module definition in the
		// configuration file.
		//
		// Other relevant sources:
		//    + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
		//	  + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
		//
		//*********************************************************************
		public SiteConfiguration.ModuleDefinitionRow GetSingleModuleDefinition(int defId) 
		{
			// 从HttpContext中获取全局设置对象
			SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];

			// Find the appropriate Module in the Module table
			return siteSettings.ModuleDefinition.FindByModuleDefId(defId);
		}

		#region 获取站点全局设置(已站点设置数据集的形式返回数据)

		//*********************************************************************
		//
		// GetSiteSettings Static Method
		//
		// The Configuration.GetSiteSettings Method returns a typed
		// dataset of the all of the site configuration settings from the
		// XML configuration file.  This method is used in Global.asax to
		// push the settings into the current HttpContext, so that all of the 
		// pages, content modules and classes throughout the rest of the request
		// may access them.
		//
		// The SiteConfiguration object is cached using the ASP.NET Cache API,
		// with a file-change dependency on the XML configuration file.  Normallly,
		// this method just returns a copy of the object in the cache.  When the
		// configuration is updated and changes are saved to the the XML file,
		// the SiteConfiguration object is evicted from the cache.  The next time 
		// this method runs, it will read from the XML file again and insert a
		// fresh copy of the SiteConfiguration into the cache.
		//
		//*********************************************************************
		
		/// <summary>
		/// 获取站点全局设置(已站点设置数据集的形式返回数据)
		/// </summary>
		/// <returns></returns>
		public static SiteConfiguration GetSiteSettings()
		{
			// 从缓存中获取站点设置数据集
			SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Cache["SiteSettings"];

			// If the SiteConfiguration isn't cached, load it from the XML file and add it into the cache.
			// 如果在缓存中没有则从XML文件中读取并写入缓存
			if(siteSettings == null)
			{
				// Create the dataset
				// 创建站点设置数据集
				siteSettings = new SiteConfiguration();

				// Retrieve the location of the XML configuration file
				// 找到全局设置文件的物理路径
				string configFile = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["configFile"]);

				// Set the AutoIncrement property to true for easier adding of rows
				siteSettings.Tab.TabIdColumn.AutoIncrement = true;
				siteSettings.Module.ModuleIdColumn.AutoIncrement = true;
				siteSettings.ModuleDefinition.ModuleDefIdColumn.AutoIncrement = true;

				// Load the XML data into the DataSet
				// 从XML文件中读出数据填充数据集
				siteSettings.ReadXml(configFile);
		
				// Store the dataset in the cache
				// 将数据集存储到缓存中
				HttpContext.Current.Cache.Insert("SiteSettings", siteSettings, new CacheDependency(configFile));
			}

			return siteSettings;
		}

		#endregion

		#region 保存站点设置

		//*********************************************************************
		//
		// SaveSiteSettings Method <a name="SaveSiteSettings"></a>
		//
		// The Configuration.SaveSiteSettings overwrites the the XML file with the
		// settings in the SiteConfiguration object in context.  The object will in 
		// turn be evicted from the cache and be reloaded from the XML file the next
		// time GetSiteSettings() is called.
		//
		//*********************************************************************
		/// <summary>
		/// 保存站点设置
		/// </summary>
		public void SaveSiteSettings()
		{
			// Obtain SiteSettings from the Cache
			// 原来的:从Cache中获取站点设置信息数据集(好像是个Bug,因为每次更新数据是更新的HttpContext.Current.Items中的)
			//SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Cache["SiteSettings"];
			//修改后的
			SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"];

			// Check the object
			// 如果Cache中没有,则重新构建
			if(siteSettings == null)
			{
				// If SaveSiteSettings() is called once, the cache is cleared.  If it is
				// then called again before Global.Application_BeginRequest is called, 
				// which reloads the cache, the siteSettings object will be Null 
				// 如果SaveSiteSettings()被调用过一次后,Cache就回被清除。如果它再一次被调用在Global.Application_BeginRequest前siteSettings为null则重新写Cache
				siteSettings = GetSiteSettings();
			}
			string configFile = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["configFile"]);

			// Object is evicted from the Cache here.  
			// 将变更后的数据集写入到Xml文件
			siteSettings.WriteXml(configFile);
		}

		#endregion
	}

	#region PortalSettings Class 门户站点设置的信息类

	//*********************************************************************
	//
	// PortalSettings Class
	//
	// This class encapsulates all of the settings for the Portal, as well
	// as the configuration settings required to execute the current tab
	// view within the portal.
	// 该类用于设置门户站点的信息
	//
	//*********************************************************************

	/// <summary>
	/// 门户站点设置的信息
	/// </summary>
	public class PortalSettings 
	{

		public int          PortalId;							//门户站点Id
		public String       PortalName;							//门户站点名称
		public bool         AlwaysShowEditButton;				//是否显示编辑按钮
		public ArrayList    DesktopTabs = new ArrayList();		//门户站点“桌面浏览器”显示部分的导航栏标签的ArrayList
		public ArrayList    MobileTabs = new ArrayList();
		public TabSettings  ActiveTab = new TabSettings();		//当前标签

		//*********************************************************************
		//
		// PortalSettings Constructor
		//
		// The PortalSettings Constructor encapsulates all of the logic
		// necessary to obtain configuration settings necessary to render
		// a Portal Tab view for a given request.
		//
		// These Portal Settings are stored within PortalCFG.xml, and are
		// fetched below by calling config.GetSiteSettings().
		// The method config.GetSiteSettings() fills the SiteConfiguration
		// class, derived from a DataSet, which PortalSettings accesses.
		//       
		//*********************************************************************

		/// <summary>
		/// 构造门户站点设置信息对象
		/// </summary>
		/// <param name="tabIndex"></param>
		/// <param name="tabId"></param>
		public PortalSettings(int tabIndex, int tabId) 
		{
			// Get the configuration data
			// 获取配置文件数据
			SiteConfiguration siteSettings = Configuration.GetSiteSettings();

			// Read the Desktop Tab Information, and sort by Tab Order
			// 根据标签排序号按顺序读取“桌面浏览器”上显示的导航栏标签信息
			foreach(SiteConfiguration.TabRow tRow in siteSettings.Tab.Select("", "TabOrder"))
			{
				//构造标签详细信息对象实例
				TabStripDetails tabDetails = new TabStripDetails();
				//赋值
				tabDetails.TabId = tRow.TabId;
				tabDetails.TabName = tRow.TabName;
				tabDetails.TabOrder = tRow.TabOrder;
				tabDetails.AuthorizedRoles = tRow.AccessRoles;
				//将对象添加到DesktopTabs中
				this.DesktopTabs.Add(tabDetails);
			}

			// If the PortalSettings.ActiveTab property is set to 0, change it to the TabID of the first tab in the DesktopTabs collection
			// 设置当前活动标签,当前标签的TabId为0时,取“桌面浏览器”的标签列表的第一项为当前项
			if(this.ActiveTab.TabId == 0)
			{
				this.ActiveTab.TabId = ((TabStripDetails)this.DesktopTabs[0]).TabId;
			}


			// Read the Mobile Tab Information, and sort by Tab Order
			foreach(SiteConfiguration.TabRow mRow in siteSettings.Tab.Select("ShowMobile='true'", "TabOrder"))
			{
				TabStripDetails tabDetails = new TabStripDetails();

				tabDetails.TabId = mRow.TabId;
				tabDetails.TabName = mRow.MobileTabName;
				tabDetails.AuthorizedRoles = mRow.AccessRoles;
				
				this.MobileTabs.Add(tabDetails);
			}

			// Read the Module Information for the current (Active) tab
			// 获取当前活动标签所在行信息
			SiteConfiguration.TabRow activeTab = siteSettings.Tab.FindByTabId(tabId);

			// Get Modules for this Tab based on the Data Relation
			// 找到当前标签的关联的模块信息
			foreach(SiteConfiguration.ModuleRow moduleRow in activeTab.GetModuleRows())
			{
				ModuleSettings moduleSettings = new ModuleSettings();

				moduleSettings.ModuleTitle = moduleRow.ModuleTitle;
				moduleSettings.ModuleId = moduleRow.ModuleId;
				moduleSettings.ModuleDefId = moduleRow.ModuleDefId;
				moduleSettings.ModuleOrder = moduleRow.ModuleOrder;
				moduleSettings.TabId = tabId;
				moduleSettings.PaneName = moduleRow.PaneName;
				moduleSettings.AuthorizedEditRoles = moduleRow.EditRoles;
				moduleSettings.CacheTime = moduleRow.CacheTimeout;
				moduleSettings.ShowMobile = moduleRow.ShowMobile;

				// ModuleDefinition data
				SiteConfiguration.ModuleDefinitionRow modDefRow = siteSettings.ModuleDefinition.FindByModuleDefId(moduleSettings.ModuleDefId);

				moduleSettings.DesktopSrc = modDefRow.DesktopSourceFile;
				moduleSettings.MobileSrc = modDefRow.MobileSourceFile;
				
				this.ActiveTab.Modules.Add(moduleSettings);

⌨️ 快捷键说明

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