private static bool IsDatabaseModified(EcasCondition c, EcasContext ctx) { PwDatabase pd = null; uint uSel = EcasUtil.GetParamUInt(c.Parameters, 0, 0); if (uSel == 0) { pd = Program.MainForm.ActiveDatabase; } else if (uSel == 1) { pd = ctx.Properties.Get <PwDatabase>(EcasProperty.Database); } else { Debug.Assert(false); } if ((pd == null) || !pd.IsOpen) { return(false); } return(pd.Modified); }
private static bool IsMatchEnvironmentVar(EcasCondition c, EcasContext ctx) { string strName = EcasUtil.GetParamString(c.Parameters, 0, true); uint uCompareType = EcasUtil.GetParamEnum(c.Parameters, 1, EcasUtil.StdStringCompareEquals, EcasUtil.StdStringCompare); string strValue = EcasUtil.GetParamString(c.Parameters, 2, true); if (string.IsNullOrEmpty(strName) || (strValue == null)) { return(false); } try { string strVar = Environment.GetEnvironmentVariable(strName); if (strVar == null) { return(false); } return(EcasUtil.CompareStrings(strVar, strValue, uCompareType)); } catch (Exception) { Debug.Assert(false); } return(false); }
private static bool IsHostReachable(EcasCondition c, EcasContext ctx) { string strHost = EcasUtil.GetParamString(c.Parameters, 0, true); if (string.IsNullOrEmpty(strHost)) { return(true); } int[] vTimeOuts = { 250, 1250 }; const string strBuffer = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] pbBuffer = Encoding.ASCII.GetBytes(strBuffer); try { Ping ping = new Ping(); // We have sufficient privileges? PingOptions options = new PingOptions(64, true); foreach (int nTimeOut in vTimeOuts) { PingReply reply = ping.Send(strHost, nTimeOut, pbBuffer, options); if (reply.Status == IPStatus.Success) { return(true); } } return(false); } catch (Exception) { } return(false); }
private static bool IsDatabaseModified(EcasCondition c, EcasContext ctx) { PwDatabase pd = Program.MainForm.ActiveDatabase; if ((pd == null) || !pd.IsOpen) { return(false); } return(pd.Modified); }
private static bool IsMatchString(EcasCondition c, EcasContext ctx) { string str = EcasUtil.GetParamString(c.Parameters, 0, true); uint uCompareType = EcasUtil.GetParamEnum(c.Parameters, 1, EcasUtil.StdStringCompareEquals, EcasUtil.StdStringCompare); string strValue = EcasUtil.GetParamString(c.Parameters, 2, true); if ((str == null) || (strValue == null)) { return(false); } return(EcasUtil.CompareStrings(str, strValue, uCompareType)); }
private static bool IsMatchFile(EcasCondition c, EcasContext ctx) { string strFile = EcasUtil.GetParamString(c.Parameters, 0, true); if (string.IsNullOrEmpty(strFile)) { return(true); } try { return(File.Exists(strFile)); } catch (Exception) { } return(false); }
public bool EvaluateCondition(EcasCondition c, EcasContext ctx) { if(c == null) throw new ArgumentNullException("c"); foreach(EcasConditionProvider p in m_vConditionProviders) { if(p.IsSupported(c.Type)) { bool bResult = p.Evaluate(c, ctx); return (c.Negate ? !bResult : bResult); } } throw new Exception(KPRes.TriggerConditionTypeUnknown + " " + KPRes.TypeUnknownHint + MessageService.NewParagraph + c.TypeString); }
public bool Evaluate(EcasCondition c, EcasContext ctx) { if (c == null) { throw new ArgumentNullException("c"); } foreach (EcasConditionType t in m_conditions) { if (t.Type.Equals(c.Type)) { return(t.EvaluateMethod(c, ctx)); } } throw new NotSupportedException(); }
private static bool IsMatchFileExists(EcasCondition c, EcasContext ctx) { string strFile = EcasUtil.GetParamString(c.Parameters, 0, true); if (string.IsNullOrEmpty(strFile)) { return(true); } try { // return File.Exists(strFile); IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile); return(IOConnection.FileExists(ioc)); } catch (Exception) { } return(false); }
private static bool EcasConditionEvaluateTrue(EcasCondition c, EcasContext ctx) { return(true); }
public static string ParametersToString(IEcasObject ecasObj, EcasParameter[] vParamInfo) { if (ecasObj == null) { throw new ArgumentNullException("ecasObj"); } if (ecasObj.Parameters == null) { throw new ArgumentException(); } bool bParamInfoValid = true; if ((vParamInfo == null) || (ecasObj.Parameters.Count > vParamInfo.Length)) { Debug.Assert(false); bParamInfoValid = false; } StringBuilder sb = new StringBuilder(); EcasCondition eCond = (ecasObj as EcasCondition); if (eCond != null) { if (eCond.Negate) { sb.Append(KPRes.Not); } } for (int i = 0; i < ecasObj.Parameters.Count; ++i) { string strParam = ecasObj.Parameters[i]; string strAppend; if (bParamInfoValid) { EcasValueType t = vParamInfo[i].Type; if (t == EcasValueType.String) { strAppend = strParam; } else if (t == EcasValueType.Bool) { strAppend = (StrUtil.StringToBool(strParam) ? KPRes.Yes : KPRes.No); } else if (t == EcasValueType.EnumStrings) { uint uEnumID; if (uint.TryParse(strParam, out uEnumID) == false) { Debug.Assert(false); } EcasEnum ee = vParamInfo[i].EnumValues; if (ee != null) { strAppend = ee.GetItemString(uEnumID, string.Empty); } else { Debug.Assert(false); strAppend = strParam; } } else if (t == EcasValueType.Int64) { strAppend = FilterTypeI64(strParam); } else if (t == EcasValueType.UInt64) { strAppend = FilterTypeU64(strParam); } else { Debug.Assert(false); strAppend = strParam; } } else { strAppend = strParam; } if (string.IsNullOrEmpty(strAppend)) { continue; } string strAppTrimmed = strAppend.Trim(); if (strAppTrimmed.Length == 0) { continue; } if (sb.Length > 0) { sb.Append(", "); } sb.Append(strAppTrimmed); } return(sb.ToString()); }