public void Sort() { logger.Info("Entered"); try { if (SortingFields.Count == 0) { logger.Warn("No sorting field is found to sort data, please set a sorting field first"); throw new InvalidOperationException("No sorting field is found to sort data, please set a sorting field first"); } SortingField rootSF = SortingFields[0];//xpath is null form grid var endElement = workflowFile.RootNode.Descendants(rootSF.GetLeafName()).First(); var parentElement = endElement.Parent; var grandParentElement = parentElement.Parent; if (grandParentElement == null) { TwoLevelSort(rootSF); } else { MultiLevelSort(rootSF, grandParentElement, parentElement); } } catch (Exception ex) { logger.Error(ex, "XML Sorting Error, DataFile {0}", workflowFile.FilePath); throw ex; } logger.Info("Leaving"); }
/// <summary> /// Called by multi level child nodes for second level ordering /// </summary> /// <param name="orderNodeTree"></param> /// <param name="sf"></param> /// <returns></returns> public IOrderedEnumerable <XElement> Process(IOrderedEnumerable <XElement> orderNodeTree, SortingField sf) { string elementName = sf.GetLeafName(); if (sf.SortingType == SortingType.Ascending) { orderNodeTree = orderNodeTree.ThenBy(m => m.Element(elementName).Value, sf.GetComparer()); } else { orderNodeTree = orderNodeTree.ThenByDescending(m => m.Element(elementName).Value, sf.GetComparer()); } return(orderNodeTree); }