PageRenderTime 23ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms 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
 18using System;
 19using System.Collections.Generic;
 20using System.Linq;
 21using System.Text;
 22using Modularity.AcceptanceTests.TestInfrastructure;
 23
 24namespace Modularity.AcceptanceTests.Helpers
 25{
 26    public static class HelperExtensions
 27    {
 28        private static List<Module> sortedList = new List<Module>();
 29
 30        public static List<Module> SortModulesInLoadOrder(this List<Module> lm)
 31        {
 32            foreach (Module m in lm)
 33            {
 34                if (m.Dependencies.Count == 0 && !sortedList.Contains(m))
 35                {
 36                    sortedList.Add(m);
 37                }
 38                else
 39                {
 40                    foreach (string dependency in m.Dependencies)
 41                    {
 42                        lm.SortModulesInLoadOrder(dependency);
 43                    }
 44
 45                    if (!sortedList.Contains(m))
 46                    {
 47                        sortedList.Add(m);
 48                    }
 49                }
 50            }
 51
 52            return sortedList;
 53        }
 54
 55        public static List<Module> SortModulesInLoadOrder(this List<Module> lm, string moduleName)
 56        {
 57            Module mod;
 58
 59            if (null != moduleName && moduleName.Length > 0)
 60            {
 61                mod = lm.Find(l => l.ModuleName.Equals(moduleName));
 62                if (mod.Dependencies.Count == 0 && !sortedList.Contains(mod))
 63                {
 64                    sortedList.Add(mod);
 65                }
 66                else
 67                {
 68                    foreach (string dependency in mod.Dependencies)
 69                    {
 70                        lm.SortModulesInLoadOrder(dependency);
 71                    }
 72
 73                    if (!sortedList.Contains(mod))
 74                    {
 75                        sortedList.Add(mod);
 76                    }
 77                }
 78            }
 79            else
 80            {
 81                foreach (Module m in lm)
 82                {
 83                    if (m.Dependencies.Count == 0 && !sortedList.Contains(m))
 84                    {
 85                        sortedList.Add(m);
 86                    }
 87                    else
 88                    {
 89                        foreach (string dependency in m.Dependencies)
 90                        {
 91                            lm.SortModulesInLoadOrder(dependency);
 92                        }
 93
 94                        if (!sortedList.Contains(m))
 95                        {
 96                            sortedList.Add(m);
 97                        }
 98                    }
 99                }
100            }
101
102            return sortedList;
103        }
104    }
105}