protected virtual void MapRegionalSettings(ClientRuntimeContext context, RegionalSettings settings, RegionalSettingsDefinition definition,
                                                   out bool shouldUpdate)
        {
            shouldUpdate = false;

            if (!SupportSetters(settings))
            {
                return;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "AdjustHijriDays") &&
                definition.AdjustHijriDays.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "AdjustHijriDays", definition.AdjustHijriDays.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "AlternateCalendarType") &&
                definition.AlternateCalendarType.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "AlternateCalendarType", definition.AlternateCalendarType.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "CalendarType") &&
                definition.CalendarType.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "CalendarType", definition.CalendarType.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "Collation") &&
                definition.Collation.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "Collation", definition.Collation.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "FirstDayOfWeek") &&
                definition.FirstDayOfWeek.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "FirstDayOfWeek", definition.FirstDayOfWeek.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "FirstWeekOfYear") &&
                definition.FirstWeekOfYear.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "FirstWeekOfYear", definition.FirstWeekOfYear.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "LocaleId") &&
                definition.LocaleId.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "LocaleId", definition.LocaleId.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "WorkDayStartHour") &&
                definition.WorkDayStartHour.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "WorkDayStartHour", definition.WorkDayStartHour.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "WorkDayEndHour") &&
                definition.WorkDayEndHour.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "WorkDayEndHour", definition.WorkDayEndHour.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "WorkDays") &&
                definition.WorkDays.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "WorkDays", definition.WorkDays.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "ShowWeeks") &&
                definition.ShowWeeks.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "ShowWeeks", definition.ShowWeeks.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "Time24") &&
                definition.Time24.HasValue)
            {
                ClientRuntimeQueryService.SetProperty(settings, "Time24", definition.Time24.Value);
                shouldUpdate = true;
            }

            if (ReflectionUtils.HasPropertyPublicSetter(settings, "TimeZone") &&
                definition.TimeZoneId.HasValue)
            {
                var targetZone = settings.TimeZones
                                 .ToArray()
                                 .FirstOrDefault(z => z.Id == definition.TimeZoneId.Value);

                if (targetZone == null)
                {
                    throw new SPMeta2Exception(
                              string.Format("Cannot find TimeZone by ID:[{0}]", definition.TimeZoneId));
                }

                ClientRuntimeQueryService.SetProperty(settings, "TimeZone", targetZone);
                shouldUpdate = true;
            }
        }
示例#2
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostWrapper          = modelHost.WithAssertAndCast <ContentTypeModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeFieldLinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            //var site = modelHostWrapper.Site;
            var web         = modelHostWrapper.HostWeb;
            var contentType = modelHostWrapper.HostContentType;

            var context = contentType.Context;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Getting content type field link by ID: [{0}]", contentTypeFieldLinkModel.FieldId);

            FieldLink fieldLink = FindExistingFieldLink(contentType, contentTypeFieldLinkModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            if (fieldLink == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type field link");

                var targetField = FindAvailableField(web, contentTypeFieldLinkModel);

                fieldLink = contentType.FieldLinks.Add(new FieldLinkCreationInformation
                {
                    Field = targetField
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type field link");
            }

            if (contentTypeFieldLinkModel.Required.HasValue)
            {
                fieldLink.Required = contentTypeFieldLinkModel.Required.Value;
            }

            if (contentTypeFieldLinkModel.Hidden.HasValue)
            {
                fieldLink.Hidden = contentTypeFieldLinkModel.Hidden.Value;
            }

            if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName))
            {
                // CSOM limitation - DisplayName is not available yet.
                // https://officespdev.uservoice.com/forums/224641-general/suggestions/7024931-enhance-fieldlink-class-with-additional-properties

                //   fieldLink.DisplayName = contentTypeFieldLinkModel.DisplayName;

                // Enhance FieldLinkDefinition - DisplayName, ReadOnly, ShowInDisplayForm #892
                // https://github.com/SubPointSolutions/spmeta2/issues/892
                if (ReflectionUtils.HasProperty(fieldLink, "DisplayName"))
                {
                    if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName))
                    {
                        ClientRuntimeQueryService.SetProperty(fieldLink, "DisplayName", contentTypeFieldLinkModel.DisplayName);
                    }
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                                          "CSOM runtime doesn't have FieldLink.DisplayName. Update CSOM runtime to a new version. Provision is skipped");
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            contentType.Update(true);
            context.ExecuteQueryWithTrace();
        }
示例#3
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModel  = model.WithAssertAndCast <SupportedUICultureDefinition>("model", value => value.RequireNotNull());
            var typedHost = modelHost.WithAssertAndCast <WebModelHost>("model", value => value.RequireNotNull());

            var web     = typedHost.HostWeb;
            var context = web.Context;

            context.Load(web);
            context.Load(web, w => w.SupportedUILanguageIds);

            context.ExecuteQuery();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = web,
                ObjectType       = typeof(Web),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            var shouldUpdate     = false;
            var currentLanguages = web.SupportedUILanguageIds;

            if (!currentLanguages.Contains(webModel.LCID))
            {
                // if running nice CSOM, so that method is there and a few web's props
                var supportedRuntime = ReflectionUtils.HasProperty(web, "IsMultilingual") &&
                                       ReflectionUtils.HasMethod(web, "AddSupportedUILanguage");


                if (supportedRuntime)
                {
                    // TODO, wrap up into extensions

                    // that's the trick to get all working on CSOM SP2013 SP1+
                    // once props are there, we setup them
                    // if not, giving critical messages in logs

                    // pushing IsMultilingual to true if false
                    var objectData       = GetPropertyValue(web, "ObjectData");
                    var objectProperties = GetPropertyValue(objectData, "Properties") as Dictionary <string, object>;

                    var isMultilingual = Convert.ToBoolean(objectProperties["IsMultilingual"]);

                    if (!isMultilingual)
                    {
                        ClientRuntimeQueryService.SetProperty(web, "IsMultilingual", true);
                    }

                    // adding languages
                    ClientRuntimeQueryService.InvokeMethod(web, "AddSupportedUILanguage", webModel.LCID);

                    // upating the web
                    web.Update();

                    shouldUpdate = true;
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                                          "CSOM runtime doesn't have Web.IsMultilingual and Web.AddSupportedUILanguage() methods support. Update CSOM runtime to a new version. SupportedUILanguage provision is skipped");
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = web,
                ObjectType       = typeof(Web),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            if (shouldUpdate)
            {
                context.ExecuteQueryWithTrace();
            }
        }
示例#4
0
        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"))
                {
                    ClientRuntimeQueryService.SetProperty(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"))
                {
                    ClientRuntimeQueryService.SetProperty(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"))
                {
                    ClientRuntimeQueryService.SetProperty(list, "ReadSecurity", 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"))
                {
                    ClientRuntimeQueryService.SetProperty(list, "WriteSecurity", 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
        }
示例#5
0
        protected virtual 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))
                {
                    ClientRuntimeQueryService.SetProperty(web, "AlternateCssUrl", webModel.AlternateCssUrl);
                }

                if (!string.IsNullOrEmpty(webModel.SiteLogoUrl))
                {
                    ClientRuntimeQueryService.SetProperty(web, "SiteLogoUrl", 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 (!string.IsNullOrEmpty(webModel.RequestAccessEmail))
            {
                if (ReflectionUtils.HasProperty(web, "RequestAccessEmail"))
                {
                    ClientRuntimeQueryService.SetProperty(web, "RequestAccessEmail", webModel.RequestAccessEmail);
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                                          "CSOM runtime doesn't have Web.RequestAccessEmail. Update CSOM runtime to a new version. Provision is skipped");
                }
            }
            if (webModel.MembersCanShare.HasValue)
            {
                if (ReflectionUtils.HasProperty(web, "MembersCanShare"))
                {
                    ClientRuntimeQueryService.SetProperty(web, "MembersCanShare", webModel.MembersCanShare.Value);
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                                          "CSOM runtime doesn't have Web.MembersCanShare. 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
        }