private void ProcessPropertyWithConverterPackUri(BamlPropertyWithConverter bamlPropertyWithConverter)
        {
            string value = bamlPropertyWithConverter.Value;

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            var uri = PackUri.Parse(value);

            if (uri == null)
            {
                return;
            }

            if (uri.Assembly == null)
            {
                return;
            }

            var assemblyRef = uri.Assembly;

            var targetAssembly = _assembly.AssemblyManager.Resolve(assemblyRef, _assembly.Module, false) as BuildAssembly;

            if (targetAssembly == null)
            {
                return;
            }

            bool    changed = false;
            string  name    = assemblyRef.Name;
            Version version = assemblyRef.Version;

            byte[] publicKeyToken = assemblyRef.PublicKeyToken;

            if (targetAssembly.NameChanged)
            {
                name    = targetAssembly.NewName;
                changed = true;
            }

            if (version != null && targetAssembly.VersionChanged)
            {
                version = targetAssembly.NewVersion;
                changed = true;
            }

            if (publicKeyToken != null && targetAssembly.PublicKeyChanged)
            {
                publicKeyToken = targetAssembly.NewPublicKeyToken;
                changed        = true;
            }

            if (changed)
            {
                uri.Assembly = new AssemblyReference(name, null, version, publicKeyToken);
                AddMapping(new PropertyWithConverterMap(bamlPropertyWithConverter, uri.ToString()));
            }
        }
Example #2
0
        public static StreamResourceInfo GetResourceStream(Uri uriResource)
        {
            if (uriResource == null)
            {
                throw new ArgumentNullException("uriResource");
            }

            if (uriResource.OriginalString == null)
            {
                throw new ArgumentException("uriResource.OriginalString is null.");
            }

            if (uriResource.IsAbsoluteUri)
            {
                if (uriResource.Scheme == "pack")
                {
                    throw new NotSupportedException("pack: resources not yet supported.");
                }
                else
                {
                    throw new ArgumentException("uriResource is not relative and doesn't use the pack: scheme.");
                }
            }

            PackUri         pack         = new PackUri(uriResource);
            string          assemblyName = pack.Assembly;
            Assembly        assembly     = (assemblyName != null) ? Assembly.Load(assemblyName) : Assembly.GetEntryAssembly();
            string          resourceName = assembly.GetName().Name + ".g";
            ResourceManager manager      = new ResourceManager(resourceName, assembly);

            using (ResourceSet resourceSet = manager.GetResourceSet(CultureInfo.CurrentCulture, true, true))
            {
                Stream s = (Stream)resourceSet.GetObject(pack.GetAbsolutePath(), true);

                if (s == null)
                {
                    throw new IOException(
                              "The requested resource could not be found: " +
                              uriResource.OriginalString);
                }

                return(new StreamResourceInfo(s, null));
            }
        }
        public void ImplicitConversionToUri_Works()
        {
            Uri uri = new PackUri(null, "pack://host/Path");

            uri.ToString().Should().Be(@"pack://host/Path");
        }