public static FeatureParent GetFeatureParentUndefined(string displayName = "") { var p = new FeatureParent() { DisplayName = string.IsNullOrEmpty(displayName) ? "undefined" : displayName, Url = "undefined", Id = Guid.Empty, Scope = SPFeatureScope.ScopeInvalid }; return(p); }
public static FeatureParent GetFeatureParent(SPWebService farmWebService) { try { if (farmWebService == null) { return(GetFeatureParentUndefined()); } var p = new FeatureParent() { DisplayName = "Farm", Url = "Farm", Id = farmWebService.Id, Scope = SPFeatureScope.Farm }; return(p); } catch (Exception ex) { return(GetFeatureParentUndefined(ex.Message)); } }
public static FeatureParent GetFeatureParent(SPSite siCo) { try { if (siCo == null) { return(GetFeatureParentUndefined()); } var p = new FeatureParent() { DisplayName = siCo.RootWeb.Title, Url = siCo.Url, Id = siCo.ID, Scope = SPFeatureScope.Site }; return(p); } catch (Exception ex) { return(GetFeatureParentUndefined(ex.Message)); } }
public static FeatureParent GetFeatureParent(SPWebApplication webApp, string name = "") { try { if (webApp == null) { return(GetFeatureParentUndefined()); } var p = new FeatureParent() { DisplayName = string.IsNullOrEmpty(name) ? webApp.Name : name, // + " (" + web.Name + ")", Url = webApp.GetResponseUri(SPUrlZone.Default).ToString(), Id = webApp.Id, Scope = SPFeatureScope.WebApplication }; return(p); } catch (Exception ex) { return(GetFeatureParentUndefined(ex.Message)); } }
public static FeatureParent GetFeatureParent(SPWeb web) { try { if (web == null) { return(GetFeatureParentUndefined()); } var p = new FeatureParent() { DisplayName = web.Title, // + " (" + web.Name + ")", Url = web.Url, Id = web.ID, Scope = SPFeatureScope.Web }; return(p); } catch (Exception ex) { return(GetFeatureParentUndefined(ex.Message)); } }
private static ActivatedFeature MapSpFeatureToActivatedFeature(SPFeature feature, FeatureParent parent) { var af = GetActivatedFeature(feature, parent); return(af); }
/// <summary> /// Factory to map SPFeatureCollections to ActivatedFeatures /// </summary> /// <param name="featureCollection"></param> /// <param name="parent"></param> /// <returns></returns> public static List <ActivatedFeature> MapSpFeatureToActivatedFeature(SPFeatureCollection featureCollection, FeatureParent parent) { List <ActivatedFeature> activatedFeatures = new List <ActivatedFeature>(); if (featureCollection != null) { foreach (SPFeature f in featureCollection) { var af = MapSpFeatureToActivatedFeature(f, parent); activatedFeatures.Add(af); } } return(activatedFeatures); }
/// <summary> /// Generate ActivatedFeature /// </summary> /// <param name="spFeature"></param> /// <param name="parent"></param> /// <returns></returns> public static ActivatedFeature GetActivatedFeature(SPFeature spFeature, FeatureParent parent = null) { if (spFeature == null) { return(null); } // create preliminary feature with default values ... ActivatedFeature af = new ActivatedFeature() { Id = Guid.Empty, Version = new Version("0.0.0.0"), Parent = parent, SharePointFeature = spFeature, Name = "undefined", Faulty = false }; // in case of faulty features, many of these settings can not be set // therefore, every property is set in try / catch statement // ID try { af.Id = spFeature.DefinitionId; } catch (Exception ex) { if (af.Name.Equals("undefined")) { af.Name = ex.Message; } af.Faulty = true; } // Version try { af.TimeActivated = spFeature.TimeActivated; } catch (Exception ex) { if (af.Name.Equals("undefined")) { af.Name = ex.Message; } af.Faulty = true; } // Version try { af.Version = spFeature.Version; } catch (Exception ex) { if (af.Name.Equals("undefined")) { af.Name = ex.Message; } af.Faulty = true; } // Parent try { af.Parent = parent == null?FeatureParent.GetFeatureParent(spFeature) : parent; } catch (Exception ex) { if (af.Name.Equals("undefined")) { af.Name = ex.Message; } af.Faulty = true; } // SharePointFeature is already set on initialization of af // Name try { var def = spFeature.Definition; if (def != null) { af.Name = def.DisplayName; } else { af.Name = string.Format(Common.Constants.Text.UndefinedActivatedFeature, af.Id); af.Faulty = true; } } catch (Exception ex) { if (af.Name.Equals("undefined")) { af.Name = ex.Message; } af.Faulty = true; } return(af); }