public IEnumerable<ModuleDependency> GetDependencyModules(string directory, string assemblyPath)
        {
            _dependencies = new List<ModuleDependency>();

            foreach (string file in _pathToAssembly)
            {
                AssemblyName asmName = null;
                try
                {
                    asmName = AssemblyName.GetAssemblyName(file);
                }
                catch (BadImageFormatException)
                {
                    // nothing happens, return empty list
                    continue;
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("Access to file is somewhat corrupted", e);
                }

                var dependency = new ModuleDependency
                                 	{
                                 		ModuleName = asmName.Name,
                                 		MinimalVersion = new Version(asmName.Version),
                                 		ProcessorArchitecture = asmName.ProcessorArchitecture,
                                 		HasLoadingOrderPriority = false,
                                 	};

                _dependencies.Add(dependency);
            }

            return _dependencies;
        }
Exemplo n.º 2
0
        protected static IModulesDependenciesProvider GetModuleDependenciesOnSingleModule(string s, string versionString)
        {
            var moduleAonBDependency = new ModuleDependency()
                                           {
                                               HasLoadingOrderPriority = false,
                                               MinimalVersion = new Version(versionString),
                                               ModuleName = s,
                                               ProcessorArchitecture = ProcessorArchitecture.MSIL
                                           };

            var moduleDependencyProviderMock = new Mock<IModulesDependenciesProvider>(MockBehavior.Loose);
            moduleDependencyProviderMock
                .Setup(x => x.GetDependencyModules(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(new List<ModuleDependency>() { moduleAonBDependency });

            return moduleDependencyProviderMock.Object;
        }
        public IEnumerable<ModuleDependency> GetDependencyModules(string directory,
            string assemblyPath)
        {
            var dependencies = new List<ModuleDependency>();

            // check for existence
            if (!File.Exists(_depFileName))
            {
                //NOTE: if not find file then use empty list
                return dependencies;
            }

            // open file
            using (StreamReader reader = File.OpenText(_depFileName))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    try
                    {
                        string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, line);
                        AssemblyName asmName = AssemblyName.GetAssemblyName(path);
                        var dependency = new ModuleDependency
                                             {
                                                 HasLoadingOrderPriority = false,
                                                 ModuleName = asmName.Name,
                                                 MinimalVersion = new Version(asmName.Version),
                                                 ProcessorArchitecture =
                                                     asmName.ProcessorArchitecture
                                             };
                        dependencies.Add(dependency);
                    }
                    catch (Exception e)
                    {
                        throw new FileFormatException("File corrupted", e);
                    }
                }
            }

            return dependencies;
        }