protected override CmsContext CreateContext(Action<ICmsConfigurator> configure = null)
 {
     var unity = new UnityContainer();
     var configurator = unity.ConfigureCms();
     SharedConfiguration(configurator);
     if (configure != null)
         configure(configurator);
     return new TestCmsContext(new CmsContainerProvider(() => new UnityCmsContainer(unity)));
 }
示例#2
0
        public WebApiFixture()
        {
            var unity = new UnityContainer();
            unity.ConfigureCms()
                .UseMemoryStorage()
                .UseLuceneSearch(new RAMDirectory())
                .UseTextRenderer()
                .UseHtmlRenderer()
                .UseMarkdownRenderer()
                .UseSourceCodeRenderer();
            Cms.Configure(() => new UnityCmsContainer(unity.CreateChildContainer()));
            using (var context = Cms.CreateContext())
            {
                ExampleDocument = new CmsDocument("Example");
                context.Documents.Save(ExampleDocument);
                ExampleView = new CmsView("Example");
                context.Views.Save(ExampleView);
            }

            //CmsTesting.Initialize(() => new UnityCmsContainer(unity.CreateChildContainer()));
            _WebApp = WebApp.Start<Startup>(WebUrl.ToString());
        }
示例#3
0
        private void ConfigureCms()
        {
            var rootFolder = Server.MapPath("~/");
            var cmsDirectory = new DirectoryInfo(Path.Combine(rootFolder, @"App_Data\Cms"));

            if (cmsDirectory.Exists && !UseSql)
            {
                cmsDirectory.Delete(true);
            }

            var unity = new UnityContainer();
            var configuration = unity.ConfigureCms()
                .UseHtmlRenderer()
                .UseTextRenderer()
                .UseMarkdownRenderer()
                .UseSourceCodeRenderer();

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (UseAzure)
            {
                var azureStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
                configuration
                    .UseAzureStorage(azureStorageAccount.CreateCloudBlobClient(), "cms")
                    .UseLuceneSearch(new AzureDirectory(azureStorageAccount, "cms-index", new RAMDirectory()));
            }
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            else if (UseRedis)
            {
                configuration
                    .UseRedisStorage()
                    .UseLuceneSearch(new SimpleFSDirectory(new DirectoryInfo(Path.Combine(cmsDirectory.FullName, "Index"))));
            }
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            else if (UseSql)
            {
                // To configure db via web.config, uncomment entityFramework section and connection string and pass in connection string
                // name to ICmsConfigurator; e.g. .UseSqlStorage("DefaultConnection")
                if (!cmsDirectory.Exists)
                    cmsDirectory.Create();
                string connectionString =
                    string.Format(
                        @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={0}\{1}.mdf;Initial Catalog={1};Integrated Security=True;MultipleActiveResultSets=true",
                        cmsDirectory.FullName, "MicroCmsSqlDb");
                configuration
                    .UseSqlStorage(connectionString)
                    .UseSqlSearch(connectionString);
            }
            else
            {
                configuration
                    .UseFileSystemStorage(cmsDirectory)
                    .UseLuceneSearch(new SimpleFSDirectory(new DirectoryInfo(Path.Combine(cmsDirectory.FullName, "Index"))));
            }

            Cms.Configure(() => new UnityCmsContainer(unity.CreateChildContainer()));
            using (var context = Cms.CreateContext())
            {
                if (!context.Documents.GetAll().Any())
                {
                    var rowView = new CmsView("RowView", "<div class=\"row\">{0}</div>");
                    var sidebarView = new CmsView("SidebarView", "<div>{0}</div>");
                    context.Views.Save(rowView);
                    context.Views.Save(sidebarView);
                    var document = new CmsDocument("Example Rows",
                        CreateMarkdown("#MD4", 4),
                        CreateMarkdown("#MD8", 8),
                        CreateMarkdown("#MD3", 3),
                        CreateMarkdown("#MD3", 3),
                        CreateMarkdown("#MD3", 3),
                        CreateMarkdown("#MD3", 3),
                        CreateMarkdown("#MD12", 12));
                    document.Tags.Add("documents");
                    context.Documents.Save(document);
                    context.Documents.Save(new CmsDocument("Source Code Example", CreateMarkdown(@"#CODE
            {{CSharp}}
            public class Thing
            {
            public string Name { get; set; }
            }
            ", 12)));
                    var sidebar = new CmsDocument("TableOfContents", new CmsPart(CmsTypes.Markdown, @"[Home](/)

            [Docs](/docs/)"));
                    sidebar.Tags.Add("TableOfContents");
                    context.Documents.Save(sidebar);

                    var readmeText = File.ReadAllText(Path.Combine(rootFolder, @"..\..\README.md"));

                    var homeDocument = new CmsDocument("Readme", CreateMarkdown(readmeText, 12));
                    homeDocument.Tags.Add("home");
                    Cms.CreateContext().Documents.Save(homeDocument);
                }
            }
        }