static IEnumerable<CompareSet> GetAllNuGetVersions(string package, ICompareStrategy compareStrategy) { var browser = new NuGetBrowser(new List<string> { "https://www.nuget.org/api/v2" }); Console.Out.Write("Loading version history for {0}", package); var allVersions = browser.GetAllVersions(package); Console.Out.WriteLine(" - done"); var semverCompliantVersions = allVersions.Where(v => v.Version.Major > 0) .ToList(); return compareStrategy.GetVersionsToCompare(semverCompliantVersions) .Select(pair => CreateCompareSet(package, pair)) .ToList(); }
public static T[] SortByStrategy <T>(this T[] list, ICompareStrategy <T> compare) { if (list == null || compare == null) { throw new ArgumentException("list can't be null"); } for (int i = 1; i < list.Count(); i++) { for (int j = i; j < list.Count(); j++) { //自訂一個規則介面,比較方式由外部提供 由外部注入!! if (compare.Compare(list[i - 1], list[j]) > 0) { Swap(list, j, i); } } } return(list); }
static IEnumerable <CompareSet> GetAllNuGetVersions(string package, ICompareStrategy compareStrategy) { var browser = new NuGetBrowser(new List <string> { "https://www.nuget.org/api/v2" }); Console.Out.Write("Loading version history for {0}", package); var allVersions = browser.GetAllVersions(package); Console.Out.WriteLine(" - done"); var semverCompliantVersions = allVersions.Where(v => v.Version.Major > 0) .ToList(); return(compareStrategy.GetVersionsToCompare(semverCompliantVersions) .Select(pair => CreateCompareSet(package, pair)) .ToList()); }
public static IEnumerable <T> SortBy <T>(this T[] list, ICompareStrategy <T> compare) { if (list == null || compare == null) { throw new ArgumentException("list can't be null"); } for (int i = 1; i < list.Count(); i++) { for (int j = i; j < list.Count(); j++) { if (compare.Compare(list[i - 1], list[j]) > 0) { T temp = list[j]; list[j] = list[i - 1]; list[i - 1] = temp; } } } return(list); }
public DefaultStrategy(ICompareStrategy compareStrategy, IWriter writer, string parent) { _compareStrategy = compareStrategy; _writer = writer; _parent = parent; }
public void SetStrategy(ICompareStrategy strategy) { this.strategy = strategy; }
public ContextCompare(ICompareStrategy strategy) { this.strategy = strategy; }
private static void applyVisitors(NodesVisitor visitor, XmlNodeList nodes1, XmlNodeList nodes2, ICompareStrategy compareStrategy) { ArrayList leftNodes = new ArrayList(); ArrayList leftKeys = new ArrayList(); ArrayList rightNodes = new ArrayList(); ArrayList rightKeys = new ArrayList(); foreach (XmlNode node in nodes1) { string key = compareStrategy.GetSortValue(node); leftNodes.Add(node); leftKeys.Add(key); } foreach (XmlNode node in nodes2) { string key = compareStrategy.GetSortValue(node); rightNodes.Add(node); rightKeys.Add(key); } int idxLeft = 0; int idxRight = 0; visitor.Initialize(); while (idxLeft < leftKeys.Count || idxRight < rightKeys.Count) { string leftKey, rightKey; XmlNode leftNode = null, rightNode = null; if (idxLeft < leftKeys.Count) { if (idxRight < rightKeys.Count) { leftKey = (string)leftKeys[idxLeft]; leftNode = (XmlNode)leftNodes[idxLeft]; rightKey = (string)rightKeys[idxRight]; rightNode = (XmlNode)rightNodes[idxRight]; if (leftKey.CompareTo(rightKey) < 0) { rightKey = ""; rightNode = null; ++idxLeft; } else if (leftKey.CompareTo(rightKey) > 0) { leftKey = ""; leftNode = null; ++idxRight; } else { ++idxLeft; ++idxRight; } } else { leftKey = (string)leftKeys[idxLeft]; leftNode = (XmlNode)leftNodes[idxLeft]; rightKey = ""; rightNode = null; ++idxLeft; } } else { leftKey = ""; leftNode = null; rightKey = (string)rightKeys[idxRight]; rightNode = (XmlNode)rightNodes[idxRight]; ++idxRight; } visitor.visitNodes(leftNode, leftKey, rightNode, rightKey); } visitor.Uninitialize(); }