IAssembly implementation that is used for marshalling information across app domains.
Inheritance: System.MarshalByRefObject, IAssembly
 private static IEnumerable <IAssembly> GetAssemblies(IEnumerable <string> paths, AppDomain domain)
 {
     foreach (var path in paths)
     {
         yield return(RemoteAssembly.LoadAssembly(path, domain));
     }
 }
コード例 #2
0
        public void Load(string path)
        {
            // The cache key is the file name plus the full name of the assembly.
            // This is so we don't load the same assembly more than once from different paths
            string fileName = Path.GetFileName(path).ToUpperInvariant();
            var    cacheKey = Tuple.Create(fileName, AssemblyName.GetAssemblyName(path).FullName);

            Assembly assembly;

            if (!_assemblyCache.TryGetValue(cacheKey, out assembly))
            {
                // Load the assembly in a reflection only context
                assembly = Assembly.ReflectionOnlyLoadFrom(path);
                _assemblyCache[cacheKey] = assembly;
            }

            // Get the assembly name and set the properties on this object
            CopyAssemblyProperties(assembly.GetName(), this);

            // Do the same for referenced assemblies
            foreach (AssemblyName referencedAssemblyName in assembly.GetReferencedAssemblies())
            {
                // Copy the properties to the referenced assembly
                var referencedAssembly = new RemoteAssembly();
                _referencedAssemblies.Add(CopyAssemblyProperties(referencedAssemblyName, referencedAssembly));
            }
        }
コード例 #3
0
        public void Load(string path)
        {
            // The cache key is the file name plus the full name of the assembly.
            // This is so we don't load the same assembly more than once from different paths
            string fileName = Path.GetFileName(path).ToUpperInvariant();
            var cacheKey = Tuple.Create(fileName, AssemblyName.GetAssemblyName(path).FullName);

            Assembly assembly;
            if (!_assemblyCache.TryGetValue(cacheKey, out assembly))
            {
                // Load the assembly in a reflection only context
                assembly = Assembly.ReflectionOnlyLoadFrom(path);
                _assemblyCache[cacheKey] = assembly;
            }

            // Get the assembly name and set the properties on this object
            CopyAssemblyProperties(assembly.GetName(), this);

            // Do the same for referenced assemblies
            foreach (AssemblyName referencedAssemblyName in assembly.GetReferencedAssemblies())
            {
                // Copy the properties to the referenced assembly
                var referencedAssembly = new RemoteAssembly();
                _referencedAssemblies.Add(CopyAssemblyProperties(referencedAssemblyName, referencedAssembly));
            }
        }
コード例 #4
0
        private static RemoteAssembly CopyAssemblyProperties(AssemblyName assemblyName, RemoteAssembly assembly)
        {
            assembly.Name = assemblyName.Name;
            assembly.Version = assemblyName.Version;
            assembly.PublicKeyToken = assemblyName.GetPublicKeyTokenString();
            string culture = assemblyName.CultureInfo.ToString();
            assembly.Culture = String.IsNullOrEmpty(culture) ? "neutral" : culture;

            return assembly;
        }
コード例 #5
0
        internal static IAssembly LoadAssembly(string path, AppDomain domain)
        {
            if (!ReferenceEquals(domain, AppDomain.CurrentDomain))
            {
                RemoteAssembly local1 = domain.CreateInstance <RemoteAssembly>();
                local1.Load(path);
                return(local1);
            }
            RemoteAssembly assembly1 = new RemoteAssembly();

            assembly1.Load(path);
            return(assembly1);
        }
コード例 #6
0
        public void RemoteAssemblyComparesById()
        {
            // Arrange
            var assemblyA = new RemoteAssembly("A", null, null, null);
            var assemblyB = new Mock<IAssembly>(MockBehavior.Strict);
            assemblyB.SetupGet(b => b.Name).Returns("Z").Verifiable();

            // Act
            var result = RemoteAssembly.Compare(assemblyA, assemblyB.Object);

            // Assert
            Assert.Equal(-25, result);
            assemblyB.Verify();
        }
コード例 #7
0
        internal static IAssembly LoadAssembly(string path, AppDomain domain)
        {
            if (domain != AppDomain.CurrentDomain)
            {
                var crossDomainAssembly = domain.CreateInstance <RemoteAssembly>();
                crossDomainAssembly.Load(path);

                return(crossDomainAssembly);
            }

            var assembly = new RemoteAssembly();

            assembly.Load(path);
            return(assembly);
        }
コード例 #8
0
        public void RemoteAssemblyComparesByVersionIfIdsAreIdentical()
        {
            // Arrange
            var assemblyA = new RemoteAssembly("A", new Version("2.0.0.0"), null, null);
            var assemblyB = new Mock<IAssembly>(MockBehavior.Strict);
            assemblyB.SetupGet(b => b.Name).Returns("A").Verifiable();
            assemblyB.SetupGet(b => b.Version).Returns(new Version("1.0.0.0")).Verifiable();

            // Act
            var result = RemoteAssembly.Compare(assemblyA, assemblyB.Object);

            // Assert
            Assert.Equal(1, result);
            assemblyB.Verify();
        }
コード例 #9
0
        public void RemoteAssemblyComparesByCultureIfIdVersionAndPublicKeyAreIdentical()
        {
            // Arrange
            var assemblyA = new RemoteAssembly("A", new Version("1.0.0.0"), "public-key", "en-us");
            var assemblyB = new Mock<IAssembly>(MockBehavior.Strict);
            assemblyB.SetupGet(b => b.Name).Returns("A").Verifiable();
            assemblyB.SetupGet(b => b.Version).Returns(new Version("1.0.0.0")).Verifiable();
            assemblyB.SetupGet(b => b.PublicKeyToken).Returns("public-key").Verifiable();
            assemblyB.SetupGet(b => b.Culture).Returns("en-uk").Verifiable();

            // Act
            var result = RemoteAssembly.Compare(assemblyA, assemblyB.Object);

            // Assert
            Assert.Equal(8, result);
            assemblyB.Verify();
        }
コード例 #10
0
        public void Load(string path)
        {
            Assembly assembly;
            Tuple <string, string> key = Tuple.Create <string, string>(Path.GetFileName(path).ToUpperInvariant(), AssemblyName.GetAssemblyName(path).FullName);

            if (!_assemblyCache.TryGetValue(key, out assembly))
            {
                assembly            = Assembly.ReflectionOnlyLoadFrom(path);
                _assemblyCache[key] = assembly;
            }
            CopyAssemblyProperties(assembly.GetName(), this);
            foreach (AssemblyName name in assembly.GetReferencedAssemblies())
            {
                RemoteAssembly assembly2 = new RemoteAssembly();
                this._referencedAssemblies.Add(CopyAssemblyProperties(name, assembly2));
            }
        }
コード例 #11
0
        private static RemoteAssembly CopyAssemblyProperties(AssemblyName assemblyName, RemoteAssembly assembly)
        {
            assembly.Name           = assemblyName.Name;
            assembly.Version        = assemblyName.Version;
            assembly.PublicKeyToken = assemblyName.GetPublicKeyTokenString();
            string culture = assemblyName.CultureInfo.ToString();

            assembly.Culture = String.IsNullOrEmpty(culture) ? "neutral" : culture;

            return(assembly);
        }
コード例 #12
0
        public void RemoteAssemblyReturns0IfAllValuesAreIdentical()
        {
            // Arrange
            var assemblyA = new RemoteAssembly("A", new Version("1.0.0.0"), "public-key", "en-us");
            var assemblyB = new RemoteAssembly("A", new Version("1.0.0.0"), "public-key", "en-us");

            // Act
            var result = RemoteAssembly.Compare(assemblyA, assemblyB);

            // Assert
            Assert.Equal(0, result);
        }
コード例 #13
0
        public void EqualReturnsFalseIfValuesAreNotIdentical()
        {
            // Arrange
            var assemblyA = new RemoteAssembly("A", new Version("1.0.0.0"), "public-key", "en-us");
            var assemblyB = new RemoteAssembly("A", new Version("1.0.0.1"), "public-key", "en-us");

            // Act
            var result = assemblyA.Equals(assemblyB);

            // Assert
            Assert.False(result);
        }
コード例 #14
0
        public void RemoteAssemblyReturns1IfValueToBeComparedToIsNull()
        {
            // Arrange
            RemoteAssembly assemblyA = new RemoteAssembly("A", new Version("1.0.0.0"), "public-key", "en-us");
            RemoteAssembly assemblyB = null;

            // Act
            var result = assemblyA.CompareTo(assemblyB);

            // Assert
            Assert.Equal(1, result);
        }
コード例 #15
0
ファイル: RemoteAssembly.cs プロジェクト: jacksonh/nuget
        internal static IAssembly LoadAssembly(string path, AppDomain domain)
        {
            if (domain != AppDomain.CurrentDomain) {
                var crossDomainAssembly = domain.CreateInstance<RemoteAssembly>();
                crossDomainAssembly.Load(path);

                return crossDomainAssembly;
            }

            var assembly = new RemoteAssembly();
            assembly.Load(path);
            return assembly;
        }