当前位置: 首页>>代码示例>>C#>>正文


C# Web.SetPropertyBagValue方法代码示例

本文整理汇总了C#中Web.SetPropertyBagValue方法的典型用法代码示例。如果您正苦于以下问题:C# Web.SetPropertyBagValue方法的具体用法?C# Web.SetPropertyBagValue怎么用?C# Web.SetPropertyBagValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Web的用法示例。


在下文中一共展示了Web.SetPropertyBagValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateTemplateOnWeb

        private void UpdateTemplateOnWeb(Web targetWeb, RefreshSitesJob job)
        {
            targetWeb.EnsureProperty(w => w.Url);

            var infoJson = targetWeb.GetPropertyBagValueString(PnPPartnerPackConstants.PropertyBag_TemplateInfo, null);
            if (!String.IsNullOrEmpty(infoJson))
            {
                Console.WriteLine($"Updating template for site: {targetWeb.Url}");

                var info = JsonConvert.DeserializeObject<SiteTemplateInfo>(infoJson);

                // If we have the template info
                if (info != null && !String.IsNullOrEmpty(info.TemplateProviderType))
                {
                    ProvisioningTemplate template = null;

                    // Try to retrieve the template
                    var templatesProvider = PnPPartnerPackSettings.TemplatesProviders[info.TemplateProviderType];
                    if (templatesProvider != null)
                    {
                        template = templatesProvider.GetProvisioningTemplate(info.TemplateUri);
                    }

                    // If we have the template
                    if (template != null)
                    {
                        // Configure proper settings for the provisioning engine
                        ProvisioningTemplateApplyingInformation ptai =
                            new ProvisioningTemplateApplyingInformation();

                        // Write provisioning steps on console log
                        ptai.MessagesDelegate += delegate (string message, ProvisioningMessageType messageType)
                        {
                            Console.WriteLine("{0} - {1}", messageType, messageType);
                        };
                        ptai.ProgressDelegate += delegate (string message, int step, int total)
                        {
                            Console.WriteLine("{0:00}/{1:00} - {2}", step, total, message);
                        };

                        // Exclude handlers not supported in App-Only
                        ptai.HandlersToProcess ^=
                            OfficeDevPnP.Core.Framework.Provisioning.Model.Handlers.TermGroups;
                        ptai.HandlersToProcess ^=
                            OfficeDevPnP.Core.Framework.Provisioning.Model.Handlers.SearchSettings;

                        // Configure template parameters
                        if (info.TemplateParameters != null)
                        {
                            foreach (var key in info.TemplateParameters.Keys)
                            {
                                if (info.TemplateParameters.ContainsKey(key))
                                {
                                    template.Parameters[key] = info.TemplateParameters[key];
                                }
                            }
                        }

                        targetWeb.ApplyProvisioningTemplate(template, ptai);

                        // Save the template information in the target site
                        var updatedInfo = new SiteTemplateInfo()
                        {
                            TemplateProviderType = info.TemplateProviderType,
                            TemplateUri = info.TemplateUri,
                            TemplateParameters = template.Parameters,
                            AppliedOn = DateTime.Now,
                        };
                        var jsonInfo = JsonConvert.SerializeObject(updatedInfo);
                        targetWeb.SetPropertyBagValue(PnPPartnerPackConstants.PropertyBag_TemplateInfo, jsonInfo);

                        Console.WriteLine($"Updated template on site: {targetWeb.Url}");

                        // Update (recursively) all the subwebs of the current web
                        targetWeb.EnsureProperty(w => w.Webs);

                        foreach (var subweb in targetWeb.Webs)
                        {
                            UpdateTemplateOnWeb(subweb, job);
                        }
                    }
                }
            }
        }
开发者ID:OfficeDev,项目名称:PnP-Partner-Pack,代码行数:84,代码来源:RefreshSitesJobHandler.cs

示例2: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                // Check if this is not a noscript site as we're not allowed to write to the web property bag is that one
                bool isNoScriptSite = web.IsNoScriptSite();
                if (isNoScriptSite)
                {

                    return parser;
                }

                web.SetPropertyBagValue("_PnP_ProvisioningTemplateId", template.Id != null ? template.Id : "");
                web.AddIndexedPropertyBagKey("_PnP_ProvisioningTemplateId");

                ProvisioningTemplateInfo info = new ProvisioningTemplateInfo();
                info.TemplateId = template.Id != null ? template.Id : "";
                info.TemplateVersion = template.Version;
                info.TemplateSitePolicy = template.SitePolicy;
                info.Result = true;
                info.ProvisioningTime = DateTime.Now;

                string jsonInfo = JsonConvert.SerializeObject(info);

                web.SetPropertyBagValue("_PnP_ProvisioningTemplateInfo", jsonInfo);
            }
            return parser;
        }
开发者ID:s-KaiNet,项目名称:PnP-Sites-Core,代码行数:28,代码来源:ObjectPersistTemplateInfo.cs

示例3: ProvisionObjects

        public override void ProvisionObjects(Web web, ProvisioningTemplate template)
        {
            web.SetPropertyBagValue("_PnP_ProvisioningTemplateId", template.Id != null ? template.Id : "");
            web.AddIndexedPropertyBagKey("_PnP_ProvisioningTemplateId");

            ProvisioningTemplateInfo info = new ProvisioningTemplateInfo();
            info.TemplateId = template.Id != null ? template.Id : "";
            info.TemplateVersion = template.Version;
            info.TemplateSitePolicy = template.SitePolicy;
            info.Result = true;
            info.ProvisioningTime = DateTime.Now;

            string jsonInfo = JsonConvert.SerializeObject(info);
            
            web.SetPropertyBagValue("_PnP_ProvisioningTemplateInfo", jsonInfo);
        }
开发者ID:ipbhattarai,项目名称:PnP,代码行数:16,代码来源:ObjectPersistTemplateInfo.cs

示例4: ApplyRemoteTemplate

        /// <summary>
        /// Actual implementation of the apply templates
        /// </summary>
        /// <param name="web"></param>
        /// <param name="template"></param>
        internal void ApplyRemoteTemplate(Web web, ProvisioningTemplate template)
        {
            // Site Security
            new ObjectSiteSecurity().ProvisionObjects(web, template);

            // Features
            new ObjectFeatures().ProvisionObjects(web, template);

            // Site Fields
            new ObjectField().ProvisionObjects(web, template);

            // Content Types
            new ObjectContentType().ProvisionObjects(web, template);

            // Lists
            new ObjectListInstance().ProvisionObjects(web, template);

            // Files
            new ObjectFiles().ProvisionObjects(web, template);

            // Custom actions
            new ObjectCustomActions().ProvisionObjects(web, template);

            // Composite look (commented)
            //new ObjectComposedLook().ProvisionObjects(web, template);

            // Property Bag Entries
            new ObjectPropertyBagEntry().ProvisionObjects(web, template);

            // Extensibility Provider CallOut the last thing we do.
            new ObjectExtensibilityProviders().ProvisionObjects(web, template);

            web.SetPropertyBagValue("_PnP_ProvisioningTemplateId", template.ID != null ? template.ID : "");
            web.AddIndexedPropertyBagKey("_PnP_ProvisioningTemplateId");

            ProvisioningTemplateInfo info = new ProvisioningTemplateInfo();
            info.TemplateID = template.ID != null ? template.ID : "";
            info.TemplateVersion = template.Version;
            info.TemplateSitePolicy = template.SitePolicy;
            info.Result = true;
            info.ProvisioningTime = DateTime.Now;

            var s = new JavaScriptSerializer();
            string jsonInfo = s.Serialize(info);

            web.SetPropertyBagValue("_PnP_ProvisioningTemplateInfo", jsonInfo);
        }
开发者ID:xaviayala,项目名称:Birchman,代码行数:52,代码来源:SiteToTemplateConversion.cs

示例5: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                if (template.ComposedLook != null &&
                    !template.ComposedLook.Equals(ComposedLook.Empty))
                {
                    bool executeQueryNeeded = false;
                    if (executeQueryNeeded)
                    {
                        web.Context.ExecuteQueryRetry();
                    }

                    if (String.IsNullOrEmpty(template.ComposedLook.ColorFile) &&
                        String.IsNullOrEmpty(template.ComposedLook.FontFile) &&
                        String.IsNullOrEmpty(template.ComposedLook.BackgroundFile))
                    {
                        // Apply OOB theme
                        web.SetComposedLookByUrl(template.ComposedLook.Name);
                    }
                    else
                    {
                        // Apply custom theme
                        string colorFile = null;
                        if (!string.IsNullOrEmpty(template.ComposedLook.ColorFile))
                        {
                            colorFile = parser.ParseString(template.ComposedLook.ColorFile);
                        }
                        string backgroundFile = null;
                        if (!string.IsNullOrEmpty(template.ComposedLook.BackgroundFile))
                        {
                            backgroundFile = parser.ParseString(template.ComposedLook.BackgroundFile);
                        }
                        string fontFile = null;
                        if (!string.IsNullOrEmpty(template.ComposedLook.FontFile))
                        {
                            fontFile = parser.ParseString(template.ComposedLook.FontFile);
                        }

                        string masterUrl = null;
                        if (template.WebSettings != null && !string.IsNullOrEmpty(template.WebSettings.MasterPageUrl))
                        {
                            masterUrl = parser.ParseString(template.WebSettings.MasterPageUrl);
                        }
                        web.CreateComposedLookByUrl(template.ComposedLook.Name, colorFile, fontFile, backgroundFile, masterUrl);
                        web.SetComposedLookByUrl(template.ComposedLook.Name, colorFile, fontFile, backgroundFile, masterUrl);

                        var composedLookJson = JsonConvert.SerializeObject(template.ComposedLook);

                        web.SetPropertyBagValue("_PnP_ProvisioningTemplateComposedLookInfo", composedLookJson);
                    }

                    // Persist composed look info in property bag

                }
            }
            return parser;
        }
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:58,代码来源:ObjectComposedLook.cs

示例6: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                web.SetPropertyBagValue("_PnP_ProvisioningTemplateId", template.Id != null ? template.Id : "");
                web.AddIndexedPropertyBagKey("_PnP_ProvisioningTemplateId");

                ProvisioningTemplateInfo info = new ProvisioningTemplateInfo();
                info.TemplateId = template.Id != null ? template.Id : "";
                info.TemplateVersion = template.Version;
                info.TemplateSitePolicy = template.SitePolicy;
                info.Result = true;
                info.ProvisioningTime = DateTime.Now;

                string jsonInfo = JsonConvert.SerializeObject(info);

                web.SetPropertyBagValue("_PnP_ProvisioningTemplateInfo", jsonInfo);
            }
            return parser;
        }
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:20,代码来源:ObjectPersistTemplateInfo.cs

示例7: ProvisionObjects

        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                if (template.Navigation != null)
                {
                    // The Navigation handler works only for sites with Publishing Features enabled
                    if (!web.IsPublishingWeb())
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Navigation_Context_web_is_not_publishing);
                        return parser;
                    }

                    // Retrieve the current web navigation settings
                    var navigationSettings = new WebNavigationSettings(web.Context, web);
                    web.Context.Load(navigationSettings, ns => ns.CurrentNavigation, ns => ns.GlobalNavigation);
                    web.Context.ExecuteQueryRetry();

                    if (template.Navigation.GlobalNavigation != null)
                    {
                        switch (template.Navigation.GlobalNavigation.NavigationType)
                        {
                            case GlobalNavigationType.Inherit:
                                navigationSettings.GlobalNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
                                break;
                            case GlobalNavigationType.Managed:
                                if (template.Navigation.GlobalNavigation.ManagedNavigation == null)
                                {
                                    throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_global_managed_navigation);
                                }
                                navigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider;
                                navigationSettings.GlobalNavigation.TermStoreId = Guid.Parse(parser.ParseString(template.Navigation.GlobalNavigation.ManagedNavigation.TermStoreId));
                                navigationSettings.GlobalNavigation.TermSetId = Guid.Parse(parser.ParseString(template.Navigation.GlobalNavigation.ManagedNavigation.TermSetId));
                                break;
                            case GlobalNavigationType.Structural:
                            default:
                                if (template.Navigation.GlobalNavigation.StructuralNavigation == null)
                                {
                                    throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_global_structural_navigation);
                                }
                                ProvisionGlobalStructuralNavigation(web,
                                    template.Navigation.GlobalNavigation.StructuralNavigation, parser);
                                break;
                        }
                        web.Context.ExecuteQueryRetry();
                    }

                    if (template.Navigation.CurrentNavigation != null)
                    {
                        switch (template.Navigation.CurrentNavigation.NavigationType)
                        {
                            case CurrentNavigationType.Inherit:
                                navigationSettings.CurrentNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
                                break;
                            case CurrentNavigationType.Managed:
                                if (template.Navigation.CurrentNavigation.ManagedNavigation == null)
                                {
                                    throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_managed_navigation);
                                }
                                navigationSettings.CurrentNavigation.Source = StandardNavigationSource.TaxonomyProvider;
                                navigationSettings.CurrentNavigation.TermStoreId = Guid.Parse(parser.ParseString(template.Navigation.CurrentNavigation.ManagedNavigation.TermStoreId));
                                navigationSettings.CurrentNavigation.TermSetId = Guid.Parse(parser.ParseString(template.Navigation.CurrentNavigation.ManagedNavigation.TermSetId));
                                break;
                            case CurrentNavigationType.StructuralLocal:
                                web.SetPropertyBagValue(NavigationShowSiblings, "false");
                                if (template.Navigation.CurrentNavigation.StructuralNavigation == null)
                                {
                                    throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_structural_navigation);
                                }
                                ProvisionCurrentStructuralNavigation(web,
                                    template.Navigation.CurrentNavigation.StructuralNavigation, parser);
                                break;
                            case CurrentNavigationType.Structural:
                            default:
                                if (template.Navigation.CurrentNavigation.StructuralNavigation == null)
                                {
                                    throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_structural_navigation);
                                }
                                ProvisionCurrentStructuralNavigation(web,
                                    template.Navigation.CurrentNavigation.StructuralNavigation, parser);
                                break;
                        }
                        web.Context.ExecuteQueryRetry();
                    }
                }
            }

            return parser;
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:89,代码来源:ObjectNavigation.cs

示例8: ApplyBrandingOnWeb

        public static void ApplyBrandingOnWeb(Web targetWeb, BrandingSettings brandingSettings, ProvisioningTemplate template)
        {
            targetWeb.EnsureProperties(w => w.MasterUrl, w => w.Url);

            // Configure proper settings for the provisioning engine
            ProvisioningTemplateApplyingInformation ptai =
                new ProvisioningTemplateApplyingInformation();

            // Write provisioning steps on console log
            ptai.MessagesDelegate += delegate (string message, ProvisioningMessageType messageType) {
                Console.WriteLine("{0} - {1}", messageType, messageType);
            };
            ptai.ProgressDelegate += delegate (string message, int step, int total) {
                Console.WriteLine("{0:00}/{1:00} - {2}", step, total, message);
            };

            // Include only required handlers
            ptai.HandlersToProcess = Core.Framework.Provisioning.Model.Handlers.ComposedLook |
                Core.Framework.Provisioning.Model.Handlers.Files |
                Core.Framework.Provisioning.Model.Handlers.WebSettings;

            // Check if we really need to apply/update the branding
            var siteBrandingUpdatedOn = targetWeb.GetPropertyBagValueString(
                PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn, null);

            // If the branding updated on date and time are missing
            // or older than the branding update date and time
            if (String.IsNullOrEmpty(siteBrandingUpdatedOn) ||
                DateTime.Parse(siteBrandingUpdatedOn) < brandingSettings.UpdatedOn.Value.ToUniversalTime())
            {
                Console.WriteLine($"Appling branding to site: {targetWeb.Url}");

                // Confirm the master page URL
                template.WebSettings.MasterPageUrl = targetWeb.MasterUrl;

                // Apply the template
                targetWeb.ApplyProvisioningTemplate(template, ptai);

                // Apply a custom JSLink, if any
                if (!String.IsNullOrEmpty(brandingSettings.UICustomActionsUrl))
                {
                    targetWeb.AddJsLink(
                        PnPPartnerPackConstants.BRANDING_SCRIPT_LINK_KEY,
                        brandingSettings.UICustomActionsUrl);
                }

                // Store Property Bag to set the last date and time when we applied the branding
                targetWeb.SetPropertyBagValue(
                    PnPPartnerPackConstants.PropertyBag_Branding_AppliedOn,
                    DateTime.Now.ToUniversalTime().ToString());

                Console.WriteLine($"Applied branding to site: {targetWeb.Url}");
            }

            // Apply branding (recursively) on all the subwebs of the current web
            targetWeb.EnsureProperty(w => w.Webs);

            foreach (var subweb in targetWeb.Webs)
            {
                ApplyBrandingOnWeb(subweb, brandingSettings, template);
            }
        }
开发者ID:OfficeDev,项目名称:PnP-Partner-Pack,代码行数:62,代码来源:BrandingJobHandler.cs


注:本文中的Web.SetPropertyBagValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。