public void ExecuteOn(ShWeb shweb, ClientContext context) { if (context == null) throw new ArgumentNullException("context"); var web = context.Site.RootWeb; web.Title = "This site has been updated by a custom task"; web.Update(); context.ExecuteQuery(); }
public void ExecuteTasks(ShWeb rootWeb, ClientContext context) { foreach (var taskConfig in rootWeb.CustomTaskTypes) { TypeInfo taskTypeInfo = null; Tasks.TryGetValue(taskConfig.FullName, out taskTypeInfo); if (taskTypeInfo != null) { var instance = (ITask)Activator.CreateInstance(taskTypeInfo.AsType()); instance.ExecuteOn(rootWeb,context); } } foreach (var web in rootWeb.Webs) { ExecuteTasks(web, context); } }
public void ExecuteTasks(ShWeb rootWeb, ClientContext context) { foreach (var taskConfig in rootWeb.CustomTaskTypes) { TypeInfo taskTypeInfo = null; Tasks.TryGetValue(taskConfig.FullName, out taskTypeInfo); if (taskTypeInfo != null) { var instance = (ITask) Activator.CreateInstance(taskTypeInfo.AsType()); instance.ExecuteOn(rootWeb, context); } else { Log.ErrorFormat("Could not find loaded task with name {0}", taskConfig.FullName); } } foreach (var web in rootWeb.Webs) { ExecuteTasks(web, context); } }
private void SetWelcomePageUrlIfConfigured(ClientContext context, Web webToConfigure, ShWeb configWeb) { if (!string.IsNullOrEmpty(configWeb.WelcomePageUrl)) { Log.Debug("Setting WelcomePageUrl for web " + configWeb.Name); var rootFolder = webToConfigure.RootFolder; rootFolder.WelcomePage = configWeb.WelcomePageUrl; rootFolder.Update(); context.Load(webToConfigure.RootFolder); context.ExecuteQuery(); } }
private WebCreationInformation GetWebCreationInformationFromConfig(ShWeb configWeb) { return new WebCreationInformation { Title = configWeb.Name, Description = configWeb.Description, Language = configWeb.Language, Url = configWeb.Url, UseSamePermissionsAsParentSite = true, WebTemplate = configWeb.Template }; }
private Web EnsureWeb(ClientContext context, Web parentWeb, ShWeb configWeb) { Log.Debug("Ensuring web with url " + configWeb.Url); Web webToConfigure; if (parentWeb == null) { //We assume that the root web always exists webToConfigure = context.Site.RootWeb; } else { webToConfigure = GetSubWeb(context, parentWeb, configWeb.Url); if (webToConfigure == null) { Log.Info("Creating web " + configWeb.Url); webToConfigure = parentWeb.Webs.Add(GetWebCreationInformationFromConfig(configWeb)); } } context.Load(webToConfigure, w => w.Url); context.ExecuteQuery(); return webToConfigure; }
/// <summary> /// Assumptions: /// 1. The order of webs and subwebs in the config file follows the structure of SharePoint sites /// 2. No config element is present without their parent web already being defined in the config file, except the root web /// </summary> private void EnsureAndConfigureWebAndActivateFeatures(ClientContext context, Web parentWeb, ShWeb configWeb) { var webToConfigure = EnsureWeb(context, parentWeb, configWeb); FeatureManager.ActivateWebFeatures(context, webToConfigure, configWeb.WebFeatures); ListManager.CreateLists(context, webToConfigure, configWeb.Lists); QuicklaunchManager.CreateQuicklaunchNodes(context, webToConfigure, configWeb.Quicklaunch); PropertyManager.SetProperties(context, webToConfigure, configWeb.Properties); ContentUploadManager.UploadFilesInFolder(context, webToConfigure, configWeb.ContentFolders); SetWelcomePageUrlIfConfigured(context, webToConfigure, configWeb); SetAlternateCssUrlForWeb(context, configWeb, webToConfigure); AddComposedLooks(context, configWeb, webToConfigure, configWeb.ComposedLook); foreach (ShWeb subWeb in configWeb.Webs) { EnsureAndConfigureWebAndActivateFeatures(context, webToConfigure, subWeb); } }
private void AddComposedLooks(Microsoft.SharePoint.Client.ClientContext context, ShWeb configWeb, Web web, ShComposedLook composedLook) { if (composedLook != null) { Log.Debug("Setting Composed Look for web " + configWeb.Name); var themeUrl = string.Empty; var fontSchemeUrl = string.Empty; List themeList = web.GetCatalog(124); web.Context.Load(themeList); web.Context.ExecuteQuery(); // We are assuming that the theme exists CamlQuery query = new CamlQuery(); string camlString = @" <View> <Query> <Where> <Eq> <FieldRef Name='Name' /> <Value Type='Text'>{0}</Value> </Eq> </Where> </Query> </View>"; camlString = string.Format(camlString, composedLook.Name); query.ViewXml = camlString; var found = themeList.GetItems(query); web.Context.Load(found); web.Context.ExecuteQuery(); if (found.Count == 0) { if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl")) { context.Load(web); context.ExecuteQuery(); } ListItemCreationInformation itemInfo = new ListItemCreationInformation(); Microsoft.SharePoint.Client.ListItem item = themeList.AddItem(itemInfo); item["Name"] = composedLook.Name; item["Title"] = composedLook.Title; if (!string.IsNullOrEmpty(composedLook.ThemeUrl)) { themeUrl = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(composedLook.ThemeUrl))); item["ThemeUrl"] = themeUrl; } if (!string.IsNullOrEmpty(composedLook.FontSchemeUrl)) { fontSchemeUrl = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(composedLook.FontSchemeUrl))); item["FontSchemeUrl"] = fontSchemeUrl; } if (string.IsNullOrEmpty(composedLook.MasterPageUrl)) { item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master"); } else { item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/masterpage/{0}", Path.GetFileName(composedLook.MasterPageUrl))); } item["DisplayOrder"] = 11; item.Update(); context.ExecuteQuery(); } else { Microsoft.SharePoint.Client.ListItem item = found[0]; themeUrl = MakeAsRelativeUrl((item["ThemeUrl"] as FieldUrlValue).Url); fontSchemeUrl = MakeAsRelativeUrl((item["FontSchemeUrl"] as FieldUrlValue).Url); } web.ApplyTheme(themeUrl, fontSchemeUrl, null, false); context.ExecuteQuery(); } }
private static void SetAlternateCssUrlForWeb(ClientContext context, ShWeb configWeb, Web webToConfigure) { if (!string.IsNullOrEmpty(configWeb.AlternateCssUrl)) { Log.Debug("Setting AlternateCssUrl for web " + configWeb.Name); webToConfigure.AlternateCssUrl = ContentUploadManager.GetPropertyValueWithTokensReplaced(configWeb.AlternateCssUrl, context); webToConfigure.Update(); context.ExecuteQuery(); } }