private static SPFeature ActivateFeature(this SPFeatureCollection features, Guid featureId, SPFeaturePropertyCollection properties) { if (features[featureId] != null) { // The feature is already activated. No action required return null; } var type = typeof(SPFeatureCollection); // now we have to get "AddInternal" Method with this signature: //internal SPFeature AddInternal(Guid featureId, Version version, SPFeaturePropertyCollection properties, bool force, bool fMarkOnly, SPFeatureDefinitionScope featdefScope) var param = new[] { typeof (Guid), typeof (Version), typeof (SPFeaturePropertyCollection), typeof (bool), typeof (bool), typeof (SPFeatureDefinitionScope) }; var addInternal = type.GetMethod("AddInternal", BindingFlags.Instance | BindingFlags.NonPublic, null, param, null); if (addInternal == null) { // faild to find the method return null; } var result = addInternal.Invoke(features, new object[] { featureId, null, properties, false, false, SPFeatureDefinitionScope.Farm }); return result as SPFeature; }
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { configurationproperties = properties.Feature.Properties; RemoveConfigurationSecureTokenServices(); RemoveConfigurationRootWebServices(); RemoveConfigurationCentralAdministration(); }); }
public static Dictionary <string, string> ToProperties(this SPFeaturePropertyCollection featureProperties) { var properties = new Dictionary <string, string>(); foreach (SPFeatureProperty p in featureProperties) { properties.Add(p.Name, p.Value); } return(properties); }
internal static void TeamSiteWebFeatureActivatedHandler(SPWeb web, SPFeaturePropertyCollection properties) { // Create three additional libraries CreateNewList(web, "Meeting Notes", "Meeting notes", SPListTemplateType.DocumentLibrary); CreateNewList(web, "Presentations", "Presentations", SPListTemplateType.DocumentLibrary); CreateNewList(web, "Issues", "Issues", SPListTemplateType.IssueTracking); // Set master page web.MasterUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, "/_catalogs/masterpage/contoso.master"); web.Update(); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { configurationproperties = properties.Feature.Properties; if (properties.Feature.Parent.GetType() == typeof(SPWebApplication)) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; //SPSite site = webApp.Sites.Where(p => p.ServerRelativeUrl.Equals("/", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); CreateVirtualDirectory(webApp); SPWebApplication wap = SPWebService.ContentService.WebApplications[webApp.Id]; List <SPWebConfigModification> process = new List <SPWebConfigModification>(); process.AddRange(ZimbraWebConfigModification.Modifications); foreach (SPWebConfigModification mod in process) { try { if (!wap.WebConfigModifications.Contains(mod)) { wap.WebConfigModifications.Add(mod); } if (!SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Contains(mod)) { SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Add(mod); } } catch (Exception ex) { diagSvc.WriteEvent(0, new SPDiagnosticsCategory("ClubCloud", TraceSeverity.Monitorable, EventSeverity.Warning), EventSeverity.Error, "Exception occured {0}", new object[] { ex }); } } try { wap.Update(false); SPWebService.ContentService.WebApplications[wap.Id].Update(false); SPWebService.ContentService.WebApplications[wap.Id].WebService.ApplyWebConfigModifications(); //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); wap.WebConfigModifications.Clear(); wap.Update(false); } catch { }; } }); }
public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary <string, string> parameters) { SPSecurity.RunWithElevatedPrivileges(delegate() { configurationproperties = properties.Feature.Properties; RemoveConfigurationSecureTokenServices(); AppendConfigurationSecureTokenServices(); RemoveConfigurationRootWebServices(); AppendConfigurationRootWebServices(); RemoveConfigurationCentralAdministration(); AppendConfigurationCentralAdministration(); }); }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { configurationproperties = properties.Feature.Properties; if (properties.Feature.Parent.GetType() == typeof(SPWebApplication)) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; //SPSite site = webApp.Sites.Where(p => p.ServerRelativeUrl.Equals("/", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); RemoveVirtualDirectory(webApp); SPWebApplication wap = SPWebService.ContentService.WebApplications[webApp.Id]; List <SPWebConfigModification> process = new List <SPWebConfigModification>(); process.AddRange(ZimbraWebConfigModification.Modifications); foreach (SPWebConfigModification mod in process) { try { if (wap.WebConfigModifications.Contains(mod)) { wap.WebConfigModifications.Remove(mod); } if (SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Contains(mod)) { SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Remove(mod); } } catch { }; } try { wap.Update(false); SPWebService.ContentService.WebApplications[wap.Id].Update(false); SPWebService.ContentService.WebApplications[wap.Id].WebService.ApplyWebConfigModifications(); //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); wap.WebConfigModifications.Clear(); wap.Update(); } catch { }; } }); }
//public override void FeatureInstalled(SPFeatureReceiverProperties properties) //{ //} //public override void FeatureUninstalling(SPFeatureReceiverProperties properties) //{ //} //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters) //{ //} private static bool ApplyWebConfigMods(SPFeatureReceiverProperties properties) { bool bApplyChanges = true; SPFeaturePropertyCollection featureProps = properties.Feature.Properties; if (featureProps != null && featureProps.Count > 0) { SPFeatureProperty applyModsProp = null; try { applyModsProp = featureProps["ApplyWebConfigModifications"]; if (applyModsProp != null) { bool.TryParse(applyModsProp.Value, out bApplyChanges); } } catch (Exception) { // we'll go ahead and make the web.config changes if the property is not present.. } } return(bApplyChanges); }
/// <summary> /// Returns the assembly information for the LobSystems. /// </summary> /// <param name="featurePropertyCollection">Collection of LobSystem Properties.</param> /// <param name="featureFolder">Feature folder.</param> /// <returns>Collection of assembly information for the LobSystems.</returns> private Dictionary<string, LobSystemAssemblies> GetLobSystemAssemblies(SPFeaturePropertyCollection featurePropertyCollection, string featureFolder) { //Get a list of all lobSystems defined by the model. XmlNodeList lobSystemList = this.modelDocument.GetElementsByTagName("LobSystem"); Dictionary<string, string> lobSystemProperties = new Dictionary<string, string>(lobSystemList.Count); foreach (XmlNode node in lobSystemList) { XmlAttribute lobSystemNameAttribute = node.Attributes["Name"]; //If lobSystem does not have a Name, import will fail with XSD validation. if (lobSystemNameAttribute != null) { string lobSystemName = lobSystemNameAttribute.Value; if (featurePropertyCollection[lobSystemName] != null && !String.IsNullOrEmpty(featurePropertyCollection[lobSystemName].Value)) { string lobSystemProperty = featurePropertyCollection[lobSystemName].Value; lobSystemProperties.Add(lobSystemName, lobSystemProperty); } } } Dictionary<string, LobSystemAssemblies> lobSystemAssemblies = new Dictionary<string, LobSystemAssemblies>(); foreach (string lobSystemName in lobSystemProperties.Keys) { string[] assembliesPath = ParseSemicolonDelimitedNames(lobSystemProperties[lobSystemName]); LobSystemAssemblies assemblies = new LobSystemAssemblies(); //Add full path to assembly names and load them. for (int i = 0; i < assembliesPath.Length; i++) { try { assembliesPath[i] = Path.Combine(featureFolder, assembliesPath[i]); } catch (ArgumentException ex) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Feature property '{0}' has invalid value. Feature activation failed with the following message: {1}", lobSystemName, ex.Message)); } if (File.Exists(assembliesPath[i]) == false) { throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "Assembly file '{0}' does not exist.", assembliesPath[i])); } // First assembly is the main assembly if (i == 0) { assemblies.MainAssembly = GetAssemblyBytes(assembliesPath[0]); } else { if (assemblies.DependentAssemblies == null) { assemblies.DependentAssemblies = new List<byte[]>(assembliesPath.Length - 1); } assemblies.DependentAssemblies.Add(GetAssemblyBytes(assembliesPath[i])); } } lobSystemAssemblies.Add(lobSystemName, assemblies); } return lobSystemAssemblies; }
internal static void PublishingSiteWebFeatureActivatedHandler(SPWeb web, SPFeaturePropertyCollection properties) { // Create two additional libraries CreateNewList(web, "Presentations", "Presentations", SPListTemplateType.DocumentLibrary); CreateNewList(web, "Contacts", "Contacts", SPListTemplateType.Contacts); }
private static SPFeature ActivateFeature(this SPFeatureCollection features, Guid featureId, SPFeaturePropertyCollection properties) { if (features[featureId] != null) { // The feature is already activated. No action required return(null); } var type = typeof(SPFeatureCollection); // now we have to get "AddInternal" Method with this signature: //internal SPFeature AddInternal(Guid featureId, Version version, SPFeaturePropertyCollection properties, bool force, bool fMarkOnly, SPFeatureDefinitionScope featdefScope) var param = new[] { typeof(Guid), typeof(Version), typeof(SPFeaturePropertyCollection), typeof(bool), typeof(bool), typeof(SPFeatureDefinitionScope) }; var addInternal = type.GetMethod("AddInternal", BindingFlags.Instance | BindingFlags.NonPublic, null, param, null); if (addInternal == null) { // faild to find the method return(null); } var result = addInternal.Invoke(features, new object[] { featureId, null, properties, false, false, SPFeatureDefinitionScope.Farm }); return(result as SPFeature); }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { ClubCloud.Common.RemoteAdministrator.Enable(); //FeatureCleaning(properties); configurationproperties = properties.Feature.Properties; if (properties.Feature.Parent.GetType() == typeof(SPWebApplication)) { webApp = properties.Feature.Parent as SPWebApplication; SPWebApplication wap = SPWebService.ContentService.WebApplications[webApp.Id]; List <SPWebConfigModification> process = new List <SPWebConfigModification>(); process.AddRange(ClubCloud.Common.Common.Modifications); //process.AddRange(Syncfusion.Modifications); process.AddRange(Ajax.Modifications); //process.AddRange(CrossSiteScripting.Modifications); foreach (SPWebConfigModification mod in process) { using (new SPMonitoredScope("Common Feature Deactivating")) { try { if (wap.WebConfigModifications.Contains(mod)) { wap.WebConfigModifications.Remove(mod); } if (SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Contains(mod)) { SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Remove(mod); } } catch (Exception ex) { diagSvc.WriteEvent(0, new SPDiagnosticsCategory("ClubCloud", TraceSeverity.Monitorable, EventSeverity.Warning), EventSeverity.Error, "Exception occured {0}", new object[] { ex }); } } } using (new SPMonitoredScope("Common Feature Deactivating")) { try { wap.Update(false); SPWebService.ContentService.WebApplications[wap.Id].Update(false); SPWebService.ContentService.WebApplications[wap.Id].WebService.ApplyWebConfigModifications(); //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); wap.WebConfigModifications.Clear(); wap.Update(); } catch (Exception ex) { diagSvc.WriteEvent(0, new SPDiagnosticsCategory("ClubCloud", TraceSeverity.Monitorable, EventSeverity.Warning), EventSeverity.Error, "Exception occured {0}", new object[] { ex }); } } //FeatureUninstalling(properties); //List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>(); /* * foreach (SPWebConfigModification mod in webApp.WebConfigModifications) * { * string name = mod.Name; * string owner = mod.Owner; * string path = mod.Path; * Microsoft.SharePoint.Administration.SPWebConfigModification.SPWebConfigModificationType type = mod.Type; * string value = mod.Value; * * if (mod.Name == "ClubCloudSaveControls") * { * mod.Name = "SafeControl[@Assembly='ClubCloud.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=144fd205e283172e'][@Namespace='ClubCloud.Common.Controls'][@TypeName='*'][@Safe='True'][SafeAgainstScript='True']"; * mod.Value = "<SafeControl Assembly='ClubCloud.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=144fd205e283172e' Namespace='ClubCloud.Common.Controls' TypeName='*' Safe='True' SafeAgainstScript='True' />"; * * //toDelete.Add(mod); * } * * } */ /* * foreach (SPWebApplication wap in SPWebService.ContentService.WebApplications) * { * List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>(); * try * { * Debug.Write(wap.Name); * //Console.WriteLine(wap.Name); * //Console.WriteLine("=========================================================="); * foreach (SPWebConfigModification mod in wap.WebConfigModifications) * { * string name = mod.Name; * string owner = mod.Owner; * string path = mod.Path; * Microsoft.SharePoint.Administration.SPWebConfigModification.SPWebConfigModificationType type = mod.Type; * string value = mod.Value; * * //Console.WriteLine(mod.ToString()); * Debug.Write(mod.ToString()); * if (mod.Owner.Contains("ClubCloud") || mod.Owner.Contains("Syncfusion") || mod.Owner.Contains("ajax") || mod.Owner.Contains("Ajax")) // == "ClubCloudCommonSaveControls" || mod.Owner == "ClubCloudCommonControls") * { * toDelete.Add(mod); * } * } * * foreach (SPWebConfigModification mod in toDelete) * { * wap.WebConfigModifications.Remove(mod); * SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Remove(mod); * } * * SPWebService.ContentService.WebApplications[wap.Id].Update(); * SPWebService.ContentService.WebApplications[wap.Id].WebService.ApplyWebConfigModifications(); * * * Console.WriteLine("=========================================================="); * * } * catch(Exception ex) * { * Debug.Write(ex.ToString()); * } * * } */ /* * foreach (SPWebConfigModification mod in toDelete) * { * * webApp.WebConfigModifications.Remove(mod); * SPWebService.ContentService.WebApplications[webApp.Id].WebConfigModifications.Remove(mod); * } */ /* * try * { * webApp.Update(); * SPWebService.ContentService.WebApplications[webApp.Id].Update(); * SPWebService.ContentService.WebApplications[webApp.Id].WebService.ApplyWebConfigModifications(); * } * catch { }; */ } }); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate() { ClubCloud.Common.RemoteAdministrator.Enable(); //using (new SPMonitoredScope("Common Feature Cleaning")) //{ // FeatureCleaning(properties); // SetCustomPages(properties); //} configurationproperties = properties.Feature.Properties; if (properties.Feature.Parent.GetType() == typeof(SPWebApplication)) { webApp = properties.Feature.Parent as SPWebApplication; SPWebApplication wap = SPWebService.ContentService.WebApplications[webApp.Id]; List <SPWebConfigModification> process = new List <SPWebConfigModification>(); process.AddRange(ClubCloud.Common.Common.Modifications); //process.AddRange(Syncfusion.Modifications); process.AddRange(Ajax.Modifications); //process.AddRange(CrossSiteScripting.Modifications); foreach (SPWebConfigModification mod in process) { using (new SPMonitoredScope("Common Feature Activated")) { try { if (!wap.WebConfigModifications.Contains(mod)) { wap.WebConfigModifications.Add(mod); } if (!SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Contains(mod)) { SPWebService.ContentService.WebApplications[wap.Id].WebConfigModifications.Add(mod); } } catch (Exception ex) { diagSvc.WriteEvent(0, new SPDiagnosticsCategory("ClubCloud", TraceSeverity.Monitorable, EventSeverity.Warning), EventSeverity.Error, "Exception occured {0}", new object[] { ex }); } } } using (new SPMonitoredScope("Common Feature Activated")) { try { wap.Update(false); SPWebService.ContentService.WebApplications[wap.Id].Update(false); SPWebService.ContentService.WebApplications[wap.Id].WebService.ApplyWebConfigModifications(); //webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); wap.WebConfigModifications.Clear(); wap.Update(false); } catch (Exception ex) { diagSvc.WriteEvent(0, new SPDiagnosticsCategory("ClubCloud", TraceSeverity.Monitorable, EventSeverity.Warning), EventSeverity.Error, "Exception occured {0}", new object[] { ex }); } } } }); }