/// <summary> /// Validates the specified key values. /// </summary> /// <param name="keyValues">The key values.</param> public override void Validate(StringDictionary keyValues) { SPMultiParameterValidator.Validate(Params, new string[] { "add", "close", "open", "delete" }, 1, 1); SPBinaryParameterValidator.Validate("id", Params["id"].Value, "title", Params["title"].Value); if (Params["properties"].UserTypedIn) { string properties = Params["properties"].Value; string seperator = Params["propertyseperator"].Value; properties = properties.Replace(seperator + seperator, "[STSADM_COMMA]"); string[] props = properties.Split(seperator.ToCharArray()); foreach (string prop in props) { if (prop.Split(new[] { '=' }, 2).Length != 2) { throw new SPSyntaxException( "The format of the properties parameter is incorrect: \"prop1=val1" + seperator + "prop2=val2\""); } } } if (Params["properties"].UserTypedIn && Params["propertiesfile"].UserTypedIn) { throw new SPSyntaxException("The properties parameter and propertiesfile parameters are incompatible."); } base.Validate(keyValues); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; SPBinaryParameterValidator.Validate("id", Params["id"].Value, "title", Params["title"].Value); if (!Params["zone"].UserTypedIn && !Params["zoneindex"].UserTypedIn) { throw new SPSyntaxException("You must specify at least the zone or zoneindex parameters."); } string url = Params["url"].Value; string webPartId = Params["id"].Value; string webPartTitle = Params["title"].Value; string webPartZone = Params["zone"].Value; string webPartZoneIndex = Params["zoneindex"].Value; bool publish = Params["publish"].UserTypedIn; if (Params["title"].UserTypedIn) { Common.WebParts.MoveWebPart.MoveByTitle(url, webPartTitle, webPartZone, webPartZoneIndex, publish); } else if (Params["id"].UserTypedIn) { Common.WebParts.MoveWebPart.MoveById(url, webPartId, webPartZone, webPartZoneIndex, publish); } return((int)ErrorCodes.NoError); }
/// <summary> /// Validates the specified key values. /// </summary> /// <param name="keyValues">The key values.</param> public override void Validate(StringDictionary keyValues) { SPBinaryParameterValidator.Validate("rules", Params["rules"].Value, "rulesfile", Params["rulesfile"].Value); SPBinaryParameterValidator.Validate("serviceappname", Params["serviceappname"].Value, "contextsite", Params["contextsite"].Value); if (Params["clear"].UserTypedIn && (Params["appendop"].UserTypedIn || Params["groupexisting"].UserTypedIn)) { throw new SPSyntaxException("The -clear parameter cannot be used with the -appendop or -groupexisting parameters."); } base.Validate(keyValues); }
/// <summary> /// Validates the specified key values. /// </summary> /// <param name="keyValues">The key values.</param> public override void Validate(StringDictionary keyValues) { SPBinaryParameterValidator.Validate("id", Params["id"].Value, "title", Params["title"].Value); if (Params["allmatching"].UserTypedIn && Params["id"].UserTypedIn) { throw new ArgumentException(SPResource.GetString("IncompatibleParametersSpecified", new object[] { "allmatching", "id" })); } if (Params["list"].UserTypedIn && Params["site"].UserTypedIn) { throw new ArgumentException(SPResource.GetString("IncompatibleParametersSpecified", new object[] { "list", "site" })); } base.Validate(keyValues); }
/// <summary> /// Validates the specified key values. /// </summary> /// <param name="keyValues">The key values.</param> public override void Validate(StringDictionary keyValues) { SPBinaryParameterValidator.Validate("serviceappname", Params["serviceappname"].Value, "contextsite", Params["contextsite"].Value); base.Validate(keyValues); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; SPBinaryParameterValidator.Validate("template", Params["template"].Value, "allowalltemplates", (Params["allowalltemplates"].UserTypedIn ? "true" : Params["allowalltemplates"].Value)); string url = Params["url"].Value.TrimEnd('/'); string templateName = Params["template"].Value; bool resetAllSubsites = Params["resetallsubsites"].UserTypedIn; using (SPSite site = new SPSite(url)) { using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)]) { uint lcid = web.Language; bool localeProvided = Params["lcid"].UserTypedIn; if (localeProvided) { lcid = uint.Parse(Params["lcid"].Value); } bool exists = false; #if MOSS PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); if (Params["allowalltemplates"].UserTypedIn) { pubweb.AllowAllWebTemplates(resetAllSubsites); pubweb.Update(); return((int)ErrorCodes.NoError); } SPWebTemplateCollection existingLanguageNeutralTemplatesCollection = pubweb.GetAvailableCrossLanguageWebTemplates(); SPWebTemplateCollection existingLanguageSpecificTemplatesCollection = pubweb.GetAvailableWebTemplates(lcid); #else if (Params["allowalltemplates"].UserTypedIn) { web.AllowAllWebTemplates(); web.Update(); return((int)ErrorCodes.NoError); } SPWebTemplateCollection existingLanguageNeutralTemplatesCollection = web.GetAvailableCrossLanguageWebTemplates(); SPWebTemplateCollection existingLanguageSpecificTemplatesCollection = web.GetAvailableWebTemplates(lcid); #endif Collection <SPWebTemplate> newLanguageNeutralTemplatesCollection = new Collection <SPWebTemplate>(); Collection <SPWebTemplate> newLanguageSpecificTemplatesCollection = new Collection <SPWebTemplate>(); foreach (SPWebTemplate existingTemplate in existingLanguageNeutralTemplatesCollection) { if (existingTemplate.Name == templateName && !localeProvided) { exists = true; continue; } newLanguageNeutralTemplatesCollection.Add(existingTemplate); } foreach (SPWebTemplate existingTemplate in existingLanguageSpecificTemplatesCollection) { if (existingTemplate.Name == templateName && localeProvided) { exists = true; continue; } newLanguageSpecificTemplatesCollection.Add(existingTemplate); } if (!exists) { output = "Template is not assigned."; return((int)ErrorCodes.GeneralError); } if (newLanguageSpecificTemplatesCollection.Count == 0 && newLanguageNeutralTemplatesCollection.Count == 0) { output = "There must be at least one template available."; return((int)ErrorCodes.GeneralError); } #if MOSS pubweb.SetAvailableCrossLanguageWebTemplates(newLanguageNeutralTemplatesCollection, resetAllSubsites); pubweb.SetAvailableWebTemplates(newLanguageSpecificTemplatesCollection, lcid, resetAllSubsites); #else web.SetAvailableCrossLanguageWebTemplates(newLanguageNeutralTemplatesCollection); web.SetAvailableWebTemplates(newLanguageSpecificTemplatesCollection, lcid); #endif } } return((int)ErrorCodes.NoError); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; SPBinaryParameterValidator.Validate("template", Params["template"].Value, "allowalltemplates", (Params["allowalltemplates"].UserTypedIn ? "true" : Params["allowalltemplates"].Value)); string url = Params["url"].Value.TrimEnd('/'); string templateName = Params["template"].Value; bool resetAllSubsites = Params["resetallsubsites"].UserTypedIn; using (SPSite site = new SPSite(url)) { using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)]) { uint lcid = web.Language; if (!string.IsNullOrEmpty(keyValues["lcid"])) { lcid = uint.Parse(keyValues["lcid"]); } bool localeProvided = keyValues.ContainsKey("lcid"); #if MOSS PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); if (Params["allowalltemplates"].UserTypedIn) { pubweb.AllowAllWebTemplates(resetAllSubsites); pubweb.Update(); return((int)ErrorCodes.NoError); } #else if (Params["allowalltemplates"].UserTypedIn) { web.AllowAllWebTemplates(); web.Update(); return((int)ErrorCodes.NoError); } #endif SPWebTemplateCollection templateColl; if (localeProvided) { templateColl = web.GetAvailableWebTemplates(lcid); } else { templateColl = web.GetAvailableCrossLanguageWebTemplates(); } bool exists; try { exists = (templateColl[templateName] != null); } catch (ArgumentException) { exists = false; } if (exists && !web.AllWebTemplatesAllowed) { output = "Template is already installed."; return((int)ErrorCodes.GeneralError); } Collection <SPWebTemplate> list = new Collection <SPWebTemplate>(); if (!web.AllWebTemplatesAllowed) { foreach (SPWebTemplate existingTemplate in templateColl) { list.Add(existingTemplate); } } SPWebTemplate newTemplate = GetWebTemplate(site, lcid, templateName); if (newTemplate == null) { output = "Template not found."; return((int)ErrorCodes.GeneralError); } else { list.Add(newTemplate); } #if MOSS if (!localeProvided) { pubweb.SetAvailableCrossLanguageWebTemplates(list, resetAllSubsites); } else { pubweb.SetAvailableWebTemplates(list, lcid, resetAllSubsites); } #else if (!localeProvided) { web.SetAvailableCrossLanguageWebTemplates(list); } else { web.SetAvailableWebTemplates(list, lcid); } #endif } } return((int)ErrorCodes.NoError); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; SPBinaryParameterValidator.Validate("fielddisplayname", Params["fielddisplayname"].Value, "fieldinternalname", Params["fieldinternalname"].Value); string url = Params["url"].Value; string fieldTitle = Params["fielddisplayname"].Value; string fieldName = Params["fieldinternalname"].Value; bool useTitle = Params["fielddisplayname"].UserTypedIn; bool useName = Params["fieldinternalname"].UserTypedIn; bool force = Params["force"].UserTypedIn; SPField field = Utilities.GetField(url, fieldName, fieldTitle, useName, useTitle); if (field.ReadOnlyField && force) { field.ReadOnlyField = false; field.Update(); } if (!field.CanBeDeleted) { if (field.FromBaseType) { throw new Exception( "The field is derived from a base type and cannot be deleted. You must delete the field from the base type."); } else if (field.Sealed) { if (force) { field.Sealed = false; field.Update(); } else { throw new Exception("This field is sealed and cannot be deleted - specify \"-force\" to ignore this setting and attempt deletion regardless."); } } else if (field.AllowDeletion.HasValue && !field.AllowDeletion.Value && !force) { throw new Exception( "Field is marked as not allowing deletion - specify \"-force\" to ignore this setting and attempt deletion regardless."); } else if (field.AllowDeletion.HasValue && !field.AllowDeletion.Value && force) { field.AllowDeletion = true; field.Update(); } else { throw new Exception("Field cannot be deleted."); } } if (field.Hidden) { if (force) { if (field.CanToggleHidden) { field.Hidden = false; field.Update(); } else { MethodInfo setFieldBoolValue = field.GetType().GetMethod("SetFieldBoolValue", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, new Type[] { typeof(string), typeof(bool) }, null); //field.SetFieldBoolValue("Hidden", false); setFieldBoolValue.Invoke(field, new object[] { "Hidden", false }); //field.SetFieldBoolValue("CanToggleHidden", true); setFieldBoolValue.Invoke(field, new object[] { "CanToggleHidden", true }); field.Update(); } } else { throw new Exception( "You cannot delete hidden fields - specify \"-force\" to ignore this restriction and attempt deletion regardless."); } } field.Delete(); return((int)ErrorCodes.NoError); }