//-----------------------------------------------------------------------
// <copyright file="CentralAdminOnlyFeatureReceiver.cs" company="motion10">
// Copyright (c) motion10. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Globalization;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Security;
namespace Motion10.SharePoint2007 {
/// <summary>
/// You can use the CentralAdminOnlyFeatureReceiver class for those feature that can only be activated on the Central Administration Web Application. On other web applications the feature will be removed and an error is thrown to indicate that activation did not succeed.
/// </summary>
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class CentralAdminOnlyFeatureReceiver : SPFeatureReceiver {
/// <summary>
/// Occurs after a Feature is activated.
/// </summary>
/// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
if (!webApp.IsAdministrationWebApplication) {
Guid featureId = properties.Feature.DefinitionId;
webApp.Features.Remove(featureId, true);
webApp.Update();
throw new SPException(string.Format(CultureInfo.InvariantCulture, "You can activate the feature with ID {0} on the Central Administration Web Application only!", featureId));
}
}
/// <summary>
/// Occurs when a Feature is deactivated.
/// </summary>
/// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {
//throw new NotImplementedException();
}
/// <summary>
/// Occurs after a Feature is installed.
/// </summary>
/// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>
public override void FeatureInstalled(SPFeatureReceiverProperties properties) {
//throw new NotImplementedException();
}
/// <summary>
/// Occurs when a Feature is uninstalled.
/// </summary>
/// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {
//throw new NotImplementedException();
}
}
}