Ejemplo n.º 1
0
        private ResourceRequiredContext[] DoGetRequiredResources(string resourceType)
        {
            if (_builtResources.TryGetValue(resourceType, out var requiredResources) && requiredResources != null)
            {
                return(requiredResources);
            }

            var allResources = new OrderedDictionary();

            foreach (var settings in ResolveRequiredResources(resourceType))
            {
                var resource = FindResource(settings);
                if (resource == null)
                {
                    throw new InvalidOperationException($"Could not find a resource of type '{settings.Type}' named '{settings.Name}' with version '{settings.Version ?? "any"}.");
                }
                ExpandDependencies(resource, settings, allResources);
            }

            requiredResources = new ResourceRequiredContext[allResources.Count];
            var i = 0;

            foreach (DictionaryEntry entry in allResources)
            {
                requiredResources[i++] = new ResourceRequiredContext
                {
                    Resource            = (ResourceDefinition)entry.Key,
                    Settings            = (RequireSettings)entry.Value,
                    FileVersionProvider = _fileVersionProvider
                };
            }

            _builtResources[resourceType] = requiredResources;
            return(requiredResources);
        }
Ejemplo n.º 2
0
        private ResourceRequiredContext[] DoGetRequiredResources(string resourceType)
        {
            if (_builtResources.TryGetValue(resourceType, out var requiredResources) && requiredResources != null)
            {
                return(requiredResources);
            }

            var allResources = new ResourceDictionary();

            foreach (var settings in ResolveRequiredResources(resourceType))
            {
                var resource = FindResource(settings);
                if (resource == null)
                {
                    throw new InvalidOperationException($"Could not find a resource of type '{settings.Type}' named '{settings.Name}' with version '{settings.Version ?? "any"}'.");
                }

                ExpandDependencies(resource, settings, allResources);
            }

            requiredResources = new ResourceRequiredContext[allResources.Count];
            int i, first = 0, byDependency = allResources.FirstCount, last = allResources.Count - allResources.LastCount;

            foreach (DictionaryEntry entry in allResources)
            {
                var settings = (RequireSettings)entry.Value;
                if (settings.Position == ResourcePosition.First)
                {
                    i = first++;
                }
                else if (settings.Position == ResourcePosition.Last)
                {
                    i = last++;
                }
                else
                {
                    i = byDependency++;
                }

                requiredResources[i] = new ResourceRequiredContext
                {
                    Settings            = settings,
                    Resource            = (ResourceDefinition)entry.Key,
                    FileVersionProvider = _fileVersionProvider
                };
            }

            return(_builtResources[resourceType] = requiredResources);
        }