コード例 #1
0
 public static void DeployWebPartToPage(SPLimitedWebPartManager webPartManager,
     WebPartDefinition webpartDefinitions,
     Action<WebPart> onUpdating,
     Action<WebPart> onUpdated)
 {
     DeployWebPartToPage(webPartManager, webpartDefinitions, onUpdating, onUpdated, null);
 }
コード例 #2
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<PageViewerWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<PageViewerWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(definition.ContentLink))
            {
                var contentLinkValue = definition.ContentLink ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original contentLinkValue: [{0}]", contentLinkValue);

                contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = contentLinkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced contentLinkValue: [{0}]", contentLinkValue);

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(definition.SourceType))
            {
                typedWebpart.SourceType = (PathPattern)Enum.Parse(typeof(PathPattern), definition.SourceType);
            }
        }
コード例 #3
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty();
                    currentProperty.Name = prop.Name;

                    typedWebpart.Properties.Add(currentProperty);
                }

                currentProperty.Value = prop.Value;
            }
        }
コード例 #4
0
        protected override void OnBeforeDeployModel(WebpartPageModelHost host, WebPartDefinition webpartModel)
        {
            _host = host;

            var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());
            typedModel.WebpartType = typeof(ClientWebPart).AssemblyQualifiedName;
        }
コード例 #5
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SilverlightWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = webpartModel.WithAssertAndCast<SilverlightWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedDefinition.Url))
            {
                var linkValue = typedDefinition.Url;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original Url: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced Url: [{0}]", linkValue);

                typedWebpart.Url = linkValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.CustomInitParameters))
            {
                typedWebpart.CustomInitParameters = typedDefinition.CustomInitParameters;
            }
        }
コード例 #6
0
        //protected void WithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
        //  Action<WebPart> action)
        //{
        //    WithExistingWebPart(listItem.File, webPartModel, action);
        //}

        protected void WithExistingWebPart(File file, WebPartDefinition webPartModel,
           Action<WebPart> action)
        {
            WithExistingWebPart(file, webPartModel, (w, d) =>
            {
                action(w);
            });
        }
コード例 #7
0
        //protected void WithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
        //  Action<WebPart> action)
        //{
        //    WithExistingWebPart(listItem.File, webPartModel, action);
        //}

        protected void WithExistingWebPart(File file, WebPartDefinition webPartModel,
                                           Action <WebPart> action)
        {
            WithExistingWebPart(file, webPartModel, (w, d) =>
            {
                action(w);
            });
        }
コード例 #8
0
 protected void WithWithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
                                        Action <WebPart> action)
 {
     WithWithExistingWebPart(listItem, webPartModel, (w, d) =>
     {
         action(w);
     });
 }
コード例 #9
0
 protected void WithWithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
     Action<WebPart> action)
 {
     WithWithExistingWebPart(listItem, webPartModel, (w, d) =>
     {
         action(w);
     });
 }
コード例 #10
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContactFieldControl>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ContactFieldControlDefinition>("webpartModel", value => value.RequireNotNull());

        }
コード例 #11
0
        public void WebPartDefinitionTests_WebpartType_NonAssemblyQualifiedName_ShouldFail()
        {
            var type = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=16.0.0.0, Culture=neutral";

            var def = new WebPartDefinition
            {
                WebpartType = type
            };
        }
コード例 #12
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<UserDocsWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<UserDocsWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // TODO, specific provision
        }
コード例 #13
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ScriptEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ScriptEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.Content = typedModel.Content ?? string.Empty;
        }
コード例 #14
0
        public void WebPartDefinitionTests_WebpartType_AssemblyQualifiedName_ShouldPass()
        {
            var type = "Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";

            var def = new WebPartDefinition
            {
                WebpartType = type
            };

            Assert.IsTrue(type == def.WebpartType);
        }
コード例 #15
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.FeatureId = typedModel.FeatureId;
            typedWebpart.ProductId = typedModel.ProductId;
            typedWebpart.WebPartName = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
コード例 #16
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<RefinementScriptWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = definition.WithAssertAndCast<RefinementScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            if (!string.IsNullOrEmpty(typedModel.SelectedRefinementControlsJson))
                typedWebpart.SelectedRefinementControlsJson = typedModel.SelectedRefinementControlsJson;

            if (!string.IsNullOrEmpty(typedModel.EmptyMessage))
                typedWebpart.EmptyMessage = typedModel.EmptyMessage;
        }
コード例 #17
0
        protected virtual void ProcessWebpartProperties(WebPart instance, WebPartDefinition definition)
        {
            if (definition.Width.HasValue)
                instance.Width = new Unit(definition.Width.Value);

            if (definition.Height.HasValue)
                instance.Height = new Unit(definition.Height.Value);

            if (!string.IsNullOrEmpty(definition.ChromeState))
                instance.ChromeState = (PartChromeState)Enum.Parse(typeof(PartChromeState), definition.ChromeState);

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                instance.ChromeType = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                instance.ImportErrorMessage = definition.ImportErrorMessage;

            if (!string.IsNullOrEmpty(definition.Description))
                instance.Description = definition.Description;

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                instance.TitleIconImageUrl = definition.TitleIconImageUrl;

            if (!string.IsNullOrEmpty(definition.TitleUrl))
            {
                var urlValue = definition.TitleUrl ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original value: [{0}]",
                    urlValue);

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = urlValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced value: [{0}]", urlValue);

                instance.TitleUrl = urlValue;
            }

            if (!string.IsNullOrEmpty(definition.ExportMode))
                instance.ExportMode = (WebPartExportMode)Enum.Parse(typeof(WebPartExportMode), definition.ExportMode);

            ProcessWebpartCustomProperties(instance, definition);
            ProcessParameterBindings(instance, definition);
        }
コード例 #18
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SiteFeedWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<SiteFeedWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            //typedWebpart.ContentLink = typedModel.ContentLink ?? string.Empty;

            //var xmlDoc = new XmlDocument();
            //var xmlElement = xmlDoc.CreateElement("ContentElement");
            //xmlElement.InnerText = typedModel.Content ?? string.Empty;

            //typedWebpart.Content = xmlElement;
        }
コード例 #19
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty
                    {
                        Name = prop.Name
                    };

                    typedWebpart.Properties.Add(currentProperty);
                }

                if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
                {
                    // Enhance 'UserCodeWebPartDefinition' 
                    // UserCodeProperty should support ~sitecollection/~site tokens #485

                    var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Value = prop.Value,
                        Context = CurrentHost.HostFile.Web
                    }).Value;

                    currentProperty.Value = value;
                }
                else
                {
                    currentProperty.Value = prop.Value;
                }
            }
        }
コード例 #20
0
        public void Deploy_WebParts()
        {
            // Step 1, define security groups
            var gettingStarted = new SPMeta2.Definitions.WebPartDefinition
            {
                Title              = "Getting started with site",
                Id                 = "spmGettingStarted",
                ZoneId             = "Main",
                ZoneIndex          = 100,
                WebpartXmlTemplate = ResourceReader.ReadFromResourceName("Templates.Webparts.Get started with your site.webpart")
            };

            var contentEditor = new SPMeta2.Definitions.WebPartDefinition
            {
                Title              = "SPMeta2 Content Editor Webpart",
                Id                 = "spmContentEditorWebpart",
                ZoneId             = "Main",
                ZoneIndex          = 200,
                WebpartXmlTemplate = ResourceReader.ReadFromResourceName("Templates.Webparts.Content Editor.dwp")
            };

            var webpartPage = new WebPartPageDefinition
            {
                Title              = "Getting started",
                FileName           = "Getting-Started.aspx",
                PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1
            };

            // Step 2, define web model and artifact relationships - add security groups t the web
            var model = SPMeta2Model
                        .NewWebModel(web =>
            {
                web
                .AddList(BuiltInListDefinitions.SitePages, list =>
                {
                    list
                    .AddWebPartPage(webpartPage, page =>
                    {
                        page
                        .AddWebPart(gettingStarted)
                        .AddWebPart(contentEditor);
                    });
                });
            });

            // Step 3, deploy model
            DeployWebModel(model);
        }
コード例 #21
0
        protected virtual void ProcessWebpartProperties(WebPart instance, WebPartDefinition definition)
        {
            if (definition.Width.HasValue)
                instance.Width = new Unit(definition.Width.Value);

            if (definition.Height.HasValue)
                instance.Height = new Unit(definition.Height.Value);

            if (!string.IsNullOrEmpty(definition.ChromeState))
                instance.ChromeState = (PartChromeState)Enum.Parse(typeof(PartChromeState), definition.ChromeState);

            if (!string.IsNullOrEmpty(definition.ChromeType))
            {
                var chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType);
                instance.ChromeType = (PartChromeType)Enum.Parse(typeof(PartChromeType), chromeType);
            }

            if (!string.IsNullOrEmpty(definition.ImportErrorMessage))
                instance.ImportErrorMessage = definition.ImportErrorMessage;

            if (!string.IsNullOrEmpty(definition.Description))
                instance.Description = definition.Description;

            if (!string.IsNullOrEmpty(definition.TitleIconImageUrl))
                instance.TitleIconImageUrl = definition.TitleIconImageUrl;

            if (!string.IsNullOrEmpty(definition.TitleUrl))
                instance.TitleUrl = definition.TitleUrl;

            if (!string.IsNullOrEmpty(definition.ExportMode))
                instance.ExportMode = (WebPartExportMode)Enum.Parse(typeof(WebPartExportMode), definition.ExportMode);


            var dataFomWebPart = instance as DataFormWebPart;

            if (dataFomWebPart != null
                && definition.ParameterBindings != null
                && definition.ParameterBindings.Count > 0)
            {
                var parameterBinder = new WebPartParameterBindingsOptions();

                foreach (var binding in definition.ParameterBindings)
                    parameterBinder.AddParameterBinding(binding.Name, binding.Location);

                var parameterBindingValue = SecurityElement.Escape(parameterBinder.ParameterBinding);
                dataFomWebPart.ParameterBindings = parameterBindingValue;
            }
        }
コード例 #22
0
        protected WebPart FindExistingWebPart(IEnumerable <Microsoft.SharePoint.Client.WebParts.WebPartDefinition> webPartDefenitions,
                                              WebPartDefinition webPartModel)
        {
            // gosh, you got to be kidding
            // internally, SharePoint returns StorageKey as ID. hence.. no ability to trace unique web part on the page
            // the only thing is comparing Titles an utilize them as a primary key

            foreach (var webPartDefinition in webPartDefenitions)
            {
                if (String.Compare(webPartDefinition.WebPart.Title, webPartModel.Title, System.StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(webPartDefinition.WebPart);
                }
            }

            return(null);
        }
コード例 #23
0
        //protected void WithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
        //    Action<WebPart, Microsoft.SharePoint.Client.WebParts.WebPartDefinition> action)
        //{
        //    WithExistingWebPart(listItem.File, webPartModel, action);
        //}



        protected void WithExistingWebPart(File pageFile, WebPartDefinition webPartModel,
                                           Action <WebPart, Microsoft.SharePoint.Client.WebParts.WebPartDefinition> action)
        {
            var context        = pageFile.Context;
            var webPartManager = pageFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

            // web part on the page
            var webpartOnPage      = webPartManager.WebParts.Include(wp => wp.Id, wp => wp.WebPart);
            var webPartDefenitions = context.LoadQuery(webpartOnPage);

            context.ExecuteQueryWithTrace();

            Microsoft.SharePoint.Client.WebParts.WebPartDefinition def = null;
            var existingWebPart = FindExistingWebPart(webPartDefenitions, webPartModel, out def);

            action(existingWebPart, def);
        }
コード例 #24
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentBySearchWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = definition.WithAssertAndCast<ContentBySearchWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // templates
            if (!string.IsNullOrEmpty(typedModel.GroupTemplateId))
                typedWebpart.GroupTemplateId = typedModel.GroupTemplateId;

            if (!string.IsNullOrEmpty(typedModel.ItemTemplateId))
                typedWebpart.ItemTemplateId = typedModel.ItemTemplateId;

            if (!string.IsNullOrEmpty(typedModel.RenderTemplateId))
                typedWebpart.RenderTemplateId = typedModel.RenderTemplateId;

            if (!string.IsNullOrEmpty(typedModel.DataProviderJSON))
                typedWebpart.DataProviderJSON = typedModel.DataProviderJSON;

            if (!string.IsNullOrEmpty(typedModel.PropertyMappings))
                typedWebpart.PropertyMappings = typedModel.PropertyMappings;

            if (typedModel.OverwriteResultPath.HasValue)
                typedWebpart.OverwriteResultPath = typedModel.OverwriteResultPath.Value;

            if (typedModel.ShouldHideControlWhenEmpty.HasValue)
                typedWebpart.ShouldHideControlWhenEmpty = typedModel.ShouldHideControlWhenEmpty.Value;

            if (typedModel.LogAnalyticsViewEvent.HasValue)
                typedWebpart.LogAnalyticsViewEvent = typedModel.LogAnalyticsViewEvent.Value;

            if (typedModel.AddSEOPropertiesFromSearch.HasValue)
                typedWebpart.AddSEOPropertiesFromSearch = typedModel.AddSEOPropertiesFromSearch.Value;

            if (typedModel.StartingItemIndex.HasValue)
                typedWebpart.StartingItemIndex = typedModel.StartingItemIndex.Value;

            // misc
            if (typedModel.NumberOfItems.HasValue)
                typedWebpart.NumberOfItems = typedModel.NumberOfItems.Value;

            if (typedModel.ResultsPerPage.HasValue)
                typedWebpart.ResultsPerPage = typedModel.ResultsPerPage.Value;
        }
コード例 #25
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ResultScriptWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<ResultScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(definition.DataProviderJSON))
                typedWebpart.DataProviderJSON = definition.DataProviderJSON;

            if (!string.IsNullOrEmpty(definition.EmptyMessage))
                typedWebpart.EmptyMessage = definition.EmptyMessage;

            if (definition.ResultsPerPage.HasValue)
                typedWebpart.ResultsPerPage = definition.ResultsPerPage.Value;

            if (definition.ShowResultCount.HasValue)
                typedWebpart.ShowResultCount = definition.ShowResultCount.Value;
        }
コード例 #26
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // Enhance 'ClientWebPart' provision - ProductWebId should be current web by default #623
            // https://github.com/SubPointSolutions/spmeta2/issues/623
            var productId = typedModel.ProductId;

            if (!productId.HasGuidValue())
                productId = _host.SPLimitedWebPartManager.Web.ID;

            typedWebpart.FeatureId = typedModel.FeatureId;
            typedWebpart.ProductId = productId.Value;
            typedWebpart.WebPartName = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
コード例 #27
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;
            SPList list = null;

            if (typedModel.ListId.HasGuidValue())
                list = web.Lists[typedModel.ListId.Value];
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
                list = web.Lists.TryGetList(typedModel.ListTitle);


            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId = list.ID;

            // view check
            if (list != null)
            {
                SPView view = null;

                if (typedModel.ViewId.HasGuidValue())
                    view = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    view = list.Views[typedModel.ViewName];

                if (view != null)
                {
                    typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
                    typedWebpart.TitleUrl = view.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;
        }
コード例 #28
0
        protected void WithWithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
                                               Action <WebPart> action)
        {
            var context  = listItem.Context;
            var filePath = listItem["FileRef"].ToString();

            var web = listItem.ParentList.ParentWeb;

            var pageFile       = web.GetFileByServerRelativeUrl(filePath);
            var webPartManager = pageFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

            // web part on the page
            var webpartOnPage      = webPartManager.WebParts.Include(wp => wp.Id, wp => wp.WebPart);
            var webPartDefenitions = context.LoadQuery(webpartOnPage);

            context.ExecuteQueryWithTrace();

            var existingWebPart = FindExistingWebPart(webPartDefenitions, webPartModel);

            action(existingWebPart);
        }
コード例 #29
0
        protected void WithWithExistingWebPart(ListItem listItem, WebPartDefinition webPartModel,
             Action<WebPart, Microsoft.SharePoint.Client.WebParts.WebPartDefinition> action)
        {
            var context = listItem.Context;
            var filePath = listItem["FileRef"].ToString();

            var web = listItem.ParentList.ParentWeb;

            var pageFile = web.GetFileByServerRelativeUrl(filePath);
            var webPartManager = pageFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

            // web part on the page
            var webpartOnPage = webPartManager.WebParts.Include(wp => wp.Id, wp => wp.WebPart);
            var webPartDefenitions = context.LoadQuery(webpartOnPage);

            context.ExecuteQueryWithTrace();


            Microsoft.SharePoint.Client.WebParts.WebPartDefinition def = null;
            var existingWebPart = FindExistingWebPart(webPartDefenitions, webPartModel, out def);

            action(existingWebPart, def);
        }
コード例 #30
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ContentEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedModel.ContentLink))
            {
                var contentLinkValue = typedModel.ContentLink ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original contentLinkValue: [{0}]",
                    contentLinkValue);

                contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = contentLinkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced contentLinkValue: [{0}]", contentLinkValue);

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(typedModel.Content))
            {

                var xmlDoc = new XmlDocument();
                var xmlElement = xmlDoc.CreateElement("ContentElement");

                var content = typedModel.Content ?? string.Empty;

                xmlElement.InnerText = content;
                typedWebpart.Content = xmlElement;
            }
        }
コード例 #31
0
 public static ModelNode AddWebPart(this ModelNode model, WebPartDefinition definition)
 {
     return AddWebPart(model, definition, null);
 }
コード例 #32
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<XsltListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            // bind list
            SPList list = null;

            if (typedModel.ListId.HasValue && typedModel.ListId != default(Guid))
                list = web.Lists[typedModel.ListId.Value];
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
                list = web.Lists.TryGetList(typedModel.ListTitle);
            else
            {
                throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined.");
            }

            if (list != null)
            {
                typedWebpart.ListName = list.ID.ToString("B").ToUpperInvariant();
                typedWebpart.TitleUrl = list.DefaultViewUrl;
            }

            // view check
            if (list != null)
            {
                SPView srcView = null;

                if (typedModel.ViewId.HasValue && typedModel.ViewId != default(Guid))
                    srcView = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    srcView = list.Views[typedModel.ViewName];

                if (srcView != null)
                {
                    if (!string.IsNullOrEmpty(typedWebpart.ViewGuid))
                    {
                        // update hidden view, otherwise we can have weird SharePoint exception
                        // https://github.com/SubPointSolutions/spmeta2/issues/487

                        var hiddenView = list.Views[new Guid(typedWebpart.ViewGuid)];

                        hiddenView.ViewFields.DeleteAll();

                        foreach (string f in srcView.ViewFields)
                            hiddenView.ViewFields.Add(f);

                        hiddenView.RowLimit = srcView.RowLimit;
                        hiddenView.Query = srcView.Query;
#if !NET35
                        hiddenView.JSLink = srcView.JSLink;
#endif
                        hiddenView.IncludeRootFolder = srcView.IncludeRootFolder;
                        hiddenView.Scope = srcView.Scope;

                        hiddenView.Update();
                    }
                    else
                    {
                        typedWebpart.ViewGuid = srcView.ID.ToString("B").ToUpperInvariant();
                    }

                    typedWebpart.TitleUrl = srcView.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;

            // weird, but it must be set to avoid null-ref exceptions
            typedWebpart.GhostedXslLink = "main.xsl";

#if !NET35
            // rest
            typedWebpart.JSLink = typedModel.JSLink;
#endif

            if (typedModel.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedModel.CacheXslStorage.Value;

            if (typedModel.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedModel.CacheXslTimeOut.Value;

#if !NET35
            if (typedModel.ShowTimelineIfAvailable.HasValue)
                typedWebpart.ShowTimelineIfAvailable = typedModel.ShowTimelineIfAvailable.Value;
#endif

            if (!string.IsNullOrEmpty(typedModel.Xsl))
            {
                typedWebpart.Xsl = typedModel.Xsl;
            }

            if (!string.IsNullOrEmpty(typedModel.XslLink))
            {
                var urlValue = typedModel.XslLink;

                typedWebpart.XslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinition))
            {
                typedWebpart.XmlDefinition = typedModel.XmlDefinition;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinitionLink))
            {
                var urlValue = typedModel.XmlDefinitionLink;
                typedWebpart.XmlDefinitionLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.GhostedXslLink))
            {
                var urlValue = typedModel.GhostedXslLink;
                typedWebpart.GhostedXslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.BaseXsltHashKey))
                typedWebpart.BaseXsltHashKey = typedModel.BaseXsltHashKey;

            if (typedModel.DisableColumnFiltering.HasValue)
                typedWebpart.DisableColumnFiltering = typedModel.DisableColumnFiltering.Value;

#if !NET35
            if (typedModel.DisableSaveAsNewViewButton.HasValue)
                typedWebpart.DisableSaveAsNewViewButton = typedModel.DisableSaveAsNewViewButton.Value;

            if (typedModel.DisableViewSelectorMenu.HasValue)
                typedWebpart.DisableViewSelectorMenu = typedModel.DisableViewSelectorMenu.Value;

            if (typedModel.InplaceSearchEnabled.HasValue)
                typedWebpart.InplaceSearchEnabled = typedModel.InplaceSearchEnabled.Value;
#endif
        }
コード例 #33
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentByQueryWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = definition.WithAssertAndCast<ContentByQueryWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original MainXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced MainXslLink: [{0}]", linkValue);

                typedWebpart.MainXslLink = linkValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.ItemXslLink))
            {
                var linkValue = typedDefinition.ItemXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original ItemXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced ItemXslLink: [{0}]", linkValue);

                typedWebpart.ItemXslLink = linkValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.HeaderXslLink))
            {
                var linkValue = typedDefinition.HeaderXslLink;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original HeaderXslLink: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced HeaderXslLink: [{0}]", linkValue);

                typedWebpart.HeaderXslLink = linkValue;
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
                typedWebpart.ItemStyle = typedDefinition.ItemStyle;

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
                typedWebpart.GroupStyle = typedDefinition.GroupStyle;


            // cache settings
            if (typedDefinition.UseCache.HasValue)
                typedWebpart.UseCache = typedDefinition.UseCache.Value;

            if (typedDefinition.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedDefinition.CacheXslStorage.Value;

            if (typedDefinition.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedDefinition.CacheXslTimeOut.Value;

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
                typedWebpart.ItemLimit = typedDefinition.ItemLimit.Value;

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
                typedWebpart.DataMappings = typedDefinition.DataMappings;

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
                typedWebpart.DataMappingViewFields = typedDefinition.DataMappingViewFields;

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
                typedWebpart.ShowUntargetedItems = typedDefinition.ShowUntargetedItems.Value;

            if (typedDefinition.PlayMediaInBrowser.HasValue)
                typedWebpart.PlayMediaInBrowser = typedDefinition.PlayMediaInBrowser.Value;

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
                typedWebpart.FilterType1 = typedDefinition.FilterType1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
                typedWebpart.FilterType2 = typedDefinition.FilterType2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
                typedWebpart.FilterType3 = typedDefinition.FilterType3;

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
                typedWebpart.FilterField1 = typedDefinition.FilterField1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
                typedWebpart.FilterField2 = typedDefinition.FilterField2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
                typedWebpart.FilterField3 = typedDefinition.FilterField3;

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
                typedWebpart.Filter1IsCustomValue = typedDefinition.Filter1IsCustomValue.Value;

            if (typedDefinition.Filter2IsCustomValue.HasValue)
                typedWebpart.Filter2IsCustomValue = typedDefinition.Filter2IsCustomValue.Value;

            if (typedDefinition.Filter3IsCustomValue.HasValue)
                typedWebpart.Filter3IsCustomValue = typedDefinition.Filter3IsCustomValue.Value;

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
                typedWebpart.FilterValue1 = typedDefinition.FilterValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
                typedWebpart.FilterValue2 = typedDefinition.FilterValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
                typedWebpart.FilterValue3 = typedDefinition.FilterValue3;


            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                typedWebpart.Filter1ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter1ChainingOperator);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                typedWebpart.Filter2ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter2ChainingOperator);
            }


            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
                typedWebpart.SortBy = typedDefinition.SortBy;

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
                typedWebpart.SortByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.SortByDirection);

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
                typedWebpart.SortByFieldType = typedDefinition.SortByFieldType;

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                typedWebpart.GroupByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.GroupByDirection);
            }


            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                typedWebpart.FilterOperator1 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                typedWebpart.FilterOperator2 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                typedWebpart.FilterOperator3 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator3);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
                typedWebpart.FilterDisplayValue1 = typedDefinition.FilterDisplayValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
                typedWebpart.FilterDisplayValue2 = typedDefinition.FilterDisplayValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
                typedWebpart.FilterDisplayValue3 = typedDefinition.FilterDisplayValue3;


            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
                typedWebpart.ServerTemplate = typedDefinition.ServerTemplate.ToString();

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
                typedWebpart.ContentTypeName = typedDefinition.ContentTypeName;

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
                typedWebpart.ContentTypeBeginsWithId = typedDefinition.ContentTypeBeginsWithId;

            if (typedDefinition.ListId.HasGuidValue())
                typedWebpart.ListId = typedDefinition.ListId.Value;

            if (typedDefinition.ListGuid.HasGuidValue())
                typedWebpart.ListGuid = typedDefinition.ListGuid.Value.ToString("D");

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
                typedWebpart.ListName = typedDefinition.ListName;

            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
                typedWebpart.WebUrl = typedDefinition.WebUrl;

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
                typedWebpart.ListsOverride = typedDefinition.ListsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
                typedWebpart.ViewFieldsOverride = typedDefinition.ViewFieldsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
                typedWebpart.QueryOverride = typedDefinition.QueryOverride;

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
                typedWebpart.CommonViewFields = typedDefinition.CommonViewFields;

            if (typedDefinition.FilterByAudience.HasValue)
                typedWebpart.FilterByAudience = typedDefinition.FilterByAudience.Value;
        }
コード例 #34
0
 public static ModelNode AddWebPart(this ModelNode model, WebPartDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
コード例 #35
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<XsltListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            // bind list
            var targetWeb = web;

            if (!string.IsNullOrEmpty(typedModel.WebUrl) || typedModel.WebId.HasGuidValue())
                targetWeb = new LookupFieldModelHandler().GetTargetWeb(web.Site, typedModel.WebUrl, typedModel.WebId);

            var list = GetTargetList(targetWeb, typedModel.ListTitle, typedModel.ListUrl, typedModel.ListId);

            if (list != null)
            {
                typedWebpart.ListName = list.ID.ToString("B").ToUpperInvariant();
                typedWebpart.TitleUrl = list.DefaultViewUrl;
            }

            // view check
            if (list != null)
            {
                SPView srcView = null;

                if (typedModel.ViewId.HasValue && typedModel.ViewId != default(Guid))
                    srcView = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    srcView = list.Views[typedModel.ViewName];

                if (srcView != null)
                {
                    if (!string.IsNullOrEmpty(typedWebpart.ViewGuid))
                    {
                        // update hidden view, otherwise we can have weird SharePoint exception
                        // https://github.com/SubPointSolutions/spmeta2/issues/487

                        var hiddenView = list.Views[new Guid(typedWebpart.ViewGuid)];

                        hiddenView.SetViewXml(srcView.GetViewXml());
                     
                        hiddenView.Update();
                    }
                    else
                    {
                        typedWebpart.ViewGuid = srcView.ID.ToString("B").ToUpperInvariant();
                    }

                    typedWebpart.TitleUrl = srcView.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;

            // weird, but it must be set to avoid null-ref exceptions
            typedWebpart.GhostedXslLink = "main.xsl";

#if !NET35
            // rest
            typedWebpart.JSLink = typedModel.JSLink;
#endif

            if (typedModel.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedModel.CacheXslStorage.Value;

            if (typedModel.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedModel.CacheXslTimeOut.Value;

#if !NET35
            if (typedModel.ShowTimelineIfAvailable.HasValue)
                typedWebpart.ShowTimelineIfAvailable = typedModel.ShowTimelineIfAvailable.Value;
#endif

            if (!string.IsNullOrEmpty(typedModel.Xsl))
            {
                typedWebpart.Xsl = typedModel.Xsl;
            }

            if (!string.IsNullOrEmpty(typedModel.XslLink))
            {
                var urlValue = typedModel.XslLink;

                typedWebpart.XslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinition))
            {
                typedWebpart.XmlDefinition = typedModel.XmlDefinition;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinitionLink))
            {
                var urlValue = typedModel.XmlDefinitionLink;
                typedWebpart.XmlDefinitionLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.GhostedXslLink))
            {
                var urlValue = typedModel.GhostedXslLink;
                typedWebpart.GhostedXslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.BaseXsltHashKey))
                typedWebpart.BaseXsltHashKey = typedModel.BaseXsltHashKey;

            if (typedModel.DisableColumnFiltering.HasValue)
                typedWebpart.DisableColumnFiltering = typedModel.DisableColumnFiltering.Value;

#if !NET35
            if (typedModel.DisableSaveAsNewViewButton.HasValue)
                typedWebpart.DisableSaveAsNewViewButton = typedModel.DisableSaveAsNewViewButton.Value;

            if (typedModel.DisableViewSelectorMenu.HasValue)
                typedWebpart.DisableViewSelectorMenu = typedModel.DisableViewSelectorMenu.Value;

            if (typedModel.InplaceSearchEnabled.HasValue)
                typedWebpart.InplaceSearchEnabled = typedModel.InplaceSearchEnabled.Value;
#endif
        }
コード例 #36
0
        protected override void OnAfterDeployModel(WebpartPageModelHost host, WebPartDefinition definition)
        {
            var typedDefinition = definition.WithAssertAndCast<XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedDefinition.Toolbar))
            {
                var existingWebPart = host.SPLimitedWebPartManager
                    .WebParts
                    .OfType<System.Web.UI.WebControls.WebParts.WebPart>()
                    .FirstOrDefault(wp => !string.IsNullOrEmpty(wp.ID) &&
                                          wp.ID.ToUpper() == definition.Id.ToUpper());

                if (existingWebPart != null)
                {
                    // patching up the view -> ToolbarType
                    var xsltWebPart = existingWebPart as XsltListViewWebPart;

                    if (xsltWebPart != null)
                    {

                        // big TODO for .NET 35
                        // xsltWebPart.View does not exist for .NET 35
                        // the implementation will be done upon the community demand

#if !NET35

                        var targetView = xsltWebPart.View;

                        // fixing up the Toolbar
                        if (!string.IsNullOrEmpty(typedDefinition.Toolbar))
                        {
                            var htmlSchemaXml = XDocument.Parse(targetView.HtmlSchemaXml);

                            var useShowAlwaysValue =
                                (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper())
                                && typedDefinition.ToolbarShowAlways.HasValue
                                && typedDefinition.ToolbarShowAlways.Value;

                            var toolbarNode = htmlSchemaXml.Root
                                .Descendants("Toolbar")
                                .FirstOrDefault();

                            if (toolbarNode == null)
                            {
                                toolbarNode = new XElement("Toolbar");
                                htmlSchemaXml.Root.Add(toolbarNode);
                            }

                            toolbarNode.SetAttributeValue("Type", typedDefinition.Toolbar);

                            if (useShowAlwaysValue)
                            {
                                toolbarNode.SetAttributeValue("ShowAlways", "TRUE");
                            }
                            else
                            {
                                XAttribute attr = toolbarNode.Attribute("ShowAlways");
                                if (attr != null && string.IsNullOrEmpty(attr.Value))
                                    attr.Remove();
                            }

                            var field = targetView.GetType()
                                                  .GetProperty("ListViewXml",
                                                     BindingFlags.NonPublic | BindingFlags.Instance);

                            if (field != null)
                            {
                                field.SetValue(targetView, htmlSchemaXml.Root.GetInnerXmlAsString(), null);
                            }
                        }

                        targetView.Update();

#endif
                    }
                }
            }
        }