/* T O S T R I N G */ /*---------------------------------------------------------------------------- * %%Function: String * %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.String * %%Contact: rlittle * * Return the string (either static or fetched from datasource) * ----------------------------------------------------------------------------*/ public string String(ILogFilterItem ilf) { object o = m_ds == DataSource.Static ? m_oValue : ilf.OGetValue(m_vt, m_ds, m_lc); if (m_vt != ValueType.String) { throw new Exception("type mismatch"); } return((string)o); }
/* D T T M */ /*---------------------------------------------------------------------------- * %%Function: Dttm * %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.Dttm * %%Contact: rlittle * * Return the DateTime (either static, or fetched from datasource) * ----------------------------------------------------------------------------*/ public DateTime Dttm(ILogFilterItem ilf) { object o = m_ds == DataSource.Static ? m_oValue : ilf.OGetValue(m_vt, m_ds, m_lc); if (m_vt != ValueType.DateTime) { throw new Exception("type mismatch"); } return((DateTime)o); }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- * %%Function: FEvaluate * %%Qualified: AzLog.AzLogFilter.FEvaluate * %%Contact: rlittle * * Evaluate the item against the filter, return true if it matches * ----------------------------------------------------------------------------*/ public bool FEvaluate(ILogFilterItem ilf) { if (m_plazlfo == null || m_plazlfo.Count == 0) { return(true); } // evaluate the list using a stack... List <bool> plfStack = new List <bool>(); for (int i = 0; i < m_plazlfo.Count; i++) { AzLogFilterOperation azlfo = m_plazlfo[i]; switch (azlfo.Op) { case AzLogFilterOperation.OperationType.Value: plfStack.Add(azlfo.Condition.FEvaluate(ilf)); break; case AzLogFilterOperation.OperationType.And: { bool f1 = plfStack[plfStack.Count - 1]; bool f2 = plfStack[plfStack.Count - 2]; plfStack.RemoveRange(plfStack.Count - 2, 2); plfStack.Add(f1 && f2); break; } case AzLogFilterOperation.OperationType.Or: { bool f1 = plfStack[plfStack.Count - 1]; bool f2 = plfStack[plfStack.Count - 2]; plfStack.RemoveRange(plfStack.Count - 2, 2); plfStack.Add(f1 || f2); break; } } } if (plfStack.Count > 1) { throw new Exception("expression did not reduce"); } return(plfStack[0]); }
/* T O S T R I N G */ /*---------------------------------------------------------------------------- %%Function: String %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.String %%Contact: rlittle Return the string (either static or fetched from datasource) ----------------------------------------------------------------------------*/ public string String(ILogFilterItem ilf) { object o = m_ds == DataSource.Static ? m_oValue : ilf.OGetValue(m_vt, m_ds, m_lc); if (m_vt != ValueType.String) throw new Exception("type mismatch"); return (string) o; }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- %%Function: FEvaluate %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.FEvaluate %%Contact: rlittle ----------------------------------------------------------------------------*/ public bool FEvaluate(AzLogFilterCondition.CmpOp cmpOp, AzLogFilterValue azlfvRHS, ILogFilterItem ilf) { int nCmp; bool fNoCase; cmpOp = CmpOpGenericFromCmpOp(cmpOp, out fNoCase); if (m_vt != azlfvRHS.m_vt) throw new Exception("cannot evaluate dissimilar value types"); if (m_vt == ValueType.String) nCmp = System.String.Compare(this.String(ilf), azlfvRHS.String(ilf), fNoCase); else if (m_vt == ValueType.DateTime) nCmp = DateTime.Compare(this.Dttm(ilf), azlfvRHS.Dttm(ilf)); else nCmp = 0; switch (cmpOp) { case AzLogFilterCondition.CmpOp.Eq: return nCmp == 0; case AzLogFilterCondition.CmpOp.SEq: return nCmp == 0; case AzLogFilterCondition.CmpOp.Ne: return nCmp != 0; case AzLogFilterCondition.CmpOp.SNe: return nCmp == 0; case AzLogFilterCondition.CmpOp.Gt: return nCmp > 0; case AzLogFilterCondition.CmpOp.Gte: return nCmp >= 0; case AzLogFilterCondition.CmpOp.Lt: return nCmp < 0; case AzLogFilterCondition.CmpOp.Lte: return nCmp <= 0; } return false; }
/* D T T M */ /*---------------------------------------------------------------------------- %%Function: Dttm %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.Dttm %%Contact: rlittle Return the DateTime (either static, or fetched from datasource) ----------------------------------------------------------------------------*/ public DateTime Dttm(ILogFilterItem ilf) { object o = m_ds == DataSource.Static ? m_oValue : ilf.OGetValue(m_vt, m_ds, m_lc); if (m_vt != ValueType.DateTime) throw new Exception("type mismatch"); return (DateTime) o; }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- %%Function: FEvaluate %%Qualified: AzLog.AzLogFilter.AzLogFilterCondition.FEvaluate %%Contact: rlittle Actually evaluate this condition, using the given interface to the item to bind datasources ----------------------------------------------------------------------------*/ public bool FEvaluate(ILogFilterItem ilf) { return m_azlfvLHS.FEvaluate(m_cmpop, m_azlfvRHS, ilf); }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- %%Function: FEvaluate %%Qualified: AzLog.AzLogFilter.FEvaluate %%Contact: rlittle Evaluate the item against the filter, return true if it matches ----------------------------------------------------------------------------*/ public bool FEvaluate(ILogFilterItem ilf) { // evaluate the list using a stack... List<bool> plfStack = new List<bool>(); for (int i = 0; i < m_plazlfo.Count; i++) { AzLogFilterOperation azlfo = m_plazlfo[i]; switch (azlfo.Op) { case AzLogFilterOperation.OperationType.Value: plfStack.Add(azlfo.Condition.FEvaluate(ilf)); break; case AzLogFilterOperation.OperationType.And: { bool f1 = plfStack[plfStack.Count - 1]; bool f2 = plfStack[plfStack.Count - 2]; plfStack.RemoveRange(plfStack.Count - 2, 2); plfStack.Add(f1 && f2); break; } case AzLogFilterOperation.OperationType.Or: { bool f1 = plfStack[plfStack.Count - 1]; bool f2 = plfStack[plfStack.Count - 2]; plfStack.RemoveRange(plfStack.Count - 2, 2); plfStack.Add(f1 || f2); break; } } } if (plfStack.Count > 1) throw new Exception("expression did not reduce"); return plfStack[0]; }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- * %%Function: FEvaluate * %%Qualified: AzLog.AzLogFilter.AzLogFilterCondition.FEvaluate * %%Contact: rlittle * * Actually evaluate this condition, using the given interface to the item * to bind datasources * ----------------------------------------------------------------------------*/ public bool FEvaluate(ILogFilterItem ilf) { return(m_azlfvLHS.FEvaluate(m_cmpop, m_azlfvRHS, ilf)); }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- * %%Function: FEvaluate * %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.FEvaluate * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public bool FEvaluate(AzLogFilterCondition.CmpOp cmpOp, AzLogFilterValue azlfvRHS, ILogFilterItem ilf) { int nCmp; bool fNoCase; cmpOp = CmpOpGenericFromCmpOp(cmpOp, out fNoCase); if (m_vt != azlfvRHS.m_vt) { throw new Exception("cannot evaluate dissimilar value types"); } if (m_vt == ValueType.String) { nCmp = System.String.Compare(this.String(ilf), azlfvRHS.String(ilf), fNoCase); } else if (m_vt == ValueType.DateTime) { nCmp = DateTime.Compare(this.Dttm(ilf), azlfvRHS.Dttm(ilf)); } else { nCmp = 0; } switch (cmpOp) { case AzLogFilterCondition.CmpOp.Eq: return(nCmp == 0); case AzLogFilterCondition.CmpOp.SEq: return(nCmp == 0); case AzLogFilterCondition.CmpOp.Ne: return(nCmp != 0); case AzLogFilterCondition.CmpOp.SNe: return(nCmp == 0); case AzLogFilterCondition.CmpOp.Gt: return(nCmp > 0); case AzLogFilterCondition.CmpOp.Gte: return(nCmp >= 0); case AzLogFilterCondition.CmpOp.Lt: return(nCmp < 0); case AzLogFilterCondition.CmpOp.Lte: return(nCmp <= 0); } return(false); }