/// <summary>
 /// Initializes a new instance of the <see cref="DefaultMediaService"/> class.
 /// </summary>
 public DefaultMediaService(IRepository repository, IUnitOfWork unitOfWork, IAccessControlService accessControlService, ICmsConfiguration configuration)
 {
     this.repository = repository;
     this.unitOfWork = unitOfWork;
     this.accessControlService = accessControlService;
     this.configuration = configuration;
 }
 /// <summary>
 /// Populates the roles from configuration.
 /// </summary>
 /// <param name="config">The config.</param>
 /// <param name="filterContext">The filter context.</param>
 protected internal virtual void PopulateRolesFromConfiguration(ICmsConfiguration config, AuthorizationContext filterContext)
 {
     this.Roles = config.AdminRoles;
     if (config.HostAuthorizations.Any())
     {
         var host = util.GetTenantHost(filterContext.HttpContext.Request.Url);
         var found = config.HostAuthorizations.FirstOrDefault(cfg => string.Compare(host, cfg.Key, StringComparison.OrdinalIgnoreCase) == 0);
         if (found != null)
         {
             this.Roles = found.Value;
         }
         else
         {
             // attempt to resolve with wildcard
             foreach (var auth in config.HostAuthorizations.Where(ha => ha.Key.Contains("*")))
             {
                 var endHost = auth.Key.Replace("*", string.Empty);
                 if (host.EndsWith(endHost, StringComparison.OrdinalIgnoreCase))
                 {
                     this.Roles = auth.Value;
                     break;
                 }
             }
         }
     }
 }
 /// <summary>
 /// Registers module types.
 /// </summary>
 /// <param name="context">The area registration context.</param>
 /// <param name="containerBuilder">The container builder.</param>
 /// <param name="configuration">The configuration.</param>
 public override void RegisterModuleTypes(ModuleRegistrationContext context, ContainerBuilder containerBuilder, ICmsConfiguration configuration)
 {
     if (configuration.Cache.CacheType == CacheServiceType.Auto)
     {
         containerBuilder.RegisterType<AppFabricCacheService>().As<ICacheService>().SingleInstance();
     }
 }
 /// <summary>
 /// Registers the style sheet files.
 /// </summary>
 /// <param name="containerBuilder">The container builder.</param>
 /// <param name="configuration">The configuration.</param>
 /// <returns>Enumerator of known module style sheet files.</returns>
 public override IEnumerable<string> RegisterStyleSheetFiles(ContainerBuilder containerBuilder, ICmsConfiguration configuration)
 {
     return new[]
         {
             "/file/bcms-users/Content/Css/bcms.users.css"
         };
 }
        public override void Up(ICmsConfiguration configuration)
        {
            using (var pagesApi = CmsContext.CreateApiContextOf<PagesApiContext>())
            {
                const string WidgetPath = "~/Areas/bcms-newsletter/Views/Widgets/SubscribeToNewsletter.cshtml";
                var request = new GetServerControlWidgetsRequest(e => e.Url == WidgetPath);
                var widgets = pagesApi.GetServerControlWidgets(request);
                if (widgets.Items.Count > 0)
                {
                    return;
                }

                using (var transactionScope = new TransactionScope())
                {
                    pagesApi.CreateServerControlWidget(
                    new CreateServerControlWidgetRequest()
                    {
                        Name = "Newsletter Widget",
                        WidgetPath = WidgetPath,
                        Options =
                            new List<ContentOptionDto>()
                                    {
                                        new ContentOptionDto() { Type = OptionType.Text, Key = "Email placeholder", DefaultValue = "email..." },
                                        new ContentOptionDto() { Type = OptionType.Text, Key = "Label title", DefaultValue = "Subscribe to newsletter" },
                                        new ContentOptionDto() { Type = OptionType.Text, Key = "Submit title", DefaultValue = "Submit" },
                                        new ContentOptionDto() { Type = OptionType.Text, Key = "Submit is disabled", DefaultValue = "false" }
                                    }
                    });
                    transactionScope.Complete();
                }
            }
        }
 public DefaultIndexerService(ICmsConfiguration cmsConfiguration, IRepository repository, ISecurityService securityService, IAccessControlService accessControlService)
 {
     this.repository = repository;
     this.cmsConfiguration = cmsConfiguration;
     this.securityService = securityService;
     this.accessControlService = accessControlService;
 }
 /// <summary>
 /// Ups the specified configuration.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public override void Up(ICmsConfiguration configuration)
 {
     using (var api = CmsContext.CreateApiContextOf<MigrationApiContext>())
     {
         api.UpdateFolderContentTypes();
     }
 }
 public override System.Collections.Generic.IEnumerable<string> RegisterStyleSheetFiles(Autofac.ContainerBuilder containerBuilder, ICmsConfiguration configuration)
 {
     return new[]
         {
             "/file/bcms-blog/Content/Styles/bcms.blog.css"
         };
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhunFileSystem" /> class.
 /// </summary>
 /// <param name="api">The API.</param>
 /// <param name="connector">The connector.</param>
 /// <param name="context">The context.</param>
 public PhunFileSystem(IPhunApi api, IContentConnector connector)
 {
     this.connector = connector;
     this.api = api;
     this.config = Bootstrapper.Default.Config;
     this.myUtility = new ResourcePathUtility();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlogModuleDescriptor" /> class.
        /// </summary>
        public BlogModuleDescriptor(ICmsConfiguration configuration)
            : base(configuration)
        {
            blogJsModuleIncludeDescriptor = new BlogJsModuleIncludeDescriptor(this);

            RootApiContext.Events.PageRetrieved += Events_PageRetrieved;
        }
 public DefaultModuleManager(IPackageRepository packageRepository, ICmsConfiguration cmsConfiguration)
 {
     this.packageRepository = PackageRepositoryFactory.Default.CreateRepository(cmsConfiguration.ModuleGallery.FeedUrl);
     this.packageManager = new PackageManager(
         this.packageRepository,
         cmsConfiguration.WorkingDirectoryRootPath) { Logger = null };
 }
Exemple #12
0
 public UploadFileService(IRepository repository, IMediaFileService mediaFileService, IAccessControlService accessControlService, ICmsConfiguration configuration)
 {
     this.repository = repository;
     this.mediaFileService = mediaFileService;
     this.accessControlService = accessControlService;
     this.configuration = configuration;
 }
Exemple #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CmsController" /> class.
 /// </summary>
 /// <param name="pageAccessor">The page accessor.</param>
 /// <param name="cmsConfiguration">The configuration loader.</param>
 /// <param name="cacheService">The cache service.</param>
 /// <param name="securityService">The security service.</param>
 public CmsController(IPageAccessor pageAccessor, ICmsConfiguration cmsConfiguration, ICacheService cacheService, ISecurityService securityService)
 {
     this.securityService = securityService;
     this.pageAccessor = pageAccessor;
     this.cmsConfiguration = cmsConfiguration;
     this.cacheService = cacheService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaManagerModuleDescriptor" /> class.
 /// </summary>
 public MediaManagerModuleDescriptor(ICmsConfiguration cmsConfiguration)
     : base(cmsConfiguration)
 {
     mediaJsModuleIncludeDescriptor = new MediaManagerJsModuleIncludeDescriptor(this);
     mediaUploadModuleIncludeDescriptor = new MediaUploadJsModuleIncludeDescriptor(this);
     imageEditorModuleIncludeDescriptor = new ImageEditorJsModuleIncludeDescriptor(this);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="LuceneSearchModuleDescriptor" class./>
        /// </summary>
        /// <param name="configuration">The configuration</param>
        public LuceneSearchModuleDescriptor(ICmsConfiguration configuration)
            : base(configuration)
        {
            WebCoreEvents.Instance.HostStart += x =>
                {
                    Logger.Info("OnHostStart: preparing Lucene Search index workers...");

                    // Content indexer
                    TimeSpan indexerFrequency;
                    if (TimeSpan.TryParse(configuration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexerFrequency), out indexerFrequency))
                    {
                        if (indexerFrequency > TimeSpan.FromSeconds(0))
                        {
                            workers.Add(new DefaultContentIndexingRobot(indexerFrequency));
                        }
                    }

                    // New page URLs watcher
                    TimeSpan watcherFrequency;
                    if (TimeSpan.TryParse(configuration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LucenePagesWatcherFrequency), out watcherFrequency))
                    {
                        if (watcherFrequency > TimeSpan.FromSeconds(0))
                        {
                            workers.Add(new DefaultIndexSourceWatcher(watcherFrequency));
                        }
                    }

                    workers.ForEach(f => f.Start());

                    Logger.Info("OnHostStart: preparing Lucene Search index workers completed.");
                };
        }
 public override System.Collections.Generic.IEnumerable<JavaScriptModuleDescriptor> RegisterJavaScriptModules(Autofac.ContainerBuilder containerBuilder, ICmsConfiguration configuration)
 {
     return new[]
         {
             blogJavaScriptModuleDescriptor
         };
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlogModuleDescriptor" /> class.
        /// </summary>
        public BlogModuleDescriptor(ICmsConfiguration configuration)
            : base(configuration)
        {
            blogJsModuleIncludeDescriptor = new BlogJsModuleIncludeDescriptor(this);

            Events.RootEvents.Instance.PageRetrieved += Events_PageRetrieved;
        }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultSitemapService" /> class.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="unitOfWork">The unit of work.</param>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 /// <param name="accessControlService">The access control service.</param>
 public DefaultSitemapService(IRepository repository, IUnitOfWork unitOfWork, ICmsConfiguration cmsConfiguration, IAccessControlService accessControlService)
 {
     this.repository = repository;
     this.unitOfWork = unitOfWork;
     this.cmsConfiguration = cmsConfiguration;
     this.accessControlService = accessControlService;
 }
 public DefaultCategoryNodeService(IRepository repository, ICmsConfiguration cmsConfiguration, ISessionFactoryProvider sessionFactoryProvider, IUnitOfWork unitOfWork)
 {
     Repository = repository;
     this.cmsConfiguration = cmsConfiguration;
     this.sessionFactoryProvider = sessionFactoryProvider;
     this.unitOfWork = unitOfWork;
 }
        public DefaultWebCrawlerService(ICmsConfiguration cmsConfiguration)
        {
            this.cmsConfiguration = cmsConfiguration;

            webServer = cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneWebSiteUrl) ?? string.Empty;

            bool.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexPrivatePages), out indexPrivatePages);

            if (indexPrivatePages)
            {
                var authModeString = cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneAuthorizationMode);
                if (!string.IsNullOrWhiteSpace(authModeString))
                {
                    switch (authModeString.ToLower().Trim())
                    {
                        case "windows":
                            authMode = AuthMode.Windows;
                            break;
                        default:
                            authMode = AuthMode.Forms;
                            break;
                    }
                }
            }

            HtmlAgilityPackHelper.FixMissingTagClosings();

            TimeSpan timeout;
            if (TimeSpan.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexerPageFetchTimeout), out timeout)
                && timeout > TimeSpan.FromSeconds(0))
            {
                fetchTimeout = timeout;
            }
        }
        public WindowsAzureStorageService(ICmsConfiguration config)
        {
            try
            {
                var serviceSection = config.Storage;
                string accountName = serviceSection.GetValue("AzureAccountName");
                string secretKey = serviceSection.GetValue("AzureSecondaryKey");
                bool useHttps = bool.Parse(serviceSection.GetValue("AzureUseHttps"));

                if (!TimeSpan.TryParse(serviceSection.GetValue("AzureTokenExpiryTime"), out tokenExpiryTime))
                {
                    tokenExpiryTime = TimeSpan.FromMinutes(10);
                }

                timeout = serviceSection.ProcessTimeout;
                
                accessControlEnabledGlobally = config.Security.AccessControlEnabled;
                containerName = serviceSection.GetValue("AzureContainerName");
                securedContainerName = serviceSection.GetValue("AzureSecuredContainerName");
                if (string.IsNullOrWhiteSpace(securedContainerName))
                {
                    securedContainerName = containerName;
                }

                cloudStorageAccount = new CloudStorageAccount(new StorageCredentials(accountName, secretKey), useHttps);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to initialize storage service {0}.", GetType()), e);
            }
        }
        public FtpStorageService(ICmsConfiguration config)
        {
            try
            {
                var serviceSection = config.Storage;
                var mode = serviceSection.GetValue("UsePassiveMode");

                rootUrl = config.Storage.ContentRoot;
                usePassiveMode = mode != null && bool.Parse(mode);
                ftpRoot = serviceSection.GetValue("FtpRoot");
                userName = serviceSection.GetValue("FtpUserName");
                password = serviceSection.GetValue("FtpPassword");

                if (string.IsNullOrEmpty(rootUrl))
                {
                    throw new StorageException("ContentRoot is missing in a storage configuration.");
                }

                rootUrl = rootUrl.TrimEnd('/');
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to initialize storage service {0}.", GetType()), e);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlogModuleDescriptor" /> class.
        /// </summary>
        public BlogModuleDescriptor(ICmsConfiguration configuration) : base(configuration)
        {
            blogJsModuleIncludeDescriptor = new BlogJsModuleIncludeDescriptor(this);

            RootEvents.Instance.PageRetrieved += Events_PageRetrieved;

            RegisterRenderingPageProperties();
        }
 public DefaultDraftService(ICmsConfiguration cmsConfiguration, IAccessControlService accessControlService,
     IRepository repository, IUnitOfWork unitOfWork)
 {
     this.accessControlService = accessControlService;
     this.cmsConfiguration = cmsConfiguration;
     this.repository = repository;
     this.unitOfWork = unitOfWork;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultLayoutService" /> class.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="optionService">The option service.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="accessControlService">The access control service.</param>
 public DefaultLayoutService(IRepository repository, IOptionService optionService, ICmsConfiguration configuration,
     IAccessControlService accessControlService)
 {
     this.repository = repository;
     this.optionService = optionService;
     this.configuration = configuration;
     this.accessControlService = accessControlService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="UsersModuleDescriptor" /> class.
        /// </summary>
        public UsersModuleDescriptor(ICmsConfiguration configuration)
            : base(configuration)
        {
            userJsModuleIncludeDescriptor = new UserJsModuleIncludeDescriptor(this);

            CoreEvents.Instance.HostStart += OnHostStart;
            CoreEvents.Instance.HostAuthenticateRequest += HostAuthenticateRequest;            
        }            
        /// <summary>
        /// Ups the specified configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public override void Up(ICmsConfiguration configuration)
        {
            using (var blogsApi = CmsContext.CreateApiContextOf<BlogsApiContext>())
            {
                var blogs = blogsApi.GetBlogPosts(new GetBlogPostsRequest(includeUnpublished: true, includeNotActive: true)).Items;
                if (!blogs.Any())
                {
                    return;
                }

                var updateRequests = new List<UpdateBlogPostRequest>();

                using (var pagesApi = CmsContext.CreateApiContextOf<PagesApiContext>())
                {
                    foreach (var blog in blogs)
                    {
                        var requestToGet = new GetPageContentsRequest(blog.Id, e => e.Content is BlogPostContent, includeUnpublished: true, includeNotActive: true);
                        var pageContent = pagesApi.GetPageContents(requestToGet).FirstOrDefault();
                        if (pageContent == null)
                        {
                            continue;
                        }

                        var content = pageContent.Content as HtmlContent;
                        if (content == null)
                        {
                            continue;
                        }

                        updateRequests.Add(
                            new UpdateBlogPostRequest
                                {
                                    Id = blog.Id,
                                    Version = blog.Version,
                                    Title = blog.Title,
                                    IntroText = blog.Description,
                                    LiveFromDate = content.ActivationDate,
                                    LiveToDate = content.ExpirationDate,
                                    ImageId = blog.Image != null ? (Guid?)blog.Image.Id : null,
                                    AuthorId = blog.Author != null ? (Guid?)blog.Author.Id : null,
                                    CategoryId = blog.Category != null ? (Guid?)blog.Category.Id : null,
                                    Tags = blog.PageTags.Select(t => t.Tag.Name).ToList()
                                });
                    }
                }

                using (var transactionScope = new TransactionScope())
                {
                    foreach (var request in updateRequests)
                    {
                        blogsApi.UpdateBlogPost(request);
                    }

                    transactionScope.Complete();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultMediaImageService" /> class.
 /// </summary>
 /// <param name="mediaFileService">The media file service.</param>
 /// <param name="storageService">The storage service.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="repository">The repository.</param>
 /// <param name="unitOfWork">The unit of work.</param>
 /// <param name="sessionFactoryProvider">The session factory provider.</param>
 public DefaultMediaImageService(IMediaFileService mediaFileService, IStorageService storageService, ICmsConfiguration configuration, IRepository repository, ISessionFactoryProvider sessionFactoryProvider, IUnitOfWork unitOfWork)
 {
     this.mediaFileService = mediaFileService;
     this.sessionFactoryProvider = sessionFactoryProvider;
     this.storageService = storageService;
     this.configuration = configuration;
     this.repository = repository;
     this.unitOfWork = unitOfWork;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RootModuleDescriptor" /> class.
        /// </summary>
        public RootModuleDescriptor(ICmsConfiguration configuration)
            : base(configuration)
        {
            authenticationJsModuleIncludeDescriptor = new AuthenticationJsModuleIncludeDescriptor(this);
            siteSettingsJsModuleIncludeDescriptor = new SiteSettingsJsModuleIncludeDescriptor(this);
            tagsJsModuleIncludeDescriptor = new TagsJsModuleIncludeDescriptor(this);

            InitializeSecurity();
        }
        /// <summary>
        /// Should upload file to storage successfuly.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="storageService">The storage service.</param>
        /// <param name="useSmallImage">if set to <c>true</c> [use small image].</param>
        protected void ShouldUploadObject(ICmsConfiguration configuration, IStorageService storageService, bool useSmallImage = true)
        {
            // Upload
            var request = CreateUploadRequest(configuration, useSmallImage);
            storageService.UploadObject(request);
            request.InputStream.Dispose();

            // Remove
            storageService.RemoveObject(request.Uri);
        }
Exemple #31
0
        protected void ShouldDownloadUrlUnsecured(ICmsConfiguration configuration, IStorageService storageService)
        {
            // Upload
            var request      = CreateUploadRequest(configuration);
            var uploadedSize = request.InputStream.Length;

            storageService.UploadObject(request);
            request.InputStream.Dispose();

            var downloadRequest = WebRequest.Create(request.Uri.AbsoluteUri);
            var response        = downloadRequest.GetResponse();

            Assert.NotNull(response);
            Assert.AreEqual(response.ContentLength, uploadedSize);

            // Remove
            storageService.RemoveObject(request.Uri);
        }
Exemple #32
0
        public DefaultScrapeService(IRepository repository, IUnitOfWork unitOfWork, ICmsConfiguration cmsConfiguration)
        {
            Repository = repository;
            UnitOfWork = unitOfWork;

            if (!int.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneMaxPagesPerQuery), out scrapeLimit) ||
                scrapeLimit < 0)
            {
                scrapeLimit = 1000;
            }

            if (!TimeSpan.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LucenePageExpireTimeout), out pageExpireTimeout))
            {
                pageExpireTimeout = TimeSpan.FromMinutes(10);
            }

            bool.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexPrivatePages), out scrapePrivatePages);
        }
        public override void Up(ICmsConfiguration configuration)
        {
            using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>())
            {
                const string WidgetPath = "~/Areas/bcms-newsletter/Views/Widgets/SubscribeToNewsletter.cshtml";
                var          request    = new GetServerControlWidgetsRequest(e => e.Url == WidgetPath);
                var          widgets    = pagesApi.GetServerControlWidgets(request);
                if (widgets.Items.Count > 0)
                {
                    return;
                }

                using (var transactionScope = new TransactionScope())
                {
                    pagesApi.CreateServerControlWidget(
                        new CreateServerControlWidgetRequest()
                    {
                        Name       = "Newsletter Widget",
                        WidgetPath = WidgetPath,
                        Options    =
                            new List <ContentOptionDto>()
                        {
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Email placeholder", DefaultValue = "email..."
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Label title", DefaultValue = "Subscribe to newsletter"
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Submit title", DefaultValue = "Submit"
                            },
                            new ContentOptionDto()
                            {
                                Type = OptionType.Text, Key = "Submit is disabled", DefaultValue = "false"
                            }
                        }
                    });
                    transactionScope.Complete();
                }
            }
        }
Exemple #34
0
        private static void RegisterStorageService(ICmsConfiguration cmsConfiguration, ContainerBuilder builder)
        {
            try
            {
                if (cmsConfiguration.Storage.ServiceType == StorageServiceType.FileSystem || cmsConfiguration.Storage.ServiceType == StorageServiceType.Auto)
                {
                    builder.RegisterType <FileSystemStorageService>().As <IStorageService>().SingleInstance();
                }
                else if (cmsConfiguration.Storage.ServiceType == StorageServiceType.Ftp)
                {
                    builder.RegisterType <FtpStorageService>().As <IStorageService>().SingleInstance();
                }
                else
                {
                    string customStorageTypeName = cmsConfiguration.Storage.GetValue("typeName");
                    if (!string.IsNullOrEmpty(customStorageTypeName))
                    {
                        Type customStorageType = Type.GetType(customStorageTypeName);
                        if (customStorageType == null)
                        {
                            throw new CmsException(string.Format("Failed to register a storage service. A specified type '{0}' was not found.", customStorageTypeName));
                        }

                        if (typeof(IStorageService).IsAssignableFrom(customStorageType))
                        {
                            builder.RegisterType(customStorageType).As <IStorageService>().SingleInstance();
                        }
                        else
                        {
                            throw new CmsException(string.Format("Failed to register a storage service. Specified type {0} is not inherited from the {1} interface.", customStorageTypeName, typeof(IStorageService).FullName));
                        }
                    }
                    else
                    {
                        throw new CmsException(
                                  "Failed to register a storage service. The type name of the custom storage service is not specified. Please add to cms.config under cache section <add key=\"typeName\" value=\"your.full.custom.type.name\" />");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CmsException("Failed to register a storage service.", ex);
            }
        }
        public DefaultPageService(
            IRepository repository,
            IRedirectService redirectService,
            IUrlService urlService,
            IAccessControlService accessControlService,
            ICmsConfiguration cmsConfiguration,
            ISitemapService sitemapService,
            IUnitOfWork unitOfWork)
        {
            this.repository           = repository;
            this.redirectService      = redirectService;
            this.urlService           = urlService;
            this.accessControlService = accessControlService;
            this.cmsConfiguration     = cmsConfiguration;
            this.unitOfWork           = unitOfWork;
            this.sitemapService       = sitemapService;

            temporaryPageCache = new Dictionary <string, IPage>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PagesModuleDescriptor" /> class.
        /// </summary>
        public PagesModuleDescriptor(ICmsConfiguration configuration) : base(configuration)
        {
            pagesJsModuleIncludeDescriptor          = new PagesJsModuleIncludeDescriptor(this);
            pagePropertiesJsModuleIncludeDescriptor = new PagePropertiesJsModuleIncludeDescriptor(this);
            seoJsModuleIncludeDescriptor            = new SeoJsModuleIncludeDescriptor(this);
            pagesContentJsModuleIncludeDescriptor   = new PagesContentJsModuleIncludeDescriptor(this);
            widgetsJsModuleIncludeDescriptor        = new WidgetsJsModuleIncludeDescriptor(this);
            redirectsJsModuleIncludeDescriptor      = new RedirectsJsModuleIncludeDescriptor(this);
            templatesJsModuleIncludeDescriptor      = new TemplatesJsModuleIncludeDescriptor(this);
            masterPagesJsModuleIncludeDescriptor    = new MasterPagesJsModuleIncludeDescriptor(this);
            historyJsModuleIncludeDescriptor        = new HistoryJsModuleIncludeDescriptor(this);
            sitemapJsModuleIncludeDescriptor        = new SitemapJsModuleIncludeDescriptor(this);
//            CategoryAccessors.Register<PageCategory, PageProperties>(PageProperties.CategorizableItemKeyForPages);
            CategoryAccessors.Register <PageCategoryAccessor>();

            RootEvents.Instance.PageRetrieved += Events_PageRetrieved;

            RegisterRenderingPageProperties();
        }
        public override void Up(ICmsConfiguration configuration)
        {
            using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>())
            {
                var request = new GetPagesRequest(page => page.PageUrl == Urls.Page404, includeUnpublished: true, includePrivate: true);
                var add404  = configuration.Installation.Install404ErrorPage && !pagesApi.GetPages(request).Items.Any();

                request = new GetPagesRequest(page => page.PageUrl == Urls.Page500, includeUnpublished: true, includePrivate: true);
                var add500 = configuration.Installation.Install500ErrorPage && !pagesApi.GetPages(request).Items.Any();

                request = new GetPagesRequest(page => page.PageUrl == Urls.DefaultPage, includeUnpublished: true, includePrivate: true);
                var addDefault = configuration.Installation.InstallDefaultPage && !pagesApi.GetPages(request).Items.Any();

                if (!add404 && !add500 && !addDefault)
                {
                    return;
                }

                using (var transactionScope = new TransactionScope())
                {
                    var layout       = AddLayout(pagesApi);
                    var headerWidget = AddHtmlWidget(pagesApi, "Header", "<a href=\"/\" class=\"bcms-logo\"><img src=\"/file/bcms-pages/content/styles/images/logo.png\" alt=\"Better CMS\"></a>");
                    var footerWidget = AddHtmlWidget(pagesApi, "Footer", "<span class=\"copyright\">Better CMS 2012 ©</span>");

                    if (add404)
                    {
                        Add404ErrorPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    if (add500)
                    {
                        Add500ErrorPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    if (addDefault)
                    {
                        AddDefaultPage(pagesApi, layout, headerWidget, footerWidget);
                    }

                    transactionScope.Complete();
                }
            }
        }
Exemple #38
0
        /// <summary>
        /// Creates the configured BetterCMS root dependencies container.
        /// </summary>
        /// <returns>The container builder.</returns>
        public static ContainerBuilder InitializeContainer()
        {
            IConfigurationLoader configurationLoader = new DefaultConfigurationLoader();
            ICmsConfiguration    cmsConfiguration    = configurationLoader.LoadCmsConfiguration();

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(configurationLoader).As <IConfigurationLoader>().SingleInstance();
            builder.RegisterInstance(cmsConfiguration).As <ICmsConfiguration>().SingleInstance();

            builder.RegisterType <DefaultCmsHost>().As <ICmsHost>().SingleInstance();
            builder.RegisterType <ApiContext>().AsSelf().SingleInstance();
            builder.RegisterType <DefaultSessionFactoryProvider>().As <ISessionFactoryProvider>().SingleInstance();
            builder.RegisterType <DefaultAssemblyLoader>().As <IAssemblyLoader>().SingleInstance();
            builder.RegisterType <DefaultAssemblyManager>().As <IAssemblyManager>().SingleInstance();
            builder.RegisterType <DefaultUnitOfWorkFactory>().As <IUnitOfWorkFactory>().SingleInstance();

            builder.RegisterType <DefaultModulesRegistration>().As <IModulesRegistration>().SingleInstance();
            builder.RegisterType <DefaultMappingResolver>().As <IMappingResolver>().SingleInstance();
            builder.RegisterType <DefaultWorkingDirectory>().As <IWorkingDirectory>().SingleInstance();
            builder.RegisterType <DefaultCmsControllerFactory>().SingleInstance();
            builder.RegisterType <DefaultEmbeddedResourcesProvider>().As <IEmbeddedResourcesProvider>().SingleInstance();
            builder.RegisterType <DefaultHttpContextAccessor>().As <IHttpContextAccessor>().SingleInstance();
            builder.RegisterType <DefaultControllerExtensions>().As <IControllerExtensions>().SingleInstance();
            builder.RegisterType <DefaultCommandResolver>().As <ICommandResolver>().InstancePerLifetimeScope();

            builder.RegisterType <DefaultUnitOfWork>().As <IUnitOfWork>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultRepository>().As <IRepository>().InstancePerLifetimeScope();

            builder.RegisterInstance(new DefaultRouteTable(RouteTable.Routes)).As <IRouteTable>().SingleInstance();

            builder.RegisterType <PerWebRequestContainerProvider>().InstancePerLifetimeScope();

            builder.RegisterType <DefaultVersionChecker>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <DefaultMigrationRunner>().AsImplementedInterfaces().SingleInstance();

            RegisterCacheService(cmsConfiguration, builder);

            RegisterStorageService(cmsConfiguration, builder);

            return(builder);
        }
Exemple #39
0
        private static void Migrate()
        {
            ICmsConfigurationLoader configurationLoader = new CmsConfigurationLoader();
            ICmsConfiguration       cmsConfiguration    = configurationLoader.LoadCmsConfiguration();

            var builder = ApplicationContext.InitializeContainer(null, cmsConfiguration);

            builder.RegisterInstance(cmsConfiguration)
            .As <IConfiguration>()
            .As <IWebConfiguration>()
            .As <ICmsConfiguration>()
            .SingleInstance();
            ContextScopeProvider.RegisterTypes(builder);
            ApplicationContext.LoadAssemblies();

            IVersionChecker        versionChecker = new VersionCheckerStub();
            DefaultMigrationRunner runner         = new DefaultMigrationRunner(new DefaultAssemblyLoader(), cmsConfiguration, versionChecker);

            runner.MigrateStructure(descriptors.Cast <ModuleDescriptor>().ToList());
        }
Exemple #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultBlogService" /> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="urlService">The URL service.</param>
 /// <param name="repository">The repository.</param>
 /// <param name="optionService">The option service.</param>
 /// <param name="accessControlService">The access control service.</param>
 /// <param name="securityService">The security service.</param>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 /// <param name="contentService">The content service.</param>
 /// <param name="tagService">The tag service.</param>
 /// <param name="pageService">The page service.</param>
 /// <param name="redirectService">The redirect service.</param>
 /// <param name="masterPageService">The master page service.</param>
 /// <param name="unitOfWork">The unit of work.</param>
 public DefaultBlogService(ICmsConfiguration configuration, IUrlService urlService, IRepository repository,
                           IOptionService optionService, IAccessControlService accessControlService, ISecurityService securityService,
                           ICmsConfiguration cmsConfiguration, IContentService contentService, ITagService tagService,
                           IPageService pageService, IRedirectService redirectService, IMasterPageService masterPageService,
                           IUnitOfWork unitOfWork)
 {
     this.configuration        = configuration;
     this.urlService           = urlService;
     this.repository           = repository;
     this.optionService        = optionService;
     this.accessControlService = accessControlService;
     this.securityService      = securityService;
     this.cmsConfiguration     = cmsConfiguration;
     this.contentService       = contentService;
     this.pageService          = pageService;
     this.redirectService      = redirectService;
     this.masterPageService    = masterPageService;
     this.tagService           = tagService;
     this.unitOfWork           = unitOfWork;
 }
Exemple #41
0
        /// <summary>
        /// Should download file from storage successfully.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="storageService">The storage service.</param>
        protected void ShouldDownloadObject(ICmsConfiguration configuration, IStorageService storageService)
        {
            // Upload
            var request      = CreateUploadRequest(configuration);
            var uploadedSize = request.InputStream.Length;

            storageService.UploadObject(request);
            request.InputStream.Dispose();

            // Download
            var file = storageService.DownloadObject(request.Uri);

            Assert.IsNotNull(file);
            Assert.IsNotNull(file.ResponseStream);
            Assert.IsTrue(file.ResponseStream.Length > 0);
            Assert.AreEqual(file.ResponseStream.Length, uploadedSize);

            // Remove
            storageService.RemoveObject(request.Uri);
        }
        public AmazonS3StorageService(ICmsConfiguration config)
        {
            try
            {
                var serviceSection = config.Storage;

                accessKey  = serviceSection.GetValue("AmazonAccessKey");
                secretKey  = serviceSection.GetValue("AmazonSecretKey");
                bucketName = serviceSection.GetValue("AmazonBucketName");

                try
                {
                    if (serviceSection.ProcessTimeout.TotalMilliseconds > Int32.MaxValue)
                    {
                        timeout = Int32.MaxValue;
                    }
                    else
                    {
                        timeout = Convert.ToInt32(serviceSection.ProcessTimeout.TotalMilliseconds);
                        if (timeout <= 0)
                        {
                            timeout = DefaultTimeout;
                        }
                    }
                }
                catch (OverflowException)
                {
                    timeout = DefaultTimeout;
                }

                if (!TimeSpan.TryParse(serviceSection.GetValue("AmazonTokenExpiryTime"), out tokenExpiryTime))
                {
                    tokenExpiryTime = TimeSpan.FromMinutes(10);
                }
                accessControlEnabledGlobally = config.Security.AccessControlEnabled;
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to initialize storage service {0}.", GetType()), e);
            }
        }
Exemple #43
0
        public AmazonS3StorageService(ICmsConfiguration config)
        {
            try
            {
                var serviceSection = config.Storage;

                accessKey  = serviceSection.GetValue("AmazonAccessKey");
                secretKey  = serviceSection.GetValue("AmazonSecretKey");
                bucketName = serviceSection.GetValue("AmazonBucketName");

                if (!TimeSpan.TryParse(serviceSection.GetValue("AmazonTokenExpiryTime"), out tokenExpiryTime))
                {
                    tokenExpiryTime = TimeSpan.FromMinutes(10);
                }
                accessControlEnabledGlobally = config.AccessControlEnabled;
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to initialize storage service {0}.", GetType()), e);
            }
        }
        public WindowsAzureStorageService(ICmsConfiguration config)
        {
            try
            {
                var    serviceSection = config.Storage;
                string accountName    = serviceSection.GetValue("AzureAccountName");
                string secretKey      = serviceSection.GetValue("AzureSecondaryKey");
                bool   useHttps       = bool.Parse(serviceSection.GetValue("AzureUseHttps"));

                if (!TimeSpan.TryParse(serviceSection.GetValue("AzureTokenExpiryTime"), out tokenExpiryTime))
                {
                    tokenExpiryTime = TimeSpan.FromMinutes(10);
                }
                accessControlEnabledGlobally = config.AccessControlEnabled;
                containerName = serviceSection.GetValue("AzureContainerName");

                cloudStorageAccount = new CloudStorageAccount(new StorageCredentials(accountName, secretKey), useHttps);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to initialize storage service {0}.", GetType()), e);
            }
        }
Exemple #45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SitemapService" /> class.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="unitOfWork">The unit of work.</param>
 /// <param name="treeService">The tree service.</param>
 /// <param name="nodeService">The node service.</param>
 /// <param name="nodesService">The nodes service.</param>
 /// <param name="tagService">The tag service.</param>
 /// <param name="accessControlService">The access control service.</param>
 /// <param name="securityService">The security service.</param>
 /// <param name="sitemapService">The sitemap service.</param>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 public SitemapService(
     IRepository repository,
     IUnitOfWork unitOfWork,
     ISitemapTreeService treeService,
     INodeService nodeService,
     INodesService nodesService,
     ITagService tagService,
     IAccessControlService accessControlService,
     ISecurityService securityService,
     Module.Pages.Services.ISitemapService sitemapService,
     ICmsConfiguration cmsConfiguration)
 {
     this.repository           = repository;
     this.unitOfWork           = unitOfWork;
     this.treeService          = treeService;
     this.nodeService          = nodeService;
     this.nodesService         = nodesService;
     this.tagService           = tagService;
     this.accessControlService = accessControlService;
     this.securityService      = securityService;
     this.sitemapService       = sitemapService;
     this.cmsConfiguration     = cmsConfiguration;
 }
Exemple #46
0
        /// <summary>
        /// Should copy storage file successfuly.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="storageService">The storage service.</param>
        protected void ShouldCopyObject(ICmsConfiguration configuration, IStorageService storageService)
        {
            // Upload
            var request = CreateUploadRequest(configuration);

            storageService.UploadObject(request);
            request.InputStream.Dispose();

            // Copy
            string copyUrl = Path.Combine(configuration.Storage.ContentRoot, TestImageCopyFileName);
            var    copyUri = new Uri(copyUrl);

            storageService.CopyObject(request.Uri, copyUri);

            // Exists
            var exists = storageService.ObjectExists(copyUri);

            Assert.IsTrue(exists);

            // Remove
            storageService.RemoveObject(request.Uri);
            storageService.RemoveObject(copyUri);
        }
Exemple #47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SavePagePropertiesCommand" /> class.
 /// </summary>
 /// <param name="pageService">The page service.</param>
 /// <param name="redirectService">The redirect service.</param>
 /// <param name="tagService">The tag service.</param>
 /// <param name="sitemapService">The sitemap service.</param>
 /// <param name="urlService">The URL service.</param>
 /// <param name="optionService">The option service.</param>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 /// <param name="accessControlService">The access control service.</param>
 /// <param name="contentService">The content service.</param>
 /// <param name="masterPageService">The master page service.</param>
 public SavePagePropertiesCommand(
     IPageService pageService,
     IRedirectService redirectService,
     ITagService tagService,
     ISitemapService sitemapService,
     IUrlService urlService,
     IOptionService optionService,
     ICmsConfiguration cmsConfiguration,
     IAccessControlService accessControlService,
     IContentService contentService,
     IMasterPageService masterPageService)
 {
     this.pageService          = pageService;
     this.redirectService      = redirectService;
     this.tagService           = tagService;
     this.sitemapService       = sitemapService;
     this.urlService           = urlService;
     this.optionService        = optionService;
     this.cmsConfiguration     = cmsConfiguration;
     this.accessControlService = accessControlService;
     this.contentService       = contentService;
     this.masterPageService    = masterPageService;
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region NtkCmsFactoryIocConfig
            WebApiIocConfig.Register(NtkCmsFactoryIocConfig.binder);
            NtkCmsFactoryIocConfig.RegisterConfigServiceCollection(services);
            NtkCmsFactoryIocConfig.Initilizer();
            #endregion NtkCmsFactoryIocConfig


            cmsConfiguration = appSettingRead();
            PerformanceLogStartup.ConfigureServices(services, cmsConfiguration);

            services.AddCors(o => o.AddPolicy("Policy", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Ntk.Autoactiva.Greenvideo.WebApi v1",
                    Version = "V1",
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });


            services.AddScoped <UploadPartAttribute>();
            services.AddScoped <UploadCompeleteAttribute>();

            services.AddControllers();
        }
Exemple #49
0
        protected void ShouldNotDownloadUrlSecured(ICmsConfiguration configuration, IStorageService storageService)
        {
            // Upload
            var request = CreateUploadRequest(configuration);

            storageService.UploadObject(request);
            request.InputStream.Dispose();

            var downloadRequest = WebRequest.Create(request.Uri.AbsoluteUri);
            var failed          = false;

            try
            {
                downloadRequest.GetResponse();
            }
            catch (WebException)
            {
                failed = true;
            }
            Assert.IsTrue(failed);

            // Remove
            storageService.RemoveObject(request.Uri);
        }
        public DefaultWebCrawlerService(ICmsConfiguration cmsConfiguration)
        {
            this.cmsConfiguration = cmsConfiguration;

            webServer = cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneWebSiteUrl) ?? string.Empty;

            bool.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexPrivatePages), out indexPrivatePages);

            if (indexPrivatePages)
            {
                var authModeString = cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneAuthorizationMode);
                if (!string.IsNullOrWhiteSpace(authModeString))
                {
                    switch (authModeString.ToLower().Trim())
                    {
                    case "windows":
                        authMode = AuthMode.Windows;
                        break;

                    default:
                        authMode = AuthMode.Forms;
                        break;
                    }
                }
            }

            HtmlAgilityPackHelper.FixMissingTagClosings();

            TimeSpan timeout;

            if (TimeSpan.TryParse(cmsConfiguration.Search.GetValue(LuceneSearchConstants.ConfigurationKeys.LuceneIndexerPageFetchTimeout), out timeout) &&
                timeout > TimeSpan.FromSeconds(0))
            {
                fetchTimeout = timeout;
            }
        }
Exemple #51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreviewController"/> class.
 /// </summary>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 public PreviewController(ICmsConfiguration cmsConfiguration)
 {
     this.cmsConfiguration = cmsConfiguration;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SuggestPagesCommand" /> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="pageService">The page service.</param>
 public SuggestPagesCommand(ICmsConfiguration configuration, IPageService pageService)
 {
     this.configuration = configuration;
     this.pageService   = pageService;
 }
Exemple #53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetContentHistoryCommand" /> class.
 /// </summary>
 /// <param name="historyService">The history service.</param>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 public GetContentHistoryCommand(IHistoryService historyService, ICmsConfiguration cmsConfiguration)
 {
     this.historyService   = historyService;
     this.cmsConfiguration = cmsConfiguration;
 }
Exemple #54
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SidebarController" /> class.
 /// </summary>
 /// <param name="modulesRegistration">The modules.</param>
 /// <param name="configuration">The CMS configuration.</param>
 public SidebarController(ICmsModulesRegistration modulesRegistration, ICmsConfiguration configuration)
 {
     this.configuration       = configuration;
     this.modulesRegistration = modulesRegistration;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UsersModuleDescriptor" /> class.
 /// </summary>
 public UsersModuleDescriptor(ICmsConfiguration configuration) : base(configuration)
 {
     userJsModuleIncludeDescriptor = new UserJsModuleIncludeDescriptor(this);
 }
Exemple #56
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchUsersCommand" /> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="cacheService">The cache service.</param>
 public SearchUsersCommand(ICmsConfiguration configuration, ICacheService cacheService)
 {
     this.configuration = configuration;
     this.cacheService  = cacheService;
 }
Exemple #57
0
 public GoogleAnalyticsScriptAccessor(ICmsConfiguration cmsConfiguration, Guid analyticsScriptGuid)
 {
     this.cmsConfiguration    = cmsConfiguration;
     this.analyticsScriptGuid = analyticsScriptGuid;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApiModuleDescriptor" /> class.
 /// </summary>
 /// <param name="cmsConfiguration">The CMS configuration.</param>
 public ApiModuleDescriptor(ICmsConfiguration cmsConfiguration)
     : base(cmsConfiguration)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultBlogService" /> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="urlService">The URL service.</param>
 /// <param name="repository">The repository.</param>
 public DefaultBlogService(ICmsConfiguration configuration, IUrlService urlService, IRepository repository)
 {
     this.configuration = configuration;
     this.urlService    = urlService;
     this.repository    = repository;
 }
Exemple #60
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstallationModuleDescriptor" /> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 public InstallationModuleDescriptor(ICmsConfiguration configuration) : base(configuration)
 {
 }