public override void AddComponentWithParameters(string key, Type serviceType, Type classType, IDictionary <string, string> properties) { logger.InfoFormat("Add component, key:{0}, service:{1}, implementation:{2}, properties:{3}" + key, serviceType, serviceType, classType, properties.Count); var registration = Component.For(serviceType) .ImplementedBy(classType); if (properties.Count > 0) { registration.DependsOn(properties.Select(p => Dependency.OnValue(p.Key, p.Value))); } container.Register(registration); }
protected override Result <LightweightHitData> CreateResults(N2.Persistence.Search.Query query, IndexSearcher s, TopDocs hits) { logger.InfoFormat("Creating results for query {0} and {1} hits", query.Text, hits.TotalHits); var result = new Result <LightweightHitData>(); result.Total = hits.TotalHits; var resultHits = hits.ScoreDocs.Skip(query.SkipHits).Take(query.TakeHits).Select(hit => { var doc = s.Doc(hit.Doc); int id = int.Parse(doc.Get("ID")); return(new Hit <LightweightHitData> { Content = new LightweightHitData { ID = id, AlteredPermissions = (Security.Permission) int.Parse(doc.Get("AlteredPermissions")), State = (ContentState)int.Parse(doc.Get("State")), Visible = Convert.ToBoolean(doc.Get("Visible")), AuthorizedRoles = doc.Get("Roles").Split(' '), Path = doc.Get("Path") }, Title = doc.Get("Title"), Url = doc.Get("Url"), Score = hit.Score }); }).ToList(); result.Hits = resultHits; result.Count = resultHits.Count; return(result); }
public Result <T> Search(N2.Persistence.Search.Query query) { if (!query.IsValid()) { logger.Warn("Invalid query"); return(Result <T> .Empty); } var luceneQuery = query.ToLuceneQuery(); logger.InfoFormat("Prepared lucene query {0}", luceneQuery); var q = accessor.GetQueryParser().Parse(luceneQuery); var s = accessor.GetSearcher(); TopDocs hits; if (string.IsNullOrEmpty(query.SortField)) { hits = s.Search(q, query.SkipHits + query.TakeHits); } else { hits = s.Search( query: q, filter: null, n: query.SkipHits + query.TakeHits, sort: new Sort( query.SortFields.Select( field => new SortField(field.SortField, GetSortFieldType(field.SortField), field.SortDescending)).ToArray())); } return(CreateResults(query, s, hits)); }
private ContentItem LocateStartPage(ContentItem startPageConfigured) { ContentItem startPage = startPageConfigured; lock (_syncLock) { if (host.CurrentSite.StartPageID != host.CurrentSite.RootItemID) // only when start <> root { if (startPage != null) { if (!(startPage is IStartPage)) { logger.WarnFormat("Configured start page is no IStartPage #{0} -> {1}", host.CurrentSite.StartPageID, startPage.GetType().FullName); startPage = null; } if (startPage != null && !startPage.IsPublished()) { logger.ErrorFormat("Configured start page is not published #{0} -> {1}", startPage.ID, startPage.GetType().FullName); startPage = null; } } if (startPage == null) { // try to locate start page below root var root = persister.Repository.Get(host.CurrentSite.RootItemID); if (root == null) { // no content? return(null); } ItemList children = root.GetChildren(new TypeFilter(typeof(IStartPage)), new PublishedFilter()); if (children.Count == 1) { startPage = children[0]; logger.InfoFormat("Auto updated start page to #{0} -> {1}", startPage.ID, startPage.GetType().FullName); var newSite = new Site(root.ID, startPage.ID); host.ReplaceSites(newSite, new List <Site>()); } } if (startPage == null) { return(startPageConfigured); // keep configured } } } return(startPage); }
private VirtualPathProviderViewEngine GetOrCreateViewEngine(ControllerContext controllerContext, string theme) { if (string.IsNullOrEmpty(theme)) { theme = "Default"; } T engine; if (!engines.TryGetValue(theme, out engine)) { string themePath = themeFolderPath + theme + "/"; string defaultThemePath = themeFolderPath + "Default/"; string rootViewsPath = "~/"; var paths = new List <string>(); if (defaultThemePath != themePath) { paths.Add(themePath); } if (FallbackToRootViews) { paths.Add(rootViewsPath); } if (FallbackToDefaultTheme) { paths.Add(defaultThemePath); } logger.InfoFormat("Creating themed view engine for theme {0} below paths {1}", theme, string.Join(", ", paths)); engine = new T(); engine.AreaMasterLocationFormats = GetAreaLocations(paths, masterExtensions); engine.AreaViewLocationFormats = GetAreaLocations(paths, viewExtensions); engine.AreaPartialViewLocationFormats = engine.AreaViewLocationFormats; engine.MasterLocationFormats = GetLocations(paths, masterExtensions); engine.ViewLocationFormats = GetLocations(paths, viewExtensions); engine.PartialViewLocationFormats = engine.ViewLocationFormats; engine.ViewLocationCache = new ThemeViewLocationCache(); Utility.TrySetProperty(engine, "FileExtensions", viewExtensions); var temp = new Dictionary <string, T>(engines); temp[theme] = engine; engines = temp; } if (controllerContext != null) { controllerContext.RouteData.DataTokens["ThemeViewEngine.ThemeFolderPath"] = themeFolderPath; } return(engine); }
/// <summary>Attaches to events from the application instance.</summary> public virtual void Attach(HttpApplication application) { logger.InfoFormat("Attaching to {0} ({1})", application, application.GetHashCode()); application.BeginRequest += Application_BeginRequest; application.AuthorizeRequest += Application_AuthorizeRequest; application.PostResolveRequestCache += Application_PostResolveRequestCache; application.PostMapRequestHandler += Application_PostMapRequestHandler; application.AcquireRequestState += Application_AcquireRequestState; application.PreRequestHandlerExecute += Application_PreRequestHandlerExecute; application.Error += Application_Error; application.EndRequest += Application_EndRequest; application.Disposed += Application_Disposed; }
private IViewEngine GetOrCreateViewEngine(ControllerContext controllerContext, string theme) { if (string.IsNullOrEmpty(theme)) { theme = "Default"; } T engine; if (!engines.TryGetValue(theme, out engine)) { string fallbackPath = themeFolderPath + "Default/"; string themePath = themeFolderPath + theme + "/"; logger.InfoFormat("Creating themed view engine for theme {0} below path {1}", theme, themePath); engine = new T(); engine.AreaMasterLocationFormats = GetAreaLocations(themePath, fallbackPath, masterExtensions); engine.AreaViewLocationFormats = GetAreaLocations(themePath, fallbackPath, viewExtensions); engine.AreaPartialViewLocationFormats = engine.AreaViewLocationFormats; engine.MasterLocationFormats = GetLocations(themePath, fallbackPath, masterExtensions); engine.ViewLocationFormats = GetLocations(themePath, fallbackPath, viewExtensions); engine.PartialViewLocationFormats = engine.ViewLocationFormats; engine.ViewLocationCache = new ThemeViewLocationCache(); Utility.TrySetProperty(engine, "FileExtensions", viewExtensions); var temp = new Dictionary <string, T>(engines); temp[theme] = engine; engines = temp; } if (controllerContext != null) { controllerContext.RouteData.DataTokens["ThemeViewEngine.ThemeFolderPath"] = themeFolderPath; } return(engine); }