private static void AddWikiWebPart(Web w, string serverRelativeHomepageUrl, string webpartXml, int row, int col, string listTitle, string[] fieldsInView) { try { List l = w.Lists.GetByTitle(listTitle); w.Context.Load(l, x => x.RootFolder); w.Context.ExecuteQuery(); w.AddWebPartToWikiPage(serverRelativeHomepageUrl, new OfficeDevPnP.Core.Entities.WebPartEntity { WebPartXml = string.Format(webpartXml, l.RootFolder.Name) }, row, col, true); if (fieldsInView != null && fieldsInView.Length > 0) { var viewQuery = l.Views.Where(x => x.Hidden); w.Context.LoadQuery(l.Views.Where(x => x.Hidden)); if (viewQuery != null) { var viewHidd = viewQuery.First(); viewHidd.ViewFields.RemoveAll(); foreach (string item in fieldsInView) { viewHidd.ViewFields.Add(item); } viewHidd.RowLimit = 10; w.Context.ExecuteQuery(); } } } catch (Exception) { throw; } }
private static List FindSourceList(string listIdentifier, Web web, Web rootWeb) { Guid listGuid = Guid.Empty; if (!Guid.TryParse(listIdentifier, out listGuid)) { var sourceListUrl = UrlUtility.Combine(web.ServerRelativeUrl, listIdentifier); return web.Lists.FirstOrDefault(l => l.RootFolder.ServerRelativeUrl.Equals(sourceListUrl, StringComparison.OrdinalIgnoreCase)); } else { List retVal = rootWeb.Lists.FirstOrDefault(l => l.Id.Equals(listGuid)); if(retVal == null) { retVal = web.Lists.FirstOrDefault(l => l.Id.Equals(listGuid)); } if(retVal == null) { Log.Warning(Constants.LOGGING_SOURCE, CoreResources.Provisioning_ObjectHandlers_LookupFields_LookupTargetListLookupFailed__0, listIdentifier); } return retVal; } }
private static void CreateContentTypeIfDoesNotExist(ClientContext cc, Web web) { ContentTypeCollection contentTypes = web.ContentTypes; cc.Load(contentTypes); cc.ExecuteQuery(); foreach (var item in contentTypes) { if (item.StringId == "0x0101009189AB5D3D2647B580F011DA2F356FB3") return; } // Create a Content Type Information object ContentTypeCreationInformation newCt = new ContentTypeCreationInformation(); // Set the name for the content type newCt.Name = "Contoso Sample Document"; //Inherit from oob document - 0x0101 and assign newCt.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB3"; // Set content type to be avaialble from specific group newCt.Group = "Contoso Content Types"; // Create the content type ContentType myContentType = contentTypes.Add(newCt); cc.ExecuteQuery(); Console.WriteLine("Content type created."); }
public Web Connect(string url) { using (var site = CreateSite(url)) { using (var web = site.OpenWeb()) { Web = new Web(this) { Id = web.ID, Url = url, Title = web.Title }; Web.Lists = web.Lists.Cast<SPList>().Select(l => new SList { Web = Web, Title = l.Title, Id = l.ID, IsHidden = l.Hidden }).ToList(); return Web; } } }
private static void SetDocumentAsTemplate(ClientContext cc, Web web) { ContentType ct = web.ContentTypes.GetById("0x0101009189AB5D3D2647B580F011DA2F356FB3"); cc.Load(ct); cc.ExecuteQuery(); // Get instance to the _cts folder created for the each of the content types string ctFolderServerRelativeURL = "_cts/" + ct.Name; Folder ctFolder = web.GetFolderByServerRelativeUrl(ctFolderServerRelativeURL); cc.Load(ctFolder); cc.ExecuteQuery(); // Load the local template document string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "template.docx"); string fileName = System.IO.Path.GetFileName(path); byte[] filecontent = System.IO.File.ReadAllBytes(path); // Uplaod file to the Office365 using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open)) { FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = filecontent; newFile.Url = ctFolderServerRelativeURL + "/" + fileName; Microsoft.SharePoint.Client.File uploadedFile = ctFolder.Files.Add(newFile); cc.Load(uploadedFile); cc.ExecuteQuery(); } ct.DocumentTemplate = fileName; ct.Update(true); cc.ExecuteQuery(); Console.WriteLine("Document template uploaded and set to the content type."); }
internal List GetList(Web web) { List list = null; if (List != null) { list = List; } else if (Id != Guid.Empty) { list = web.Lists.GetById(Id); } else if (!string.IsNullOrEmpty(Title)) { list = web.GetListByTitle(Title); if (list == null) { list = web.GetListByUrl(Title); } } if (list != null) { web.Context.Load(list, l => l.Id, l => l.BaseTemplate, l => l.OnQuickLaunch, l => l.DefaultViewUrl, l => l.Title, l => l.Hidden, l => l.ContentTypesEnabled, l => l.RootFolder.ServerRelativeUrl); web.Context.ExecuteQueryRetry(); } return list; }
internal void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, string folderPath, string fileName, Boolean decodeFileName = false) { if (creationInfo.FileConnector != null) { SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy"); Uri u = new Uri(web.Url); if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1) { folderPath = folderPath.Replace(u.PathAndQuery, ""); } using (Stream s = connector.GetFileStream(fileName, folderPath)) { if (s != null) { creationInfo.FileConnector.SaveFileStream(decodeFileName ? HttpUtility.UrlDecode(fileName) : fileName, s); } } } else { WriteWarning("No connector present to persist homepage.", ProvisioningMessageType.Error); scope.LogError("No connector present to persist homepage"); } }
private static void LocalizeParts(Web web, TokenParser parser, string url, WebPartCollection webParts, PnPMonitoredScope scope) { if (CanUseAcceptLanguageHeaderForLocalization(web)) { var context = web.Context; var allParts = web.GetWebParts(parser.ParseString(url)).ToList(); foreach (var webPart in webParts) { #if !SP2016 var partOnPage = allParts.FirstOrDefault(w => w.ZoneId == webPart.Zone && w.WebPart.ZoneIndex == webPart.Order); #else var partOnPage = allParts.FirstOrDefault(w => w.WebPart.ZoneIndex == webPart.Order); #endif if (webPart.Title.ContainsResourceToken() && partOnPage != null) { var resourceValues = parser.GetResourceTokenResourceValues(webPart.Title); foreach (var resourceValue in resourceValues) { // Save property with correct locale on the request to make it stick // http://sadomovalex.blogspot.no/2015/09/localize-web-part-titles-via-client.html context.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = resourceValue.Item1; partOnPage.WebPart.Properties["Title"] = resourceValue.Item2; partOnPage.SaveWebPartChanges(); context.ExecuteQueryRetry(); } } } context.PendingRequest.RequestExecutor.WebRequest.Headers.Remove("Accept-Language"); } else { // warning scope.LogWarning(CoreResources.Provisioning_Extensions_WebPartLocalization_Skip); } }
private void DeployRegionalSettings(object modelHost, Web web, RegionalSettingsDefinition definition) { var settings = GetCurrentRegionalSettings(web); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = settings, ObjectType = typeof(RegionalSettings), ObjectDefinition = definition, ModelHost = modelHost }); MapRegionalSettings(settings, definition); //web.RegionalSettings = settings; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = settings, ObjectType = typeof(RegionalSettings), ObjectDefinition = definition, ModelHost = modelHost }); }
/// <summary> /// Adds a list to a site /// </summary> /// <param name="properties">Site to operate on</param> /// <param name="listType">Type of the list</param> /// <param name="featureID">Feature guid that brings this list type</param> /// <param name="listName">Name of the list</param> /// <param name="enableVersioning">Enable versioning on the list</param> public static List AddList(ClientContext ctx, Web web, ListTemplateType listType, string listName) { ListCollection listCollection = web.Lists; ctx.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listName)); ctx.ExecuteQuery(); if (listCollection.Count == 0) { ListCollection listCol = web.Lists; ListCreationInformation lci = new ListCreationInformation(); lci.Title = listName; lci.TemplateType = (int)listType; List newList = listCol.Add(lci); newList.Description = "Demo list for remote event receiver lab"; newList.Fields.AddFieldAsXml("<Field DisplayName='Description' Type='Text' />",true,AddFieldOptions.DefaultValue); newList.Fields.AddFieldAsXml("<Field DisplayName='AssignedTo' Type='Text' />",true,AddFieldOptions.DefaultValue); newList.Update(); return newList; //ctx.Load(listCol); //ctx.ExecuteQuery(); } else { return listCollection[0]; } }
public ActionResult Edit(int id, Web.Models.SlotModel model) { _wrapper.UpdateSlot( Mapper.Map<Model.SlotModel>(Mapper.Map<Model.SlotModel>(model)) ); return RedirectToAction("Index", new { taskId = model.TaskId }); }
public void Run(Web.Quote quote) { var db = new QuotesDBEntities(); foreach (var vehicle in quote.Vehicles) { if (vehicle.AntiLock) { var stateId = (int) db.Drivers.Single(p => p.ID == vehicle.PrimaryDriver).DLState; var discount = db.DiscountPerStates.Single(d => d.DiscountId == this.discountId && d.StateId == stateId); var appliedDiscountValue = new VehicleDiscount() { AppliedDiscountValue = discount.Amount, DiscountId = this.discountId, StateId = stateId, VehicleId = vehicle.ID }; db.AddToVehicleDiscounts(appliedDiscountValue); } } db.SaveChanges(); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { using (var scope = new PnPMonitoredScope(this.Name)) { var context = web.Context as ClientContext; foreach (var handler in template.ExtensibilityHandlers .Union(template.Providers) .Union(applyingInformation.ExtensibilityHandlers)) { if (handler.Enabled) { try { if (!string.IsNullOrEmpty(handler.Configuration)) { //replace tokens in configuration data handler.Configuration = parser.ParseString(handler.Configuration); } scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_extensibility_callout__0_, handler.Assembly); _extManager.ExecuteExtensibilityProvisionCallOut(context, handler, template, applyingInformation, parser, scope); } catch (Exception ex) { scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_callout_failed___0_____1_, ex.Message, ex.StackTrace); throw; } } } } return parser; }
public Web CreateSubSite(Microsoft.SharePoint.Client.ClientContext ctx, Web hostWeb, string txtUrl, string template, string title, string description) { // Create web creation configuration WebCreationInformation information = new WebCreationInformation(); information.WebTemplate = template; information.Description = description; information.Title = title; information.Url = txtUrl; // Currently all english, could be extended to be configurable based on language pack usage information.Language = 1033; Microsoft.SharePoint.Client.Web newWeb = null; newWeb = hostWeb.Webs.Add(information); ctx.ExecuteQuery(); ctx.Load(newWeb); ctx.ExecuteQuery(); // Add sub site link override new LabHelper().AddJsLink(ctx, newWeb, this.Request); // Set oob theme to the just created site new LabHelper().SetThemeBasedOnName(ctx, newWeb, hostWeb, "Orange"); // All done, let's return the newly created site return newWeb; }
public static bool Validate(CustomActions sourceCustomActions, CustomActions targetCustomActions, TokenParser tokenParser, Web web) { if (web.IsNoScriptSite()) { Console.WriteLine("Skipping validation of custom actions due to noscript site."); return true; } Console.WriteLine("Custom Action validation started..."); bool isSiteCustomActionsMatch = false; bool isWebCustomActionsMatch = false; if (sourceCustomActions.SiteCustomActions.Count > 0) { isSiteCustomActionsMatch = ValidateCustomActions(sourceCustomActions.SiteCustomActions, targetCustomActions.SiteCustomActions, tokenParser, web); Console.WriteLine("Site Custom Actions validation " + isSiteCustomActionsMatch); } if (sourceCustomActions.WebCustomActions.Count > 0) { isWebCustomActionsMatch = ValidateCustomActions(sourceCustomActions.WebCustomActions, targetCustomActions.WebCustomActions, tokenParser, web); Console.WriteLine("Web Custom Actions validation " + isWebCustomActionsMatch); } if (!isSiteCustomActionsMatch || !isWebCustomActionsMatch) { return false; } else { return true; } }
internal static void CreateSearchNavigationNodes(ClientContext clientContext, Web web, Dictionary<string, string> searchNavigationNodes) { if (searchNavigationNodes == null || searchNavigationNodes.Count == 0) return; var searchNavigation = web.Navigation.GetNodeById(1040); NavigationNodeCollection nodeCollection = searchNavigation.Children; clientContext.Load(searchNavigation); clientContext.Load(nodeCollection); clientContext.ExecuteQuery(); for (int i = nodeCollection.Count - 1; i >= 0; i--) { nodeCollection[i].DeleteObject(); } foreach (KeyValuePair<string, string> newNode in searchNavigationNodes.Reverse<KeyValuePair<string, string>>()) { nodeCollection.Add(new NavigationNodeCreationInformation { Title = newNode.Key, Url = newNode.Value }); } clientContext.ExecuteQuery(); }
static void Main() { Console.WriteLine("Adding Team Site Content"); Console.WriteLine(); clientContext = new ClientContext(siteUrl); site = clientContext.Web; clientContext.Load(site); clientContext.ExecuteQuery(); WingtipContentGenerator.CreateProductCategoriesTermset(); WingtipContentGenerator.CreateProductsLists(); Console.WriteLine(); Console.WriteLine("The program has finsihed. Press ENTER to close this window"); Console.WriteLine(); Console.ReadLine(); clientContext.ExecuteQuery(); }
public void SetProperties(ClientContext context, Web webToConfigure, Dictionary<string, string> properties) { foreach (KeyValuePair<string, string> property in properties) { SetProperty(context, webToConfigure, property); } }
public void UploadFilesInFolder(ClientContext context, Web web, List<ShContentFolder> contentFolders) { foreach (ShContentFolder folder in contentFolders) { UploadFilesInFolder(context, web, folder); } }
/// <summary> /// Adds a list to a site /// </summary> /// <param name="properties">Site to operate on</param> /// <param name="listType">Type of the list</param> /// <param name="featureID">Feature guid that brings this list type</param> /// <param name="listName">Name of the list</param> /// <param name="enableVersioning">Enable versioning on the list</param> public bool AddList(ClientContext ctx, Web web, int listType, Guid featureID, string listName, bool enableVersioning) { bool created = false; ListCollection listCollection = web.Lists; ctx.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listName)); ctx.ExecuteQuery(); if (listCollection.Count == 0) { ListCreationInformation lci = new ListCreationInformation(); lci.Title = listName; lci.TemplateFeatureId = featureID; lci.TemplateType = listType; List newList = web.Lists.Add(lci); if (enableVersioning) { newList.EnableVersioning = true; newList.EnableMinorVersions = true; } newList.Update(); ctx.ExecuteQuery(); created = true; } return created; }
public void SetThemeBasedOnName(ClientContext ctx, Web web, Web rootWeb, string themeName) { // Let's get instance to the composite look gallery List themeList = rootWeb.GetCatalog(124); ctx.Load(themeList); ctx.ExecuteQuery(); CamlQuery query = new CamlQuery(); string camlString = @" <View> <Query> <Where> <Eq> <FieldRef Name='Name' /> <Value Type='Text'>{0}</Value> </Eq> </Where> </Query> </View>"; // Let's update the theme name accordingly camlString = string.Format(camlString, themeName); query.ViewXml = camlString; var found = themeList.GetItems(query); ctx.Load(found); ctx.ExecuteQuery(); if (found.Count > 0) { Microsoft.SharePoint.Client.ListItem themeEntry = found[0]; //Set the properties for applying custom theme which was jus uplaoded string spColorURL = null; if (themeEntry["ThemeUrl"] != null && themeEntry["ThemeUrl"].ToString().Length > 0) { spColorURL = MakeAsRelativeUrl((themeEntry["ThemeUrl"] as FieldUrlValue).Url); } string spFontURL = null; if (themeEntry["FontSchemeUrl"] != null && themeEntry["FontSchemeUrl"].ToString().Length > 0) { spFontURL = MakeAsRelativeUrl((themeEntry["FontSchemeUrl"] as FieldUrlValue).Url); } string backGroundImage = null; if (themeEntry["ImageUrl"] != null && themeEntry["ImageUrl"].ToString().Length > 0) { backGroundImage = MakeAsRelativeUrl((themeEntry["ImageUrl"] as FieldUrlValue).Url); } // Set theme for demonstration web.ApplyTheme(spColorURL, spFontURL, backGroundImage, false); // Let's also update master page, if needed if (themeEntry["MasterPageUrl"] != null && themeEntry["MasterPageUrl"].ToString().Length > 0) { web.MasterUrl = MakeAsRelativeUrl((themeEntry["MasterPageUrl"] as FieldUrlValue).Url); ; } ctx.ExecuteQuery(); } }
private void Delete(Web web) { if (!base.ShouldProcess(Identity.ToString())) return; var ctx = base.Context; if (!web.IsObjectPropertyInstantiated("Webs")) { ctx.Load(web.Webs); ctx.ExecuteQuery(); } if (web.Webs.Count > 0) { foreach (Web childWeb in web.Webs) { Delete(childWeb); } if (web.Webs.Count == 0) { web.DeleteObject(); web.Context.ExecuteQuery(); } } else { web.DeleteObject(); web.Context.ExecuteQuery(); } }
public ActionResult Edit(int id, Web.Models.TaskModel model) { _wrapper.UpdateTask( Mapper.Map<Model.TaskModel>(Mapper.Map<Model.TaskModel>(model)) ); return RedirectToAction("Index", new { projectId = model.ProjectId }); }
public static void AddPublishingPage(PublishingPage page, ClientContext ctx, Web web) { SPPublishing.PublishingPage publishingPage = web.GetPublishingPage(page.FileName + ".aspx"); RemovePublishingPage(publishingPage, page, ctx, web); web.AddPublishingPage(page.FileName, page.Layout, page.Title, false); //DO NOT Publish here or it will fail if library doesn't enable Minor versions (PnP bug) publishingPage = web.GetPublishingPage(page.FileName + ".aspx"); Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File; pageFile.CheckOut(); if (page.Properties != null && page.Properties.Count > 0) { ctx.Load(pageFile, p => p.Name, p => p.CheckOutType); //need these values in SetFileProperties ctx.ExecuteQuery(); pageFile.SetFileProperties(page.Properties, false); } if (page.WebParts != null && page.WebParts.Count > 0) { Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr = pageFile.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared); ctx.Load(mgr); ctx.ExecuteQuery(); AddWebpartsToPublishingPage(page, ctx, mgr); } List pagesLibrary = publishingPage.ListItem.ParentList; ctx.Load(pagesLibrary); ctx.ExecuteQueryRetry(); ListItem pageItem = publishingPage.ListItem; web.Context.Load(pageItem, p => p.File.CheckOutType); web.Context.ExecuteQueryRetry(); if (pageItem.File.CheckOutType != CheckOutType.None) { pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn); } if (page.Publish && pagesLibrary.EnableMinorVersions) { pageItem.File.Publish(String.Empty); if (pagesLibrary.EnableModeration) { pageItem.File.Approve(String.Empty); } } if (page.WelcomePage) { SetWelcomePage(web, pageFile); } ctx.ExecuteQuery(); }
public SPOWebPipeBind() { _id = Guid.Empty; _url = string.Empty; _spOnlineWeb = null; _web = null; }
public TokenParser AddExtendedTokens(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { using (var scope = new PnPMonitoredScope(this.Name)) { var context = web.Context as ClientContext; foreach (var provider in template.Providers) { if (provider.Enabled) { try { if (!string.IsNullOrEmpty(provider.Configuration)) { provider.Configuration = parser.ParseString(provider.Configuration); } scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_tokenprovider_extensibility_callout__0_, provider.Assembly); var _providedTokens = _extManager.ExecuteTokenProviderCallOut(context, provider, template); if (_providedTokens != null) { foreach (var token in _providedTokens) { parser.AddToken(token); } } } catch (Exception ex) { scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_tokenprovider_callout_failed___0_____1_, ex.Message, ex.StackTrace); throw; } } } return parser; } }
private static void RemovePublishingPage(SPPublishing.PublishingPage publishingPage, PublishingPage page, ClientContext ctx, Web web) { if (publishingPage != null && publishingPage.ServerObjectIsNull.Value == false) { if (!web.IsPropertyAvailable("RootFolder")) { web.Context.Load(web.RootFolder); web.Context.ExecuteQueryRetry(); } if (page.Overwrite) { if (page.WelcomePage && web.RootFolder.WelcomePage.Contains(page.FileName + ".aspx")) { //set the welcome page to a Temp page to allow remove the page web.RootFolder.WelcomePage = "home.aspx"; web.RootFolder.Update(); web.Update(); ctx.Load(publishingPage); ctx.ExecuteQuery(); } publishingPage.ListItem.DeleteObject(); ctx.ExecuteQuery(); } else { return; } } }
public static List CreateList(string title, string description, string url, ListTemplateType templateType, Web web, QuickLaunchOptions quicklaunchOptions) { ClientContext clientContext = web.Context as ClientContext; ListCreationInformation createInfo = new ListCreationInformation(); createInfo.Title = title; createInfo.TemplateType = (int)templateType; createInfo.QuickLaunchOption = quicklaunchOptions; if (!string.IsNullOrEmpty(description)) { createInfo.Description = description; } if (!string.IsNullOrEmpty(url)) { createInfo.Url = url; } // clientContext.Load(web.Lists); List newList = web.Lists.Add(createInfo); clientContext.ExecuteQuery(); clientContext.Load(newList); clientContext.ExecuteQuery(); return newList; }
public SPOWeb(Web web) { _web = web; //if (web.IsObjectPropertyInstantiated("AvailableFields")) // AvailableFields = web.AvailableFields; //if (web.IsPropertyAvailable("EffectiveBasePermissions")) // EffectiveBasePermissions = web.EffectiveBasePermissions; //if (web.IsObjectPropertyInstantiated("Features")) // Features = web.Features; //if (web.IsObjectPropertyInstantiated("Fields")) // Fields = web.Fields; //if (web.IsObjectPropertyInstantiated("ListTemplates")) // ListTemplates = web.ListTemplates; //if (web.IsObjectPropertyInstantiated("Navigation")) // Navigation = web.Navigation; //if (web.IsObjectPropertyInstantiated("RootFolder")) // RootFolder = web.RootFolder; //if (web.IsObjectPropertyInstantiated("SiteGroups")) // SiteGroups = web.SiteGroups; //if (web.IsObjectPropertyInstantiated("SiteUserInfoList")) // SiteUserInfoList = web.SiteUserInfoList; //if (web.IsObjectPropertyInstantiated("SiteUsers")) // SiteUsers = web.SiteUsers; }
/// <summary> /// Deploy new theme to site collection. Resolves root web, if sub site is given as paraneter /// </summary> /// <param name="cc">Client Context with connection information</param> /// <param name="web">Site to be processed - can be root web or sub site</param> /// <param name="themeName">Name for the new theme</param> /// <param name="colorFilePath">Color file for the theme</param> /// <param name="fontFilePath">Font file for the theme</param> /// <param name="backgroundImagePath">Background image for the team</param> /// <param name="masterPageName">Master page name for the theme. Only name of the master page needed, no full path to catalog</param> public void DeployContosoThemeToWeb(ClientContext cc, Web web, string themeName, string colorFilePath, string fontFilePath, string backgroundImagePath, string masterPageName) { Web rootWeb; if (EnsureWeb(cc, web, "ServerRelativeUrl").ServerRelativeUrl.ToLowerInvariant() != EnsureSite(cc, cc.Site, "ServerRelativeUrl").ServerRelativeUrl.ToLowerInvariant()) { // get instances to root web, since we are processign currently sub site rootWeb = cc.Site.RootWeb; cc.Load(rootWeb); cc.ExecuteQuery(); } else { // Let's double check that the web is available rootWeb = EnsureWeb(cc, web, "Title"); } // Deploy files one by one to proper location if (!string.IsNullOrEmpty(colorFilePath)) { DeployFileToThemeFolderSite(cc, rootWeb, colorFilePath); } if (!string.IsNullOrEmpty(fontFilePath)) { DeployFileToThemeFolderSite(cc, rootWeb, fontFilePath); } if (!string.IsNullOrEmpty(backgroundImagePath)) { DeployFileToThemeFolderSite(cc, rootWeb, backgroundImagePath); } // Let's also add entry to the Theme catalog. This is not actually required, but provides visibility for the theme option, if manually changed AddNewThemeOptionToSite(cc, rootWeb, themeName, colorFilePath, fontFilePath, backgroundImagePath, masterPageName); }
public override bool WillExtract(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { return(!web.IsSubSite()); }
/// <summary> /// Activates a site collection or site scoped feature /// </summary> /// <param name="web">Web to be processed - can be root web or sub web</param> /// <param name="featureID">ID of the feature to activate</param> /// <param name="sandboxed">Set to true if the feature is defined in a sandboxed solution</param> /// <param name="pollingIntervalSeconds">The time in seconds between polls for "IsActive"</param> public static void ActivateFeature(this Web web, Guid featureID, bool sandboxed = false, int pollingIntervalSeconds = 30) { Log.Info(Constants.LOGGING_SOURCE, CoreResources.FeatureExtensions_ActivateWebFeature, featureID); Task.Run(() => web.ProcessFeature(featureID, true, sandboxed, pollingIntervalSeconds)).GetAwaiter().GetResult(); }
/// <summary> /// Checks if a feature is active /// </summary> /// <param name="web">Web to operate against</param> /// <param name="featureID">ID of the feature to check</param> /// <returns>True if active, false otherwise</returns> public static async Task <bool> IsFeatureActiveAsync(this Web web, Guid featureID) { await new SynchronizationContextRemover(); return(await IsFeatureActiveInternal(web.Features, featureID)); }
/// <summary> /// Checks if a feature is active /// </summary> /// <param name="web">Web to operate against</param> /// <param name="featureID">ID of the feature to check</param> /// <returns>True if active, false otherwise</returns> public static bool IsFeatureActive(this Web web, Guid featureID) { return(Task.Run(() => IsFeatureActiveInternal(web.Features, featureID)).GetAwaiter().GetResult()); }
/// <summary> /// Analyses a web for it's workflow usage /// </summary> /// <param name="cc">ClientContext instance used to retrieve workflow data</param> /// <returns>Duration of the workflow analysis</returns> public override TimeSpan Analyze(ClientContext cc) { try { // Workflow analysis does not work as the xoml / xaml files can't be read with Sites.Read.All permission if (!this.ScanJob.AppOnlyHasFullControl) { return(TimeSpan.Zero); } Web web = cc.Web; // Pre-load needed properties in a single call cc.Load(web, w => w.Id, w => w.ServerRelativeUrl, w => w.Url, w => w.WorkflowTemplates, w => w.WorkflowAssociations); cc.Load(web, p => p.ContentTypes.Include(ct => ct.WorkflowAssociations, ct => ct.Name, ct => ct.StringId)); cc.Load(web, p => p.Lists.Include(li => li.Id, li => li.Title, li => li.Hidden, li => li.DefaultViewUrl, li => li.BaseTemplate, li => li.RootFolder.ServerRelativeUrl, li => li.ItemCount, li => li.WorkflowAssociations)); cc.ExecuteQueryRetry(); var lists = web.Lists; // ******************************************* // Site, reusable and list level 2013 workflow // ******************************************* // Retrieve the 2013 site level workflow definitions (including unpublished ones) WorkflowDefinition[] siteDefinitions = null; // Retrieve the 2013 site level workflow subscriptions WorkflowSubscription[] siteSubscriptions = null; try { var servicesManager = new WorkflowServicesManager(web.Context, web); var deploymentService = servicesManager.GetWorkflowDeploymentService(); var subscriptionService = servicesManager.GetWorkflowSubscriptionService(); var definitions = deploymentService.EnumerateDefinitions(false); web.Context.Load(definitions); var subscriptions = subscriptionService.EnumerateSubscriptions(); web.Context.Load(subscriptions); web.Context.ExecuteQueryRetry(); siteDefinitions = definitions.ToArray(); siteSubscriptions = subscriptions.ToArray(); } catch (ServerException ex) { // If there is no workflow service present in the farm this method will throw an error. // Swallow the exception } // We've found SP2013 site scoped workflows if (siteDefinitions != null && siteDefinitions.Count() > 0) { foreach (var siteDefinition in siteDefinitions.Where(p => p.RestrictToType.Equals("site", StringComparison.InvariantCultureIgnoreCase) || p.RestrictToType.Equals("universal", StringComparison.InvariantCultureIgnoreCase))) { // Check if this workflow is also in use var siteWorkflowSubscriptions = siteSubscriptions.Where(p => p.DefinitionId.Equals(siteDefinition.Id)); // Perform workflow analysis var workFlowAnalysisResult = WorkflowManager.Instance.ParseWorkflowDefinition(siteDefinition.Xaml, WorkflowTypes.SP2013); var workFlowTriggerAnalysisResult = WorkflowManager.Instance.ParseWorkflowTriggers(GetWorkflowPropertyBool(siteDefinition.Properties, "SPDConfig.StartOnCreate"), GetWorkflowPropertyBool(siteDefinition.Properties, "SPDConfig.StartOnChange"), GetWorkflowPropertyBool(siteDefinition.Properties, "SPDConfig.StartManually")); if (siteWorkflowSubscriptions.Count() > 0) { foreach (var siteWorkflowSubscription in siteWorkflowSubscriptions) { WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = "", ListUrl = "", ContentTypeId = "", ContentTypeName = "", Version = "2013", Scope = "Site", RestrictToType = siteDefinition.RestrictToType, DefinitionName = siteDefinition.DisplayName, DefinitionDescription = siteDefinition.Description, SubscriptionName = siteWorkflowSubscription.Name, HasSubscriptions = true, Enabled = siteWorkflowSubscription.Enabled, DefinitionId = siteDefinition.Id, IsOOBWorkflow = false, SubscriptionId = siteWorkflowSubscription.Id, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, UnsupportedActionsInFlow = workFlowAnalysisResult?.UnsupportedActions, UnsupportedActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.UnsupportedAccountCount : 0, LastDefinitionEdit = GetWorkflowPropertyDateTime(siteDefinition.Properties, "Definition.ModifiedDateUTC"), LastSubscriptionEdit = GetWorkflowPropertyDateTime(siteWorkflowSubscription.PropertyDefinitions, "SharePointWorkflowContext.Subscription.ModifiedDateUTC"), }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2013 site workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } else { WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = "", ListUrl = "", ContentTypeId = "", ContentTypeName = "", Version = "2013", Scope = "Site", RestrictToType = siteDefinition.RestrictToType, DefinitionName = siteDefinition.DisplayName, DefinitionDescription = siteDefinition.Description, SubscriptionName = "", HasSubscriptions = false, Enabled = false, DefinitionId = siteDefinition.Id, IsOOBWorkflow = false, SubscriptionId = Guid.Empty, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UnsupportedActionsInFlow = workFlowAnalysisResult?.UnsupportedActions, UnsupportedActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.UnsupportedAccountCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, LastDefinitionEdit = GetWorkflowPropertyDateTime(siteDefinition.Properties, "Definition.ModifiedDateUTC"), }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2013 site workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } } // We've found SP2013 list scoped workflows if (siteDefinitions != null && siteDefinitions.Count() > 0) { foreach (var listDefinition in siteDefinitions.Where(p => p.RestrictToType.Equals("list", StringComparison.InvariantCultureIgnoreCase) || p.RestrictToType.Equals("universal", StringComparison.InvariantCultureIgnoreCase))) { // Check if this workflow is also in use var listWorkflowSubscriptions = siteSubscriptions.Where(p => p.DefinitionId.Equals(listDefinition.Id)); // Perform workflow analysis var workFlowAnalysisResult = WorkflowManager.Instance.ParseWorkflowDefinition(listDefinition.Xaml, WorkflowTypes.SP2013); var workFlowTriggerAnalysisResult = WorkflowManager.Instance.ParseWorkflowTriggers(GetWorkflowPropertyBool(listDefinition.Properties, "SPDConfig.StartOnCreate"), GetWorkflowPropertyBool(listDefinition.Properties, "SPDConfig.StartOnChange"), GetWorkflowPropertyBool(listDefinition.Properties, "SPDConfig.StartManually")); if (listWorkflowSubscriptions.Count() > 0) { foreach (var listWorkflowSubscription in listWorkflowSubscriptions) { Guid associatedListId = Guid.Empty; string associatedListTitle = ""; string associatedListUrl = ""; if (Guid.TryParse(GetWorkflowProperty(listWorkflowSubscription, "Microsoft.SharePoint.ActivationProperties.ListId"), out Guid associatedListIdValue)) { associatedListId = associatedListIdValue; // Lookup this list and update title and url var listLookup = lists.Where(p => p.Id.Equals(associatedListId)).FirstOrDefault(); if (listLookup != null) { associatedListTitle = listLookup.Title; associatedListUrl = listLookup.RootFolder.ServerRelativeUrl; } } WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = associatedListTitle, ListUrl = associatedListUrl, ListId = associatedListId, ContentTypeId = "", ContentTypeName = "", Version = "2013", Scope = "List", RestrictToType = listDefinition.RestrictToType, DefinitionName = listDefinition.DisplayName, DefinitionDescription = listDefinition.Description, SubscriptionName = listWorkflowSubscription.Name, HasSubscriptions = true, Enabled = listWorkflowSubscription.Enabled, DefinitionId = listDefinition.Id, IsOOBWorkflow = false, SubscriptionId = listWorkflowSubscription.Id, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, UnsupportedActionsInFlow = workFlowAnalysisResult?.UnsupportedActions, UnsupportedActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.UnsupportedAccountCount : 0, LastDefinitionEdit = GetWorkflowPropertyDateTime(listDefinition.Properties, "Definition.ModifiedDateUTC"), LastSubscriptionEdit = GetWorkflowPropertyDateTime(listWorkflowSubscription.PropertyDefinitions, "SharePointWorkflowContext.Subscription.ModifiedDateUTC"), }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2013 list workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } else { WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = "", ListUrl = "", ListId = Guid.Empty, ContentTypeId = "", ContentTypeName = "", Version = "2013", Scope = "List", RestrictToType = listDefinition.RestrictToType, DefinitionName = listDefinition.DisplayName, DefinitionDescription = listDefinition.Description, SubscriptionName = "", HasSubscriptions = false, Enabled = false, DefinitionId = listDefinition.Id, IsOOBWorkflow = false, SubscriptionId = Guid.Empty, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, UnsupportedActionsInFlow = workFlowAnalysisResult?.UnsupportedActions, UnsupportedActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.UnsupportedAccountCount : 0, LastDefinitionEdit = GetWorkflowPropertyDateTime(listDefinition.Properties, "Definition.ModifiedDateUTC"), }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2013 list workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } } // *********************************************** // Site, list and content type level 2010 workflow // *********************************************** // Find all places where we have workflows associated (=subscribed) to SharePoint objects if (web.WorkflowAssociations.Count > 0) { foreach (var workflowAssociation in web.WorkflowAssociations) { this.sp2010WorkflowAssociations.Add(new SP2010WorkFlowAssociation() { Scope = "Site", WorkflowAssociation = workflowAssociation }); } } foreach (var list in lists.Where(p => p.WorkflowAssociations.Count > 0)) { foreach (var workflowAssociation in list.WorkflowAssociations) { this.sp2010WorkflowAssociations.Add(new SP2010WorkFlowAssociation() { Scope = "List", WorkflowAssociation = workflowAssociation, AssociatedList = list }); } } foreach (var ct in web.ContentTypes.Where(p => p.WorkflowAssociations.Count > 0)) { foreach (var workflowAssociation in ct.WorkflowAssociations) { this.sp2010WorkflowAssociations.Add(new SP2010WorkFlowAssociation() { Scope = "ContentType", WorkflowAssociation = workflowAssociation, AssociatedContentType = ct }); } } // Process 2010 worflows List <Guid> processedWorkflowAssociations = new List <Guid>(this.sp2010WorkflowAssociations.Count); if (web.WorkflowTemplates.Count > 0) { // Process the templates foreach (var workflowTemplate in web.WorkflowTemplates) { // do we have workflows associated for this template? var associatedWorkflows = this.sp2010WorkflowAssociations.Where(p => p.WorkflowAssociation.BaseId.Equals(workflowTemplate.Id)); if (associatedWorkflows.Count() > 0) { // Perform workflow analysis // If returning null than this workflow template was an OOB workflow one WorkflowActionAnalysis workFlowAnalysisResult = null; var loadedWorkflow = LoadWorkflowDefinition(cc, workflowTemplate); if (!string.IsNullOrEmpty(loadedWorkflow?.Item1)) { workFlowAnalysisResult = WorkflowManager.Instance.ParseWorkflowDefinition(loadedWorkflow.Item1, WorkflowTypes.SP2010); } foreach (var associatedWorkflow in associatedWorkflows) { processedWorkflowAssociations.Add(associatedWorkflow.WorkflowAssociation.Id); // Skip previous versions of a workflow // TODO: non-english sites will use another string if (associatedWorkflow.WorkflowAssociation.Name.Contains("(Previous Version:")) { continue; } var workFlowTriggerAnalysisResult = WorkflowManager.Instance.ParseWorkflowTriggers(associatedWorkflow.WorkflowAssociation.AutoStartCreate, associatedWorkflow.WorkflowAssociation.AutoStartChange, associatedWorkflow.WorkflowAssociation.AllowManual); WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.Title : "", ListUrl = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.RootFolder.ServerRelativeUrl : "", ListId = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.Id : Guid.Empty, ContentTypeId = associatedWorkflow.AssociatedContentType != null ? associatedWorkflow.AssociatedContentType.StringId : "", ContentTypeName = associatedWorkflow.AssociatedContentType != null ? associatedWorkflow.AssociatedContentType.Name : "", Version = "2010", Scope = associatedWorkflow.Scope, RestrictToType = "N/A", DefinitionName = workflowTemplate.Name, DefinitionDescription = workflowTemplate.Description, SubscriptionName = associatedWorkflow.WorkflowAssociation.Name, HasSubscriptions = true, Enabled = associatedWorkflow.WorkflowAssociation.Enabled, DefinitionId = workflowTemplate.Id, IsOOBWorkflow = IsOOBWorkflow(workflowTemplate.Id.ToString()), SubscriptionId = associatedWorkflow.WorkflowAssociation.Id, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, UnsupportedActionsInFlow = workFlowAnalysisResult?.UnsupportedActions, UnsupportedActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.UnsupportedAccountCount : 0, LastDefinitionEdit = loadedWorkflow != null ? loadedWorkflow.Item2 : associatedWorkflow.WorkflowAssociation.Modified, LastSubscriptionEdit = associatedWorkflow.WorkflowAssociation.Modified, }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2010 {associatedWorkflow.Scope} type workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } else { // Only add non OOB workflow templates when there's no associated workflow - makes the dataset smaller if (!IsOOBWorkflow(workflowTemplate.Id.ToString())) { // Perform workflow analysis WorkflowActionAnalysis workFlowAnalysisResult = null; var loadedWorkflow = LoadWorkflowDefinition(cc, workflowTemplate); if (!string.IsNullOrEmpty(loadedWorkflow?.Item1)) { workFlowAnalysisResult = WorkflowManager.Instance.ParseWorkflowDefinition(loadedWorkflow.Item1, WorkflowTypes.SP2010); } var workFlowTriggerAnalysisResult = WorkflowManager.Instance.ParseWorkflowTriggers(workflowTemplate.AutoStartCreate, workflowTemplate.AutoStartChange, workflowTemplate.AllowManual); WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = "", ListUrl = "", ListId = Guid.Empty, ContentTypeId = "", ContentTypeName = "", Version = "2010", Scope = "", RestrictToType = "N/A", DefinitionName = workflowTemplate.Name, DefinitionDescription = workflowTemplate.Description, SubscriptionName = "", HasSubscriptions = false, Enabled = false, DefinitionId = workflowTemplate.Id, IsOOBWorkflow = IsOOBWorkflow(workflowTemplate.Id.ToString()), SubscriptionId = Guid.Empty, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, LastDefinitionEdit = loadedWorkflow != null ? loadedWorkflow.Item2 : DateTime.MinValue, }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2010 type workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } } } // Are there associated workflows for which we did not find a template (especially when the WF is created for a list) foreach (var associatedWorkflow in this.sp2010WorkflowAssociations) { if (!processedWorkflowAssociations.Contains(associatedWorkflow.WorkflowAssociation.Id)) { // Skip previous versions of a workflow // TODO: non-english sites will use another string if (associatedWorkflow.WorkflowAssociation.Name.Contains("(Previous Version:")) { continue; } // Perform workflow analysis WorkflowActionAnalysis workFlowAnalysisResult = null; var loadedWorkflow = LoadWorkflowDefinition(cc, associatedWorkflow.WorkflowAssociation); if (!string.IsNullOrEmpty(loadedWorkflow?.Item1)) { workFlowAnalysisResult = WorkflowManager.Instance.ParseWorkflowDefinition(loadedWorkflow.Item1, WorkflowTypes.SP2010); } var workFlowTriggerAnalysisResult = WorkflowManager.Instance.ParseWorkflowTriggers(associatedWorkflow.WorkflowAssociation.AutoStartCreate, associatedWorkflow.WorkflowAssociation.AutoStartChange, associatedWorkflow.WorkflowAssociation.AllowManual); WorkflowScanResult workflowScanResult = new WorkflowScanResult() { SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, ListTitle = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.Title : "", ListUrl = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.RootFolder.ServerRelativeUrl : "", ListId = associatedWorkflow.AssociatedList != null ? associatedWorkflow.AssociatedList.Id : Guid.Empty, ContentTypeId = associatedWorkflow.AssociatedContentType != null ? associatedWorkflow.AssociatedContentType.StringId : "", ContentTypeName = associatedWorkflow.AssociatedContentType != null ? associatedWorkflow.AssociatedContentType.Name : "", Version = "2010", Scope = associatedWorkflow.Scope, RestrictToType = "N/A", DefinitionName = associatedWorkflow.WorkflowAssociation.Name, DefinitionDescription = "", SubscriptionName = associatedWorkflow.WorkflowAssociation.Name, HasSubscriptions = true, Enabled = associatedWorkflow.WorkflowAssociation.Enabled, DefinitionId = Guid.Empty, IsOOBWorkflow = false, SubscriptionId = associatedWorkflow.WorkflowAssociation.Id, UsedActions = workFlowAnalysisResult?.WorkflowActions, ActionCount = workFlowAnalysisResult != null ? workFlowAnalysisResult.ActionCount : 0, UsedTriggers = workFlowTriggerAnalysisResult?.WorkflowTriggers, LastSubscriptionEdit = associatedWorkflow.WorkflowAssociation.Modified, LastDefinitionEdit = loadedWorkflow != null ? loadedWorkflow.Item2 : associatedWorkflow.WorkflowAssociation.Modified, }; if (!this.ScanJob.WorkflowScanResults.TryAdd($"workflowScanResult.SiteURL.{Guid.NewGuid()}", workflowScanResult)) { ScanError error = new ScanError() { Error = $"Could not add 2010 {associatedWorkflow.Scope} type workflow scan result for {workflowScanResult.SiteColUrl}", SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", }; this.ScanJob.ScanErrors.Push(error); } } } } catch (Exception ex) { ScanError error = new ScanError() { Error = ex.Message, SiteColUrl = this.SiteCollectionUrl, SiteURL = this.SiteUrl, Field1 = "WorkflowAnalyzer", Field2 = ex.StackTrace, }; // Send error to telemetry to make scanner better if (this.ScanJob.ScannerTelemetry != null) { this.ScanJob.ScannerTelemetry.LogScanError(ex, error); } this.ScanJob.ScanErrors.Push(error); Console.WriteLine("Error during Workflow analysis for site {1}: {0}", ex.Message, $"{this.SiteUrl}"); } finally { this.StopTime = DateTime.Now; } // return the duration of this scan return(new TimeSpan((this.StopTime.Subtract(this.StartTime).Ticks))); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { using (var scope = new PnPMonitoredScope(this.Name)) { var context = web.Context as ClientContext; web.EnsureProperties(w => w.ServerRelativeUrl); // Check if this is not a noscript site as we're not allowed to update some properties bool isNoScriptSite = web.IsNoScriptSite(); foreach (var clientSidePage in template.ClientSidePages) { // determine pages library string pagesLibrary = "SitePages"; string pageName = $"{System.IO.Path.GetFileNameWithoutExtension(clientSidePage.PageName)}.aspx"; string url = $"{pagesLibrary}/{pageName}"; url = UrlUtility.Combine(web.ServerRelativeUrl, url); var exists = true; Microsoft.SharePoint.Client.File file = null; try { file = web.GetFileByServerRelativeUrl(url); web.Context.Load(file); web.Context.ExecuteQueryRetry(); } catch (ServerException ex) { if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException") { exists = false; } } Pages.ClientSidePage page = null; if (exists) { if (clientSidePage.Overwrite) { // Get the existing page page = web.LoadClientSidePage(pageName); // Clear the page page.ClearPage(); } else { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ClientSidePages_NoOverWrite, pageName); } } else { // Create new client side page page = web.AddClientSidePage(pageName); } // Load existing available controls var componentsToAdd = page.AvailableClientSideComponents(); // if no section specified then add a default single column section if (!clientSidePage.Sections.Any()) { clientSidePage.Sections.Add(new CanvasSection() { Type = CanvasSectionType.OneColumn, Order = 10 }); } int sectionCount = -1; // Apply the "layout" and content foreach (var section in clientSidePage.Sections) { sectionCount++; switch (section.Type) { case CanvasSectionType.OneColumn: page.AddSection(Pages.CanvasSectionTemplate.OneColumn, section.Order); break; case CanvasSectionType.OneColumnFullWidth: page.AddSection(Pages.CanvasSectionTemplate.OneColumnFullWidth, section.Order); break; case CanvasSectionType.TwoColumn: page.AddSection(Pages.CanvasSectionTemplate.TwoColumn, section.Order); break; case CanvasSectionType.ThreeColumn: page.AddSection(Pages.CanvasSectionTemplate.ThreeColumn, section.Order); break; case CanvasSectionType.TwoColumnLeft: page.AddSection(Pages.CanvasSectionTemplate.TwoColumnLeft, section.Order); break; case CanvasSectionType.TwoColumnRight: page.AddSection(Pages.CanvasSectionTemplate.TwoColumnRight, section.Order); break; default: page.AddSection(Pages.CanvasSectionTemplate.OneColumn, section.Order); break; } // Add controls to the section if (section.Controls.Any()) { // Safety measure: reset column order to 1 for columns marked with 0 or lower foreach (var control in section.Controls.Where(p => p.Column <= 0).ToList()) { control.Column = 1; } foreach (var control in section.Controls) { Pages.ClientSideComponent baseControl = null; // Is it a text control? if (control.Type == WebPartType.Text) { Pages.ClientSideText textControl = new Pages.ClientSideText(); if (control.ControlProperties.Any()) { var textProperty = control.ControlProperties.First(); textControl.Text = textProperty.Value; // Reduce column number by 1 due 0 start indexing page.AddControl(textControl, page.Sections[sectionCount].Columns[control.Column - 1], control.Order); } } // It is a web part else { // Is a custom developed client side web part (3rd party) if (control.Type == WebPartType.Custom) { if (!string.IsNullOrEmpty(control.CustomWebPartName)) { baseControl = componentsToAdd.Where(p => p.Name.Equals(control.CustomWebPartName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); } else if (control.ControlId != Guid.Empty) { baseControl = componentsToAdd.Where(p => p.Id.Equals($"{{{control.ControlId.ToString()}}}", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); } } // Is an OOB client side web part (1st party) else { string webPartName = ""; switch (control.Type) { case WebPartType.Image: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.Image); break; case WebPartType.BingMap: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.BingMap); break; case WebPartType.ContentEmbed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.ContentEmbed); break; case WebPartType.ContentRollup: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.ContentRollup); break; case WebPartType.DocumentEmbed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.DocumentEmbed); break; case WebPartType.Events: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.Events); break; case WebPartType.GroupCalendar: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.GroupCalendar); break; case WebPartType.Hero: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.Hero); break; case WebPartType.ImageGallery: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.ImageGallery); break; case WebPartType.LinkPreview: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.LinkPreview); break; case WebPartType.List: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.List); break; case WebPartType.NewsFeed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.NewsFeed); break; case WebPartType.NewsReel: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.NewsReel); break; case WebPartType.PageTitle: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.PageTitle); break; case WebPartType.People: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.People); break; case WebPartType.PowerBIReportEmbed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.PowerBIReportEmbed); break; case WebPartType.QuickChart: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.QuickChart); break; case WebPartType.QuickLinks: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.QuickLinks); break; case WebPartType.SiteActivity: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.SiteActivity); break; case WebPartType.VideoEmbed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.VideoEmbed); break; case WebPartType.YammerEmbed: webPartName = Pages.ClientSidePage.ClientSideWebPartEnumToName(Pages.DefaultClientSideWebParts.YammerEmbed); break; default: break; } baseControl = componentsToAdd.Where(p => p.Name.Equals(webPartName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); } if (baseControl != null) { Pages.ClientSideWebPart myWebPart = new Pages.ClientSideWebPart(baseControl) { Order = control.Order }; // Reduce column number by 1 due 0 start indexing page.AddControl(myWebPart, page.Sections[sectionCount].Columns[control.Column - 1], control.Order); // set properties using json string if (!String.IsNullOrEmpty(control.JsonControlData)) { myWebPart.PropertiesJson = control.JsonControlData; } // set using property collection if (control.ControlProperties.Any()) { // grab the "default" properties so we can deduct their types, needed to correctly apply the set properties var controlManifest = JObject.Parse(baseControl.Manifest); JToken controlProperties = null; if (controlManifest != null) { controlProperties = controlManifest.SelectToken("preconfiguredEntries[0].properties"); } foreach (var property in control.ControlProperties) { Type propertyType = typeof(string); if (controlProperties != null) { var defaultProperty = controlProperties.SelectToken(property.Key, false); if (defaultProperty != null) { propertyType = Type.GetType($"System.{defaultProperty.Type.ToString()}"); if (propertyType == null) { if (defaultProperty.Type.ToString().Equals("integer", StringComparison.InvariantCultureIgnoreCase)) { propertyType = typeof(int); } } } } myWebPart.Properties[property.Key] = JToken.FromObject(Convert.ChangeType(parser.ParseString(property.Value), propertyType)); } } } else { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ClientSidePages_BaseControlNotFound, control.ControlId, control.CustomWebPartName); } } } } } // Persist the page page.Save(pageName); // Make it a news page if requested if (clientSidePage.PromoteAsNewsArticle) { page.PromoteAsNewsArticle(); } } } return(parser); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { using (var scope = new PnPMonitoredScope(this.Name)) { if (template.ApplicationLifecycleManagement != null) { var manager = new AppManager(web.Context as ClientContext); // The ALM API do not support the local Site Collection App Catalog // Thus, so far we skip the AppCatalog section // NOOP if (template.ApplicationLifecycleManagement.Apps != null && template.ApplicationLifecycleManagement.Apps.Count > 0) { //Get tenant app catalog var appCatalogUri = web.GetAppCatalog(); if (appCatalogUri != null) { // Get the apps already installed in the site var siteApps = manager.GetAvailable()?.Where(a => a.InstalledVersion != null)?.ToList(); foreach (var app in template.ApplicationLifecycleManagement.Apps) { var appId = Guid.Parse(parser.ParseString(app.AppId)); var alreadyExists = siteApps.Any(a => a.Id == appId); var working = false; if (app.Action == AppAction.Install && !alreadyExists) { manager.Install(appId); working = true; } else if (app.Action == AppAction.Install && alreadyExists) { WriteMessage($"App with ID {appId} already exists in the target site and will be skipped", ProvisioningMessageType.Warning); } else if (app.Action == AppAction.Uninstall && alreadyExists) { manager.Uninstall(appId); working = true; } else if (app.Action == AppAction.Uninstall && !alreadyExists) { WriteMessage($"App with ID {appId} does not exist in the target site and cannot be uninstalled", ProvisioningMessageType.Warning); } else if (app.Action == AppAction.Update && alreadyExists) { manager.Upgrade(appId); working = true; } else if (app.Action == AppAction.Update && !alreadyExists) { WriteMessage($"App with ID {appId} does not exist in the target site and cannot be updated", ProvisioningMessageType.Warning); } if (app.SyncMode == SyncMode.Synchronously && working) { // We need to wait for the app management // to be completed before proceeding switch (app.Action) { case AppAction.Install: case AppAction.Update: { PollforAppInstalled(manager, appId); break; } case AppAction.Uninstall: { PollforAppUninstalled(manager, appId); break; } } } } } else { WriteMessage($"Tenant app catalog doesn't exist. ALM step will be skipped.", ProvisioningMessageType.Warning); } } } } return(parser); }
public override ProvisioningTemplateCreationInformation GetProvisionInformation(Web web, Handlers handlers) { var templateCi = new ProvisioningTemplateCreationInformation(web) { IncludeContentTypesFromSyndication = true }; templateCi.HandlersToProcess = handlers; return(templateCi); }
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector, PnPMonitoredScope scope, List <Microsoft.SharePoint.Client.ContentType> existingCTs = null, List <Microsoft.SharePoint.Client.Field> existingFields = null, bool isNoScriptSite = false) { var name = parser.ParseString(templateContentType.Name); var description = parser.ParseString(templateContentType.Description); var id = parser.ParseString(templateContentType.Id); var group = parser.ParseString(templateContentType.Group); var createdCT = web.CreateContentType(name, description, id, group); foreach (var fieldRef in templateContentType.FieldRefs) { Microsoft.SharePoint.Client.Field field = null; try { field = web.AvailableFields.GetById(fieldRef.Id); } catch (ArgumentException) { if (!string.IsNullOrEmpty(fieldRef.Name)) { field = web.AvailableFields.GetByInternalNameOrTitle(fieldRef.Name); } } // Add it to the target content type // Notice that this code will fail if the field does not exist web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden); } // Add new CTs parser.AddToken(new ContentTypeIdToken(web, name, id)); #if !ONPREMISES // Set resources if (templateContentType.Name.ContainsResourceToken()) { createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser); } if (templateContentType.Description.ContainsResourceToken()) { createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser); } #endif //Reorder the elements so that the new created Content Type has the same order as defined in the //template. The order can be different if the new Content Type inherits from another Content Type. //In this case the new Content Type has all field of the original Content Type and missing fields //will be added at the end. To fix this issue we ordering the fields once more. createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => parser.ParseString(fld.Name)).ToArray()); createdCT.ReadOnly = templateContentType.ReadOnly; createdCT.Hidden = templateContentType.Hidden; createdCT.Sealed = templateContentType.Sealed; if (templateContentType.DocumentSetTemplate == null) { // Only apply a document template when the contenttype is not a document set if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate))) { createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate); } } // Skipping updates of forms as we can't upload forms to noscript sites if (!isNoScriptSite) { if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl))) { createdCT.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl); } if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl))) { createdCT.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl); } if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl))) { createdCT.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl); } } else { if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) || !string.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) || !string.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl))) { // log message scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, name); } } createdCT.Update(true); web.Context.ExecuteQueryRetry(); // If the CT is a DocumentSet if (templateContentType.DocumentSetTemplate != null) { // Retrieve a reference to the DocumentSet Content Type Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate documentSetTemplate = Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, createdCT); // Load the collections to allow for deletion scenarions web.Context.Load(documentSetTemplate, d => d.AllowedContentTypes, d => d.DefaultDocuments, d => d.SharedFields, d => d.WelcomePageFields); web.Context.ExecuteQueryRetry(); if (!String.IsNullOrEmpty(templateContentType.DocumentSetTemplate.WelcomePage)) { // TODO: Customize the WelcomePage of the DocumentSet } // Add additional content types to the set of allowed content types bool hasDefaultDocumentContentTypeInTemplate = false; foreach (String ctId in templateContentType.DocumentSetTemplate.AllowedContentTypes) { Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == ctId); if (ct != null) { if (ct.Id.StringValue.Equals("0x0101", StringComparison.InvariantCultureIgnoreCase)) { hasDefaultDocumentContentTypeInTemplate = true; } documentSetTemplate.AllowedContentTypes.Add(ct.Id); } } // If the default document content type (0x0101) is not in our definition then remove it if (!hasDefaultDocumentContentTypeInTemplate) { Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == "0x0101"); if (ct != null) { documentSetTemplate.AllowedContentTypes.Remove(ct.Id); } } if (!isNoScriptSite) { foreach (var doc in templateContentType.DocumentSetTemplate.DefaultDocuments) { Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == doc.ContentTypeId); if (ct != null) { using (Stream fileStream = connector.GetFileStream(doc.FileSourcePath)) { documentSetTemplate.DefaultDocuments.Add(doc.Name, ct.Id, ReadFullStream(fileStream)); } } } } else { if (templateContentType.DocumentSetTemplate.DefaultDocuments.Any()) { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipDocumentSetDefaultDocuments, name); } } foreach (var sharedField in templateContentType.DocumentSetTemplate.SharedFields) { Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == sharedField); if (field != null) { documentSetTemplate.SharedFields.Add(field); } } foreach (var welcomePageField in templateContentType.DocumentSetTemplate.WelcomePageFields) { Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == welcomePageField); if (field != null) { documentSetTemplate.WelcomePageFields.Add(field); } } documentSetTemplate.Update(true); web.Context.ExecuteQueryRetry(); } else if (templateContentType.Id.StartsWith(BuiltInContentTypeId.Workflow2013Task + "00")) { // If the Workflow Task (SP2013) contains more than one outcomeChoice, the Form UI will not show // the buttons associated each to choices, but fallback to classic Save and Cancel buttons. // +"00" is used to target only inherited content types and not alter OOB var outcomeFields = web.Context.LoadQuery( createdCT.Fields.Where(f => f.TypeAsString == "OutcomeChoice")); web.Context.ExecuteQueryRetry(); if (outcomeFields.Count() > 1) { // 2 OutcomeChoice specified means the user has certainly push its own. // Let's remove the default outcome field var field = outcomeFields.FirstOrDefault(f => f.StaticName == "TaskOutcome"); if (field != null) { var fl = createdCT.FieldLinks.GetById(field.Id); fl.DeleteObject(); createdCT.Update(true); web.Context.ExecuteQueryRetry(); } } } web.Context.Load(createdCT); web.Context.ExecuteQueryRetry(); return(createdCT); }
public static async Task DownloadTitle(string id, string outputDir, string contentType, string version) { #region Setup var workingId = id.ToUpper(); if (contentType == "Patch") { workingId = $"0005000E{workingId.Substring(8)}"; if (Settings.Cemu173Patch) { outputDir = Path.Combine(Settings.BasePatchDir, workingId.Substring(8)); } } if (contentType == "DLC") { workingId = $"0005000C{workingId.Substring(8)}"; if (Settings.Cemu173Patch) { outputDir = Path.Combine(Settings.BasePatchDir, workingId.Substring(8), "aoc"); } } Title title; if ((title = SearchById(workingId)) == null) { throw new Exception("Could not locate the title key"); } var key = title.Key; var name = title.Name; if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(name)) { return; } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } var str = $"Download {contentType} content to the following location?\n\"{outputDir}\""; var result = MessageBox.Show(str, name, MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { return; } Toolbelt.AppendLog($"Output Directory '{outputDir}'"); #endregion #region TMD Toolbelt.AppendLog(" - Loading TMD..."); TMD tmd = null; var nusUrls = new List <string> { "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/", "http://nus.cdn.shop.wii.com/ccs/download/", "http://ccs.cdn.c.shop.nintendowifi.net/ccs/download/" }; foreach (var nusUrl in nusUrls) { string titleUrl = $"{nusUrl}{workingId}/"; tmd = await LoadTmd(id, key, outputDir, titleUrl, version); if (tmd != null) { break; } } if (tmd == null) { TextLog.MesgLog.WriteError("Could not locate TMD. Is this content request valid?"); return; } #endregion #region Ticket Toolbelt.AppendLog("Generating Ticket..."); var ticket = Ticket.Load(MapleTicket.Create(SearchById(id))); ticket.Save(Path.Combine(outputDir, "cetk")); #endregion #region Content Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion}"); Toolbelt.SetStatus($"Output Directory: {outputDir}"); foreach (var nusUrl in nusUrls) { var url = nusUrl + workingId; if (await DownloadContent(tmd, outputDir, url) != 1) { continue; } Toolbelt.AppendLog(string.Empty); Toolbelt.AppendLog(" - Decrypting Content"); Toolbelt.AppendLog(" + This may take a minute. Please wait..."); Toolbelt.SetStatus("Decrypting Content. This may take a minute. Please wait...", Color.OrangeRed); var code = await Toolbelt.CDecrypt(outputDir); if (code != 0) { Toolbelt.AppendLog($"Error while decrypting {name}"); return; } CleanUpdate(outputDir, tmd); break; } #endregion Web.ResetDownloadProgressChanged(); Toolbelt.AppendLog($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); Toolbelt.SetStatus($"[+] [{contentType}] {name} v{tmd.TitleVersion} Finished."); }
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite = false) { var isDirty = false; var reOrderFields = false; if (existingContentType.Hidden != templateContentType.Hidden) { scope.LogPropertyUpdate("Hidden"); existingContentType.Hidden = templateContentType.Hidden; isDirty = true; } if (existingContentType.ReadOnly != templateContentType.ReadOnly) { scope.LogPropertyUpdate("ReadOnly"); existingContentType.ReadOnly = templateContentType.ReadOnly; isDirty = true; } if (existingContentType.Sealed != templateContentType.Sealed) { scope.LogPropertyUpdate("Sealed"); existingContentType.Sealed = templateContentType.Sealed; isDirty = true; } if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description)) { scope.LogPropertyUpdate("Description"); existingContentType.Description = parser.ParseString(templateContentType.Description); isDirty = true; } if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate)) { scope.LogPropertyUpdate("DocumentTemplate"); existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate); isDirty = true; } if (existingContentType.Name != parser.ParseString(templateContentType.Name)) { scope.LogPropertyUpdate("Name"); existingContentType.Name = parser.ParseString(templateContentType.Name); isDirty = true; // CT is being renamed, add an extra token to the tokenparser parser.AddToken(new ContentTypeIdToken(web, existingContentType.Name, existingContentType.StringId)); } if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group)) { scope.LogPropertyUpdate("Group"); existingContentType.Group = parser.ParseString(templateContentType.Group); isDirty = true; } if (!isNoScriptSite) { if (templateContentType.DisplayFormUrl != null && existingContentType.DisplayFormUrl != parser.ParseString(templateContentType.DisplayFormUrl)) { scope.LogPropertyUpdate("DisplayFormUrl"); existingContentType.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl); isDirty = true; } if (templateContentType.EditFormUrl != null && existingContentType.EditFormUrl != parser.ParseString(templateContentType.EditFormUrl)) { scope.LogPropertyUpdate("EditFormUrl"); existingContentType.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl); isDirty = true; } if (templateContentType.NewFormUrl != null && existingContentType.NewFormUrl != parser.ParseString(templateContentType.NewFormUrl)) { scope.LogPropertyUpdate("NewFormUrl"); existingContentType.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl); isDirty = true; } } else { if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) || !string.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) || !string.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl))) { // log message scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, existingContentType.Name); } } #if !SP2013 if (templateContentType.Name.ContainsResourceToken()) { existingContentType.NameResource.SetUserResourceValue(templateContentType.Name, parser); isDirty = true; } if (templateContentType.Description.ContainsResourceToken()) { existingContentType.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser); isDirty = true; } #endif if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } // Set flag to reorder fields CT fields are not equal to template fields var existingFieldNames = existingContentType.FieldLinks.AsEnumerable().Select(fld => fld.Name).ToArray(); var ctFieldNames = templateContentType.FieldRefs.Select(fld => parser.ParseString(fld.Name)).ToArray(); reOrderFields = !existingFieldNames.SequenceEqual(ctFieldNames); // Delta handling existingContentType.EnsureProperty(c => c.FieldLinks); var targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList(); var sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList(); var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray(); if (fieldsNotPresentInTarget.Any()) { // Set flag to reorder fields when new fields are added. reOrderFields = true; foreach (var fieldId in fieldsNotPresentInTarget) { var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); var field = web.AvailableFields.GetById(fieldRef.Id); scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, fieldId); web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden); } } // Reorder fields if (reOrderFields) { existingContentType.FieldLinks.Reorder(ctFieldNames); isDirty = true; } foreach (var fieldId in targetIds.Intersect(sourceIds)) { var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId); var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); if (fieldRef != null) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Field__0__exists_in_content_type, fieldId); if (fieldLink.Required != fieldRef.Required) { scope.LogPropertyUpdate("Required"); fieldLink.Required = fieldRef.Required; isDirty = true; } if (fieldLink.Hidden != fieldRef.Hidden) { scope.LogPropertyUpdate("Hidden"); fieldLink.Hidden = fieldRef.Hidden; isDirty = true; } } } // The new CT is a DocumentSet, and the target should be, as well if (templateContentType.DocumentSetTemplate != null) { if (!Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.IsChildOfDocumentSetContentType(web.Context, existingContentType).Value) { scope.LogError(CoreResources.Provisioning_ObjectHandlers_ContentTypes_InvalidDocumentSet_Update_Request, existingContentType.Id, existingContentType.Name); } else { Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate templateToUpdate = Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, existingContentType); // TODO: Implement Delta Handling scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_DocumentSet_DeltaHandling_OnHold, existingContentType.Id, existingContentType.Name); } } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } }
private IEnumerable <ContentType> GetEntities(Web web, PnPMonitoredScope scope, ProvisioningTemplateCreationInformation creationInfo, ProvisioningTemplate template) { var cts = web.ContentTypes; web.Context.Load(cts, ctCollection => ctCollection.IncludeWithDefaultProperties(ct => ct.FieldLinks, ct => ct.SchemaXmlWithResourceTokens)); web.Context.ExecuteQueryRetry(); if (cts.Count > 0 && web.IsSubSite()) { WriteMessage("We discovered content types in this subweb. While technically possible, we recommend moving these content types to the root site collection. Consider excluding them from this template.", ProvisioningMessageType.Warning); } List <ContentType> ctsToReturn = new List <ContentType>(); var currentCtIndex = 0; foreach (var ct in cts) { currentCtIndex++; WriteMessage($"Content Type|{ct.Name}|{currentCtIndex}|{cts.Count()}", ProvisioningMessageType.Progress); if (!BuiltInContentTypeId.Contains(ct.StringId) && (creationInfo.ContentTypeGroupsToInclude.Count == 0 || creationInfo.ContentTypeGroupsToInclude.Contains(ct.Group))) { // Exclude the content type if it's from syndication, and if the flag is not set if (!creationInfo.IncludeContentTypesFromSyndication && IsContentTypeFromSyndication(ct)) { scope.LogInfo($"Content type {ct.Name} excluded from export because it's a syndicated content type."); continue; } string ctDocumentTemplate = null; if (!string.IsNullOrEmpty(ct.DocumentTemplate)) { if (!ct.DocumentTemplate.StartsWith("_cts/")) { ctDocumentTemplate = ct.DocumentTemplate; } } var newCT = new ContentType( ct.StringId, ct.Name, ct.Description, ct.Group, ct.Sealed, ct.Hidden, ct.ReadOnly, ctDocumentTemplate, false, (from fieldLink in ct.FieldLinks.AsEnumerable <FieldLink>() select new FieldRef(fieldLink.Name) { Id = fieldLink.Id, Hidden = fieldLink.Hidden, Required = fieldLink.Required, }) ) { DisplayFormUrl = ct.DisplayFormUrl, EditFormUrl = ct.EditFormUrl, NewFormUrl = ct.NewFormUrl, }; if (creationInfo.PersistMultiLanguageResources) { #if !SP2013 // only persist language values for content types we actually will keep...no point in spending time on this is we clean the field afterwards var persistLanguages = true; if (creationInfo.BaseTemplate != null) { int index = creationInfo.BaseTemplate.ContentTypes.FindIndex(c => c.Id.Equals(ct.StringId)); if (index > -1) { persistLanguages = false; } } if (persistLanguages) { var escapedCTName = ct.Name.Replace(" ", "_"); if (UserResourceExtensions.PersistResourceValue(ct.NameResource, $"ContentType_{escapedCTName}_Title", template, creationInfo)) { newCT.Name = $"{{res:ContentType_{escapedCTName}_Title}}"; } if (UserResourceExtensions.PersistResourceValue(ct.DescriptionResource, $"ContentType_{escapedCTName}_Description", template, creationInfo)) { newCT.Description = $"{{res:ContentType_{escapedCTName}_Description}}"; } } #endif } // If the Content Type is a DocumentSet if (Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.IsChildOfDocumentSetContentType(web.Context, ct).Value || ct.StringId.StartsWith(BuiltInContentTypeId.DocumentSet)) // TODO: This is kind of an hack... we should find a better solution ... { Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate documentSetTemplate = Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, ct); // Retrieve the Document Set web.Context.Load(documentSetTemplate, t => t.AllowedContentTypes, t => t.DefaultDocuments, t => t.SharedFields, t => t.WelcomePageFields); web.Context.ExecuteQueryRetry(); newCT.DocumentSetTemplate = new DocumentSetTemplate( null, // TODO: WelcomePage not yet supported (from allowedCT in documentSetTemplate.AllowedContentTypes.AsEnumerable() select allowedCT.StringValue).ToArray(), (from defaultDocument in documentSetTemplate.DefaultDocuments.AsEnumerable() select new DefaultDocument { ContentTypeId = defaultDocument.ContentTypeId.StringValue, Name = defaultDocument.Name, FileSourcePath = String.Empty, // TODO: How can we extract the proper file?! }).ToArray(), (from sharedField in documentSetTemplate.SharedFields.AsEnumerable() select sharedField.Id).ToArray(), (from welcomePageField in documentSetTemplate.WelcomePageFields.AsEnumerable() select welcomePageField.Id).ToArray() ); } ctsToReturn.Add(newCT); } } WriteMessage("Done processing Content Types", ProvisioningMessageType.Completed); return(ctsToReturn); }
public override ProvisioningTemplateCreationInformation GetProvisionInformation(Web web, Handlers handlers) { var templateCi = new ProvisioningTemplateCreationInformation(web) { IncludeNativePublishingFiles = true, PersistBrandingFiles = true, PersistPublishingFiles = true }; templateCi.HandlersToProcess = handlers; templateCi.FileConnector = new FileSystemConnector(base.ExportPath, ""); return(templateCi); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { using (var scope = new PnPMonitoredScope(this.Name)) { // Check if this is not a noscript site as we're not allowed to update some properties bool isNoScriptSite = web.IsNoScriptSite(); web.Context.Load(web.ContentTypes, ct => ct.IncludeWithDefaultProperties(c => c.StringId, c => c.FieldLinks, c => c.FieldLinks.Include(fl => fl.Id, fl => fl.Required, fl => fl.Hidden))); web.Context.Load(web.Fields, fld => fld.IncludeWithDefaultProperties(f => f.Id)); web.Context.ExecuteQueryRetry(); var existingCTs = web.ContentTypes.ToList(); var existingFields = web.Fields.ToList(); var currentCtIndex = 0; var doProvision = true; if (web.IsSubSite() && !applyingInformation.ProvisionContentTypesToSubWebs) { WriteMessage("This template contains content types and you are provisioning to a subweb. If you still want to provision these content types, set the ProvisionContentTypesToSubWebs property to true.", ProvisioningMessageType.Warning); doProvision = false; } if (doProvision) { foreach (var ct in template.ContentTypes.OrderBy(ct => ct.Id)) // ordering to handle references to parent content types that can be in the same template { currentCtIndex++; WriteMessage($"Content Type|{ct.Name}|{currentCtIndex}|{template.ContentTypes.Count}", ProvisioningMessageType.Progress); var existingCT = existingCTs.FirstOrDefault(c => c.StringId.Equals(ct.Id, StringComparison.OrdinalIgnoreCase)); if (existingCT == null) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Creating_new_Content_Type___0_____1_, ct.Id, ct.Name); var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite); if (newCT != null) { existingCTs.Add(newCT); } } else { if (ct.Overwrite) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Recreating_existing_Content_Type___0_____1_, ct.Id, ct.Name); existingCT.DeleteObject(); web.Context.ExecuteQueryRetry(); var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite); if (newCT != null) { existingCTs.Add(newCT); } } else { // We can't update a sealed content type unless we change sealed to false if (!existingCT.Sealed || !ct.Sealed) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Updating_existing_Content_Type___0_____1_, ct.Id, ct.Name); UpdateContentType(web, existingCT, ct, parser, scope); } else { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Updating_existing_Content_Type_Sealed, ct.Id, ct.Name); } } } } } } WriteMessage($"Done processing Content Types", ProvisioningMessageType.Completed); return(parser); }
/// <summary> /// Extracts a client side page /// </summary> /// <param name="web">Web to extract the page from</param> /// <param name="template">Current provisioning template that will hold the extracted page</param> /// <param name="creationInfo">ProvisioningTemplateCreationInformation passed into the provisioning engine</param> /// <param name="scope">Scope used for logging</param> /// <param name="page">page to be exported</param> public void ExtractClientSidePage(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, PageToExport page) { bool excludeAuthorInformation = false; if (creationInfo.ExtractConfiguration != null && creationInfo.ExtractConfiguration.Pages != null) { excludeAuthorInformation = creationInfo.ExtractConfiguration.Pages.ExcludeAuthorInformation; } try { List <string> errorneousOrNonImageFileGuids = new List <string>(); var pageToExtract = web.LoadClientSidePage(page.PageName); if (pageToExtract.Sections.Count == 0 && pageToExtract.Controls.Count == 0 && page.IsHomePage) { // This is default home page which was not customized...and as such there's no page definition stored in the list item. We don't need to extact this page. scope.LogInfo(CoreResources.Provisioning_ObjectHandlers_ClientSidePageContents_DefaultHomePage); } else { // Get the page content type string pageContentTypeId = pageToExtract.PageListItem[ContentTypeIdField].ToString(); if (!string.IsNullOrEmpty(pageContentTypeId)) { pageContentTypeId = GetParentIdValue(pageContentTypeId); } int promotedState = 0; if (pageToExtract.PageListItem[OfficeDevPnP.Core.Pages.ClientSidePage.PromotedStateField] != null) { int.TryParse(pageToExtract.PageListItem[OfficeDevPnP.Core.Pages.ClientSidePage.PromotedStateField].ToString(), out promotedState); } var isNews = pageToExtract.LayoutType != Pages.ClientSidePageLayoutType.Home && promotedState == (int)Pages.PromotedState.Promoted; // Create the page; BaseClientSidePage extractedPageInstance; if (page.IsTranslation) { extractedPageInstance = new TranslatedClientSidePage(); (extractedPageInstance as TranslatedClientSidePage).PageName = page.PageName; } else { extractedPageInstance = new ClientSidePage(); (extractedPageInstance as ClientSidePage).PageName = page.PageName; } extractedPageInstance.PromoteAsNewsArticle = isNews; extractedPageInstance.PromoteAsTemplate = page.IsTemplate; extractedPageInstance.Overwrite = true; extractedPageInstance.Publish = true; extractedPageInstance.Layout = pageToExtract.LayoutType.ToString(); extractedPageInstance.EnableComments = !pageToExtract.CommentsDisabled; extractedPageInstance.Title = pageToExtract.PageTitle; extractedPageInstance.ContentTypeID = !pageContentTypeId.Equals(BuiltInContentTypeId.ModernArticlePage, StringComparison.InvariantCultureIgnoreCase) ? pageContentTypeId : null; extractedPageInstance.ThumbnailUrl = pageToExtract.ThumbnailUrl != null?TokenizeJsonControlData(web, pageToExtract.ThumbnailUrl) : ""; if (pageToExtract.PageHeader != null) { var extractedHeader = new ClientSidePageHeader() { Type = (ClientSidePageHeaderType)Enum.Parse(typeof(Pages.ClientSidePageHeaderType), pageToExtract.PageHeader.Type.ToString()), ServerRelativeImageUrl = TokenizeJsonControlData(web, pageToExtract.PageHeader.ImageServerRelativeUrl), TranslateX = pageToExtract.PageHeader.TranslateX, TranslateY = pageToExtract.PageHeader.TranslateY, LayoutType = (ClientSidePageHeaderLayoutType)Enum.Parse(typeof(Pages.ClientSidePageHeaderLayoutType), pageToExtract.PageHeader.LayoutType.ToString()), #if !SP2019 TextAlignment = (ClientSidePageHeaderTextAlignment)Enum.Parse(typeof(Pages.ClientSidePageHeaderTitleAlignment), pageToExtract.PageHeader.TextAlignment.ToString()), ShowTopicHeader = pageToExtract.PageHeader.ShowTopicHeader, ShowPublishDate = pageToExtract.PageHeader.ShowPublishDate, TopicHeader = pageToExtract.PageHeader.TopicHeader, AlternativeText = pageToExtract.PageHeader.AlternativeText, Authors = !excludeAuthorInformation ? pageToExtract.PageHeader.Authors : "", AuthorByLine = !excludeAuthorInformation ? pageToExtract.PageHeader.AuthorByLine : "", AuthorByLineId = !excludeAuthorInformation ? pageToExtract.PageHeader.AuthorByLineId : -1 #endif }; extractedPageInstance.Header = extractedHeader; // Add the page header image to template if that was requested if (creationInfo.PersistBrandingFiles && !string.IsNullOrEmpty(pageToExtract.PageHeader.ImageServerRelativeUrl)) { IncludePageHeaderImageInExport(web, pageToExtract.PageHeader.ImageServerRelativeUrl, template, creationInfo, scope); } } // define reusable RegEx pre-compiled objects string guidPattern = "\"{?[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}}?\""; Regex regexGuidPattern = new Regex(guidPattern, RegexOptions.Compiled); string guidPatternEncoded = "=[a-fA-F0-9]{8}(?:%2D|-)([a-fA-F0-9]{4}(?:%2D|-)){3}[a-fA-F0-9]{12}"; Regex regexGuidPatternEncoded = new Regex(guidPatternEncoded, RegexOptions.Compiled); string guidPatternNoDashes = "[a-fA-F0-9]{32}"; Regex regexGuidPatternNoDashes = new Regex(guidPatternNoDashes, RegexOptions.Compiled); string siteAssetUrlsPattern = "(?:\")(?<AssetUrl>[\\w|\\.|\\/|:|-]*\\/SiteAssets\\/SitePages\\/[\\w|\\.|\\/|:|-]*)(?:\")"; // OLD RegEx with Catastrophic Backtracking: @".*""(.*?/SiteAssets/SitePages/.+?)"".*"; Regex regexSiteAssetUrls = new Regex(siteAssetUrlsPattern, RegexOptions.Compiled); if (creationInfo.PersistBrandingFiles && !string.IsNullOrEmpty(extractedPageInstance.ThumbnailUrl)) { var thumbnailFileIds = new List <Guid>(); CollectImageFilesFromGenericGuids(regexGuidPatternNoDashes, null, extractedPageInstance.ThumbnailUrl, thumbnailFileIds); if (thumbnailFileIds.Count == 1) { var file = web.GetFileById(thumbnailFileIds[0]); web.Context.Load(file, f => f.Level, f => f.ServerRelativeUrl, f => f.UniqueId); web.Context.ExecuteQueryRetry(); // Item1 = was file added to the template // Item2 = file name (if file found) var imageAddedTuple = LoadAndAddPageImage(web, file, template, creationInfo, scope); if (imageAddedTuple.Item1) { extractedPageInstance.ThumbnailUrl = Regex.Replace(extractedPageInstance.ThumbnailUrl, file.UniqueId.ToString("N"), $"{{fileuniqueid:{file.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray())}}}"); } } } // Add the sections foreach (var section in pageToExtract.Sections) { // Set order var sectionInstance = new CanvasSection() { Order = section.Order, BackgroundEmphasis = (Emphasis)section.ZoneEmphasis, }; if (section.VerticalSectionColumn != null) { sectionInstance.VerticalSectionEmphasis = (Emphasis)section.VerticalSectionColumn.VerticalSectionEmphasis; } // Set section type switch (section.Type) { case Pages.CanvasSectionTemplate.OneColumn: sectionInstance.Type = CanvasSectionType.OneColumn; break; case Pages.CanvasSectionTemplate.TwoColumn: sectionInstance.Type = CanvasSectionType.TwoColumn; break; case Pages.CanvasSectionTemplate.TwoColumnLeft: sectionInstance.Type = CanvasSectionType.TwoColumnLeft; break; case Pages.CanvasSectionTemplate.TwoColumnRight: sectionInstance.Type = CanvasSectionType.TwoColumnRight; break; case Pages.CanvasSectionTemplate.ThreeColumn: sectionInstance.Type = CanvasSectionType.ThreeColumn; break; case Pages.CanvasSectionTemplate.OneColumnFullWidth: sectionInstance.Type = CanvasSectionType.OneColumnFullWidth; break; #if !SP2019 case Pages.CanvasSectionTemplate.OneColumnVerticalSection: sectionInstance.Type = CanvasSectionType.OneColumnVerticalSection; break; case Pages.CanvasSectionTemplate.TwoColumnVerticalSection: sectionInstance.Type = CanvasSectionType.TwoColumnVerticalSection; break; case Pages.CanvasSectionTemplate.TwoColumnLeftVerticalSection: sectionInstance.Type = CanvasSectionType.TwoColumnLeftVerticalSection; break; case Pages.CanvasSectionTemplate.TwoColumnRightVerticalSection: sectionInstance.Type = CanvasSectionType.TwoColumnRightVerticalSection; break; case Pages.CanvasSectionTemplate.ThreeColumnVerticalSection: sectionInstance.Type = CanvasSectionType.ThreeColumnVerticalSection; break; #endif default: sectionInstance.Type = CanvasSectionType.OneColumn; break; } // Add controls to section foreach (var column in section.Columns) { foreach (var control in column.Controls) { // Create control CanvasControl controlInstance = new CanvasControl() { Column = column.IsVerticalSectionColumn ? section.Columns.IndexOf(column) + 1 : column.Order, ControlId = control.InstanceId, Order = control.Order, }; // Set control type if (control.Type == typeof(Pages.ClientSideText)) { controlInstance.Type = WebPartType.Text; // Set text content controlInstance.ControlProperties = new System.Collections.Generic.Dictionary <string, string>(1) { { "Text", TokenizeJsonTextData(web, (control as Pages.ClientSideText).Text) } }; } else { // set ControlId to webpart id controlInstance.ControlId = Guid.Parse((control as Pages.ClientSideWebPart).WebPartId); var webPartType = Pages.ClientSidePage.NameToClientSideWebPartEnum((control as Pages.ClientSideWebPart).WebPartId); switch (webPartType) { case Pages.DefaultClientSideWebParts.ContentRollup: controlInstance.Type = WebPartType.ContentRollup; break; #if !SP2019 case Pages.DefaultClientSideWebParts.BingMap: controlInstance.Type = WebPartType.BingMap; break; case Pages.DefaultClientSideWebParts.Button: controlInstance.Type = WebPartType.Button; break; case Pages.DefaultClientSideWebParts.CallToAction: controlInstance.Type = WebPartType.CallToAction; break; case Pages.DefaultClientSideWebParts.News: controlInstance.Type = WebPartType.News; break; case Pages.DefaultClientSideWebParts.PowerBIReportEmbed: controlInstance.Type = WebPartType.PowerBIReportEmbed; break; case Pages.DefaultClientSideWebParts.Sites: controlInstance.Type = WebPartType.Sites; break; case Pages.DefaultClientSideWebParts.GroupCalendar: controlInstance.Type = WebPartType.GroupCalendar; break; case Pages.DefaultClientSideWebParts.MicrosoftForms: controlInstance.Type = WebPartType.MicrosoftForms; break; case Pages.DefaultClientSideWebParts.ClientWebPart: controlInstance.Type = WebPartType.ClientWebPart; break; #endif case Pages.DefaultClientSideWebParts.ContentEmbed: controlInstance.Type = WebPartType.ContentEmbed; break; case Pages.DefaultClientSideWebParts.DocumentEmbed: controlInstance.Type = WebPartType.DocumentEmbed; break; case Pages.DefaultClientSideWebParts.Image: controlInstance.Type = WebPartType.Image; break; case Pages.DefaultClientSideWebParts.ImageGallery: controlInstance.Type = WebPartType.ImageGallery; break; case Pages.DefaultClientSideWebParts.LinkPreview: controlInstance.Type = WebPartType.LinkPreview; break; case Pages.DefaultClientSideWebParts.NewsFeed: controlInstance.Type = WebPartType.NewsFeed; break; case Pages.DefaultClientSideWebParts.NewsReel: controlInstance.Type = WebPartType.NewsReel; break; case Pages.DefaultClientSideWebParts.QuickChart: controlInstance.Type = WebPartType.QuickChart; break; case Pages.DefaultClientSideWebParts.SiteActivity: controlInstance.Type = WebPartType.SiteActivity; break; case Pages.DefaultClientSideWebParts.VideoEmbed: controlInstance.Type = WebPartType.VideoEmbed; break; case Pages.DefaultClientSideWebParts.YammerEmbed: controlInstance.Type = WebPartType.YammerEmbed; break; case Pages.DefaultClientSideWebParts.Events: controlInstance.Type = WebPartType.Events; break; case Pages.DefaultClientSideWebParts.Hero: controlInstance.Type = WebPartType.Hero; break; case Pages.DefaultClientSideWebParts.List: controlInstance.Type = WebPartType.List; break; case Pages.DefaultClientSideWebParts.PageTitle: controlInstance.Type = WebPartType.PageTitle; break; case Pages.DefaultClientSideWebParts.People: controlInstance.Type = WebPartType.People; break; case Pages.DefaultClientSideWebParts.QuickLinks: controlInstance.Type = WebPartType.QuickLinks; break; case Pages.DefaultClientSideWebParts.CustomMessageRegion: controlInstance.Type = WebPartType.CustomMessageRegion; break; case Pages.DefaultClientSideWebParts.Divider: controlInstance.Type = WebPartType.Divider; break; case Pages.DefaultClientSideWebParts.Spacer: controlInstance.Type = WebPartType.Spacer; break; case Pages.DefaultClientSideWebParts.ThirdParty: controlInstance.Type = WebPartType.Custom; break; default: controlInstance.Type = WebPartType.Custom; break; } if (excludeAuthorInformation) { #if !SP2019 if (webPartType == Pages.DefaultClientSideWebParts.News) { var properties = (control as Pages.ClientSideWebPart).Properties; var authorTokens = properties.SelectTokens("$..author").ToList(); foreach (var authorToken in authorTokens) { authorToken.Parent.Remove(); } var authorAccountNameTokens = properties.SelectTokens("$..authorAccountName").ToList(); foreach (var authorAccountNameToken in authorAccountNameTokens) { authorAccountNameToken.Parent.Remove(); } (control as Pages.ClientSideWebPart).PropertiesJson = properties.ToString(); } #endif } string jsonControlData = "\"id\": \"" + (control as Pages.ClientSideWebPart).WebPartId + "\", \"instanceId\": \"" + (control as Pages.ClientSideWebPart).InstanceId + "\", \"title\": " + JsonConvert.ToString((control as Pages.ClientSideWebPart).Title) + ", \"description\": " + JsonConvert.ToString((control as Pages.ClientSideWebPart).Description) + ", \"dataVersion\": \"" + (control as Pages.ClientSideWebPart).DataVersion + "\", \"properties\": " + (control as Pages.ClientSideWebPart).PropertiesJson + ""; // set the control properties if ((control as Pages.ClientSideWebPart).ServerProcessedContent != null) { // If we have serverProcessedContent then also export that one, it's important as some controls depend on this information to be present string serverProcessedContent = (control as Pages.ClientSideWebPart).ServerProcessedContent.ToString(Formatting.None); jsonControlData = jsonControlData + ", \"serverProcessedContent\": " + serverProcessedContent + ""; } if ((control as Pages.ClientSideWebPart).DynamicDataPaths != null) { // If we have serverProcessedContent then also export that one, it's important as some controls depend on this information to be present string dynamicDataPaths = (control as Pages.ClientSideWebPart).DynamicDataPaths.ToString(Formatting.None); jsonControlData = jsonControlData + ", \"dynamicDataPaths\": " + dynamicDataPaths + ""; } if ((control as Pages.ClientSideWebPart).DynamicDataValues != null) { // If we have serverProcessedContent then also export that one, it's important as some controls depend on this information to be present string dynamicDataValues = (control as Pages.ClientSideWebPart).DynamicDataValues.ToString(Formatting.None); jsonControlData = jsonControlData + ", \"dynamicDataValues\": " + dynamicDataValues + ""; } controlInstance.JsonControlData = "{" + jsonControlData + "}"; var untokenizedJsonControlData = controlInstance.JsonControlData; // Tokenize the JsonControlData controlInstance.JsonControlData = TokenizeJsonControlData(web, controlInstance.JsonControlData); // Export relevant files if this flag is set if (creationInfo.PersistBrandingFiles) { List <Guid> fileGuids = new List <Guid>(); Dictionary <string, string> exportedFiles = new Dictionary <string, string>(); Dictionary <string, string> exportedPages = new Dictionary <string, string>(); CollectSiteAssetImageFiles(regexSiteAssetUrls, web, untokenizedJsonControlData, fileGuids); CollectImageFilesFromGenericGuids(regexGuidPattern, regexGuidPatternEncoded, untokenizedJsonControlData, fileGuids); // Iterate over the found guids to see if they're exportable files foreach (var uniqueId in fileGuids) { try { if (!exportedFiles.ContainsKey(uniqueId.ToString()) && !errorneousOrNonImageFileGuids.Contains(uniqueId.ToString())) { // Try to see if this is a file var file = web.GetFileById(uniqueId); web.Context.Load(file, f => f.Level, f => f.ServerRelativeUrl); web.Context.ExecuteQueryRetry(); // Item1 = was file added to the template // Item2 = file name (if file found) var imageAddedTuple = LoadAndAddPageImage(web, file, template, creationInfo, scope); if (!string.IsNullOrEmpty(imageAddedTuple.Item2)) { if (!imageAddedTuple.Item2.EndsWith(".aspx", StringComparison.InvariantCultureIgnoreCase)) { if (imageAddedTuple.Item1) { // Keep track of the exported file path and it's UniqueId exportedFiles.Add(uniqueId.ToString(), file.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray())); } } else { if (!exportedPages.ContainsKey(uniqueId.ToString())) { exportedPages.Add(uniqueId.ToString(), file.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray())); } } } } } catch (Exception ex) { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ClientSidePageContents_ErrorDuringFileExport, ex.Message); errorneousOrNonImageFileGuids.Add(uniqueId.ToString()); } } // Tokenize based on the found files, use a different token for encoded guids do we can later on replace by a new encoded guid foreach (var exportedFile in exportedFiles) { controlInstance.JsonControlData = Regex.Replace(controlInstance.JsonControlData, exportedFile.Key.Replace("-", "%2D"), $"{{fileuniqueidencoded:{exportedFile.Value}}}", RegexOptions.IgnoreCase); controlInstance.JsonControlData = Regex.Replace(controlInstance.JsonControlData, exportedFile.Key, $"{{fileuniqueid:{exportedFile.Value}}}", RegexOptions.IgnoreCase); } foreach (var exportedPage in exportedPages) { controlInstance.JsonControlData = Regex.Replace(controlInstance.JsonControlData, exportedPage.Key.Replace("-", "%2D"), $"{{pageuniqueidencoded:{exportedPage.Value}}}", RegexOptions.IgnoreCase); controlInstance.JsonControlData = Regex.Replace(controlInstance.JsonControlData, exportedPage.Key, $"{{pageuniqueid:{exportedPage.Value}}}", RegexOptions.IgnoreCase); } } } // add control to section sectionInstance.Controls.Add(controlInstance); } } extractedPageInstance.Sections.Add(sectionInstance); } // Renumber the sections...when editing modern homepages you can end up with section with order 0.5 or 0.75...let's ensure we render section as of 1 int sectionOrder = 1; foreach (var sectionInstance in extractedPageInstance.Sections) { sectionInstance.Order = sectionOrder; sectionOrder++; } #if !SP2019 // Spaces support if (pageToExtract.LayoutType == Pages.ClientSidePageLayoutType.Spaces && !string.IsNullOrEmpty(pageToExtract.SpaceContent)) { extractedPageInstance.FieldValues.Add(Pages.ClientSidePage.SpaceContentField, pageToExtract.SpaceContent); } #endif // Add the page to the template if (page.IsTranslation) { var parentPage = template.ClientSidePages.Where(p => p.PageName == page.SourcePageName).FirstOrDefault(); if (parentPage != null) { var translatedPageInstance = (TranslatedClientSidePage)extractedPageInstance; translatedPageInstance.LCID = new CultureInfo(page.Language).LCID; parentPage.Translations.Add(translatedPageInstance); } } else { var clientSidePageInstance = (ClientSidePage)extractedPageInstance; if (page.TranslatedLanguages != null && page.TranslatedLanguages.Count > 0) { clientSidePageInstance.CreateTranslations = true; clientSidePageInstance.LCID = Convert.ToInt32(web.EnsureProperty(p => p.Language)); } template.ClientSidePages.Add(clientSidePageInstance); } // Set the homepage if (page.IsHomePage) { if (template.WebSettings == null) { template.WebSettings = new WebSettings(); } if (page.PageUrl.StartsWith(web.ServerRelativeUrl, StringComparison.InvariantCultureIgnoreCase)) { template.WebSettings.WelcomePage = page.PageUrl.Replace(web.ServerRelativeUrl + "/", ""); } else { template.WebSettings.WelcomePage = page.PageUrl; } } } } catch (ArgumentException ex) { scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ClientSidePageContents_NoValidPage, ex.Message); } }
/// <summary> /// Add web part to a wiki style page /// </summary> /// <param name="web">Site to be processed - can be root web or sub site</param> /// <param name="serverRelativePageUrl">Server relative url of the page to add the webpart to</param> /// <param name="webPart">Information about the web part to insert</param> /// <param name="row">Row of the wiki table that should hold the inserted web part</param> /// <param name="col">Column of the wiki table that should hold the inserted web part</param> /// <param name="addSpace">Does a blank line need to be added after the web part (to space web parts)</param> public static void AddWebPartToWikiPage(this Web web, string serverRelativePageUrl, WebPartEntity webPart, int row, int col, bool addSpace) { File webPartPage = web.GetFileByServerRelativeUrl(serverRelativePageUrl); if (webPartPage == null) { return; } web.Context.Load(webPartPage); web.Context.Load(webPartPage.ListItemAllFields); web.Context.ExecuteQuery(); string wikiField = (string)webPartPage.ListItemAllFields["WikiField"]; LimitedWebPartManager limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared); WebPartDefinition oWebPartDefinition = limitedWebPartManager.ImportWebPart(webPart.WebPartXml); WebPartDefinition wpdNew = limitedWebPartManager.AddWebPart(oWebPartDefinition.WebPart, "wpz", 0); web.Context.Load(wpdNew); web.Context.ExecuteQuery(); //HTML structure in default team site home page (W16) //<div class="ExternalClass284FC748CB4242F6808DE69314A7C981"> // <div class="ExternalClass5B1565E02FCA4F22A89640AC10DB16F3"> // <table id="layoutsTable" style="width:100%;"> // <tbody> // <tr style="vertical-align:top;"> // <td colspan="2"> // <div class="ms-rte-layoutszone-outer" style="width:100%;"> // <div class="ms-rte-layoutszone-inner" style="word-wrap:break-word;margin:0px;border:0px;"> // <div><span><span><div class="ms-rtestate-read ms-rte-wpbox"><div class="ms-rtestate-read 9ed0c0ac-54d0-4460-9f1c-7e98655b0847" id="div_9ed0c0ac-54d0-4460-9f1c-7e98655b0847"></div><div class="ms-rtestate-read" id="vid_9ed0c0ac-54d0-4460-9f1c-7e98655b0847" style="display:none;"></div></div></span></span><p> </p></div> // <div class="ms-rtestate-read ms-rte-wpbox"> // <div class="ms-rtestate-read c7a1f9a9-4e27-4aa3-878b-c8c6c87961c0" id="div_c7a1f9a9-4e27-4aa3-878b-c8c6c87961c0"></div> // <div class="ms-rtestate-read" id="vid_c7a1f9a9-4e27-4aa3-878b-c8c6c87961c0" style="display:none;"></div> // </div> // </div> // </div> // </td> // </tr> // <tr style="vertical-align:top;"> // <td style="width:49.95%;"> // <div class="ms-rte-layoutszone-outer" style="width:100%;"> // <div class="ms-rte-layoutszone-inner" style="word-wrap:break-word;margin:0px;border:0px;"> // <div class="ms-rtestate-read ms-rte-wpbox"> // <div class="ms-rtestate-read b55b18a3-8a3b-453f-a714-7e8d803f4d30" id="div_b55b18a3-8a3b-453f-a714-7e8d803f4d30"></div> // <div class="ms-rtestate-read" id="vid_b55b18a3-8a3b-453f-a714-7e8d803f4d30" style="display:none;"></div> // </div> // </div> // </div> // </td> // <td class="ms-wiki-columnSpacing" style="width:49.95%;"> // <div class="ms-rte-layoutszone-outer" style="width:100%;"> // <div class="ms-rte-layoutszone-inner" style="word-wrap:break-word;margin:0px;border:0px;"> // <div class="ms-rtestate-read ms-rte-wpbox"> // <div class="ms-rtestate-read 0b2f12a4-3ab5-4a59-b2eb-275bbc617f95" id="div_0b2f12a4-3ab5-4a59-b2eb-275bbc617f95"></div> // <div class="ms-rtestate-read" id="vid_0b2f12a4-3ab5-4a59-b2eb-275bbc617f95" style="display:none;"></div> // </div> // </div> // </div> // </td> // </tr> // </tbody> // </table> // <span id="layoutsData" style="display:none;">true,false,2</span> // </div> //</div> XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.LoadXml(wikiField); // Sometimes the wikifield content seems to be surrounded by an additional div? XmlElement layoutsTable = xd.SelectSingleNode("div/div/table") as XmlElement; if (layoutsTable == null) { layoutsTable = xd.SelectSingleNode("div/table") as XmlElement; } XmlElement layoutsZoneInner = layoutsTable.SelectSingleNode(string.Format("tbody/tr[{0}]/td[{1}]/div/div", row, col)) as XmlElement; // - space element XmlElement space = xd.CreateElement("p"); XmlText text = xd.CreateTextNode(" "); space.AppendChild(text); // - wpBoxDiv XmlElement wpBoxDiv = xd.CreateElement("div"); layoutsZoneInner.AppendChild(wpBoxDiv); if (addSpace) { layoutsZoneInner.AppendChild(space); } XmlAttribute attribute = xd.CreateAttribute("class"); wpBoxDiv.Attributes.Append(attribute); attribute.Value = "ms-rtestate-read ms-rte-wpbox"; attribute = xd.CreateAttribute("contentEditable"); wpBoxDiv.Attributes.Append(attribute); attribute.Value = "false"; // - div1 XmlElement div1 = xd.CreateElement("div"); wpBoxDiv.AppendChild(div1); div1.IsEmpty = false; attribute = xd.CreateAttribute("class"); div1.Attributes.Append(attribute); attribute.Value = "ms-rtestate-read " + wpdNew.Id.ToString("D"); attribute = xd.CreateAttribute("id"); div1.Attributes.Append(attribute); attribute.Value = "div_" + wpdNew.Id.ToString("D"); // - div2 XmlElement div2 = xd.CreateElement("div"); wpBoxDiv.AppendChild(div2); div2.IsEmpty = false; attribute = xd.CreateAttribute("style"); div2.Attributes.Append(attribute); attribute.Value = "display:none"; attribute = xd.CreateAttribute("id"); div2.Attributes.Append(attribute); attribute.Value = "vid_" + wpdNew.Id.ToString("D"); ListItem listItem = webPartPage.ListItemAllFields; listItem["WikiField"] = xd.OuterXml; listItem.Update(); web.Context.ExecuteQuery(); }
private string GetTitle(Web web) => $"{web.Title} - {web.Url}";
public virtual void ConfigureFieldsAndViews(ClientContext ctx, Web web) { RefreshList(ctx, web); if (RequiredFields != null && RequiredFields.Count > 0) { foreach (var field in RequiredFields) { Utility.RequireField(List, field); } } if (IndexFields != null && IndexFields.Count > 0) { foreach (var field in IndexFields) { Utility.IndexField(List, field); } } if (EnforceUniqueFields != null && EnforceUniqueFields.Count > 0) { foreach (var field in EnforceUniqueFields) { Utility.EnforceUniqueField(List, field); } } ctx.ExecuteQueryRetry(); RefreshList(ctx, web); if (HiddenFormFields != null && HiddenFormFields.Count > 0) { foreach (var fieldName in HiddenFormFields) { Utility.HideFieldOnAllForms(List, fieldName); } ctx.ExecuteQueryRetry(); RefreshList(ctx, web); } if (DisplayFormOnlyFields != null && DisplayFormOnlyFields.Count > 0) { foreach (var field in DisplayFormOnlyFields) { Utility.ShowOnDisplayFormOnly(List, field); } ctx.ExecuteQueryRetry(); RefreshList(ctx, web); } if (!string.IsNullOrEmpty(TitleFieldDisplayName)) { Utility.SetTitleFieldDisplayName(List, TitleFieldDisplayName); ctx.ExecuteQueryRetry(); RefreshList(ctx, web); } if (FieldDisplayNameOverrides != null && FieldDisplayNameOverrides.Count > 0) { foreach (var field in FieldDisplayNameOverrides.Keys) { Utility.SetFieldDisplayName(List, field, FieldDisplayNameOverrides[field]); } ctx.ExecuteQueryRetry(); RefreshList(ctx, web); } if (!string.IsNullOrEmpty(DefaultViewSchemaXml) || !string.IsNullOrEmpty(DefaultViewTitle)) { var defaultView = List.Views[0]; if (!string.IsNullOrEmpty(DefaultViewSchemaXml)) { defaultView.ListViewXml = DefaultViewSchemaXml; } if (!string.IsNullOrEmpty(DefaultViewTitle)) { defaultView.Title = DefaultViewTitle; } defaultView.Update(); ctx.ExecuteQueryRetry(); } if (ListViewSchemas != null) { foreach (var key in ListViewSchemas.Keys) { if (!ViewExists(key)) { var vcInfo = new ViewCreationInformation { Title = key }; var view = List.Views.Add(vcInfo); view.ListViewXml = ListViewSchemas[key]; view.Update(); } else { var view = List.Views.GetByTitle(key); view.ListViewXml = ListViewSchemas[key]; view.Update(); } } ctx.ExecuteQueryRetry(); } if (RemoveViewFields != null || AddToAllViewsFields != null) { foreach (var view in List.Views) { if (RemoveViewFields != null) { foreach (var field in RemoveViewFields) { if (view.ViewFields.SchemaXml.Contains(field)) { view.ViewFields.Remove(field); } } } if (AddToAllViewsFields != null) { foreach (var field in AddToAllViewsFields) { if (!view.ViewFields.SchemaXml.Contains(field)) { view.ViewFields.Add(field); } } } view.Update(); } ctx.ExecuteQueryRetry(); } }
private void CreateList(Web web, ListTemplateType listType, string listName, bool enableVersioning, bool updateAndExecuteQuery = true, string urlPath = "") { // Call actual implementation CreateListInternal(web, listType, listName, enableVersioning, updateAndExecuteQuery, urlPath); }
public override Model.ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { return(template); }
private static void MapProperties(Web web, WebDefinition webModel) { if (!string.IsNullOrEmpty(webModel.Title)) { web.Title = webModel.Title; } if (!string.IsNullOrEmpty(webModel.Description)) { web.Description = webModel.Description; } var supportedRuntime = ReflectionUtils.HasProperty(web, "AlternateCssUrl") && ReflectionUtils.HasProperty(web, "SiteLogoUrl"); if (supportedRuntime) { var context = web.Context; if (!string.IsNullOrEmpty(webModel.AlternateCssUrl)) { context.AddQuery(new ClientActionInvokeMethod(web, "AlternateCssUrl", new object[] { webModel.AlternateCssUrl })); } if (!string.IsNullOrEmpty(webModel.SiteLogoUrl)) { context.AddQuery(new ClientActionInvokeMethod(web, "SiteLogoUrl", new object[] { webModel.SiteLogoUrl })); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.AlternateCssUrl and Web.SiteLogoUrl methods support. Update CSOM runtime to a new version. Provision is skipped"); } #if !NET35 if (webModel.IndexedPropertyKeys.Any()) { var props = web.AllProperties; // may not be there at all var indexedPropertyValue = props.FieldValues.Keys.Contains("vti_indexedpropertykeys") ? ConvertUtils.ToStringAndTrim(props["vti_indexedpropertykeys"]) : string.Empty; var currentIndexedProperties = IndexedPropertyUtils.GetDecodeValueForSearchIndexProperty(indexedPropertyValue); // setup property bag foreach (var indexedProperty in webModel.IndexedPropertyKeys) { // indexed prop should exist in the prop bag // otherwise it won't be saved by SharePoint (ILSpy / Refletor to see the logic) // http://rwcchen.blogspot.com.au/2014/06/sharepoint-2013-indexed-property-keys.html var propName = indexedProperty.Name; var propValue = string.IsNullOrEmpty(indexedProperty.Value) ? string.Empty : indexedProperty.Value; props[propName] = propValue; } // merge and setup indexed prop keys, preserve existing props foreach (var indexedProperty in webModel.IndexedPropertyKeys) { if (!currentIndexedProperties.Contains(indexedProperty.Name)) { currentIndexedProperties.Add(indexedProperty.Name); } } props["vti_indexedpropertykeys"] = IndexedPropertyUtils.GetEncodedValueForSearchIndexProperty(currentIndexedProperties); } #endif }
private void ProcessAction(List <Web> webs) { bool processAction; int webCount = webs.Count; for (int webIndex = 0; webIndex < webCount; webIndex++) { Web currentWeb = webs[webIndex]; //Update current connection context to the web that is beeing process //So commands like Get-PnPList returns the correct list for the current web beeing proccess SPOnlineConnection.CurrentConnection.Context = (ClientContext)currentWeb.Context; currentWeb.LoadProperties(_webActions.Properties); UpdateWebProgressBar(webs, webIndex, webCount, 0, _totalExecutionTimeStopWatch); if (!_webActions.ShouldProcessAnyAction(currentWeb)) { continue; } processAction = ProcessAction(currentWeb, GetTitle, _webActions.Properties, _webActions.ShouldProcessAction, _webActions.Action, ref _currentWebsProcessed, ref _averageWebTime, ref _averageShouldProcessWebTime); if (!processAction) { continue; } if (_listActions.HasAnyAction || _listItemActions.HasAnyAction) { ListCollection lists = currentWeb.Lists; int listCount = lists.Count; for (int listIndex = 0; listIndex < listCount; listIndex++) { List currentList = lists[listIndex]; currentList.LoadProperties(_listActions.Properties); if (_isListNameSpecified && !currentList.Title.Equals(_listName, StringComparison.CurrentCultureIgnoreCase)) { continue; } UpdateWebProgressBar(webs, webIndex, webCount, listIndex, _totalExecutionTimeStopWatch); UpdateListProgressBar(lists, listIndex, listCount); processAction = ProcessAction(currentList, GetTitle, _listActions.Properties, _listActions.ShouldProcessAction, _listActions.Action, ref _currentListsProcessed, ref _averageListTime, ref _averageShouldProcessListTime); if (!processAction) { continue; } if (_listItemActions.HasAnyAction) { ListItemCollection listItems = currentList.GetItems(CamlQuery.CreateAllItemsQuery()); currentList.Context.Load(listItems); currentList.Context.ExecuteQueryRetry(); int listItemCount = listItems.Count; for (int listItemIndex = 0; listItemIndex < listItemCount; listItemIndex++) { ListItem currentListItem = listItems[listItemIndex]; currentListItem.LoadProperties(_listItemActions.Properties); WriteIterationProgress(ListItemProgressBarId, ListProgressBarId, "Iterating list items", GetTitle(currentListItem), listItemIndex, listItemCount, CalculateRemainingTimeForListItems(listItemCount, listItemIndex)); ProcessAction(currentListItem, GetTitle, _listItemActions.Properties, _listItemActions.ShouldProcessAction, _listItemActions.Action, ref _currentListItemsProcessed, ref _averageListItemTime, ref _averageShouldProcessListItemTime); } CompleteProgressBar(ListItemProgressBarId); } processAction = ProcessAction(currentList, GetTitle, _listActions.Properties, _listActions.ShouldProcessPostAction, _listActions.PostAction, ref _currentPostListsProcessed, ref _averagePostListTime, ref _averageShouldProcessPostListTime); } CompleteProgressBar(ListProgressBarId); } processAction = ProcessAction(currentWeb, GetTitle, _webActions.Properties, _webActions.ShouldProcessPost, _webActions.PostAction, ref _currentPostWebsProcessed, ref _averagePostWebTime, ref _averageShouldProcessPostWebTime); } CompleteProgressBar(WebProgressBarId); }
protected Web GetExistingWeb(Site site, Web parentWeb, string currentWebUrl) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Entering GetExistingWeb()"); var srcUrl = currentWebUrl.ToLower().Trim('/').Trim('\\'); #if !NET35 // for self-hosting and '/' if (parentWeb.Url.ToLower().Trim('/').Trim('\\').EndsWith(srcUrl)) { return(parentWeb); } #endif #if NET35 // for self-hosting and '/' if (parentWeb.ServerRelativeUrl.ToLower().Trim('/').Trim('\\').EndsWith(srcUrl)) { return(parentWeb); } #endif var context = parentWeb.Context; Web web; var scope = new ExceptionHandlingScope(context); using (scope.StartScope()) { using (scope.StartTry()) { web = site.OpenWeb(currentWebUrl); } using (scope.StartCatch()) { } } TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()"); context.ExecuteQueryWithTrace(); if (!scope.HasException && web != null && web.ServerObjectIsNull == false) { TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "Found web with URL: [{0}]", currentWebUrl); context.Load(web); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()"); context.ExecuteQueryWithTrace(); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Exciting GetExistingWeb()"); return(web); } TraceService.InformationFormat((int)LogEventId.ModelProvisionCoreCall, "Can't find web with URL: [{0}]. Returning NULL.", currentWebUrl); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Exciting GetExistingWeb()"); return(null); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { //using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_RetrieveTemplateInfo)) //{ } return(parser); }
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { using (var scope = new PnPMonitoredScope(this.Name)) { // Extract the Home Page web.EnsureProperties(w => w.RootFolder.WelcomePage, w => w.ServerRelativeUrl, w => w.Url); var homepageUrl = web.RootFolder.WelcomePage; if (string.IsNullOrEmpty(homepageUrl)) { homepageUrl = "Default.aspx"; } var welcomePageUrl = UrlUtility.Combine(web.ServerRelativeUrl, homepageUrl); List pagesLibrary = web.GetPagesLibrary(); var items = pagesLibrary.GetItems(CamlQuery.CreateAllItemsQuery()); web.Context.Load(items, i => i.Include(it => it.DisplayName, it => it.File)); web.Context.ExecuteQuery(); foreach (ListItem listItem in items) { try { //var listItem = file.EnsureProperty(f => f.ListItemAllFields); if (listItem != null) { File file = listItem.File; if (listItem.FieldValues.ContainsKey("WikiField") && listItem.FieldValues["WikiField"] != null) { // Wiki page var fullUri = new Uri(UrlUtility.Combine(new Uri(web.Url).GetLeftPart(UriPartial.Authority), file.ServerRelativeUrl)); var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'); LimitedWebPartManager limitedWPManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared); web.Context.Load(limitedWPManager); var webParts = web.GetWebParts(file.ServerRelativeUrl); var page = new Page() { Layout = WikiPageLayout.Custom, Overwrite = true, Url = Tokenize(fullUri.PathAndQuery, web.Url), }; var pageContents = listItem.FieldValues["WikiField"].ToString(); Regex regexClientIds = new Regex(@"id=\""div_(?<ControlId>(\w|\-)+)"); if (regexClientIds.IsMatch(pageContents)) { foreach (Match webPartMatch in regexClientIds.Matches(pageContents)) { String serverSideControlId = webPartMatch.Groups["ControlId"].Value; try { String serverSideControlIdToSearchFor = String.Format("g_{0}", serverSideControlId.Replace("-", "_")); WebPartDefinition webPart = limitedWPManager.WebParts.GetByControlId(serverSideControlIdToSearchFor); web.Context.Load(webPart, wp => wp.Id, wp => wp.WebPart.Title, wp => wp.WebPart.ZoneIndex ); web.Context.ExecuteQueryRetry(); var webPartxml = TokenizeWebPartXml(web, web.GetWebPartXml(webPart.Id, file.ServerRelativeUrl)); page.WebParts.Add(new Model.WebPart() { Title = webPart.WebPart.Title, Contents = webPartxml, Order = (uint)webPart.WebPart.ZoneIndex, Row = 1, // By default we will create a onecolumn layout, add the webpart to it, and later replace the wikifield on the page to position the webparts correctly. Column = 1 // By default we will create a onecolumn layout, add the webpart to it, and later replace the wikifield on the page to position the webparts correctly. }); pageContents = Regex.Replace(pageContents, serverSideControlId, string.Format("{{webpartid:{0}}}", webPart.WebPart.Title), RegexOptions.IgnoreCase); } catch (ServerException) { scope.LogWarning("Found a WebPart ID which is not available on the server-side. ID: {0}", serverSideControlId); } } } page.Fields.Add("WikiField", pageContents); template.Pages.Add(page); // Set the homepage if (template.WebSettings == null) { template.WebSettings = new WebSettings(); } template.WebSettings.WelcomePage = homepageUrl; } else { if (web.Context.HasMinimalServerLibraryVersion(Constants.MINIMUMZONEIDREQUIREDSERVERVERSION)) { // Not a wikipage template = GetFileContents(web, template, file.ServerRelativeUrl, creationInfo, scope); if (template.WebSettings == null) { template.WebSettings = new WebSettings(); } template.WebSettings.WelcomePage = homepageUrl; } else { WriteMessage(string.Format("Page content export requires a server version that is newer than the current server. Server version is {0}, minimal required is {1}", web.Context.ServerLibraryVersion, Constants.MINIMUMZONEIDREQUIREDSERVERVERSION), ProvisioningMessageType.Warning); scope.LogWarning("Page content export requires a server version that is newer than the current server. Server version is {0}, minimal required is {1}", web.Context.ServerLibraryVersion, Constants.MINIMUMZONEIDREQUIREDSERVERVERSION); } } } } catch (ServerException ex) { if (ex.ServerErrorCode != -2146232832) { throw; } else { if (web.Context.HasMinimalServerLibraryVersion(Constants.MINIMUMZONEIDREQUIREDSERVERVERSION)) { // Page does not belong to a list, extract the file as is template = GetFileContents(web, template, welcomePageUrl, creationInfo, scope); if (template.WebSettings == null) { template.WebSettings = new WebSettings(); } template.WebSettings.WelcomePage = homepageUrl; } else { WriteMessage(string.Format("Page content export requires a server version that is newer than the current server. Server version is {0}, minimal required is {1}", web.Context.ServerLibraryVersion, Constants.MINIMUMZONEIDREQUIREDSERVERVERSION), ProvisioningMessageType.Warning); scope.LogWarning("Page content export requires a server version that is newer than the current server. Server version is {0}, minimal required is {1}", web.Context.ServerLibraryVersion, Constants.MINIMUMZONEIDREQUIREDSERVERVERSION); } } } } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } } return(template); }
protected string GetCurrentWebUrl(ClientRuntimeContext context, Web parentWeb, WebDefinition webModel) { var result = UrlUtility.CombineUrl(parentWeb.ServerRelativeUrl, webModel.Url); return(result.ToLower()); }
/// <summary> /// Retrieves form. /// </summary> /// <param name="context">Form context.</param> /// <returns>View model used to render form.</returns> private Form GetUpdateForm(string context) { // Get website identifier and details long tenantId = _authenticationService.TenantId; Web web = _authenticationService.Web; // Construct view model Form form = new Form { Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context }; form.Fields.Add("font", new SelectListField <string> { Name = "font", Label = ThemeResource.FontLabel, Items = new List <ListFieldItem <string> > { new ListFieldItem <string> { Name = ThemeResource.FontDefaultOption, Value = string.Empty } }, Value = string.Empty }); List <string> fonts = _assetService.GetFontOptions(tenantId); foreach (string font in fonts) { ((SelectListField <string>)form.Fields["font"]).Items.Add(new ListFieldItem <string> { Name = font, Value = font }); } if (web.FontOption != null && fonts.Contains(web.FontOption)) { ((SelectListField <string>)form.Fields["font"]).Value = web.FontOption; } form.Fields.Add("colour", new SelectListField <string> { Name = "colour", Label = ThemeResource.ColourLabel, Items = new List <ListFieldItem <string> > { new ListFieldItem <string> { Name = ThemeResource.ColourDefaultOption, Value = string.Empty } }, Value = string.Empty }); List <string> colours = _assetService.GetColourOptions(tenantId); foreach (string colour in colours) { ((SelectListField <string>)form.Fields["colour"]).Items.Add(new ListFieldItem <string> { Name = colour, Value = colour }); } if (web.ColourOption != null && colours.Contains(web.ColourOption)) { ((SelectListField <string>)form.Fields["colour"]).Value = web.ColourOption; } form.SubmitLabel = ThemeResource.UpdateThemeButtonLabel; // Return form return(form); }
public ClientPortalNavigation(Web web) { _web = web; }
/// <summary> /// Extension method to apply a Theme to a target web /// </summary> /// <param name="web"></param> /// <param name="jsonTheme"></param> /// <param name="themeName"></param> /// <returns></returns> public static Boolean ApplyTheme(this Web web, String jsonTheme, String themeName = null) { return(Task.Run(() => ApplyThemeAsync(web, jsonTheme, themeName)).GetAwaiter().GetResult()); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { // This handler only extracts contents and adds them to the Files and Pages collection. return(parser); }