本文整理汇总了C#中FeatureCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# FeatureCollection.Remove方法的具体用法?C# FeatureCollection.Remove怎么用?C# FeatureCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FeatureCollection
的用法示例。
在下文中一共展示了FeatureCollection.Remove方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemovedInterfaceIsRemoved
public void RemovedInterfaceIsRemoved()
{
var interfaces = new FeatureCollection();
var thing = new Thing();
interfaces.Add(typeof(IThing), thing);
Assert.Equal(interfaces[typeof(IThing)], thing);
Assert.True(interfaces.Remove(typeof(IThing)));
object thing2;
Assert.False(interfaces.TryGetValue(typeof(IThing), out thing2));
}
示例2: ProcessFeatureInternal
/// <summary>
/// Activates or deactivates a site collection or web scoped feature
/// </summary>
/// <param name="features">Feature Collection which contains the feature</param>
/// <param name="featureID">ID of the feature to activate/deactivate</param>
/// <param name="activate">True to activate, false to deactivate the feature</param>
/// <param name="scope">Scope of the feature definition</param>
private static void ProcessFeatureInternal(FeatureCollection features, Guid featureID, bool activate, FeatureDefinitionScope scope)
{
features.Context.Load(features);
features.Context.ExecuteQueryRetry();
// The original number of active features...use this to track if the feature activation went OK
int oldCount = features.Count();
if (activate)
{
// GetById does not seem to work for site scoped features...if (clientSiteFeatures.GetById(featureID) == null)
// FeatureDefinitionScope defines how the features have been deployed. All OOB features are farm deployed
features.Add(featureID, true, scope);
features.Context.ExecuteQueryRetry();
// retry logic needed to make this more bulletproof :-(
features.Context.Load(features);
features.Context.ExecuteQueryRetry();
int tries = 0;
int currentCount = features.Count();
while (currentCount <= oldCount && tries < 5)
{
tries++;
features.Add(featureID, true, scope);
features.Context.ExecuteQueryRetry();
features.Context.Load(features);
features.Context.ExecuteQueryRetry();
currentCount = features.Count();
}
}
else
{
try
{
features.Remove(featureID, false);
features.Context.ExecuteQueryRetry();
}
catch (Exception ex)
{
Log.Error(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_FeatureActivationProblem, featureID, ex.Message);
}
}
}
示例3: ProcessFeatureInternal
/// <summary>
/// Activates or deactivates a site collection or web scoped feature
/// </summary>
/// <param name="features">Feature Collection which contains the feature</param>
/// <param name="featureID">ID of the feature to activate/deactivate</param>
/// <param name="activate">True to activate, false to deactivate the feature</param>
/// <param name="scope">Scope of the feature definition</param>
/// <param name="pollingIntervalSeconds">The time in seconds between polls for "IsActive"</param>
private static void ProcessFeatureInternal(FeatureCollection features, Guid featureID, bool activate, FeatureDefinitionScope scope, int pollingIntervalSeconds = 30)
{
if (activate)
{
// Feature enabling can take a long time, especially in case of the publishing feature...so let's make it more reliable
features.Add(featureID, true, scope);
if (pollingIntervalSeconds < 5)
{
pollingIntervalSeconds = 5;
}
try
{
string clientTag = $"{PnPCoreUtilities.PnPCoreVersionTag}:ProcessFeatureInternal";
if (clientTag.Length > 32)
{
clientTag = clientTag.Substring(0, 32);
}
features.Context.ClientTag = clientTag;
// Don't update this to ExecuteQueryRetry
features.Context.ExecuteQuery();
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureActive, featureID);
}
catch (Exception ex)
{
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureException, ex.ToString());
// Don't wait for a "feature not found" exception, which is the typical exception we'll see
if (ex.HResult != -2146233088)
{
int retryAttempts = 10;
int retryCount = 0;
// wait and keep checking if the feature is active
while (retryAttempts > retryCount)
{
Thread.Sleep(TimeSpan.FromSeconds(pollingIntervalSeconds));
if (IsFeatureActiveInternal(features, featureID, true))
{
retryCount = retryAttempts;
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureActivationState, true, featureID);
}
else
{
retryCount++;
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureActivationState, false, featureID);
}
}
}
}
}
else
{
try
{
features.Remove(featureID, false);
features.Context.ExecuteQueryRetry();
}
catch (Exception ex)
{
Log.Error(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_FeatureActivationProblem, featureID, ex.Message);
}
}
}
示例4: DeActivateFeatureInCollection
private static void DeActivateFeatureInCollection(ClientContext clientContext, ShFeature featureInfo, FeatureCollection featureCollection)
{
clientContext.Load(featureCollection);
clientContext.ExecuteQuery();
if (DoesFeatureExistInCollection(featureCollection, featureInfo.FeatureId))
{
Log.Info("Deactivating feature " + featureInfo.FeatureName);
featureCollection.Remove(featureInfo.FeatureId, true);
clientContext.ExecuteQuery();
}
}
示例5: ProcessFeature
private void ProcessFeature(
object modelHost,
ClientRuntimeContext context,
FeatureCollection features,
FeatureDefinition featureModel,
Microsoft.SharePoint.Client.FeatureDefinitionScope scope)
{
var currentFeature = GetFeature(features, featureModel);
var featureActivated = IsFeatureActivated(features, featureModel);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentFeature,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
if (!featureActivated)
{
Feature tmpFeature;
if (featureModel.Enable)
{
tmpFeature = features.Add(featureModel.Id, featureModel.ForceActivate, scope);
context.ExecuteQuery();
}
else
{
tmpFeature = GetFeature(features, featureModel);
}
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = tmpFeature,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
}
else
{
if (featureModel.Enable && featureModel.ForceActivate)
{
var f = features.Add(featureModel.Id, featureModel.ForceActivate, scope);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = f,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
context.ExecuteQuery();
}
else if (!featureModel.Enable)
{
features.Remove(featureModel.Id, featureModel.ForceActivate);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = null,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
context.ExecuteQuery();
}
else
{
var tmpFeature = GetFeature(features, featureModel);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = tmpFeature,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
}
}
}
示例6: ProcessFeature
private void ProcessFeature(
object modelHost,
ClientRuntimeContext context,
FeatureCollection features,
FeatureDefinition featureModel,
Microsoft.SharePoint.Client.FeatureDefinitionScope scope)
{
var featureId = featureModel.Id;
var currentFeature = features.GetById(featureId);
features.Context.ExecuteQueryWithTrace();
var featureActivated = IsFeatureActivated(currentFeature);
TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Is feature activated: [{0}]", featureActivated);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentFeature,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
if (!featureActivated)
{
Feature tmpFeature;
if (featureModel.Enable)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Enabling feature");
tmpFeature = SafelyActivateWebFeature(context, features, featureModel, scope);
}
else
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching feature by ID");
tmpFeature = features.GetById(featureId);
features.Context.ExecuteQueryWithTrace();
}
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = tmpFeature,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
}
else
{
if (featureModel.Enable && featureModel.ForceActivate)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Feature enabled, but ForceActivate = true. Force activating.");
var f = SafelyActivateWebFeature(context, features, featureModel, scope);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = f,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
}
else if (!featureModel.Enable)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Removing feature.");
features.Remove(featureModel.Id, featureModel.ForceActivate);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = null,
ObjectType = typeof(Feature),
ObjectDefinition = featureModel,
ModelHost = modelHost
});
context.ExecuteQueryWithTrace();
}
else
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching feature by ID");
var tmpFeature = features.GetById(featureId);
features.Context.ExecuteQueryWithTrace();
InvokeOnModelEvent(this, new ModelEventArgs
//.........这里部分代码省略.........
示例7: ProcessFeatureInternal
/// <summary>
/// Activates or deactivates a site collection or web scoped feature
/// </summary>
/// <param name="features">Feature Collection which contains the feature</param>
/// <param name="featureID">ID of the feature to activate/deactivate</param>
/// <param name="activate">True to activate, false to deactivate the feature</param>
/// <param name="scope">Scope of the feature definition</param>
/// <param name="pollingIntervalSeconds">The time in seconds between polls for "IsActive"</param>
private static void ProcessFeatureInternal(FeatureCollection features, Guid featureID, bool activate, FeatureDefinitionScope scope, int pollingIntervalSeconds = 30)
{
if (activate)
{
// Feature enabling can take a long time, especially in case of the publishing feature...so let's make it more reliable
bool cancel = false;
features.Add(featureID, true, scope);
if (pollingIntervalSeconds < 5)
{
pollingIntervalSeconds = 5;
}
// Kick off a thread that checks for the feature activation to be complete
Task.Run(() =>
{
while (!cancel)
{
Thread.Sleep(TimeSpan.FromSeconds(pollingIntervalSeconds));
if (!cancel)
{
cancel = IsFeatureActiveInternal(features, featureID);
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureActivationState, cancel, featureID);
}
}
});
// Kick off a thread that enables the feature
Task.Run(() =>
{
try
{
features.Context.ExecuteQueryRetry();
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureActive, featureID);
}
catch(Exception ex)
{
Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ProcessFeatureInternal_FeatureException, ex.ToString());
}
finally
{
cancel = true;
}
}).Wait();
}
else
{
try
{
features.Remove(featureID, false);
features.Context.ExecuteQueryRetry();
}
catch (Exception ex)
{
Log.Error(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_FeatureActivationProblem, featureID, ex.Message);
}
}
}