protected override void ExecuteCmdlet() { // Following code to handle desprecated parameter if (MyInvocation.BoundParameters.ContainsKey("FromSite")) { Scope = CustomActionScope.Site; } List<UserCustomAction> actions = new List<UserCustomAction>(); if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (!actions.Any()) return; foreach (var action in actions.Where(action => Force || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name), Resources.Confirm))) { switch (action.Scope) { case UserCustomActionScope.Web: SelectedWeb.DeleteJsLink(Name); break; case UserCustomActionScope.Site: ClientContext.Site.DeleteJsLink(Name); break; } } }
protected override void ExecuteCmdlet() { // Following code to handle deprecated parameter #pragma warning disable CS0618 // Type or member is obsolete if (ParameterSpecified(nameof(FromSite))) #pragma warning restore CS0618 // Type or member is obsolete { Scope = CustomActionScope.Site; } List <UserCustomAction> actions = new List <UserCustomAction>(); if (Identity != null && Identity.UserCustomAction != null && Identity.UserCustomAction.Location == "ScriptLink") { actions.Add(Identity.UserCustomAction); } else { if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (Identity != null) { actions = actions.Where(action => Identity.Id.HasValue ? Identity.Id.Value == action.Id : Identity.Name == action.Name).ToList(); if (!actions.Any()) { throw new ArgumentException($"No JavaScriptLink found with the {(Identity.Id.HasValue ? "Id" : "name")} '{(Identity.Id.HasValue ? Identity.Id.Value.ToString() : Identity.Name)}' within the scope '{Scope}'", "Identity"); } } if (!actions.Any()) { WriteVerbose($"No JavaScriptLink registrations found within the scope '{Scope}'"); return; } } foreach (var action in actions.Where(action => Force || (ParameterSpecified("Confirm") && !bool.Parse(MyInvocation.BoundParameters["Confirm"].ToString())) || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name, action.Id, action.Scope), Resources.Confirm))) { switch (action.Scope) { case UserCustomActionScope.Web: SelectedWeb.DeleteJsLink(action.Name); break; case UserCustomActionScope.Site: ClientContext.Site.DeleteJsLink(action.Name); break; } } }
public IEnumerable <IUserCustomAction> GetCustomActions(PnPContext context, CustomActionScope scope) { if (_coreUserCustomAction != null) { return(new List <IUserCustomAction> { _coreUserCustomAction }); } if (_userCustomAction != null) { switch (_userCustomAction.Scope) { case Microsoft.SharePoint.Client.UserCustomActionScope.Web: { return(new List <IUserCustomAction> { context.Web.UserCustomActions.Where(ca => ca.Id == _userCustomAction.Id).FirstOrDefault() }); } case Microsoft.SharePoint.Client.UserCustomActionScope.Site: { return(new List <IUserCustomAction> { context.Site.UserCustomActions.Where(ca => ca.Id == _userCustomAction.Id).FirstOrDefault() }); } } } var customActions = new List <IUserCustomAction>(); if (scope == CustomActionScope.Web || scope == CustomActionScope.All) { customActions.AddRange(context.Web.UserCustomActions.ToList()); } if (scope == CustomActionScope.Site || scope == CustomActionScope.All) { customActions.AddRange(context.Site.UserCustomActions.ToList()); } if (_id != null) { return(customActions.Where(ca => ca.Id == _id.Value)); } if (!string.IsNullOrEmpty(_name)) { return(customActions.Where(ca => ca.Name == _name)); } return(null); }
protected override void ExecuteCmdlet() { // Following code to handle desprecated parameter if (MyInvocation.BoundParameters.ContainsKey("FromSite")) { Scope = CustomActionScope.Site; } List <UserCustomAction> actions = new List <UserCustomAction>(); if (Scope == CustomActionScope.All || Scope == CustomActionScope.Web) { actions.AddRange(SelectedWeb.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (Scope == CustomActionScope.All || Scope == CustomActionScope.Site) { actions.AddRange(ClientContext.Site.GetCustomActions().Where(c => c.Location == "ScriptLink")); } if (!actions.Any()) { return; } if (!string.IsNullOrEmpty(Name)) { actions = actions.Where(action => action.Name == Name).ToList(); } foreach (var action in actions.Where(action => Force || ShouldContinue(string.Format(Resources.RemoveJavaScript0, action.Name), Resources.Confirm))) { switch (action.Scope) { case UserCustomActionScope.Web: SelectedWeb.DeleteJsLink(action.Name); break; case UserCustomActionScope.Site: ClientContext.Site.DeleteJsLink(action.Name); break; } } }