/// <summary> /// Creates an instance of <see cref="AlarmFilter"/> with /// a GUID (Alarm.ItemGuid) used for filtering. /// </summary> /// <param name="partition">Name of the Partition to filter on</param> /// <param name="alarmGuid">GUID (Alarm.ItemGuid) of the Alarm to be returned</param> /// <param name="alarmSiteName">Name of the Site to filter on</param> /// <param name="alarmTypeName">Name of the Alarm Type to filter on</param> /// <param name="itemName">Name of the Item associated with the Alarm(s) to filter on</param> /// <param name="operatorName">Name of the Operator who updated the Alarm(s) to filter on</param> public AlarmFilter(string partition, string alarmGuid, string alarmSiteName, string alarmTypeName, string itemName, string operatorName) { if (partition != null) Partition = new PartitionFilter {CV = partition}; if (alarmGuid != null) AlarmGuid = new AlarmGuidFilter{CV=alarmGuid}; if (alarmSiteName != null) AlarmSiteName = new AlarmSiteNameFilter {CV = alarmSiteName}; if (alarmTypeName != null) AlarmTypeName = new AlarmTypeNameFilter {CV = alarmTypeName}; if (itemName != null) ItemName = new ItemNameFilter {CV = itemName}; if (operatorName != null) OperatorName = new OperatorNameFilter {CV = operatorName}; }
/// <summary> /// Sets the attribute filter. /// </summary> /// <param name="attributeIds">The attribute ids.</param> /// <param name="operators">The operators.</param> /// <param name="values">The values.</param> /// <returns></returns> public int[] SetAttributeFilter(uint[] attributeIds, int[] operators, object[] values) { int[] errors = new int[attributeIds.Length]; for (int ii = 0; ii < attributeIds.Length; ii++) { // check for supported attribute. if (!m_server.IsSupportedAttribute(attributeIds[ii])) { errors[ii] = ResultIds.E_UNKNOWNATTRID; continue; } // only support filters on display name. if (attributeIds[ii] != OpcRcw.Hda.Constants.OPCHDA_ITEMID) { errors[ii] = ResultIds.W_NOFILTER; continue; } // must be a string. if (!(values[ii] is string)) { errors[ii] = ResultIds.E_INVALIDDATATYPE; continue; } // create the filter. ItemNameFilter filter = new ItemNameFilter(); filter.Operator = operators[ii]; filter.Value = (string)values[ii]; if (m_filters == null) { m_filters = new List <ItemNameFilter>(); } m_filters.Add(filter); errors[ii] = ResultIds.S_OK; } return(errors); }
/// <summary> /// Return true if the name natches the filter. /// </summary> /// <param name="name">The name.</param> /// <param name="filter">The filter.</param> /// <returns></returns> private bool MatchFilter(string name, ItemNameFilter filter) { if (String.IsNullOrEmpty(name)) { return(false); } switch ((OPCHDA_OPERATORCODES)filter.Operator) { case OPCHDA_OPERATORCODES.OPCHDA_EQUAL: { return(name == filter.Value); } case OPCHDA_OPERATORCODES.OPCHDA_GREATER: { return(name.CompareTo(filter.Value) > 0); } case OPCHDA_OPERATORCODES.OPCHDA_GREATEREQUAL: { return(name.CompareTo(filter.Value) >= 0); } case OPCHDA_OPERATORCODES.OPCHDA_LESS: { return(name.CompareTo(filter.Value) < 0); } case OPCHDA_OPERATORCODES.OPCHDA_LESSEQUAL: { return(name.CompareTo(filter.Value) <= 0); } case OPCHDA_OPERATORCODES.OPCHDA_NOTEQUAL: { return(name.CompareTo(filter.Value) != 0); } } return(false); }
/// <summary> /// Return true if the name natches the filter. /// </summary> /// <param name="name">The name.</param> /// <param name="filter">The filter.</param> /// <returns></returns> private bool MatchFilter(string name, ItemNameFilter filter) { if (String.IsNullOrEmpty(name)) { return false; } switch ((OPCHDA_OPERATORCODES)filter.Operator) { case OPCHDA_OPERATORCODES.OPCHDA_EQUAL: { return name == filter.Value; } case OPCHDA_OPERATORCODES.OPCHDA_GREATER: { return name.CompareTo(filter.Value) > 0; } case OPCHDA_OPERATORCODES.OPCHDA_GREATEREQUAL: { return name.CompareTo(filter.Value) >= 0; } case OPCHDA_OPERATORCODES.OPCHDA_LESS: { return name.CompareTo(filter.Value) < 0; } case OPCHDA_OPERATORCODES.OPCHDA_LESSEQUAL: { return name.CompareTo(filter.Value) <= 0; } case OPCHDA_OPERATORCODES.OPCHDA_NOTEQUAL: { return name.CompareTo(filter.Value) != 0; } } return false; }
/// <summary> /// Sets the attribute filter. /// </summary> /// <param name="attributeIds">The attribute ids.</param> /// <param name="operators">The operators.</param> /// <param name="values">The values.</param> /// <returns></returns> public int[] SetAttributeFilter(uint[] attributeIds, int[] operators, object[] values) { int[] errors = new int[attributeIds.Length]; for (int ii = 0; ii < attributeIds.Length; ii++) { // check for supported attribute. if (!m_server.IsSupportedAttribute(attributeIds[ii])) { errors[ii] = ResultIds.E_UNKNOWNATTRID; continue; } // only support filters on display name. if (attributeIds[ii] != OpcRcw.Hda.Constants.OPCHDA_ITEMID) { errors[ii] = ResultIds.W_NOFILTER; continue; } // must be a string. if (!(values[ii] is string)) { errors[ii] = ResultIds.E_INVALIDDATATYPE; continue; } // create the filter. ItemNameFilter filter = new ItemNameFilter(); filter.Operator = operators[ii]; filter.Value = (string)values[ii]; if (m_filters == null) { m_filters = new List<ItemNameFilter>(); } m_filters.Add(filter); errors[ii] = ResultIds.S_OK; } return errors; }