public PropertyCondition(Mobile from, Type type, PropertyInfo[] props, string prop, string oper, string arg, bool logicalNot) { m_From = from; m_LogicalNot = logicalNot; string failReason = ""; m_PropertyInfoChain = Properties.GetPropertyInfoChain(from, type, prop, true, ref failReason); if (m_PropertyInfoChain == null) { throw new Exception(failReason); } /*for ( int i = 0; i < props.Length; ++i ) * { * PropertyInfo check = props[i]; * * if ( !Insensitive.Equals( check.Name, prop ) ) * continue; * * m_Property = check; * break; * } * * if ( m_Property == null ) * throw new Exception( String.Format( "No property with the name ({0}) was found on type ({1}).", prop, type.Name ) ); * * CPA attr = Properties.GetCPA( m_Property ); * * if ( attr == null ) * throw new Exception( String.Format( "No property with the name ({0}) was found on type ({1}).", prop, type.Name ) ); * * if ( from.AccessLevel < attr.ReadLevel ) * throw new Exception( String.Format( "Getting this property ({0}) requires at least {1} access level.", prop, Mobile.GetAccessLevelName( attr.ReadLevel ) ) );*/ string error = Properties.ConstructFromString(m_PropertyInfoChain[m_PropertyInfoChain.Length - 1].PropertyType, null, arg, ref m_Argument); if (error != null) { throw new Exception(error); } switch (oper) { case "=": case "==": case "is": m_Operator = ConditionOperator.Equality; break; case "!=": m_Operator = ConditionOperator.Inequality; break; case ">": m_Operator = ConditionOperator.Greater; break; case "<": m_Operator = ConditionOperator.Lesser; break; case ">=": m_Operator = ConditionOperator.GreaterEqual; break; case "<=": m_Operator = ConditionOperator.LesserEqual; break; case "==~": case "~==": case "=~": case "~=": case "is~": case "~is": m_Operator = ConditionOperator.EqualityInsensitive; break; case "!=~": case "~!=": m_Operator = ConditionOperator.InequalityInsensitive; break; case "starts": m_Operator = ConditionOperator.StartsWith; break; case "starts~": case "~starts": m_Operator = ConditionOperator.StartsWithInsensitive; break; case "ends": m_Operator = ConditionOperator.EndsWith; break; case "ends~": case "~ends": m_Operator = ConditionOperator.EndsWithInsensitive; break; case "contains": m_Operator = ConditionOperator.Contains; break; case "contains~": case "~contains": m_Operator = ConditionOperator.ContainsInsensitive; break; } if (m_Operator != ConditionOperator.Equality && m_Operator != ConditionOperator.Inequality) { if (m_Argument != null && !(m_Argument is IComparable)) { throw new Exception(String.Format("This property ({0}) is not comparable.", prop)); } } }
public override void ExecuteList(CommandEventArgs e, ArrayList list) { if (list.Count == 0) { LogFailure("Nothing was found to use this command on."); return; } try { BaseCommand[] commands = new BaseCommand[m_BatchCommands.Count]; CommandEventArgs[] eventArgs = new CommandEventArgs[m_BatchCommands.Count]; for (int i = 0; i < m_BatchCommands.Count; ++i) { BatchCommand bc = (BatchCommand)m_BatchCommands[i]; string commandString, argString; string[] args; bc.GetDetails(out commandString, out argString, out args); BaseCommand command = (BaseCommand)m_Scope.Commands[commandString]; commands[i] = command; eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args); if (command == null) { e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier: {0}.", commandString); return; } else if (e.Mobile.AccessLevel < command.AccessLevel) { e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString); return; } else if (!command.ValidateArgs(m_Scope, eventArgs[i])) { return; } } for (int i = 0; i < commands.Length; ++i) { BaseCommand command = commands[i]; BatchCommand bc = (BatchCommand)m_BatchCommands[i]; if (list.Count > 20) { CommandLogging.Enabled = false; } ArrayList usedList; if (Utility.InsensitiveCompare(bc.Object, "Current") == 0) { usedList = list; } else { Hashtable propertyChains = new Hashtable(); usedList = new ArrayList(list.Count); for (int j = 0; j < list.Count; ++j) { object obj = list[j]; if (obj == null) { continue; } Type type = obj.GetType(); PropertyInfo[] chain = (PropertyInfo[])propertyChains[type]; string failReason = ""; if (chain == null && !propertyChains.Contains(type)) { propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason); } if (chain == null) { continue; } PropertyInfo endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason); if (endProp == null) { continue; } try { obj = endProp.GetValue(obj, null); if (obj != null) { usedList.Add(obj); } } catch { } } } command.ExecuteList(eventArgs[i], usedList); if (list.Count > 20) { CommandLogging.Enabled = true; } command.Flush(e.Mobile, list.Count > 20); } } catch (Exception ex) { e.Mobile.SendMessage(ex.Message); } }
public PropertyCondition(Mobile from, Type type, PropertyInfo[] props, string prop, string oper, string arg, bool logicalNot) { m_From = from; m_LogicalNot = logicalNot; string failReason = ""; m_PropertyInfoChain = Properties.GetPropertyInfoChain(from, type, prop, PropertyAccess.Read, ref failReason); if (m_PropertyInfoChain == null) { throw new Exception(failReason); } string error = Properties.ConstructFromString(m_PropertyInfoChain[m_PropertyInfoChain.Length - 1].PropertyType, null, arg, ref m_Argument); if (error != null) { throw new Exception(error); } switch (oper) { case "=": case "==": case "is": m_Operator = ConditionOperator.Equality; break; case "!=": m_Operator = ConditionOperator.Inequality; break; case ">": m_Operator = ConditionOperator.Greater; break; case "<": m_Operator = ConditionOperator.Lesser; break; case ">=": m_Operator = ConditionOperator.GreaterEqual; break; case "<=": m_Operator = ConditionOperator.LesserEqual; break; case "==~": case "~==": case "=~": case "~=": case "is~": case "~is": m_Operator = ConditionOperator.EqualityInsensitive; break; case "!=~": case "~!=": m_Operator = ConditionOperator.InequalityInsensitive; break; case "starts": m_Operator = ConditionOperator.StartsWith; break; case "starts~": case "~starts": m_Operator = ConditionOperator.StartsWithInsensitive; break; case "ends": m_Operator = ConditionOperator.EndsWith; break; case "ends~": case "~ends": m_Operator = ConditionOperator.EndsWithInsensitive; break; case "contains": m_Operator = ConditionOperator.Contains; break; case "contains~": case "~contains": m_Operator = ConditionOperator.ContainsInsensitive; break; } if (m_Operator != ConditionOperator.Equality && m_Operator != ConditionOperator.Inequality) { if (m_Argument != null && !(m_Argument is IComparable)) { throw new Exception(String.Format("This property ({0}) is not comparable.", prop)); } } }