Exemplo n.º 1
0
        private static void UpdateCurrentComposedLookItem(SPWeb web, ComposedLook composedLook)
        {
            var catalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
            var items = catalog.GetItems(new SPQuery
            {
                RowLimit = 1u,
                Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>",
                ViewFields = "<FieldRef Name='DisplayOrder'/>",
                ViewFieldsOnly = true
            });

            // Delete current composed look item
            if (items.Count == 1)
            {
                items[0].Delete();
            }

            // Create the new composed look item
            var item = catalog.AddItem();
            item[BuiltInFields.DisplayOrderName] = 0;
            item[SPBuiltInFieldId.Name] = SPResource.GetString(web.UICulture, "DesignGalleryCurrentItemName");
            item[SPBuiltInFieldId.Title] = SPResource.GetString(web.UICulture, "DesignGalleryCurrentItemName");
            item[BuiltInFields.MasterPageUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.MasterPagePath.Url).AbsolutePath);
            item[BuiltInFields.ThemeUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.ThemePath.Url).AbsolutePath);
            item[BuiltInFields.ImageUrlName] = composedLook.ImagePath == null ? string.Empty : HttpUtility.UrlDecode(new Uri(composedLook.ImagePath.Url).AbsolutePath);
            item[BuiltInFields.FontSchemeUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.FontSchemePath.Url).AbsolutePath);
            item.Update();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies a composed look to a web.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="composedLook">The name of the composed look.</param>
        public static void ApplyComposedLook(this SPWeb web, ComposedLook composedLook)
        {
            using (var elevatedWeb = web.Site.OpenWeb(web.ID))
            {
                // Set Master Page
                elevatedWeb.CustomMasterUrl = HttpUtility.UrlDecode(new Uri(composedLook.MasterPagePath.Url).AbsolutePath);
                elevatedWeb.MasterUrl = HttpUtility.UrlDecode(new Uri(composedLook.MasterPagePath.Url).AbsolutePath);
                elevatedWeb.Properties["DesignPreviewLayoutUrl"] = HttpUtility.UrlDecode(new Uri(composedLook.MasterPagePath.Url).AbsolutePath);
                elevatedWeb.Update();

                // Set theme
                elevatedWeb.ApplyTheme(
                    new Uri(composedLook.ThemePath.Url).AbsolutePath,
                    composedLook.FontSchemePath == null ? string.Empty : HttpUtility.UrlDecode(new Uri(composedLook.FontSchemePath.Url).AbsolutePath),
                    composedLook.ImagePath == null ? string.Empty : HttpUtility.UrlDecode(new Uri(composedLook.ImagePath.Url).AbsolutePath),
                    false);
                elevatedWeb.Update();

                // Update current selected composed look
                if (web.IsRootWeb)
                {
                    UpdateCurrentComposedLookItem(web, composedLook); 
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the specified composed look.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="entity">The entity.</param>
        /// <returns>
        /// The newly created composed look.
        /// </returns>
        public ComposedLook Create(SPWeb web, ComposedLook entity)
        {
            var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
            var item = designCatalog.Items.Add();
            this._binder.FromEntity(entity, item);
            item.Update();

            return this._binder.Get<ComposedLook>(item);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Updates the specified composed look.
 /// </summary>
 /// <param name="web">The web.</param>
 /// <param name="entity">The entity.</param>
 public void Update(SPWeb web, ComposedLook entity)
 {
     var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
     var item = designCatalog.Items.GetItemById(entity.Id);
     this._binder.FromEntity(entity, item);
     item.Update();
 }
Exemplo n.º 5
0
        private static ComposedLook DecodeUrls(ComposedLook composedLook)
        {
            if (composedLook.ImagePath != null)
            {
                composedLook.ImagePath.Url = HttpUtility.UrlDecode(composedLook.ImagePath.Url); 
            }

            if (composedLook.MasterPagePath != null)
            {
                composedLook.MasterPagePath.Url = HttpUtility.UrlDecode(composedLook.MasterPagePath.Url); 
            }

            if (composedLook.ThemePath != null)
            {
                composedLook.ThemePath.Url = HttpUtility.UrlDecode(composedLook.ThemePath.Url); 
            }

            return composedLook;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Deletes the specified composed look.
 /// </summary>
 /// <param name="web">The web.</param>
 /// <param name="entity">The entity.</param>
 public void Delete(SPWeb web, ComposedLook entity)
 {
     var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
     var item = designCatalog.GetItemById(entity.Id);
     item.Delete();
 }