private void CompleteTrace() { try { SIPMonitorConsoleEvent traceCompleteEvent = new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dialplan trace completed at " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss:fff") + ".", Owner); TraceLog.AppendLine(traceCompleteEvent.EventType + "=> " + traceCompleteEvent.Message); if (!m_traceDirectory.IsNullOrBlank() && Directory.Exists(m_traceDirectory)) { string traceFilename = m_traceDirectory + Owner + "-" + DateTime.Now.ToString("ddMMMyyyyHHmmss") + ".txt"; StreamWriter traceSW = new StreamWriter(traceFilename); traceSW.Write(TraceLog.ToString()); traceSW.Close(); } if (TraceEmailAddress != null) { logger.Debug("Emailing trace to " + TraceEmailAddress + "."); SIPSorcerySMTP.SendEmail(TraceEmailAddress, TRACE_FROM_ADDRESS, TRACE_SUBJECT, TraceLog.ToString()); } } catch (Exception traceExcp) { logger.Error("Exception DialPlanContext CompleteTrace. " + traceExcp.Message); } }
/// <summary> /// Build Trace message to sue when raising an invalid plugin exception /// </summary> /// <param name="value"></param> public virtual void Trace(string value) { if (TraceLog == null) { TraceLog = new StringBuilder(); } else { TraceLog.AppendLine(); } TraceLog.Append(value); TraceLog.Append(" - "); TraceLog.Append(DateTime.Now.ToString("hh.mm.ss.ffffff")); }
private void FireProxyLogEvent(SIPMonitorEvent monitorEvent) { try { if (monitorEvent is SIPMonitorConsoleEvent) { SIPMonitorConsoleEvent consoleEvent = monitorEvent as SIPMonitorConsoleEvent; if (TraceLog != null) { TraceLog.AppendLine(consoleEvent.EventType + "=> " + monitorEvent.Message); } } if (Log_External != null) { Log_External(monitorEvent); } } catch (Exception excp) { logger.Error("Exception FireProxyLogEvent DialPlanContext. " + excp.Message); } }
public virtual TResult Execute <TResult>(Expression expression) { var count = 0; // in case there is a predefined list of nodes, we do not execute a query (but we still need to build it) if (!this.ExecuteQuery) { count = ChildrenDefinition.BaseCollection.Count(); } var query = SnExpression.BuildQuery(expression, typeof(T), this.ContextPath, this.ChildrenDefinition, out var elementSelection); if (TracingEnabled) { TraceLog.Append("Expression: ").AppendLine(expression.ToString()); TraceLog.Append("Query: ").AppendLine(query.ToString()); TraceLog.AppendLine("--------------"); } var result = this.ExecuteQuery ? query.Execute(SnQueryContext.CreateDefault()) : null; if (query.CountOnly) { if (this.ExecuteQuery) { count = result.TotalCount; } if (query.ExistenceOnly) { return((TResult)Convert.ChangeType(count > 0, typeof(TResult))); } return((TResult)Convert.ChangeType(count, typeof(TResult))); } if (this.ExecuteQuery) { count = result.TotalCount; } if (count == 0) { if (query.ThrowIfEmpty) { if (elementSelection == "elementat") { // ReSharper disable once NotResolvedInText throw new ArgumentOutOfRangeException("Index was out of range."); } else { throw new InvalidOperationException("Sequence contains no elements."); } } return(default(TResult)); } if (typeof(Node).IsAssignableFrom(typeof(TResult))) { if (ExecuteQuery) { return((TResult)Convert.ChangeType(Node.LoadNode(result.Hits.First()), typeof(TResult))); } return((TResult)Convert.ChangeType(ChildrenDefinition.BaseCollection.First(), typeof(TResult))); } switch (elementSelection) { case "first": return(ExecuteQuery ? (TResult)Convert.ChangeType(Content.Load(result.Hits.FirstOrDefault()), typeof(TResult)) : (TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.FirstOrDefault()), typeof(TResult))); case "last": return(ExecuteQuery ? (TResult)Convert.ChangeType(Content.Load(result.Hits.LastOrDefault()), typeof(TResult)) : (TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.LastOrDefault()), typeof(TResult))); case "single": return(ExecuteQuery ? (TResult)Convert.ChangeType(Content.Load(result.Hits.SingleOrDefault()), typeof(TResult)) : (TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.SingleOrDefault()), typeof(TResult))); case "elementat": var any = ExecuteQuery ? result.Hits.Any() : ChildrenDefinition.BaseCollection.Any(); if (!any) { if (query.ThrowIfEmpty) { // ReSharper disable once NotResolvedInText throw new ArgumentOutOfRangeException("Index was out of range."); } else { return(default(TResult)); } } return(ExecuteQuery ? (TResult)Convert.ChangeType(Content.Load(result.Hits.FirstOrDefault()), typeof(TResult)) : (TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.FirstOrDefault()), typeof(TResult))); default: throw new SnNotSupportedException(); } }
public virtual TResult Execute <TResult>(System.Linq.Expressions.Expression expression) { int count = 0; // in case there is a predefined list of nodes, we do not execute a query (but we still need to build it) if (!this.ExecuteQuery) { count = ChildrenDefinition.BaseCollection.Count(); } var query = SnExpression.BuildQuery(expression, typeof(T), this.ContextPath, this.ChildrenDefinition); if (TracingEnabled) { TraceLog.Append("Expression: ").AppendLine(expression.ToString()); TraceLog.Append("Query: ").AppendLine(query.ToString()); TraceLog.AppendLine("--------------"); } var result = this.ExecuteQuery ? query.Execute() : null; if (query.CountOnly) { if (this.ExecuteQuery) { count = query.TotalCount; } if (query.ExistenceOnly) { return((TResult)Convert.ChangeType(count > 0, typeof(TResult))); } else { return((TResult)Convert.ChangeType(count, typeof(TResult))); } } if (this.ExecuteQuery) { count = result.Count(); } if (count == 0) { if (query.ThrowIfEmpty) { throw new InvalidOperationException("Sequence contains no elements."); } return(default(TResult)); } if (count == 1) { if (typeof(Node).IsAssignableFrom(typeof(TResult))) { if (this.ExecuteQuery) { return((TResult)Convert.ChangeType(Node.LoadNode(result.First().NodeId), typeof(TResult))); } return((TResult)Convert.ChangeType(ChildrenDefinition.BaseCollection.First(), typeof(TResult))); } if (this.ExecuteQuery) { return((TResult)Convert.ChangeType(Content.Load(result.First().NodeId), typeof(TResult))); } return((TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.First()), typeof(TResult))); } throw new NotImplementedException("SnLinq: ContentSet.Execute<TResult>"); }