protected virtual void SetErrorMessage(BaseValidator validator, N2.Integrity.NameOccupiedException ex) { logger.Debug(ex); string message = string.Format(GetLocalResourceString("NameOccupiedExceptionFormat", "An item named \"{0}\" already exists below \"{1}\""), ex.SourceItem.Name, ex.DestinationItem.Name); SetErrorMessage(validator, message); }
public override object Instantiate(string clazz, EntityMode entityMode, object id) { logger.Debug("Instantiate: " + clazz + " " + entityMode + " " + id); object instance = interceptor.Create(clazz, id); if (instance != null) { Session.SessionFactory.GetClassMetadata(clazz).SetIdentifier(instance, id, entityMode); } return(instance); }
protected virtual void OnReadingAuthorizedRoles(XPathNavigator navigator, ContentItem item) { if (navigator.MoveToFirstChild()) { do { logger.Debug(navigator.Value); item.AuthorizedRoles.Add(new AuthorizedRole(item, navigator.Value)); } while (navigator.MoveToNext()); navigator.MoveToParent(); } }
protected virtual IndexWriter CreateWriter(Directory d, Analyzer a) { try { return(CreateWriterNoTry(d, a)); } catch (Lucene.Net.Store.LockObtainFailedException) { logger.Debug("Failed to obtain lock, deleting it and retrying."); ClearLock(); return(CreateWriterNoTry(d, a)); } }
internal void Render(TextWriter writer) { if (!string.IsNullOrEmpty(path)) { CurrentItem = ItemUtility.WalkPath(CurrentItem, path); } if (CurrentItem == null) { return; } if (swallowExceptions) { try { RenderDisplayable(writer); } catch (Exception ex) { logger.Debug(ex); } } else { RenderDisplayable(writer); } }
public override DatabaseStatus GetStatus() { logger.Debug("checking database status"); DatabaseStatus status = new DatabaseStatus(); if (IsSql(status)) { if (UpdateConnection(status)) { if (UpdateVersion(status)) { if (UpdateSchema(status)) { if (UpdateCount(status)) { if (UpdateItems(status)) { UpdateRecordedValues(status); } } } } } } return(status); }
protected virtual ContentItem Parse(ContentItem current, Url url) { if (current == null) { throw new ArgumentNullException("current"); } logger.Debug("Parsing " + url); var path = CleanUrl(url.PathAndQuery); if (path.Length == 0) { return(current); } return(current.GetChild(path) ?? NotFoundPage(url)); }
void timer_Elapsed(object sender, ElapsedEventArgs e) { logger.Debug("Beat: " + DateTime.Now); if (Beat != null) { Beat(this, e); } }
void timer_Elapsed(object sender, ElapsedEventArgs e) { logger.Debug("Beat: " + N2.Utility.CurrentTime()); if (Beat != null) { Beat(this, e); } }
/// <summary>Adds default assemblies to NHibernate configuration.</summary> /// <param name="cfg"></param> protected virtual void AddAssemblies(NHibernate.Cfg.Configuration cfg) { foreach (Assembly a in Assemblies) { cfg.AddAssembly(a); } logger.Debug(String.Format("Added {0} assemblies to configuration", Assemblies.Count)); }
public virtual ISession CreateSession(ISessionFactory sessionFactory) { logger.Debug("Creating NH session"); var nhi = new NHInterceptor(interceptor, notifier); var s = sessionFactory.OpenSession(nhi); nhi.Session = s; return(s); }
protected override void LoadViewState(object savedState) { var p = (Triplet)savedState; base.LoadViewState(p.First); AddedDefinitions = (List <string>)p.Second; DeletedIndexes = (List <int>)p.Third; EnsureChildControls(); logger.Debug("addedTypes: " + AddedDefinitions.Count + ", deletedIndexes: " + DeletedIndexes.Count); }
public virtual void Clear() { logger.Debug("Clearing index"); if (accessor.IndexExists()) { accessor.ClearLock(); using (var iw = accessor.GetWriter()) { if (iw.NumDocs() > 0) { iw.DeleteAll(); iw.PrepareCommit(); iw.Commit(); accessor.RecreateSearcher(); } } accessor.ClearLock(); } }
public override void Execute() { if (engine == null) { engine = N2.Context.Current; } if (config == null) { config = ConfigurationManager.GetSection("n2/engine") as EngineSection; } if (config == null || !config.Scheduler.KeepAlive) { Repeat = Repeat.Once; return; } try { Url url = Url.ServerUrl; if (url == null) { return; } using (WebClient wc = new WebClient()) { wc.Headers["N2KeepAlive"] = "true"; url = url.SetPath(config.Scheduler.KeepAlivePath.ResolveUrlTokens()); logger.Debug("Pinging " + url); string response = wc.DownloadString(url); logger.Debug("Pinged " + url + ": " + response); } } catch (SecurityException ex) { N2.Engine.Logger.Warn("Stopping keep-alive after exception (probably medium trust environment): ", ex); Repeat = Repeat.Once; } }
public void DeleteFile(string virtualPath) { using (var trx = Session.BeginTransaction()) { var path = FileSystemPath.File(virtualPath); var file = GetSpecificItem(path); int deletedChunks = Session.CreateQuery("delete from " + typeof(FileSystemChunk).Name + " where BelongsTo = :file") .SetParameter("file", file) .ExecuteUpdate(); Session.Delete(file); logger.Debug("Deleted 1 item and " + deletedChunks + " chunks at " + path); trx.Commit(); } if (FileDeleted != null) { FileDeleted.Invoke(this, new FileEventArgs(virtualPath, null)); } }
public override RouteData GetRouteData(HttpContextBase httpContext) { string path = httpContext.Request.AppRelativeCurrentExecutionFilePath; RouteData routeData = null; try { if (path.StartsWith(managementPath, StringComparison.InvariantCultureIgnoreCase)) { return(new RouteData(this, new StopRoutingHandler())); } if (path.EndsWith(".axd", StringComparison.InvariantCultureIgnoreCase)) { return(new RouteData(this, new StopRoutingHandler())); } if (path.EndsWith(".ashx", StringComparison.InvariantCultureIgnoreCase)) { return(new RouteData(this, new StopRoutingHandler())); } if (httpContext.Request.QueryString["_escaped_fragment_"] != null) { return(new RouteData(this, new StopRoutingHandler())); } if (httpContext.Request.QueryString[ContentPartKey] != null) { // part in query string, this is an indicator of a request to a part, takes precendence over friendly urls routeData = CheckForContentController(httpContext); } if (routeData == null) { // this might be a friendly url routeData = GetRouteDataForPath(httpContext.Request); } if (routeData == null) { // fallback to route to controller/action routeData = CheckForContentController(httpContext); } } finally { logger.Debug(String.Format("GetRouteData for '{0}' got values: {1}", path, new RouteExtensions.QueryStringOutput(routeData))); } return(routeData); }
public void HandleMessages() { NetIncomingMessage msg; while ((msg = _client.ReadMessage()) != null) { if (msg.PeekString() != "") { LastNetMessage = msg.PeekString(); } switch (msg.MessageType) { case NetIncomingMessageType.StatusChanged: _logger.Info("StatusChanged received: " + msg.SenderConnection.Status); break; case NetIncomingMessageType.Data: LastNetMessage = (MessageType)msg.PeekInt32() + ""; HandleIncomingData(msg); break; case NetIncomingMessageType.ConnectionLatencyUpdated: LastLatency = (int)Math.Round(msg.ReadFloat() * 1000); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: _logger.Debug(msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: _logger.Warn(msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: _logger.Error(msg.ReadString()); break; default: _logger.Warn("Unhandled MessageType: " + msg.MessageType); break; } _client.Recycle(msg); } }
public void ServerThread() { NetIncomingMessage msg; while (Engine.Core.Instance.State == Engine.Core.EngineState.Running) { Thread.Sleep(5); while ((msg = _server.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.StatusChanged: _logger.Info("StatusChanged received: " + msg.SenderConnection.Status); HandleStatusChanged(msg); break; case NetIncomingMessageType.Data: HandleIncomingData(msg); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: _logger.Debug(msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: _logger.Warn(msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: _logger.Error(msg.ReadString()); break; default: _logger.Warn("Unhandled MessageType: " + msg.MessageType); break; } _server.Recycle(msg); } } _logger.Info("Terminated."); }
public MultipleSitesInitializer(IPersister persister, IHost host, ISitesProvider sitesProvider, ConnectionMonitor context, HostSection config, IDefinitionManager ignored) { logger.Debug("MultipleSitesInitializer"); if (config.MultipleSites && config.DynamicSites) { context.Online += delegate { host.AddSites(sitesProvider.GetSites()); persister.ItemSaved += delegate(object sender, ItemEventArgs e) { if (e.AffectedItem is ISitesSource) { IList <Site> sites = Host.ExtractSites(config); sites = Host.Union(sites, sitesProvider.GetSites()); host.ReplaceSites(host.DefaultSite, sites); } }; }; } }
public DatabaseStatus GetStatus() { logger.Debug("InstallationManager: checking database status"); DatabaseStatus status = new DatabaseStatus(); if (UpdateConnection(status)) { if (UpdateVersion(status)) { if (UpdateSchema(status)) { if (UpdateCount(status)) { if (UpdateItems(status)) { UpdateAppPath(status); } } } } } return(status); }
private void CheckInstallation() { string currentUrl = Url.ToRelative(webContext.Url.LocalUrl); try { AuthenticationSection authentication = ConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection; if (currentUrl.Trim('~', '/').StartsWith(Url.ToAbsolute(authentication.Forms.LoginUrl.Trim('~', '/')), StringComparison.InvariantCultureIgnoreCase)) { // don't redirect from login page return; } } catch (Exception ex) { Engine.Logger.Warn(ex); } if (Status == null) { Status = installer.GetStatus(); } Url redirectUrl = Url.ResolveTokens(welcomeUrl); if (Status == null) { Engine.Logger.Warn("Null status"); installer.UpdateStatus(SystemStatusLevel.Unknown); return; } else if (Status.NeedsUpgrade) { redirectUrl = redirectUrl.AppendQuery("action", "upgrade"); } else if (!Status.IsInstalled) { redirectUrl = redirectUrl.AppendQuery("action", "install"); } else if (Status.NeedsRebase) { redirectUrl = redirectUrl.AppendQuery("action", "rebase"); } else { this.broker.BeginRequest -= BeginRequest; installer.UpdateStatus(Status.Level); this.Status = null; return; } installer.UpdateStatus(Status.Level); bool isEditing = currentUrl.StartsWith(N2.Web.Url.ToRelative(managementUrl), StringComparison.InvariantCultureIgnoreCase); if (isEditing) { return; } logger.Debug("Redirecting to '" + redirectUrl + "' to handle status: " + Status.ToStatusString()); this.Status = null; webContext.HttpContext.Response.Redirect(redirectUrl); }
private string Request(string httpMethod, string relativePath, string requestBody) { logger.Debug(httpMethod + " " + serverUrl + relativePath + " (" + requestBody.Length + ")"); return(RemoteExtensions.RequestJson(httpMethod, serverUrl + relativePath, requestBody, timeout: timeout, sharedSecret: sharedSecret)); }
public void RewritePath(string path) { logger.Debug("Rewriting '" + Url.LocalUrl + "' to '" + path + "'"); CurrentHttpContext.RewritePath(path, false); }
protected virtual Lucene.Net.Search.Query CreateQuery(N2.Persistence.Search.Query query) { var q = ""; if (!string.IsNullOrEmpty(query.Text)) { q = query.OnlyPages.HasValue ? string.Format("+(Title:({0})^4 Text:({0}) PartsText:({0}))", query.Text) : string.Format("+(Title:({0})^4 Text:({0}))", query.Text); } if (query.Ancestor != null) { q += string.Format(" +Trail:{0}*", Utility.GetTrail(query.Ancestor)); } if (query.OnlyPages.HasValue) { q += string.Format(" +IsPage:{0}", query.OnlyPages.Value.ToString().ToLower()); } if (query.Roles != null) { q += string.Format(" +Roles:(Everyone {0})", string.Join(" ", query.Roles.ToArray())); } if (query.Types != null) { q += string.Format(" +Types:({0})", string.Join(" ", query.Types.Select(t => t.Name).ToArray())); } if (query.LanguageCode != null) { q += string.Format(" +Language:({0})", query.LanguageCode); } if (query.Exclution != null) { q += string.Format(" -({0})", CreateQuery(query.Exclution)); } if (query.Intersection != null) { q = string.Format("+({0}) +({1})", q, CreateQuery(query.Intersection)); } if (query.Union != null) { q = string.Format("({0}) ({1})", q, CreateQuery(query.Union)); } if (query.Details.Count > 0) { foreach (var kvp in query.Details) { if (LuceneIndexer.Properties.All.Contains(kvp.Key)) { q += string.Format(" +{0}:({1})", kvp.Key, kvp.Value); } else { q += string.Format(" +Detail.{0}:({1})", kvp.Key, kvp.Value); } } } logger.Debug("CreateQuery: " + q); return(accessor.GetQueryParser().Parse(q)); }
public override void AuthorizeRequest(PathData path, System.Security.Principal.IPrincipal user) { logger.Debug("AuthorizeRequest"); base.AuthorizeRequest(path, user); }
/// <summary>Executes the scheduled actions that are scheduled for executions.</summary> public void ExecuteActions() { if (!enabled) { return; } if (Debugger.IsAttached && !runWhileDebuggerAttached) { return; } for (int i = 0; i < actions.Count; i++) { ScheduledAction action = actions[i]; if (action.ShouldExecute()) { Action work = delegate { try { var config = ((System.Web.Configuration.GlobalizationSection)System.Configuration.ConfigurationManager.GetSection("system.web/globalization")); if (!string.IsNullOrEmpty(config.Culture)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(config.Culture); } if (!string.IsNullOrEmpty(config.UICulture)) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(config.UICulture); } } catch (Exception ex) { logger.Warn(ex); } try { logger.Debug("Executing " + action.GetType().Name); action.Engine = engine; action.Execute(); action.ErrorCount = 0; } catch (Exception ex) { action.ErrorCount++; action.OnError(ex); // wayne: call custom action error handler } finally { try { IClosable closable = action as IClosable; if (closable != null) { closable.Dispose(); } } catch (Exception ex) { errorHandler.Notify(ex); } } action.LastExecuted = Utility.CurrentTime(); action.IsExecuting = false; try { context.Close(); } catch (Exception ex) { errorHandler.Notify(ex); } }; action.IsExecuting = true; if (asyncActions) { worker.DoWork(work); } else { work(); } if (action.Repeat == Repeat.Once) { actions.RemoveAt(i); --i; } } } }