private static List<ServiceStarterElement> SortServices(ServiceStarterSection serviceInfo) { List<ServiceStarterElement> retValue = new List<ServiceStarterElement>(); List<RefCount> countList = new List<RefCount>(); foreach (ServiceStarterElement ele in serviceInfo.Services) { if ("true" == ele.Enabled.ToLower()) { RefCount found = countList.FirstOrDefault(c => c.Name == ele.Name); if (null == found) { found = new RefCount() { Name = ele.Name, Count = 0, Element = ele }; countList.Add(found); } else { if (null == found.Element) found.Element = ele; } if (0 != ele.DependenceServices.Count) { foreach (DependenceServiceConfigurationElement dEle in ele.DependenceServices) { RefCount refFound = countList.FirstOrDefault(c => c.Name == dEle.ServiceName); if (null != refFound) { refFound.Count++; } else { refFound = new RefCount() { Name = dEle.ServiceName, Count = 1, Element = null }; countList.Add(refFound); } } } } else { string.Format("位于 {0} 位置的 {1} 服务未配置成可启动", ele.ContentPath, ele.Name).Warn(); } } countList.Sort(new Comparison<RefCount>((left, right) => { return right.Count.CompareTo(left.Count); })); retValue.AddRange((from c in countList select c.Element).ToArray()); return retValue; }
private static List <ServiceStarterElement> SortServices(ServiceStarterSection serviceInfo) { List <ServiceStarterElement> retValue = new List <ServiceStarterElement>(); List <RefCount> countList = new List <RefCount>(); foreach (ServiceStarterElement ele in serviceInfo.Services) { if ("true" == ele.Enabled.ToLower()) { RefCount found = countList.FirstOrDefault(c => c.Name == ele.Name); if (null == found) { found = new RefCount() { Name = ele.Name, Count = 0, Element = ele }; countList.Add(found); } else { if (null == found.Element) { found.Element = ele; } } if (0 != ele.DependenceServices.Count) { foreach (DependenceServiceConfigurationElement dEle in ele.DependenceServices) { RefCount refFound = countList.FirstOrDefault(c => c.Name == dEle.ServiceName); if (null != refFound) { refFound.Count++; } else { refFound = new RefCount() { Name = dEle.ServiceName, Count = 1, Element = null }; countList.Add(refFound); } } } } else { string.Format("位于 {0} 位置的 {1} 服务未配置成可启动", ele.ContentPath, ele.Name).Warn(); } } countList.Sort(new Comparison <RefCount>((left, right) => { return(right.Count.CompareTo(left.Count)); })); retValue.AddRange((from c in countList select c.Element).ToArray()); return(retValue); }