예제 #1
0
        public MasterPage GetMasterPage(string Name)
        {
            MasterPage         _found  = MasterPage.CreateMasterPage();
            IList <MasterPage> masters = GetMasterPages();

            if (masters == null)
            {
                return(_found);
            }

            rrLock.EnterReadLock();

            try
            {
                foreach (MasterPage master in masters)
                {
                    if (master.Name.Equals(Name))
                    {
                        _found = master;
                        break;
                    }
                }

                return(_found);
            }
            finally
            {
                rrLock.ExitReadLock();
            }
        }
예제 #2
0
        private IList <MasterPage> GetMasters()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                //Attempt to reload if the settings store is null and a load hasn't been attempted, or if the last load interval is exceeded.
                //in the case of a refresh, then _settingStore will be null and missingSettings will be false.
                if ((masterPages == null) || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                {
                    rrLock.EnterWriteLock();
                    try
                    {
                        if (masterPages == null)
                        {
                            masterPages = new List <MasterPage>();
                            SPWeb currentWeb = SPContext.Current.Web;
                            SPWeb rootWeb    = currentWeb.Site.RootWeb;

                            SPList MasterPageLib = rootWeb.GetCatalog(SPListTemplateType.MasterPageCatalog);//.GetList("_catalogs/masterpage");

                            SPQuery oQuery = new SPQuery();
                            oQuery.Query = string.Format("<Where><Contains><FieldRef Name=\"FileLeafRef\" /><Value Type=\"File\">.master</Value></Contains></Where><OrderBy><FieldRef Name=\"FileLeafRef\" /></OrderBy>");
                            SPListItemCollection colListItems = MasterPageLib.GetItems(oQuery);

                            foreach (SPListItem masterPageItem in colListItems)
                            {
                                MasterPage masterpage = MasterPage.CreateMasterPage();
                                masterpage.UniqueId    = masterPageItem.UniqueId;
                                masterpage.Id          = masterPageItem.ID;
                                masterpage.Name        = masterPageItem.Name;
                                masterpage.Title       = masterpage.Name.Replace(".master", "").TrimEnd();
                                masterpage.Description = masterpage.Title + "description";
                                //TODO
                                //pageLayout.Description = pageLayoutItem["MasterPageDescription"].ToString();
                                masterpage.Url = masterPageItem.Url;

                                masterPages.Add(masterpage);
                            }
                        }
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }
                return(masterPages);
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }