|
using System.Collections.Generic;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace DeploymentFeature.WebConfigModification
{
/// <summary>
/// FeatureEventReceiver class traps the activation, deactivation, installation,
/// or uninstallation of a Feature.
/// </summary>
[System.ComponentModel.Category("1A995AC4-81CE-469B-B8C8-106019226740")] //Don't remove! This attribute is added by SPVisualDev to bind it to a WSS feature ID.
public class FeatureEventReceiver : SPFeatureReceiver
{
#region Constructors
/// <summary>
/// Initializes a new instance of the Microsoft.SharePoint.SPFeatureReceiver class.
/// </summary>
public FeatureEventReceiver()
{
}
#endregion // Constructors
#region Properties
/// <summary>
/// Gets or sets the deployment nodes.
/// </summary>
/// <value>The deployment nodes.</value>
private XmlNodeList DeploymentNodes { get; set; }
/// <summary>
/// Gets or sets the collection of DLLs to be installed into the GAC.
/// </summary>
/// <value><see cref="Dictionary"/> of dlls.</value>
private Dictionary<string, string> DllsToGac { get; set; }
#endregion // Properties
#region Methods
private void ReadDeploymentSettings(SPFeatureReceiverProperties properties)
{
// Open the reader with the source XML file
XmlTextReader reader = new XmlTextReader(properties.Definition.RootDirectory + @"\..\..\LAYOUTS\WebConfigModification\DeploymentSettings\RadControlsWebConfigAdds.xml");
// Load the source of the XML file into an XmlDocument
XmlDocument mySourceDoc = new XmlDocument();
// Load the source XML file into the first document
mySourceDoc.Load(reader);
// Close the reader
reader.Close();
XmlNode root = mySourceDoc.SelectSingleNode("WebConfigDeployments");
XmlNodeList dllsToGac = root.SelectNodes("DllToGac");
this.DeploymentNodes = root.SelectNodes("Deployment");
this.DllsToGac = new Dictionary<string, string>();
foreach (XmlNode dllToGac in dllsToGac)
{
this.DllsToGac.Add(dllToGac.Attributes["Name"].Value, dllToGac.Attributes["Folder"].Value);
}
}
#endregion // Methods
#region Events
/// <summary>
/// Occurs after a Feature is installed.
/// </summary>
/// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
/// <summary>
/// Occurs after a Feature is activated.
/// </summary>
/// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
this.ReadDeploymentSettings(properties);
SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
Installer installer = new Installer()
{
WebApplicationId = webApplication.Id,
Nodes = this.DeploymentNodes,
DllsToGac = this.DllsToGac
};
installer.Deploy(Installer.DeploymentType.Deploy);
}
/// <summary>
/// Occurs when a Feature is deactivated.
/// </summary>
/// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
this.ReadDeploymentSettings(properties);
SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
Installer installer = new Installer()
{
WebApplicationId = webApplication.Id,
Nodes = this.DeploymentNodes,
DllsToGac = this.DllsToGac
};
installer.Deploy(Installer.DeploymentType.UnDeploy);
}
/// <summary>
/// Occurs when a Feature is uninstalled.
/// </summary>
/// <param name="properties">A Microsoft.SharePoint.SPFeatureReceiverProperties object that represents properties of the event handler.</param>
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
#endregion // Events
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.