private void MapListProperties(object modelHost, List list, ListDefinition definition) { var csomModelHost = modelHost.WithAssertAndCast <CSOMModelHostBase>("modelHost", value => value.RequireNotNull()); var context = list.Context; list.Title = definition.Title; list.Description = definition.Description ?? string.Empty; list.ContentTypesEnabled = definition.ContentTypesEnabled; if (definition.Hidden.HasValue) { list.Hidden = definition.Hidden.Value; } if (!string.IsNullOrEmpty(definition.DraftVersionVisibility)) { var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility); list.DraftVersionVisibility = draftOption; } #if !NET35 // IRM if (definition.IrmEnabled.HasValue) { list.IrmEnabled = definition.IrmEnabled.Value; } if (definition.IrmExpire.HasValue) { list.IrmExpire = definition.IrmExpire.Value; } if (definition.IrmReject.HasValue) { list.IrmReject = definition.IrmReject.Value; } #endif // the rest if (definition.EnableAttachments.HasValue) { list.EnableAttachments = definition.EnableAttachments.Value; } if (definition.EnableFolderCreation.HasValue) { list.EnableFolderCreation = definition.EnableFolderCreation.Value; } if (definition.EnableMinorVersions.HasValue) { list.EnableMinorVersions = definition.EnableMinorVersions.Value; } if (definition.EnableModeration.HasValue) { list.EnableModeration = definition.EnableModeration.Value; } if (definition.EnableVersioning.HasValue) { list.EnableVersioning = definition.EnableVersioning.Value; } if (definition.ForceCheckout.HasValue) { list.ForceCheckout = definition.ForceCheckout.Value; } if (definition.Hidden.HasValue) { list.Hidden = definition.Hidden.Value; } if (definition.NoCrawl.HasValue) { list.NoCrawl = definition.NoCrawl.Value; } if (definition.OnQuickLaunch.HasValue) { list.OnQuickLaunch = definition.OnQuickLaunch.Value; } if (definition.MajorVersionLimit.HasValue) { if (ReflectionUtils.HasProperty(list, "MajorVersionLimit")) { context.AddQuery(new ClientActionSetProperty(list, "MajorVersionLimit", definition.MajorVersionLimit.Value)); } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, string.Format( "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped", string.Join(", ", new string[] { "MajorVersionLimit" }))); } } if (definition.MajorWithMinorVersionsLimit.HasValue) { if (ReflectionUtils.HasProperty(list, "MajorWithMinorVersionsLimit")) { context.AddQuery(new ClientActionSetProperty(list, "MajorWithMinorVersionsLimit", definition.MajorWithMinorVersionsLimit.Value)); } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, string.Format( "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped", string.Join(", ", new string[] { "MajorWithMinorVersionsLimit" }))); } } if (definition.ReadSecurity.HasValue) { if (ReflectionUtils.HasProperty(list, "ReadSecurity")) { context.AddQuery(new ClientActionInvokeMethod(list, "ReadSecurity", new object[] { definition.ReadSecurity.Value })); } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have List.ReadSecurity. Update CSOM runtime to a new version. Provision is skipped"); } } if (definition.WriteSecurity.HasValue) { if (ReflectionUtils.HasProperty(list, "WriteSecurity")) { context.AddQuery(new ClientActionInvokeMethod(list, "WriteSecurity", new object[] { definition.WriteSecurity.Value })); } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have List.WriteSecurity. Update CSOM runtime to a new version. Provision is skipped"); } } if (!string.IsNullOrEmpty(definition.DocumentTemplateUrl)) { var urlValue = definition.DocumentTemplateUrl; urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext { Value = urlValue, Context = csomModelHost }).Value; if (!urlValue.StartsWith("/") && !urlValue.StartsWith("http:") && !urlValue.StartsWith("https:")) { urlValue = "/" + urlValue; } list.DocumentTemplateUrl = urlValue; } ProcessLocalization(list, definition); #if !NET35 if (definition.IndexedRootFolderPropertyKeys.Any()) { var props = list.RootFolder.Properties; // 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 definition.IndexedRootFolderPropertyKeys) { // 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 definition.IndexedRootFolderPropertyKeys) { if (!currentIndexedProperties.Contains(indexedProperty.Name)) { currentIndexedProperties.Add(indexedProperty.Name); } } props["vti_indexedpropertykeys"] = IndexedPropertyUtils.GetEncodedValueForSearchIndexProperty(currentIndexedProperties); list.RootFolder.Update(); } #endif }
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 }