Exemple #1
0
		private void ReplaceContent(N2.Engine.IEngine factory)
		{
			var installer = factory.Resolve<N2.Edit.Installation.InstallationManager>();
			installer.Install();
			var root = installer.InsertExportFile(File.OpenRead(HttpContext.Current.Server.MapPath("~/App_Data/Demo.n2.xml.gz")), "Concrete_SampleData.gz");
			if (root.ID != factory.Host.DefaultSite.RootItemID)
				factory.Host.DefaultSite.RootItemID = root.ID;
			foreach (ContentItem item in root.Children)
			{
				if (item.ID == factory.Host.DefaultSite.StartPageID && item is StartPage)
				{
					CreateDemoPanel(factory, item);
					return;
				}
			}

			foreach (ContentItem item in root.Children)
			{
				if (item is StartPage)
				{
					CreateDemoPanel(factory, item);
					factory.Host.DefaultSite.StartPageID = item.ID;
					return;
				}
			}
		}
Exemple #2
0
        private static void CreateDemoPanel(N2.Engine.IEngine factory, ContentItem item)
        {
            if (ConfigurationManager.AppSettings["Demo.CreateDemoPanel"] == "true")
            {
                var part = factory.Resolve<ContentActivator>().CreateInstance<Models.DemoPart>(item);
                part.ZoneName = "Right";
                part.SortOrder = -1000000;
                item.Children.Insert(0, part);

                factory.Persister.Save(part);
            }
        }
Exemple #3
0
        private void ReplaceContent(N2.Engine.IEngine engine)
        {
            Importer imp = engine.Resolve<Importer>();
            IImportRecord record;
            HttpContext context = HttpContext.Current;
            if (context != null && File.Exists(context.Server.MapPath("~/App_Data/export.n2.xml.gz")))
            {
                record = imp.Read(context.Server.MapPath("~/App_Data/export.n2.xml.gz"));
            }
            else
            {
                record = imp.Read(GetType().Assembly.GetManifestResourceStream("Demo.Resources.export.n2.xml.gz"), "export.n2.xml.gz");
            }

            ContentItem imported = record.RootItem;

            ContentItem rootPage = engine.Persister.Get<ContentItem>(engine.Host.DefaultSite.RootItemID);

            engine.SecurityManager.ScopeEnabled = false;
            try
            {
                ((N2.Integrity.IntegrityEnforcer)engine.Resolve<N2.Integrity.IIntegrityEnforcer>()).Enabled = false;
                RemoveExistingPages(engine, rootPage);
            }
            finally
            {
                ((N2.Integrity.IntegrityEnforcer)engine.Resolve<N2.Integrity.IIntegrityEnforcer>()).Enabled = true;
            }
            UpdateRootPage(engine, imported, rootPage);

            imp.Import(record, rootPage, ImportOption.Children);

            foreach(ContentItem item in rootPage.Children)
                if (item is StartPage)
                    engine.Host.DefaultSite.StartPageID = item.ID;

            engine.Persister.Save(rootPage);

            //foreach (NewsList nl in Find.Items.Where.Type.Eq(typeof(NewsList)).Select())
            //{
            //    foreach (NewsContainer nc in Find.Items.Where.Type.Eq(typeof (NewsContainer)).Select())
            //    {
            //        nl.Container = nc;
            //        News n = engine.Definitions.CreateInstance<News>(nc);
            //        n.Title = "Demo site created";
            //        n.Introduction = "Today at " + DateTime.Now + " a demo site was generated for your convenience.";
            //        n.Text = "<p>Download the template web if you like.</p>";
            //        n["Syndicate"] = true;
            //        engine.Persister.Save(n);
            //    }
            //}

            //foreach (CalendarTeaser ct in Find.Items.Where.Type.Eq(typeof(CalendarTeaser)).Select())
            //{
            //    foreach (Calendar c in Find.Items.Where.Type.Eq(typeof(Calendar)).Select())
            //    {
            //        ct.Container = c;
            //        Event e = engine.Definitions.CreateInstance<Event>(c);
            //        e.Title = "Demo site scheduled for deletion";
            //        e.Introduction = "30 minutes from now the demo site will be re-created.";
            //        e.EventDate = DateTime.Now.AddMinutes(30);
            //        e["Syndicate"] = true;
            //        engine.Persister.Save(e);
            //    }
            //}

            ClearPreviousVersions(engine, rootPage);

            engine.SecurityManager.ScopeEnabled = true;
        }
Exemple #4
0
 private static void ClearPreviousVersions(N2.Engine.IEngine engine, ContentItem rootPage)
 {
     var repo = engine.Resolve<ContentVersionRepository>();
     foreach(var version in repo.Repository.Find().ToList())
         repo.Repository.Delete(version);
     //foreach (ContentItem version in engine.Resolve<N2.Persistence.Finder.IItemFinder>().Where.VersionOf.Eq(rootPage).Select())
     //    engine.Persister.Delete(version);
 }
Exemple #5
0
		private static void ClearPreviousVersions(N2.Engine.IEngine factory, ContentItem rootPage)
		{
			foreach (ContentItem version in factory.Resolve<N2.Persistence.Finder.IItemFinder>().Where.VersionOf.Eq(rootPage).Select())
				factory.Persister.Delete(version);
		}