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.Warn("Prepared lucene query " + 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)); }
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."); }
private void WriteToIndex(int itemID, Document doc) { if (doc == null) { return; } lock (accessor) { var iw = accessor.GetWriter(); try { iw.UpdateDocument(new Term(TextExtractor.Properties.ID, itemID.ToString()), doc); iw.PrepareCommit(); iw.Commit(); } catch (AlreadyClosedException ex) { logger.Error(ex); try { iw = accessor.GetWriter(); iw.UpdateDocument(new Term(TextExtractor.Properties.ID, itemID.ToString()), doc); iw.PrepareCommit(); iw.Commit(); } catch (Exception ex2) { logger.Error(ex2); iw.Dispose(); accessor.ClearLock(); } } catch (ThreadAbortException ex) { logger.Warn(ex); iw.Rollback(); iw.Dispose(waitForMerges: false); accessor.ClearLock(); throw; } catch (Exception ex) { logger.Error(ex); iw.Rollback(); iw.Dispose(); accessor.ClearLock(); } finally { iw.Dispose(waitForMerges: true); accessor.RecreateSearcher(); } } }
private void RedirectToFix(WrongClassException wex) { if (context.HttpContext != null) { string url = Url.Parse(beginUrl).ResolveTokens() .AppendQuery("action", "fixClass") .AppendQuery("id", wex.Identifier); logger.Warn("Redirecting to '" + url + "' to fix exception: " + wex); context.HttpContext.ClearError(); context.HttpContext.Response.Redirect(url); } }
protected virtual IndexWriter CreateWriter(Directory d, Analyzer a) { try { return(CreateWriterNoTry(d, a)); } catch (Lucene.Net.Store.LockObtainFailedException) { logger.Warn("Failed to obtain lock, deleting it and retrying."); ClearLock(); return(CreateWriterNoTry(d, a)); } }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { var security = N2.Context.Current.Resolve <ISecurityManager>(); using (security.Disable()) // TODO restrict to Admin User { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); if (_persister != null) { _persister.SaveRecursive(record.RootItem); } } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = record.RootItem.Children[0]; child.AddTo(destination); if (_persister != null) { _persister.SaveRecursive(child); } } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(_fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } } }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); persister.SaveRecursive(record.RootItem); } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = record.RootItem.Children[0]; child.AddTo(destination); persister.SaveRecursive(child); } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); try { persister.SaveRecursive(record.RootItem); } catch (Exception ex) { logger.Warn(ex); if (record.RootItem != null) { record.FailedContentItems.Add(new Tuple <ContentItem, Exception>(record.RootItem, ex)); } } } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = null; bool added = false; try { child = record.RootItem.Children[0]; child.AddTo(destination); added = true; persister.SaveRecursive(child); } catch (Exception ex) { logger.Warn(ex); if (child != null) { record.FailedContentItems.Add(new Tuple <ContentItem, Exception>(child, ex)); } // ROLL BACK: Undo child.AddTo if SaveRecursive failed. That way the import can still continue successfully. if (added && destination != null && child != null) { destination.Children.Remove(child); } } } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } }
/// <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; } } } }
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) { 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); }