Inheritance: Webform, IFolder
Beispiel #1
0
        private void DeleteWebPart(string portletId, SNP.Page page)
        {
            BinaryData sharedDataBlobBinaryData = page.PersonalizationSettings;

            if (sharedDataBlobBinaryData == null)
            {
                Console.WriteLine(String.Format("{0} has no personalization data.", page.Path));
                return;
            }

            Console.WriteLine(page.Path);

            PageState pageState = GetPageState(sharedDataBlobBinaryData);

            if (pageState == null)
            {
                return;
            }

            pageState.DynamicParts.Remove(portletId);
            pageState.WebPartSettings.Remove(portletId);
            pageState.Locations.Remove(portletId);

            SaveNewPersonalizationSettings(page, pageState);
        }
Beispiel #2
0
        // Tools ///////////////////////////////////////////////////////////////////
        private void SaveNewPersonalizationSettings(SNP.Page page, PageState pageState)
        {
            string newSharedDataString = pageState.Encode();

            byte[] newSharedDataBlob = Convert.FromBase64String(newSharedDataString);

            page.PersonalizationSettings.SetStream(new MemoryStream(newSharedDataBlob));
            page.Save();
        }
Beispiel #3
0
		public static Page CreateTestPage(string name)
		{
			Page page = null;
			page = Node.LoadNode(string.Concat("/Root/", name)) as Page;
			if (page == null)
			{
				page = new Page(Repository.Root);
				page.Name = name;
				page.Save();
			}
			return page;
		}
Beispiel #4
0
        private void ListWebPartElements(string listType, SNP.Page page)
        {
            if (String.IsNullOrEmpty(listType))
            {
                throw new ArgumentNullException("listType");
            }
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }


            //var page = Node.Load<Page>(pagePath);
            //if (page == null)
            //    throw new ApplicationException("{0} couldn't be loaded.");

            BinaryData sharedDataBlobBinaryData = page.PersonalizationSettings;

            if (sharedDataBlobBinaryData == null)
            {
                Console.WriteLine(String.Format("{0} has no personalization data.", page.Path));
                return;
            }


            Console.WriteLine(page.Path);

            PageState pageState = GetPageState(sharedDataBlobBinaryData);

            if (pageState == null)
            {
                return;
            }

            switch (listType)
            {
            case "all":
                ListZones(pageState, true);
                break;

            case "zones":
                ListZones(pageState, false);
                break;

            case "portlets":
                ListWebParts(pageState);
                break;

            default:
                throw new NotSupportedException(String.Format("{0} listtype is not supported.", listType));
            }
        }
        private string GetChangePasswordUrl(SNP.Page changePwdPage, string siteRepositoryPath)
        {
            string changePwdPageUrl;

            if (string.IsNullOrEmpty(changePwdPage.SmartUrl))
            {
                changePwdPageUrl = Configuration.ChangePasswordPagePath;
                changePwdPageUrl = changePwdPageUrl.Replace(VirtualPathUtility.AppendTrailingSlash(siteRepositoryPath), string.Empty);
            }
            else
            {
                changePwdPageUrl = changePwdPage.SmartUrl;
            }
            changePwdPageUrl = String.Concat(VirtualPathUtility.AppendTrailingSlash(PortalContext.Current.SiteUrl), changePwdPageUrl);
            return(changePwdPageUrl);
        }
Beispiel #6
0
        private void MoveWebPart(string portletId, string zoneId, SNP.Page page)
        {
            BinaryData sharedDataBlobBinaryData = page.PersonalizationSettings;

            if (sharedDataBlobBinaryData == null)
            {
                Console.WriteLine(String.Format("{0} has no personalization data.", page.Path));
                return;
            }

            Console.WriteLine(page.Path);

            PageState pageState = GetPageState(sharedDataBlobBinaryData);

            if (pageState == null)
            {
                return;
            }

            pageState.Locations[portletId].ZoneID = zoneId;

            SaveNewPersonalizationSettings(page, pageState);
        }
Beispiel #7
0
        public void GenericContent_KeepBinaryAfterUndocheckout()
        {
            Page samplePage = new Page(TestRoot);

            samplePage.Name = "SamplePage";

            //set binaries
            BinaryData pageBinaryData = CreateBinaryDataFromString("Page Binary");
            BinaryData psBinaryData = CreateBinaryDataFromString("Page PersonalizationSettings");

            samplePage.Binary = pageBinaryData;
            samplePage.PersonalizationSettings = psBinaryData;

            //save page
            samplePage.Save();
            samplePage.CheckOut();
            samplePage.UndoCheckOut();

            //asserts
            //TODO: CheckBinariesInPageByString hosszutavon folosleges
            CheckBinariesInPageByString(samplePage, "Page Binary", "Page PersonalizationSettings");
            CheckBinariesInPageByByte(samplePage, pageBinaryData.GetStream(), psBinaryData.GetStream());

        }
Beispiel #8
0
		public void Storage2_Bug_PageCheckin()
		{
            //Assert.Inconclusive("Approving off, None: CheckedOut ==> Publish");

            var binData1 = "PageBinaryData_original";
			var persData1 = "PersonalizationSettingsBinaryData_original";
			var binData2 = "PageBinaryData_edited";
			var persData2 = "PersonalizationSettingsBinaryData_edited";

			var page = new Page(TestRoot);
			page.Name = "TestPage";

			page.Binary = new BinaryData() { ContentType = "text/plain", FileName = "a.aspx" };
			page.PersonalizationSettings = new BinaryData() { ContentType = "text/plain", FileName = "a.PersonalizationSettings" };
			page.Binary.SetStream(Tools.GetStreamFromString(binData1));
			page.PersonalizationSettings.SetStream(Tools.GetStreamFromString(persData1));

			page.Save();
			var pageId = page.Id;

			page.CheckOut();

			page = Node.Load<Page>(pageId);
			page.Binary.SetStream(Tools.GetStreamFromString(binData2 + "bad"));
			page.PersonalizationSettings.SetStream(Tools.GetStreamFromString(persData2 + "bad"));
			page.Save();

			page = Node.Load<Page>(pageId);
			page.Binary.SetStream(Tools.GetStreamFromString(binData2));
			page.PersonalizationSettings.SetStream(Tools.GetStreamFromString(persData2));
			page.Save();

			page.CheckIn();

			page = Node.Load<Page>(pageId);
			var bin = Tools.GetStreamString(page.Binary.GetStream());
			var pers = Tools.GetStreamString(page.PersonalizationSettings.GetStream());

			Assert.IsTrue(bin == binData2, "#1");
			Assert.IsTrue(pers == persData2, "#2");
		}
        public static Page CreatePage(string name, Node parent)
        {
            var page = Node.LoadNode(string.Concat(parent.Path, "/", name)) as Page;
            if (page != null)
                page.ForceDelete();

            page = new Page(parent) { Name = name };
            page.Save();

            return page;
        }
Beispiel #10
0
        private void CheckPageTemplateInPage(Page page, int expectedId)
        {
            bool pageTemplatesMatch = (page.PageTemplateNode != null) && (page.PageTemplateNode.Id == expectedId);

            Assert.IsTrue(pageTemplatesMatch, "PageTemplate doesn't match the expected value.");
        }
Beispiel #11
0
        private void CheckBinariesInPageByString(Page page, string expectedBinaryValue, string expectedPSettingsValue)
        {
            string binaryValue = GetStringFromBinaryData(page.Binary);
            string personalizationSettingsValue = GetStringFromBinaryData(page.PersonalizationSettings);

            Assert.AreEqual(expectedBinaryValue, binaryValue, "The Binary of the given page doesn't match the expected value.");
            Assert.AreEqual(expectedPSettingsValue, personalizationSettingsValue, "The PersonalizationSettings of the given page doesn't match the expected value.");
        }
Beispiel #12
0
        public void GenericContent_KeepIndexAfterUndocheckout()
        {
            Page samplePage = new Page(TestRoot);

            samplePage.Name = "SamplePage";

            //set index
            int index = 15;
            samplePage.Index = index;

            samplePage.Save();
            samplePage.CheckOut();
            samplePage.UndoCheckOut();

            //asserts
            Assert.AreEqual(index, samplePage.Index, "Index property doesn't contain the expected value.");

        }
		public static BinaryData GetPageBinaryData(Page page, PageTemplate pageTemplate)
		{
			PageTemplateManager pageTemplateManager = new PageTemplateManager();
			return pageTemplateManager.GetASPXBinaryByPageTemplate(page, pageTemplate);	
		}
		public BinaryData GetASPXBinaryByPageTemplate(Page page, PageTemplate pageTemplate)
		{
			if (page == null)
			{
				throw new ArgumentNullException("page");
			}

			if (pageTemplate == null)
			{
				throw new ArgumentNullException("pageTemplate");
			}

			BinaryData binaryData = new BinaryData();
            if (page.Binary != null)
            {
				binaryData = page.Binary;
			}

			string pageTmp = Tools.GetStreamString(pageTemplate.Binary.GetStream());
			IList<object> fragments = SplitPageTemplate(pageTmp);
			StringBuilder aspx = new StringBuilder();

            //MasterPage is inside the PageTemplates folder.
            aspx.AppendFormat(ASPXHEADER, string.Concat("/", GetFileNameWithoutExt(pageTemplate.Name), MASTER), Repository.PageTemplatesFolderPath);
			for (int i = 0; i < fragments.Count; i++)
			{
				if (fragments[i] is PageZone)
				{
					PageZone zone = fragments[i] as PageZone;
					aspx.AppendFormat(WEBPARTZONE, zone.Name, zone.InnerText, zone.AttrListText);
				}
			}

			binaryData.SetStream(Tools.GetStreamFromString(aspx.ToString()));
			binaryData.FileName = new BinaryFileName (ASPX);
			binaryData.ContentType = ASPXCONTENTTYPE;

			return binaryData;
		}
Beispiel #15
0
        public static void CreateSandbox(TestContext testContext)
        {
            var site = Node.Load<Site>("/Root/TestSiteForAppModelTest");
            if (site == null)
            {
                site = new Site(Repository.Root);
                site.Name = "TestSiteForAppModelTest";
                var urlList = new Dictionary<string, string>();
                urlList.Add("testhost", "Windows");
                site.UrlList = urlList;
                site.Save();
            }
            var homePage = EnsureSiteStartPage(site);
            var webContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/WebContent1");
            if (webContent == null)
            {
                webContent = new GenericContent(homePage, "WebContent");
                webContent.Name = "WebContent1";
                webContent.Save();
            }
            var file = Node.Load<File>("/Root/TestSiteForAppModelTest/Home/File1");
            if (file == null)
            {
                file = new File(homePage);
                file.Name = "File1";
                file.GetBinary("Binary").SetStream(Tools.GetStreamFromString("File1 content"));
                file.Save();
            }

            //---- Appmodel

            var siteAppsFolder = Node.Load<SystemFolder>("/Root/TestSiteForAppModelTest/(apps)");
            if (siteAppsFolder == null)
            {
                siteAppsFolder = new SystemFolder(site);
                siteAppsFolder.Name = "(apps)";
                siteAppsFolder.Save();
            }
            var siteAppsPageFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/Page");
            if (siteAppsPageFolder == null)
            {
                siteAppsPageFolder = new SystemFolder(siteAppsFolder);
                siteAppsPageFolder.Name = "Page";
                siteAppsPageFolder.Save();
            }
            var siteAppsPageBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Browse");
            if (siteAppsPageBrowsePage == null)
            {
                siteAppsPageBrowsePage = new Page(siteAppsPageFolder);
                siteAppsPageBrowsePage.Name = "Browse";
                siteAppsPageBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page Browse App</h1></body></html>"));
                siteAppsPageBrowsePage.Save();
            }
            var siteAppsPageEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Edit");
            if (siteAppsPageEditPage == null)
            {
                siteAppsPageEditPage = new Page(siteAppsPageFolder);
                siteAppsPageEditPage.Name = "Edit";
                siteAppsPageEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page EditPage</h1></body></html>"));
                siteAppsPageEditPage.Save();
            }

            var siteAppsGenericContentFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/GenericContent");
            if (siteAppsGenericContentFolder == null)
            {
                siteAppsGenericContentFolder = new SystemFolder(siteAppsFolder);
                siteAppsGenericContentFolder.Name = "GenericContent";
                siteAppsGenericContentFolder.Save();
            }
            var siteAppsGenericContentBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Browse");
            if (siteAppsGenericContentBrowsePage == null)
            {
                siteAppsGenericContentBrowsePage = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentBrowsePage.Name = "Browse";
                siteAppsGenericContentBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent Browse App</h1></body></html>"));
                siteAppsGenericContentBrowsePage.Save();
            }

            var siteAppsGenericContentEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
            if (siteAppsGenericContentEditPage == null)
            {
                siteAppsGenericContentEditPage = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentEditPage.Name = "Edit";
                siteAppsGenericContentEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent EditPage</h1></body></html>"));
                siteAppsGenericContentEditPage.Save();
            }


            //---- SelfDispatcher node
            var selfDispatcherContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/SelfDispatcherContent1");
            if (selfDispatcherContent == null)
            {
                selfDispatcherContent = new GenericContent(homePage, "WebContent");
                selfDispatcherContent.Name = "SelfDispatcherContent1";
                selfDispatcherContent.BrowseApplication = Node.LoadNode("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
                selfDispatcherContent.Save();
            }
        }
Beispiel #16
0
        private static Page EnsureSiteStartPage(Site site)
        {
            var startPageName = "Home";
            var homePage = Node.Load<Page>(RepositoryPath.Combine(site.Path, startPageName));
            if (homePage == null)
            {
                homePage = new Page(site);
                homePage.Name = startPageName;
                homePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>TestPage</h1></body></html>"));
                homePage.Save();
                site.StartPage = homePage;
                site.Save();
            }
            else if(site.StartPage == null)
            {
                site.StartPage = homePage;
                site.Save();
            }

            return homePage;
        }
Beispiel #17
0
        // Creating test node
        private Page CreateTestPage()
        {
            string testPagePath = RepositoryPath.Combine(_rootNodePath, _pageName);
            if (Node.Exists(testPagePath))
                Node.ForceDelete(testPagePath);

			//if (Node.Exists("/Root/TestPage"))
            //    Node.DeletePhysical("/Root/TestPage");

            Page f = new Page(Node.LoadNode(_rootNodePath));
            f.Name = _pageName;
            f.PageTemplateNode = PageTemplate.LoadNode(_pageTemplatePath) as PageTemplate;
            f.Save();
            return f;
        }
Beispiel #18
0
        public void Page_Constructor_HasAllProperties()
        {
            Node parent = Repository.Root;
            Page target = new Page(parent);

            
            //Assert.IsTrue(target.HasProperty("PageNameInMenu"), "DisplayName is null.");
			Assert.IsTrue(target.HasProperty("Hidden"), "Hidden is null.");
			Assert.IsTrue(target.HasProperty("Keywords"), "Keywords is null.");
			Assert.IsTrue(target.HasProperty("MetaDescription"), "MetaDescription is null.");
			Assert.IsTrue(target.HasProperty("MetaTitle"), "MetaTitle is null.");
        }
Beispiel #19
0
        public void Page_Constructor()
        {
            Node parent = Repository.Root;

            Page target = new Page(parent);

            Assert.IsNotNull(target, "1. Page is null.");
        }
Beispiel #20
0
        public void GenericContent_KeepReferenceAfterUndocheckout()
        {
            //create page template
            PageTemplate samplePageTemplate = new PageTemplate(TestRoot);
            samplePageTemplate.Name = "Sample Page Template";
            samplePageTemplate.Binary = CreateBinaryDataFromString("<html><head></head><body></body></html>");
            samplePageTemplate.Save();

            Page samplePage = new Page(TestRoot);

            samplePage.Name = "SamplePage";

            //set reference
            samplePage.PageTemplateNode = samplePageTemplate;

            samplePage.Save();
            samplePage.CheckOut();
            samplePage.UndoCheckOut();

            //asserts
            CheckPageTemplateInPage(samplePage, samplePageTemplate.Id);

        }
Beispiel #21
0
        public void GenericContent_KeepTextPropertyAfterUndocheckout()
        {
            Page samplePage = new Page(TestRoot);

            samplePage.Name = "SamplePage";

            //set sample page
            string textProperty = "minta property";
            samplePage.Keywords = textProperty;

            samplePage.Save();
            samplePage.CheckOut();
            samplePage.UndoCheckOut();

            //asserts
            Assert.AreEqual(textProperty, samplePage.Keywords, "Keywords property doesn't contain the expected strings.");

        }
Beispiel #22
0
        internal static void RunPage(HttpContext context, string path, Page pageNode, out Exception exception)
        {
            PageBase page = null;
            string virtualPath = string.Empty;

            // prepare repository path
            try
            {
                virtualPath = CreateVirtualPath(path);
                page = InstantiatePage(context, virtualPath, pageNode);
                ExecutePage(context, virtualPath, page, pageNode, false);
                exception = null;
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                exception = exc;
            }
        }
Beispiel #23
0
        public void GenericContent_KeepIconAfterUndocheckout()
        {
            Page samplePage = new Page(TestRoot);

            samplePage.Name = "SamplePage";

            //set index
            string icon = "icon.ic";
            samplePage.Icon = icon;

            samplePage.Save();
            samplePage.CheckOut();
            samplePage.UndoCheckOut();

            //asserts
            Assert.AreEqual(icon, samplePage.Icon, "Icon property doesn't contain the expected value.");

        }
Beispiel #24
0
        static PageBase InstantiatePage(HttpContext context, string virtualPath, Page pageNode)
        {
            PageBase page = null;

            Page originalCurrentPage = PortalContext.Current.Page;
            string originalPath = context.Request.Path;

            try
            {
                PortalContext.Current.Page = pageNode;
                context.RewritePath(virtualPath);
                page = (PageBase)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(PageBase));
            }
            finally
            {
                context.RewritePath(originalPath);
                PortalContext.Current.Page = originalCurrentPage;
            }

            return page;
        }
Beispiel #25
0
 private void CheckBinariesInPageByByte(Page page, Stream expectedBinaryStream, Stream expectedPSettingsStream)
 {
     bool binariesEqual = CompareStreams(expectedBinaryStream, page.Binary.GetStream());
     bool psettingsEqual = CompareStreams(expectedPSettingsStream, page.PersonalizationSettings.GetStream());
     
     Assert.IsTrue(binariesEqual, "The Binary of the given page doesn't match the expected value.");
     Assert.IsTrue(psettingsEqual, "The PersonalizationSettings of the given page doesn't match the expected value.");
 }
Beispiel #26
0
        static void ExecutePage(HttpContext context, string virtualPath, PageBase page, Page pageNode, bool silent)
        {
            Page originalCurrentPage = PortalContext.Current.Page;
            string originalPath = context.Request.Path;

            if (originalCurrentPage.Path == pageNode.Path)
                throw new InvalidOperationException("Executing a Page within itself is forbidden!");

            try
            {
                PortalContext.Current.Page = pageNode;
                context.RewritePath(virtualPath);
                context.Server.Execute(page, TextWriter.Null, false);
            }
            catch (Exception e)
            {
                if (!silent)
                    throw e;
                else
                    Logger.WriteException(e);
            }
            finally
            {
                context.RewritePath(originalPath);
                PortalContext.Current.Page = originalCurrentPage;
            }
        }
Beispiel #27
0
        public void GenericContent_KeepBinaryAfterPublish()
        {
            Page samplePage = new Page(TestRoot);
            
            samplePage.Name = "SamplePage";
            samplePage.VersioningMode = ContentRepository.Versioning.VersioningType.MajorAndMinor;
            samplePage.ApprovingMode = ContentRepository.Versioning.ApprovingType.True;
            
            //set binaries
            BinaryData pageBinaryData = CreateBinaryDataFromString("Page Binary");
            BinaryData psBinaryData = CreateBinaryDataFromString("Page PersonalizationSettings");

            samplePage.Binary = pageBinaryData;
            samplePage.PersonalizationSettings = psBinaryData;

            //save page
            samplePage.Save();
            samplePage.CheckOut();
            samplePage.Publish();

            //asserts
            //TODO: CheckBinariesInPageByString hosszutavon folosleges
            CheckBinariesInPageByString(samplePage, "Page Binary", "Page PersonalizationSettings");
            CheckBinariesInPageByByte(samplePage,pageBinaryData.GetStream(),psBinaryData.GetStream());
            
        }
		public void PageTemplateManager_GetPageBinaryData_Test()
		{
			bool result = false;

			string guidZoneName = Guid.NewGuid().ToString();
			PageTemplate pageTemplate = CreatePageTemplate(guidZoneName, null);
			if (pageTemplate != null)
			{
				Page page = null;
				page = Node.LoadNode(string.Concat(this.TestRoot.Path, "/TestPage")) as Page;
				if (page == null)
				{
					page = new Page(this.TestRoot);
				}
				page.PageTemplateNode = pageTemplate;
				page.Name = "TestPage";
				page.PageNameInMenu = "TestPage";

				page.Save();

				if (page != null && page.Binary != null && page.Binary.GetStream() != null)
				{
					string pageString = Tools.GetStreamString(page.Binary.GetStream());
					if (!string.IsNullOrEmpty(pageString))
					{
						result = pageString.IndexOf(guidZoneName) > -1;
					}
				}
			}

			Assert.IsTrue(result);			
		}
Beispiel #29
0
		//======================================================================== Helpers

		private Page CreateTestPage()
		{
			string testPagePath = RepositoryPath.Combine(_rootNodePath, Guid.NewGuid().ToString());
			if (Node.Exists(testPagePath))
                Node.ForceDelete(testPagePath);

			Page f = new Page(Node.LoadNode(_rootNodePath));
			f.PageTemplateNode = PageTemplate.LoadNode(_pageTemplatePath) as PageTemplate;
			f.Save();
			return f;
		}
Beispiel #30
0
        public static void SetPersonalizationFromXml(HttpContext context, Page pageNode, XmlDocument xml, out string errorMessage)
        {
            string error = String.Empty;

            string virtualPath = CreateVirtualPath(pageNode.Path);
            PageBase page = InstantiatePage(context, virtualPath, pageNode);


            page.PreLoad += delegate
            {
                WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(page);
                WebPartZoneCollection webPartZones = wpm.Zones;

                foreach (WebPartZone zone in webPartZones)
                {
                    foreach (WebPart part in zone.WebParts)
                    {
                        if (!part.IsStatic)
                            wpm.DeleteWebPart(part);
                    }

                    XmlNode zoneDescriptionNode = xml.SelectNodes(@"//*[@id='" + zone.ID + "']")[0];

                    XmlElement zoneDescription = zoneDescriptionNode as XmlElement;

                    if (zoneDescription != null)
                    {
                        foreach (XmlElement webPartDescription in zoneDescription.GetElementsByTagName("webPart"))
                        {
                            string webPartXml = String.Empty;

                            using (StringWriter sw = new StringWriter())
                            {
                                using (XmlWriter writer = new XmlTextWriter(sw))
                                {
                                    writer.WriteStartElement("webParts");
                                    webPartDescription.WriteTo(writer);
                                    writer.WriteEndElement();
                                    writer.Flush();
                                }
                                webPartXml = sw.ToString();
                            }

                            using (StringReader sr = new StringReader(webPartXml))
                            {
                                using (XmlReader reader = new XmlTextReader(sr))
                                {
                                    WebPart part = wpm.ImportWebPart(reader, out error);
                                    wpm.AddWebPart(part, zone, zone.WebParts.Count);
                                }
                            }
                        }
                    }
                }
            };

            //TODO: Clever exception handling
            ExecutePage(context, virtualPath, page, pageNode, true);
            errorMessage = error;
        }
Beispiel #31
0
        public static WebPartCollection GetPortlets(HttpContext context, Page pageNode)
        {
            WebPartCollection webParts = null;

            string virtualPath = CreateVirtualPath(pageNode.Path);
            PageBase page = InstantiatePage(context, virtualPath, pageNode);

            page.PreLoad += delegate
            {
                webParts = WebPartManager.GetCurrentWebPartManager(page).WebParts;
            };
            
            ExecutePage(context, virtualPath, page, pageNode, true);

            return webParts;
        }
Beispiel #32
0
		private Page CreatePage(string name)
		{
			Page page = Node.LoadNode(string.Concat(this.TestRoot.Path, "/", name)) as Page;
			if (page == null)
			{
				page = new Page(this.TestRoot);
				page.Name = name;
				page.Save();
			}
			return page;
		}
        public void PageTemplateManager_GetASPXBinaryByPageTemplate_Test()
        {
            bool result = false;

            string guidZoneName = Guid.NewGuid().ToString();
            string pageName = Guid.NewGuid().ToString();

            PageTemplate pageTemplate = CreatePageTemplate(guidZoneName, null);
            if (pageTemplate != null)
            {
                Page page = null;
				page = Node.LoadNode(string.Concat(this.TestRoot.Path, "/", pageName)) as Page;
                if (page == null)
                {
					page = new Page(this.TestRoot);
                }

                page.PageTemplateNode = pageTemplate;
                page.Name = pageName;
                page.PageNameInMenu = pageName;

                page.Save();

                if (page != null && page.Binary != null)
                {
                    int oldID = page.Binary.Id;

                    page.Save();

                    result = (oldID == page.Binary.Id);
                }
            }

            Assert.IsTrue(result, "Page.Binary.Id changed during Page.Save(), means unnecessary db entries were created.");
        }
Beispiel #34
0
        public static XmlDocument GetPersonalizationXml(HttpContext context, Page pageNode)
        {
            XmlDocument xml = new XmlDocument();
            xml.AppendChild(xml.CreateElement("webPartZones"));

            string virtualPath = CreateVirtualPath(pageNode.Path);
            PageBase page = InstantiatePage(context, virtualPath, pageNode);

            page.PreLoad += delegate
            {
                WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(page);
                WebPartZoneCollection webPartZones = wpm.Zones;

                foreach (WebPartZone zone in webPartZones)
                {
                    XmlElement zoneElement = xml.CreateElement("webPartZone");
                    XmlAttribute zoneId = xml.CreateAttribute("id");
                    zoneId.Value = zone.ID;
                    zoneElement.SetAttributeNode(zoneId);
                    xml.DocumentElement.AppendChild(zoneElement);

                    WebPartCollection webParts = zone.WebParts;

                    foreach (WebPart webPart in webParts)
                    {
                        if (!webPart.IsStatic)
                        {
                            XmlDocument xmlFragment = new XmlDocument();
                            using (StringWriter sw = new StringWriter())
                            {
                                using (XmlWriter writer = new XmlTextWriter(sw))
                                {
                                    webPart.ExportMode = WebPartExportMode.All; // Force exporting of all information
                                    wpm.ExportWebPart(webPart, writer);
                                    writer.Flush();
                                }
                                xmlFragment.LoadXml(sw.ToString());
                            }
                            zoneElement.AppendChild(xml.ImportNode(xmlFragment.FirstChild.FirstChild, true));
                        }
                    }
                }
            };

            ExecutePage(context, virtualPath, page, pageNode, true);

            return xml;
        }