PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/Modularity/Modularity.Tests.AcceptanceTests/Helpers/HelperExtensions.cs

#
C# | 105 lines | 79 code | 10 blank | 16 comment | 15 complexity | 76d7d69ca4e4f331b78ac66399cabf55 MD5 | raw file
  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  4. //===============================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===============================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===============================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using Modularity.AcceptanceTests.TestInfrastructure;
  22. namespace Modularity.AcceptanceTests.Helpers
  23. {
  24. public static class HelperExtensions
  25. {
  26. private static List<Module> sortedList = new List<Module>();
  27. public static List<Module> SortModulesInLoadOrder(this List<Module> lm)
  28. {
  29. foreach (Module m in lm)
  30. {
  31. if (m.Dependencies.Count == 0 && !sortedList.Contains(m))
  32. {
  33. sortedList.Add(m);
  34. }
  35. else
  36. {
  37. foreach (string dependency in m.Dependencies)
  38. {
  39. lm.SortModulesInLoadOrder(dependency);
  40. }
  41. if (!sortedList.Contains(m))
  42. {
  43. sortedList.Add(m);
  44. }
  45. }
  46. }
  47. return sortedList;
  48. }
  49. public static List<Module> SortModulesInLoadOrder(this List<Module> lm, string moduleName)
  50. {
  51. Module mod;
  52. if (null != moduleName && moduleName.Length > 0)
  53. {
  54. mod = lm.Find(l => l.ModuleName.Equals(moduleName));
  55. if (mod.Dependencies.Count == 0 && !sortedList.Contains(mod))
  56. {
  57. sortedList.Add(mod);
  58. }
  59. else
  60. {
  61. foreach (string dependency in mod.Dependencies)
  62. {
  63. lm.SortModulesInLoadOrder(dependency);
  64. }
  65. if (!sortedList.Contains(mod))
  66. {
  67. sortedList.Add(mod);
  68. }
  69. }
  70. }
  71. else
  72. {
  73. foreach (Module m in lm)
  74. {
  75. if (m.Dependencies.Count == 0 && !sortedList.Contains(m))
  76. {
  77. sortedList.Add(m);
  78. }
  79. else
  80. {
  81. foreach (string dependency in m.Dependencies)
  82. {
  83. lm.SortModulesInLoadOrder(dependency);
  84. }
  85. if (!sortedList.Contains(m))
  86. {
  87. sortedList.Add(m);
  88. }
  89. }
  90. }
  91. }
  92. return sortedList;
  93. }
  94. }
  95. }