protected virtual FeatureDefinition ConvertToFeatureDefinition(string featureName, string enabledFor) { var result = new FeatureDefinition { Name = featureName, EnabledFor = new[] { new FeatureFilterConfiguration { Name = enabledFor, } } }; return(result); }
protected virtual void AddFeatureToDictionaryRecursively( Dictionary <string, FeatureDefinition> features, FeatureDefinition feature) { if (features.ContainsKey(feature.Name)) { throw new AbpException("Duplicate feature name: " + feature.Name); } features[feature.Name] = feature; foreach (var child in feature.Children) { AddFeatureToDictionaryRecursively(features, child); } }
public string ActivateFeature(FeatureDefinition feature, Location location, bool elevatedPrivileges, bool force , out ActivatedFeature activatedFeature) { activatedFeature = Core.Factories.ActivatedFeatureFactory.GetActivatedFeature( feature.Id , location.Id , feature , false , null , DateTime.Now , feature.Version ); demoActivatedFeatures.Add(activatedFeature); return(string.Empty); }
public static string ByTowar(string filter, Towar towar, FeatureDefinition featureDef, DictionaryItem value) { if (towar != null || featureDef != null) { filter = getFilter(filter); if (towar != null) { filter += "Towar = " + towar.ID; } else { filter += "Towar.Features.[" + featureDef.Name + "] = '" + value.Value + "'"; } } return(filter); }
//[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)] public void CanActivateCustomWebFeature() { var myCustomerFeature = new FeatureDefinition { Enable = true, Id = new Guid("87294C72-F260-42f3-A41B-981A2FFCE37A"), Scope = FeatureDefinitionScope.Web }; var model = SPMeta2Model.NewWebModel(web => { web .AddWebFeature(myCustomerFeature); }); DeployModel(model); }
private void tsbLoadTests_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { try { string fileName = ofd.FileName; XmlDocument doc = new XmlDocument(); doc.Load(fileName); switch (doc.DocumentElement.LocalName) { case FeatureDefinition.ROOT: FeatureDefinition def = FeatureDefinition.Load(fileName); testsTree.AddFeatureDefinitionNode(fileName, def); Context.AppContext.Instance.TreeState.FeatureDefinitionFiles.Add(fileName); break; case TestSuite.ROOT: TestSuite ts = TestSuite.Load(fileName); testsTree.AddTestSuite(fileName, ts); Context.AppContext.Instance.TreeState.TestFiles.Add(fileName); break; case TestParameters.ROOT: TestParameters parameters = TestParameters.Load(fileName); testsTree.AddParametersSet(fileName, parameters); Context.AppContext.Instance.TreeState.ParametersFiles.Add(fileName); break; case DutTest.ROOT: DutTest test = DutTest.Load(fileName); testsTree.AddTestSuite(fileName, test); Context.AppContext.Instance.TreeState.DutTestFiles.Add(fileName); break; } } catch (Exception exc) { MessageBox.Show(exc.Message); } } }
private void Trace(FeatureDefinition featureModel, Feature currentFeature) { var featureActivated = currentFeature != null; TraceUtils.WithScope(traceScope => { traceScope.WriteLine(string.Format("Validating model:[{0}] feature:[{1}]", featureModel, currentFeature)); traceScope.WriteLine(string.Format("Model prop [{0}] on obj prop [{1}]: model:[{2}] obj:[{3}]", "Enable", "Enable", featureModel.Enable, featureActivated)); Assert.AreEqual(featureModel.Enable, featureActivated); }); }
public string FarmFeatureAction(FeatureDefinition feature, Location location, FeatureAction action, bool force, out ActivatedFeature activatedFeature) { switch (action) { case FeatureAction.Activate: return(ActivateFeature(feature, location, false, force, out activatedFeature)); case FeatureAction.Deactivate: throw new NotImplementedException("This kind of action is not supported!"); case FeatureAction.Upgrade: return(UpgradeFeature(feature, location, false, force, out activatedFeature)); default: throw new NotImplementedException("This kind of action is not supported!"); } }
/// <summary> /// searches for special features with search input and scope-filter /// </summary> /// <param name="source">collection of special features to search in</param> /// <param name="searchInput">search input</param> /// <param name="selectedScopeFilter">scope filter</param> /// <returns></returns> public IEnumerable <ActiveIndicator <ActivatedFeatureSpecial> > SearchSpecialFeatures( IEnumerable <ActivatedFeatureSpecial> source, string searchInput, Scope?selectedScopeFilter, FeatureDefinition selectedFeatureDefinition) { if (source == null || source.Count() < 1) { return(new ActiveIndicator <ActivatedFeatureSpecial> [0]); } var searchResult = source; if (!string.IsNullOrEmpty(searchInput)) { var lowerCaseSearchInput = searchInput.ToLower(); searchResult = searchResult.Where( f => f.ActivatedFeature.DisplayName.ToLower().Contains(lowerCaseSearchInput) || f.Location.DisplayName.ToLower().Contains(lowerCaseSearchInput) || f.Location.Url.ToLower().Contains(lowerCaseSearchInput) || f.ActivatedFeature.FeatureId.Contains(lowerCaseSearchInput) || f.ActivatedFeature.LocationId.Contains(lowerCaseSearchInput) ); } if (selectedScopeFilter != null) { searchResult = searchResult.Where(f => f.Location.Scope == selectedScopeFilter.Value); } if (selectedFeatureDefinition == null || !searchResult.Any()) { return(searchResult.Select(afs => new ActiveIndicator <ActivatedFeatureSpecial>(afs, false)).ToArray()); } else { return(searchResult.Select(afs => new ActiveIndicator <ActivatedFeatureSpecial>( afs, afs.ActivatedFeature.FeatureId == selectedFeatureDefinition.UniqueIdentifier) ) .ToArray()); } }
public IEnumerable <Location> GetLocationsCanActivate(FeatureDefinition featureDefinition, Location location) { var allLocationsOfFeatureScope = GetChildLocationsOfScope(featureDefinition.Scope, location); var prefilteredActivatedFeatures = ActivatedFeatures.Where(f => f.FeatureId == featureDefinition.Id).ToList(); // see https://docs.microsoft.com/en-us/dotnet/csharp/linq/perform-left-outer-joins var locationsCanActivate = (from loc in allLocationsOfFeatureScope join af in prefilteredActivatedFeatures on loc.Id equals af.LocationId into gj from subAf in gj.DefaultIfEmpty() // following is the only different line compared to ..can deactivate where subAf == null select loc).ToList(); return(locationsCanActivate); }
public static List <FeatureDefinition> SelectedRowsToFeatureDefinition(DataGridViewSelectedRowCollection selectedRows) { if (selectedRows == null || selectedRows.Count == 1) { Log.Warning("No feature definitions selected!"); return(null); } var convertedRows = new List <FeatureDefinition>(); foreach (DataGridViewRow row in selectedRows) { FeatureDefinition fd = row.DataBoundItem as FeatureDefinition; convertedRows.Add(fd); } return(convertedRows); }
/// <summary> /// request to activate or deactivate a feature in a location or below /// </summary> /// <param name="featureDefinition">the feature definition</param> /// <param name="location">the location or top location</param> /// <param name="action">Activate, Deactivate or Upgrade</param> /// <remarks>force and elevated privileges are system wide settings</remarks> public FeatureToggleRequest([NotNull] FeatureDefinition featureDefinition, [NotNull] Location location, FeatureAction action, bool?force = null, bool?elevatedPrivileges = null) { FeatureDefinition = featureDefinition; Location = location; Action = action; Force = force; ElevatedPrivileges = elevatedPrivileges; TaskId = Guid.NewGuid(); string locationPrefix = FeatureDefinition.Scope < location.Scope ? "across" : "at"; Title = string.Format("Feature {3} of feature '{0}' {4} {1} '{2}'", featureDefinition.DisplayName, location.Scope.ToString(), location.DisplayName, Action.ToString().ToLower(), locationPrefix); }
private void ValidateFeatureModel(object modelHost, FeatureDefinition featureModel) { switch (featureModel.Scope) { case FeatureDefinitionScope.Farm: throw new NotSupportedException("Farm features are not supported with CSOM."); case FeatureDefinitionScope.WebApplication: throw new NotSupportedException("Web application features are not supported with CSOM."); case FeatureDefinitionScope.Site: ValidateSiteFeature(modelHost, featureModel); break; case FeatureDefinitionScope.Web: ValidateWebFeature(modelHost, featureModel); break; } }
public override IEnumerable <DefinitionBase> GetAdditionalArtifacts() { var sandboxSolution = new SandboxSolutionDefinition { FileName = string.Format("{0}.wsp", Rnd.String()), Activate = true, SolutionId = new Guid("e9a61998-07f2-45e9-ae43-9e93fa6b11bb"), Content = ModuleFileUtils.FromResource(GetType().Assembly, "SPMeta2.Containers.Templates.Apps.SPMeta2.Containers.SandboxSolutionContainer.wsp") }; var webpartFeature = new FeatureDefinition { Scope = FeatureDefinitionScope.Site, Id = new Guid("9acf0f59-3cdc-412b-a647-4185dd4cd9bc"), Enable = true }; return(new DefinitionBase[] { sandboxSolution, webpartFeature }); }
private void DeployFeatureInternal(object modelHost, FeatureDefinition featureModel) { switch (featureModel.Scope) { case FeatureDefinitionScope.Farm: DeployFarmFeature(modelHost, featureModel); break; case FeatureDefinitionScope.WebApplication: DeployWebApplicationFeature(modelHost, featureModel); break; case FeatureDefinitionScope.Site: DeploySiteFeature(modelHost, featureModel); break; case FeatureDefinitionScope.Web: DeployWebFeature(modelHost, featureModel); break; } }
/// <inheritdoc /> public async Task <FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken = default) { if (featureName == null) { throw new ArgumentNullException(nameof(featureName)); } Feature feature = await _featureService.GetByName(featureName, cancellationToken) .ConfigureAwait(false); if (feature == null) { throw new FeatureManagementException(FeatureManagementError.MissingFeature, $"Feature {featureName} not found"); } FeatureDefinition definition = _definitions.GetOrAdd(featureName, _ => ReadFeatureDefinition(feature)); return(definition); }
public IEnumerable <ActivatedFeature> GetActivatedFeatures(FeatureDefinition featureDefinition) { if (featureDefinition != null) { var result = ActivatedFeatures.Where(af => af.FeatureId == featureDefinition.UniqueIdentifier) .ToList(); // try to find some activated features, if scope is invalid (e.g. definition not available in local hive) if (!result.Any() && featureDefinition.Scope == Scope.ScopeInvalid && featureDefinition.SandBoxedSolutionLocation == null) { return(ActivatedFeatures.Where(af => af.FeatureId.Contains(featureDefinition.Id.ToString()) && (af.FeatureDefinitionScope == FeatureDefinitionScope.Farm || af.FeatureDefinitionScope == FeatureDefinitionScope.None)) .ToList()); } return(result); } return(null); }
private List <string> GetElementFiles(FileInfo featureFile, DirectoryInfo childDir) { List <string> elements = new List <string>(); FeatureDefinition featureDef = null; XmlSerializer xmlSerial = new XmlSerializer(typeof(FeatureDefinition)); // Always add the feature.xml file to the list elements.Add(childDir.Name + @"\" + featureFile.Name); using (FileStream fs = featureFile.OpenRead()) { featureDef = (FeatureDefinition)xmlSerial.Deserialize(fs); // If no ElementManifest is available, then the feature resource files // are picked up by the ResourceDefinition part of the solution. if (featureDef.ElementManifests != null && featureDef.ElementManifests.Items != null) { foreach (ElementManifestReference element in featureDef.ElementManifests.Items) { if (!String.IsNullOrEmpty(element.Location)) { elements.Add(childDir.Name + @"\" + element.Location); } } } else { // There should normally always be a ElementManifest for a feature, // but it's possible not to use one and only use FeatureReceiver objects. if (string.IsNullOrEmpty(featureDef.ReceiverAssembly) && string.IsNullOrEmpty(featureDef.ReceiverClass)) { Log.Warning("No ElementManifest and Feature receiver was found in feature '" + childDir.FullName + "'."); } } fs.Close(); } return(elements); }
public static ActivatedFeature ToActivatedFeature(this SPFeature spFeature, Guid parentId, Scope parentScope, string parentUrl) { FeatureDefinition definition = null; bool faulty = false; string definitionInstallationScope = GetDefinitionInstallationScope(spFeature.FeatureDefinitionScope == SPFeatureDefinitionScope.Farm, parentUrl); try { if (spFeature.Definition != null) { var fDef = spFeature.Definition; definition = fDef.ToFeatureDefinition(definitionInstallationScope); } else { definition = FeatureDefinitionFactory.GetFaultyDefinition(spFeature.DefinitionId, parentScope, spFeature.Version, definitionInstallationScope); faulty = true; } } catch (Exception) { faulty = true; } var feature = ActivatedFeatureFactory.GetActivatedFeature( spFeature.DefinitionId, parentId, definition, faulty, spFeature.Properties == null ? null : spFeature.Properties.ToProperties(), spFeature.TimeActivated, spFeature.Version, definitionInstallationScope ); return(feature); }
public string Uninstall(FeatureDefinition definition) { string errMsg = string.Empty; try { if (definition.SandBoxedSolutionLocation == null) { // farm feature definition var defToDelete = SPFarm.Local.FeatureDefinitions.FirstOrDefault(fd => fd.Id == definition.Id); if (defToDelete == null) { throw new Exception("Feature Definition was not found anymore in the farm! Please try to reload or restart feature admin."); } defToDelete.Delete(); var defDeleted = SPFarm.Local.FeatureDefinitions.FirstOrDefault(fd => fd.Id == definition.Id); // defDeleted should now be null, as the feature definition should be deleted if (defDeleted != null) { throw new Exception("Feature Definition could not be removed from the FeatureDefinitions collection."); } } else { throw new NotImplementedException("Uninstallation of sandboxed featre definitions is not implemented yet."); } } catch (Exception ex) { errMsg += ex.Message; } return(errMsg); }
///// <summary> ///// Add activated features to list of definitions, when definition does not exist, it gets created ///// </summary> ///// <param name="existingFeatureDefinitions"></param> ///// <param name="featureDefinitionsToAdd"></param> ///// <returns></returns> ///// <remarks>see also https://stackoverflow.com/questions/12873855/c-sharp-groupby-linq-and-foreach ///// </remarks> //public static void AddActivatedFeatures(this ICollection<FeatureDefinition> existingFeatureDefinitions, [NotNull] IEnumerable<IGrouping<FeatureDefinition, ActivatedFeature>> featuresToAdd) //{ // foreach (var featureDefinitionGroup in featuresToAdd) // { // // get feature definition from collection or add a new one if it does not exist yet // var definitionToAddFeaturesTo = existingFeatureDefinitions.FirstOrDefault(fd => fd.Equals(featureDefinitionGroup.Key)); // if (definitionToAddFeaturesTo == null) // { // definitionToAddFeaturesTo = featureDefinitionGroup.Key; // existingFeatureDefinitions.Add(definitionToAddFeaturesTo); // } // foreach (ActivatedFeature activeFeature in featureDefinitionGroup) // { // definitionToAddFeaturesTo.ToggleActivatedFeature(activeFeature, true); // } // } //} public static FeatureDefinition GetFaultyDefinition( Guid id, Scope scope, Version version ) { var featureDefinition = new FeatureDefinition(id, 0, "Faulty, orphaned feature - no feature definition available", "Faulty, orphaned feature", false, "Faulty, orphaned feature", null, scope, "Faulty, orphaned feature", Guid.Empty, "n/a", version ); return(featureDefinition); }
private FeatureDefinition GetFeatureDefinition(string featureName, bool isEnabled) { var featureDefinition = new FeatureDefinition { Name = featureName }; if (isEnabled) { featureDefinition.EnabledFor = new[] { new FeatureFilterConfiguration { Name = "AlwaysOn" } } } ; return(featureDefinition); } }
/// <inheritdoc /> public async Task <FeatureDefinition> GetFeatureDefinitionAsync(string featureName, CancellationToken cancellationToken = default) { if (featureName == null) { throw new ArgumentNullException(nameof(featureName)); } IFeatureManagementAppTierAPI featureApi = CreateFeatureManagementApi(); var feature = await featureApi.GetFeatureByNameAsync(featureName, cancellationToken) .ConfigureAwait(false) as Feature; if (feature == null) { throw new FeatureManagementException(FeatureManagementError.MissingFeature, $"Feature {featureName} not found"); } FeatureDefinition definition = _definitions?.GetOrAdd(featureName, _ => ReadFeatureDefinition(feature)); return(definition); }
public void Move(Extractwsp handler) { Log.Verbose("Moving:" + this.Location); string folderName = Path.GetDirectoryName(this.Location); string targetPath = Path.Combine(handler.TargetPath, @"12\template\features\" + this.Location); string sourcePath = Path.Combine(handler.SourcePath, this.Location); FileSystem.Move(sourcePath, targetPath, handler.Overwrite); FeatureDefinition feature = FileSystem.Load <FeatureDefinition>(targetPath); if (feature.ElementManifests != null && feature.ElementManifests.Items != null) { foreach (ElementManifestReference elementManifestRef in feature.ElementManifests.Items) { targetPath = Path.Combine(handler.TargetPath, String.Format(@"12\template\features\{0}\{1}", folderName, elementManifestRef.Location)); sourcePath = Path.Combine(handler.SourcePath, String.Format(@"{0}\{1}", folderName, elementManifestRef.Location)); FileSystem.Move(sourcePath, targetPath, handler.Overwrite); } } }
public static string SiteFeatureAction( FeatureDefinition feature, Location location, Func <SPFeatureCollection, Guid, bool, SPFeature> featureAction, bool elevatedPrivileges, bool force, out ActivatedFeature resultingFeature) { resultingFeature = null; SPSite spSite = null; try { spSite = SpLocationHelper.GetSite(location); SPFeatureCollection featureCollection = SpFeatureHelper.GetFeatureCollection(spSite, elevatedPrivileges); var spResultingFeature = featureAction(featureCollection, feature.Id, force); if (spResultingFeature != null) { resultingFeature = spResultingFeature.ToActivatedFeature(location); } } catch (Exception ex) { return(ex.Message); } finally { if (spSite != null) { spSite.Dispose(); } } return(string.Empty); }
public void AddActivatedFeature(SPFeature feature) { if (feature == null) { return; } try { var activatedFeature = ActivatedFeature.GetActivatedFeature(feature); // update activated features this.ActivatedFeatures.Add(activatedFeature); // update featureDefinition (and its activated instances) var featureDef = this.FeatureDefinitions.FirstOrDefault(fd => fd.Id == activatedFeature.Id); if (featureDef != null) { // add activated feature to feature definition featureDef.ActivatedFeatures.Add(activatedFeature); } else { // fyi - if we get here, we have most likely a group of faulty features ... // create feature definition and add features var newFeatureDef = FeatureDefinition.GetFeatureDefinition(activatedFeature); this.FeatureDefinitions.Add(newFeatureDef); Log.Warning("Unexpected - Feature Definition of activated Feature was not available - please Reload"); } } catch (Exception ex) { Log.Error("Error when trying to add new feature to InMemorySharePointDb", ex); } }
public static ActivatedFeature GetActivatedFeature( Guid featureId, Guid locationId, FeatureDefinition definition, bool faulty, Dictionary <string, string> properties, DateTime timeActivated, Version version, string definitionInstallationScope = "Farm" ) { var activatedFeature = new ActivatedFeature( featureId, locationId, definition, faulty, properties, timeActivated, version, definitionInstallationScope); return(activatedFeature); }
public void AddHighPriorityFeatureDefinition(IConfigurationSection configuration) { var featureConfigurations = configuration.GetChildren().ToList(); foreach (var featureConfiguration in featureConfigurations) { var featureDefinition = new FeatureDefinition { Name = featureConfiguration.Key, }; if (!string.IsNullOrEmpty(featureConfiguration.Value) && bool.TryParse(featureConfiguration.Value, out var isEnabled)) { featureDefinition.EnabledFor = isEnabled ? new[] { new FeatureFilterConfiguration { Name = "AlwaysOn", } } : Array.Empty <FeatureFilterConfiguration>(); } else { featureDefinition.EnabledFor = new[] { new FeatureFilterConfiguration { Name = featureConfiguration.Value, } }; } // Need to remove defined features from collection if (_featureDefinitions.Any(x => x.Name.EqualsInvariant(featureDefinition.Name))) { var definedFeature = _featureDefinitions.First(x => x.Name.EqualsInvariant(featureDefinition.Name)); _featureDefinitions.Remove(definedFeature); } _featureDefinitions.Add(featureDefinition); } }
private string DeactivateFeature(FeatureDefinition feature, Location location, bool elevatedPrivileges, bool force) { if (location == null || feature == null) { throw new ArgumentNullException("Location or feature must not be null!"); } var returnMsg = demoRepository.RemoveActivatedFeature(feature.UniqueIdentifier, location.UniqueId); // wait 1 second in the demo System.Threading.Thread.Sleep(1000); return(string.Empty); //// in sharepoint, first, the containers need to be opened ... //switch (location.Scope) //{ // case Core.Models.Enums.Scope.Web: // // get site and web // break; // case Core.Models.Enums.Scope.Site: // // get site // break; // case Core.Models.Enums.Scope.WebApplication: // // get web app // break; // case Core.Models.Enums.Scope.Farm: // // get farm // break; // case Core.Models.Enums.Scope.ScopeInvalid: // throw new Exception("Invalid scope was not expected!"); // default: // throw new Exception("Undefined scope!"); //} }
public void Deploy_ActivateCustomFeature() { // Step 1, define web feature // // For custom features we need to define Id, Scope and Enable/ForceActivate properties // Title is not used, but it is nice to have readable code var mdsFeatrure = new FeatureDefinition { Title = "Minimal Download Strategy", Id = new Guid("{87294c72-f260-42f3-a41b-981a2ffce37a}"), Scope = SPMeta2.Definitions.FeatureDefinitionScope.Web, Enable = true }; // Step 2, define web model and artifact relationships - add feature to the web var model = SPMeta2Model .NewWebModel(web => { web.AddFeature(mdsFeatrure); }); // Step 3, deploy model DeployWebModel(model); }