示例#1
0
        private static IEnumerable <SiteArea> ResolveFlattenedDependentSiteAreas(SiteArea siteArea)
        {
            // this aggregrates the dependencies etc into one list
            var _aggregrator = (Action <List <SiteArea>, SiteArea>)null;

            _aggregrator = new Action <List <SiteArea>, SiteArea>((l, a) =>
            {
                if (!l.Contains(a))
                {
                    l.Add(a);
                }
                if (!a.HasDependencies)
                {
                    return;
                }
                foreach (var _dependnecy in a.AreaDependencies)
                {
                    var _area = SiteMap.Areas[_dependnecy.Key];
                    if (!l.Contains(_area))
                    {
                        _aggregrator(l, _area);
                    }
                }
            });

            // we aggregrate all the child areas, recursively
            var _areas = new List <SiteArea>();

            _aggregrator(_areas, siteArea);
            return(_areas);
        }
示例#2
0
        private static void LoadSiteArea(SiteArea siteArea, Action <bool> loadCallback)
        {
            var _dependentAreas        = ResolveFlattenedDependentSiteAreas(siteArea);
            var _orderedDependnetAreas = new Stack <SiteArea>(TopologicallyOrderDependentSiteAreas(_dependentAreas));
            var _subscribeHandler      = (Action <LoadedResourceInfo>)null;

            _subscribeHandler = new Action <LoadedResourceInfo>((r) =>
            {
                if (r.IsLoaded)
                {
                    if (_orderedDependnetAreas.Count == 0)
                    {
                        siteArea.InternalIsInitialized = true;
                        if (loadCallback != null)
                        {
                            loadCallback(true);
                        }
                    }
                    else
                    {
                        var _nextArea = _orderedDependnetAreas.Pop();
                        ObservableExtensions.Subscribe(RemoteResourceLoader.LoadResource(new Uri(_nextArea.RemoteUrl, UriKind.RelativeOrAbsolute)), _subscribeHandler);
                    }
                }
                else
                {
                    if (loadCallback != null)
                    {
                        loadCallback(false);
                    }
                    loadCallback = null;
                }
            });

            // and we start the chain
            var _area = _orderedDependnetAreas.Pop();

            ObservableExtensions.Subscribe(RemoteResourceLoader.LoadResource(new Uri(_area.RemoteUrl, UriKind.RelativeOrAbsolute)), _subscribeHandler);
        }