예제 #1
0
        protected ListItem FindPage(List list, Folder folder, MasterPageDefinition definition)
        {
            var pageName = GetSafePageFileName(definition);
            var file = GetCurrentPage(list, folder, pageName);

            if (file != null)
                return file.ListItemAllFields;

            return null;
        }
예제 #2
0
 protected File FindPageFile(List list, Folder folder, MasterPageDefinition definition)
 {
     var pageName = GetSafePageFileName(definition);
     return GetCurrentPage(list, folder, pageName);
 }
예제 #3
0
        private SPListItem CreateObject(object modelHost, SPFolder folder, MasterPageDefinition 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);
        }
예제 #4
0
        private void DeployPage(object modelHost, SPList list, SPFolder folder, MasterPageDefinition 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[BuiltInInternalFieldNames.Title] = definition.Title;
                    pageItem["vti_title"] = definition.Title;
                    pageItem["MasterPageDescription"] = definition.Description;
                    pageItem[BuiltInInternalFieldNames.ContentTypeId] = BuiltInContentTypeId.MasterPage;

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

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

                        pageItem["UIVersion"] = value.ToString();
                    }

                    pageItem["DefaultCssFile"] = definition.DefaultCSSFile;

                    //pageItem.Update();

                    //pageItem.SystemUpdate();
                });
        }
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var item = (reverseHost as MasterPageReverseHost).HostMasterPageFile;
            var context = (reverseHost as MasterPageReverseHost).HostClientContext;

            var def = new MasterPageDefinition();

            def.FileName = item.Name;
            def.Title = item.Title;

            using (var stream = File.OpenBinaryDirect(
                context,
                item.ServerRelativeUrl).Stream)
            {
                def.Content = ModuleFileUtils.ReadFully(stream);
            }

            return new MasterPageModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }