protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, item, definition);

            var typedDefinition = definition.WithAssertAndCast<JavaScriptDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            item[BuiltInInternalFieldNames.ContentTypeId] = "0x0101002039C03B61C64EC4A04F5361F3851068";

            if (!string.IsNullOrEmpty(typedDefinition.Standalone))
                item["DisplayTemplateJSTemplateType"] = typedDefinition.Standalone;

            if (!string.IsNullOrEmpty(typedDefinition.TargetControlType))
                item["DisplayTemplateJSTargetControlType"] = typedDefinition.TargetControlType;

            if (!string.IsNullOrEmpty(typedDefinition.TargetListTemplateId))
                item["DisplayTemplateJSTargetListTemplate"] = typedDefinition.TargetListTemplateId;

            if (!string.IsNullOrEmpty(typedDefinition.TargetScope))
                item["DisplayTemplateJSTargetScope"] = typedDefinition.TargetScope;

            if (!string.IsNullOrEmpty(typedDefinition.IconUrl))
            {
                var iconValue = new FieldUrlValue { Url = typedDefinition.IconUrl };

                if (!string.IsNullOrEmpty(typedDefinition.IconDescription))
                    iconValue.Description = typedDefinition.IconDescription;

                item["DisplayTemplateJSIconUrl"] = iconValue;
            }
        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, item, definition);

            var typedDefinition = definition.WithAssertAndCast<FilterDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            item[BuiltInInternalFieldNames.ContentTypeId] = "0x0101002039C03B61C64EC4A04F5361F38510660400F643FF79F6BD764F8A469B6F153396EE";


            if (!string.IsNullOrEmpty(typedDefinition.CrawlerXSLFileURL))
            {
                var crawlerXSLFileValue = new FieldUrlValue { Url = typedDefinition.CrawlerXSLFileURL };

                if (!string.IsNullOrEmpty(typedDefinition.CrawlerXSLFileDescription))
                    crawlerXSLFileValue.Description = typedDefinition.CrawlerXSLFileDescription;

                item["CrawlerXSLFile"] = crawlerXSLFileValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.CompatibleManagedProperties))
                item["CompatibleManagedProperties"] = typedDefinition.CompatibleManagedProperties;

            if (typedDefinition.CompatibleSearchDataTypes.Count > 0)
            {
                item["CompatibleSearchDataTypes"] = typedDefinition.CompatibleSearchDataTypes.ToArray();
            }
        }
        protected override void MapProperties(object modelHost, Hashtable fileProperties, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, fileProperties, definition);

            var typedTemplateModel = definition.WithAssertAndCast<ItemControlTemplateDefinitionBase>("model", value => value.RequireNotNull());

            if (typedTemplateModel.TargetControlTypes.Count > 0)
            {
                var multiChoiceValue = new SPFieldMultiChoiceValue();

                foreach (var value in typedTemplateModel.TargetControlTypes)
                    multiChoiceValue.Add(value);

                fileProperties["TargetControlType"] = multiChoiceValue.ToString();
            }

            if (!string.IsNullOrEmpty(typedTemplateModel.PreviewURL))
            {
                var htmlPreviewValue = new SPFieldUrlValue { Url = typedTemplateModel.PreviewURL };

                if (!string.IsNullOrEmpty(typedTemplateModel.PreviewDescription))
                    htmlPreviewValue.Description = typedTemplateModel.PreviewDescription;

                fileProperties["HtmlDesignPreviewUrl"] = htmlPreviewValue.ToString();
            }
        }
        protected string GetSafePageFileName(ContentPageDefinitionBase page)
        {
            var fileName = page.FileName;
            if (!fileName.EndsWith("." + FileExtension)) fileName += "." + FileExtension;

            return fileName;
        }
        protected override void MapProperties(object modelHost, Hashtable fileProperties, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, fileProperties, definition);

            var typedDefinition = definition.WithAssertAndCast<FilterDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            fileProperties[BuiltInInternalFieldNames.ContentTypeId] = "0x0101002039C03B61C64EC4A04F5361F38510660400F643FF79F6BD764F8A469B6F153396EE";

            if (!string.IsNullOrEmpty(typedDefinition.CrawlerXSLFileURL))
            {
                var crawlerXSLFileValue = new SPFieldUrlValue { Url = typedDefinition.CrawlerXSLFileURL };

                if (!string.IsNullOrEmpty(typedDefinition.CrawlerXSLFileDescription))
                    crawlerXSLFileValue.Description = typedDefinition.CrawlerXSLFileDescription;

                fileProperties["CrawlerXSLFile"] = crawlerXSLFileValue.ToString();
            }

            if (!string.IsNullOrEmpty(typedDefinition.CompatibleManagedProperties))
                fileProperties["CompatibleManagedProperties"] = typedDefinition.CompatibleManagedProperties;

            if (typedDefinition.CompatibleSearchDataTypes.Count > 0)
            {
                var multiChoiceValue = new SPFieldMultiChoiceValue();

                foreach (var value in typedDefinition.CompatibleSearchDataTypes)
                    multiChoiceValue.Add(value);

                fileProperties["CompatibleSearchDataTypes"] = multiChoiceValue.ToString();
            }
        }
예제 #6
0
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            var typedDefinition = definition.WithAssertAndCast<TemplateDefinitionBase>("model", value => value.RequireNotNull());

            item["TemplateHidden"] = typedDefinition.HiddenTemplate;

            if (!string.IsNullOrEmpty(typedDefinition.Description))
                item["MasterPageDescription"] = typedDefinition.Description;
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var listModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());

            var folder = listModelHost.CurrentLibraryFolder;
            var templateModel = model.WithAssertAndCast<ContentPageDefinitionBase>("model", value => value.RequireNotNull());

            CurrentModel = templateModel;

            DeployPage(modelHost, listModelHost.CurrentLibrary, folder, templateModel);
        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            var typedDefinition = definition.WithAssertAndCast<MasterPagePreviewDefinition>("model", value => value.RequireNotNull());

            item[BuiltInInternalFieldNames.ContentTypeId] = BuiltInContentTypeId.MasterPagePreview;

            if (typedDefinition.UIVersion.Count > 0)
            {
                item["UIVersion"] = string.Join(";#", typedDefinition.UIVersion.ToArray());
            }
        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            var typedDefinition = definition.WithAssertAndCast<WebPartGalleryFileDefinition>("model", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedDefinition.Group))
                item["Group"] = typedDefinition.Group;

            if (!string.IsNullOrEmpty(typedDefinition.Description))
                item["WebPartDescription"] = typedDefinition.Description;

            item["QuickAddGroups"] = typedDefinition.RecommendationSettings.ToArray();
        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, item, definition);

            var typedDefinition = definition.WithAssertAndCast<ItemDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            item[BuiltInInternalFieldNames.ContentTypeId] = "0x0101002039C03B61C64EC4A04F5361F38510660300500DA5E";
            //item["DisplayTemplateLevel"] = "Item";


            if (!string.IsNullOrEmpty(typedDefinition.ManagedPropertyMappings))
                item["ManagedPropertyMapping"] = typedDefinition.ManagedPropertyMappings;
        }
        protected override void MapProperties(object modelHost, System.Collections.Hashtable fileProperties, ContentPageDefinitionBase definition)
        {
            var typedTemplateModel = definition.WithAssertAndCast<MasterPagePreviewDefinition>("model", value => value.RequireNotNull());

            fileProperties[BuiltInInternalFieldNames.ContentTypeId] = BuiltInContentTypeId.MasterPagePreview;

            if (typedTemplateModel.UIVersion.Count > 0)
            {
                var value = new SPFieldMultiChoiceValue();

                foreach (var v in typedTemplateModel.UIVersion)
                    value.Add(v);

                fileProperties["UIVersion"] = value.ToString();
            }
        }
        private void DeployPage(object modelHost, SPList list, SPFolder folder, ContentPageDefinitionBase definition)
        {
            var web = list.ParentWeb;
            var targetPage = GetCurrentObject(folder, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = targetPage == null ? null : targetPage.File,
                ObjectType = typeof(SPFile),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (targetPage == null)
                targetPage = CreateObject(modelHost, folder, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = targetPage.File,
                ObjectType = typeof(SPFile),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            ModuleFileModelHandler.WithSafeFileOperation(list, folder,
                targetPage.Url,
                GetSafePageFileName(definition),
                definition.Content,
                definition.NeedOverride,
                null,
                afterFile =>
                {
                    var pageItem = afterFile.Properties;

                    pageItem["vti_title"] = definition.Title;

                    MapProperties(modelHost, pageItem, definition);

                    //pageItem.SystemUpdate();
                });
        }
예제 #13
0
        protected override void MapProperties(object modelHost, Hashtable fileProperties, ContentPageDefinitionBase definition)
        {
            var typedTemplateModel = definition.WithAssertAndCast<TemplateDefinitionBase>("model", value => value.RequireNotNull());

            // SSOM provision for display templates sometimes gives invalid type case error #440
            // HiddenTemplate.ToString() happens to fails on some SharePoint's environentns
            // 1:0 works well
            // https://github.com/SubPointSolutions/spmeta2/issues/440
            fileProperties["TemplateHidden"] = typedTemplateModel.HiddenTemplate ? 1 : 0;

            if (!string.IsNullOrEmpty(typedTemplateModel.Description))
                fileProperties["MasterPageDescription"] = typedTemplateModel.Description;




        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, item, definition);

            var typedTemplateModel = definition.WithAssertAndCast<ControlDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            item[BuiltInInternalFieldNames.ContentTypeId] = "0x0101002039C03B61C64EC4A04F5361F385106601";

            if (!string.IsNullOrEmpty(typedTemplateModel.CrawlerXSLFileURL))
            {
                var crawlerXSLFileValue = new FieldUrlValue { Url = typedTemplateModel.CrawlerXSLFileURL };

                if (!string.IsNullOrEmpty(typedTemplateModel.CrawlerXSLFileDescription))
                    crawlerXSLFileValue.Description = typedTemplateModel.CrawlerXSLFileDescription;

                item["CrawlerXSLFile"] = crawlerXSLFileValue;
            }
        }
        protected override void MapProperties(object modelHost, Hashtable fileProperties, ContentPageDefinitionBase definition)
        {
            var typedDefinition = definition.WithAssertAndCast<WebPartGalleryFileDefinition>("model", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedDefinition.Group))
                fileProperties["Group"] = typedDefinition.Group;

            if (!string.IsNullOrEmpty(typedDefinition.Description))
                fileProperties["WebPartDescription"] = typedDefinition.Description;


            var recSettingsValue = new SPFieldMultiChoiceValue();

            foreach (var value in typedDefinition.RecommendationSettings)
                recSettingsValue.Add(value);

            fileProperties["QuickAddGroups"] = recSettingsValue.ToString();
        }
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {
            base.MapProperties(modelHost, item, definition);

            var typedDefinition = definition.WithAssertAndCast<ItemControlTemplateDefinitionBase>("model", value => value.RequireNotNull());

            if (typedDefinition.TargetControlTypes.Count > 0)
            {
                item["TargetControlType"] = typedDefinition.TargetControlTypes.ToArray();
            }

            if (!string.IsNullOrEmpty(typedDefinition.PreviewURL))
            {
                var htmlPreviewValue = new FieldUrlValue { Url = typedDefinition.PreviewURL };

                if (!string.IsNullOrEmpty(typedDefinition.PreviewDescription))
                    htmlPreviewValue.Description = typedDefinition.PreviewDescription;

                item["HtmlDesignPreviewUrl"] = htmlPreviewValue;
            }
        }
 protected abstract void MapProperties(object modelHost, Hashtable fileProperties, ContentPageDefinitionBase definition);
        protected override void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition)
        {

        }
        private SPListItem CreateObject(object modelHost, SPFolder folder, ContentPageDefinitionBase definition)
        {
            var pageName = GetSafePageFileName(definition);
            var fileContent = definition.Content;

            ModuleFileModelHandler.DeployModuleFile(folder,
                  SPUrlUtility.CombineUrl(folder.ServerRelativeUrl, pageName),
                  pageName,
                  fileContent,
                  true,
                  null,
                  null);

            return GetCurrentObject(folder, definition);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var folderModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast<ContentPageDefinitionBase>("model", value => value.RequireNotNull());

            CurrentModel = definition;

            //var definition = model.WithAssertAndCast<ControlDisplayTemplateDefinition>("model", value => value.RequireNotNull());

            var folder = folderModelHost.CurrentListFolder;
            var list = folderModelHost.CurrentList;

            var context = folder.Context;

            var pageName = GetSafePageFileName(definition);
            var currentPageFile = GetItemFile(list, folder, pageName);

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

            ModuleFileModelHandler.WithSafeFileOperation(list, currentPageFile, f =>
            {
                var file = new FileCreationInformation();

                file.Url = pageName;
                file.Content = definition.Content;
                file.Overwrite = definition.NeedOverride;

                return folder.Files.Add(file);

            },
            newFile =>
            {
                var newFileItem = newFile.ListItemAllFields;
                context.Load(newFileItem);
                context.ExecuteQueryWithTrace();

                newFileItem["Title"] = definition.Title;

                MapProperties(modelHost, newFileItem, definition);

                newFileItem.Update();

                context.ExecuteQueryWithTrace();
            });

            currentPageFile = GetItemFile(folderModelHost.CurrentList, folder, pageName);

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

            context.ExecuteQueryWithTrace();
        }
 protected abstract void MapProperties(object modelHost, ListItem item, ContentPageDefinitionBase definition);
        protected SPListItem GetCurrentObject(SPFolder folder, ContentPageDefinitionBase definition)
        {
            // TODO, CAML query
            var pageName = GetSafePageFileName(definition);

            foreach (SPFile file in folder.Files)
                if (file.Name.ToUpper() == pageName.ToUpper())
                    return file.Item;

            return null;
        }
        protected override void MapProperties(object modelHost, Hashtable fileProperties,
            ContentPageDefinitionBase definition)
        {

        }