示例#1
0
        private ResourceDefinition FindResource(RequireSettings settings, bool resolveInlineDefinitions)
        {
            // find the resource with the given type and name
            // that has at least the given version number. If multiple,
            // return the resource with the greatest version number.
            // If not found and an inlineDefinition is given, define the resource on the fly
            // using the action.
            var name = settings.Name ?? "";
            var type = settings.Type;

            var stream   = ResourceManifests.SelectMany(x => x.GetResources(type));
            var resource = FindMatchingResource(stream, settings, type, name);

            if (resource == null && _dynamicManifest != null)
            {
                stream   = _dynamicManifest.GetResources(type);
                resource = FindMatchingResource(stream, settings, type, name);
            }

            if (resolveInlineDefinitions && resource == null)
            {
                // Does not seem to exist, but it's possible it is being
                // defined by a Define() from a RequireSettings somewhere.
                if (ResolveInlineDefinitions(settings.Type))
                {
                    // if any were defined, now try to find it
                    resource = FindResource(settings, false);
                }
            }

            return(resource);
        }
示例#2
0
        private ResourceDefinition FindResource(RequireSettings settings, bool resolveInlineDefinitions)
        {
            // find the resource with the given type and name
            // that has at least the given version number. If multiple,
            // return the resource with the greatest version number.
            // If not found and an inlineDefinition is given, define the resource on the fly
            // using the action.
            var name = settings.Name ?? "";
            var type = settings.Type;
            ResourceDefinition resource;

            var resources = (from p in ResourceManifests
                             from r in p.GetResources(type)
                             where name.Equals(r.Key, StringComparison.OrdinalIgnoreCase)
                             select r.Value).SelectMany(x => x);

            if (!String.IsNullOrEmpty(settings.Version))
            {
                // Specific version, filter
                var upper = GetUpperBoundVersion(settings.Version);
                var lower = GetLowerBoundVersion(settings.Version);
                resources = from r in resources
                            let version = r.Version != null ? new Version(r.Version) : null
                                          where lower <= version && version < upper
                                          select r;
            }

            // Use the highest version of all matches
            resource = (from r in resources
                        let version = r.Version != null ? new Version(r.Version) : null
                                      orderby version descending
                                      select r).FirstOrDefault();

            if (resource == null && _dynamicManifest != null)
            {
                resources = (from r in _dynamicManifest.GetResources(type)
                             where name.Equals(r.Key, StringComparison.OrdinalIgnoreCase)
                             select r.Value).SelectMany(x => x);

                if (!String.IsNullOrEmpty(settings.Version))
                {
                    // Specific version, filter
                    var upper = GetUpperBoundVersion(settings.Version);
                    var lower = GetLowerBoundVersion(settings.Version);
                    resources = from r in resources
                                let version = r.Version != null ? new Version(r.Version) : null
                                              where lower <= version && version < upper
                                              select r;
                }

                // Use the highest version of all matches
                resource = (from r in resources
                            let version = r.Version != null ? new Version(r.Version) : null
                                          orderby version descending
                                          select r).FirstOrDefault();
            }

            if (resolveInlineDefinitions && resource == null)
            {
                // Does not seem to exist, but it's possible it is being
                // defined by a Define() from a RequireSettings somewhere.
                if (ResolveInlineDefinitions(settings.Type))
                {
                    // if any were defined, now try to find it
                    resource = FindResource(settings, false);
                }
            }

            return(resource);
        }