private void SortAdapters()
        {
            List <ProfilingTypeFacade> sortedItems = new List <ProfilingTypeFacade>();

            do
            {
                if (_adapters.Count == 0)
                {
                    break;
                }
                int lastIndex            = _adapters.Count - 1;
                ProfilingTypeFacade item = _adapters[lastIndex]; // Take last
                _adapters.RemoveAt(lastIndex);
                if (CanBeInitialized(item, sortedItems))
                {
                    sortedItems.Add(item);
                }
                else
                {
                    _adapters.Insert(0, item);
                }
            }while (true);
            _adapters.Clear();
            _adapters.AddRange(sortedItems);
        }
 private void Initialize(ProfilingTypeSettingsCollection profilingTypesSettings)
 {
     foreach (IProfilingType profilingType in _profilingTypes)
     {
         ProfilingTypeSettings settings = profilingTypesSettings[profilingType.Definition.Uid];
         if (settings != null)
         {
             ProfilingTypeFacade facade = new ProfilingTypeFacade(profilingType, settings);
             _adapters.Add(facade);
         }
     }
     SortAdapters();
 }
        private bool CanBeInitialized(ProfilingTypeFacade item, List <ProfilingTypeFacade> sortedItems)
        {
            DependencyDefinitionCollection dependencies = item.Definition.Dependencies;

            //Item doesn't have dependencies
            if (dependencies.Count == 0)
            {
                return(true);
            }
            foreach (DependencyDefinition dependency in dependencies)
            {
                //Some of the dependencies are still not in the list of sorted items - we cannot initialize current ProfilingType
                if (!ContainsItem(sortedItems, dependency))
                {
                    return(false);
                }
            }
            return(true);
        }