public override void Execute(Dictionary<string, string> variables) { if (ScriptSettings.DebugMode) logger.Debug("executing sort: " + xmlNode.OuterXml); // get our initial parsed settings from the script string arrayName = parseString(variables, Name); string parsedSortBy = parseString(variables, SortBy); // build a list of the specified array int count = 0; List<WeakTypedObject> list = new List<WeakTypedObject>(); while (variables.ContainsKey(arrayName + "[" + count + "]")) { WeakTypedObject newObj = new WeakTypedObject(arrayName + "[" + count + "]", variables); newObj.SortKey = parsedSortBy; list.Add(newObj); count++; } // sort and rewrite the sorted list to the variables dictionary list.Sort(); count = 0; foreach (WeakTypedObject currObj in list) { variables[arrayName + "[" + count + "]"] = currObj.BaseValue; foreach (KeyValuePair<string, string> currPair in currObj.Members) variables[arrayName + "[" + count + "]" + currPair.Key] = currPair.Value; count++; } }
public int CompareTo(object obj) { if (SortValue == null) { return(0); } if (obj == null || obj.GetType() != typeof(WeakTypedObject)) { return(0); } // grab the other object and assert it is valid WeakTypedObject other = (WeakTypedObject)obj; if (other.SortValue == null) { return(0); } // try assuming the values are numeric try { float thisFloat = float.Parse(SortValue, new CultureInfo("en-US", false)); float otherFloat = float.Parse(other.SortValue, new CultureInfo("en-US", false)); return(thisFloat == otherFloat ? 0 : thisFloat < otherFloat ? -1 : 1); } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) { throw e; } } // otherwise resort to string based sorting return(SortValue.CompareTo(other.SortValue)); }
public override void Execute(Dictionary <string, string> variables) { if (ScriptSettings.DebugMode) { logger.Debug("executing sort: " + xmlNode.OuterXml); } // get our initial parsed settings from the script string arrayName = parseString(variables, Name); string parsedSortBy = parseString(variables, SortBy); // build a list of the specified array int count = 0; List <WeakTypedObject> list = new List <WeakTypedObject>(); while (variables.ContainsKey(arrayName + "[" + count + "]")) { WeakTypedObject newObj = new WeakTypedObject(arrayName + "[" + count + "]", variables); newObj.SortKey = parsedSortBy; list.Add(newObj); count++; } // sort and rewrite the sorted list to the variables dictionary list.Sort(); count = 0; foreach (WeakTypedObject currObj in list) { variables[arrayName + "[" + count + "]"] = currObj.BaseValue; foreach (KeyValuePair <string, string> currPair in currObj.Members) { variables[arrayName + "[" + count + "]" + currPair.Key] = currPair.Value; } count++; } }