private void FindThread()
 {
     DependencyWalker dw = null;
     try
     {
         dw = new DependencyWalker();
         dw.ReferringAssemblyStatusChanged += this.UpdateStatus;
         this.ReferringAssemblies = dw.FindReferringAssemblies(this.TestAssembly, this.DirectoryPath, this.Recursive);
         this.UpdateStatus(this, new ReferringAssemblyStatusChangeEventArgs { StatusText = "", Progress = -3 });
     }
     catch (Exception)
     {
         this.UpdateStatus(this, new ReferringAssemblyStatusChangeEventArgs { StatusText = Resource.FailedToListBinaries, Progress = -2 });
     }
     finally
     {
         if (null != dw)
         {
             dw.ReferringAssemblyStatusChanged -= this.UpdateStatus;
         }
     }
 }
        private void FormMainLoad(object sender, EventArgs e)
        {
            string debuggableFlagsToolTipText;

            assemblyKindTextBox.Text    = assemblyInformation.AssemblyKind;
            targetProcessorTextBox.Text = assemblyInformation.TargetProcessor;

            if (assemblyInformation.DebuggingFlags != null)
            {
                debuggableFlagsToolTipText = string.Format(@"Debugging Flags: {0}", assemblyInformation.DebuggingFlags);
            }
            else
            {
                debuggableFlagsToolTipText = @"Debugging Flags: NONE";
            }
            DebuggableFlagsToolTip.Tag = debuggableFlagsToolTipText;

            // Display values
            if (assemblyInformation.JitTrackingEnabled)
            {
                txtTrackingEnabled.Text      = "Debug";
                txtTrackingEnabled.BackColor = Color.Red;
            }
            else
            {
                txtTrackingEnabled.Text      = "Release";
                txtTrackingEnabled.BackColor = Color.Green;
            }

            if (assemblyInformation.JitOptimized)
            {
                txtOptimized.Text      = "Optimized";
                txtOptimized.BackColor = Color.Green;
            }
            else
            {
                txtOptimized.Text      = "Not Optimized";
                txtOptimized.BackColor = Color.Red;
            }

            if (assemblyInformation.IgnoreSymbolStoreSequencePoints)
            {
                txtSequencing.Text      = "MSIL Sequencing";
                txtSequencing.BackColor = Color.Green;
            }
            else
            {
                txtSequencing.Text      = "PDB Sequencing";
                txtSequencing.BackColor = assemblyInformation.JitTrackingEnabled ? Color.Red : Color.Orange;
            }

            if (assemblyInformation.EditAndContinueEnabled)
            {
                txtEditAndContinue.Text      = "Edit and Continue Enabled";
                txtEditAndContinue.BackColor = Color.Red;
            }
            else
            {
                txtEditAndContinue.Text      = "Edit and Continue Disabled";
                txtEditAndContinue.BackColor = Color.Green;
            }

            frameWorkVersion.Text = assemblyInformation.FrameWorkVersion;
            txtFullName.Text      = assemblyInformation.AssemblyFullName;

            DependencyWalker dependencyWalker = new DependencyWalker();
            List <string>    errors;

            directDependencies = dependencyWalker.FindDependencies(_mAssembly, false, out errors).ToList();

            FillAssemblyReferences(directDependencies);
        }
        public IEnumerable<string> FindReferringAssemblies(Assembly testAssembly, string directory, bool recursive)
        {
            List<string> referringAssemblies = new List<string>();
            List<string> binaries = new List<string>();
            try
            {
                this.ReferringAssemblyStatusChanged(this, new ReferringAssemblyStatusChangeEventArgs { StatusText = "Finding all binaries" });
                this.FindAssemblies(new DirectoryInfo(directory), binaries, recursive);
            }
            catch (Exception)
            {
                this.UpdateProgress(Resource.FailedToListBinaries, -2);
                return null;
            }

            if (binaries.Count == 0)
            {
                return referringAssemblies;
            }

            int baseDirPathLength = directory.Length;
            if (!directory.EndsWith("\\"))
            {
                baseDirPathLength++;
            }

            int i = 0;
            foreach (var binary in binaries)
            {
                string message = String.Format(Resource.AnalyzingAssembly, Path.GetFileName(binary));
                int progress = (i++ * 100) / binaries.Count;
                if (progress == 100)
                {
                    progress = 99;
                }

                if (!this.UpdateProgress(message, progress))
                {
                    return referringAssemblies;
                }

                try
                {
                    Assembly assembly = Assembly.LoadFile(binary);
                    DependencyWalker dw = new DependencyWalker();
                    List<string> loadErrors;
                    var dependencies = dw.FindDependencies(assembly, false, out loadErrors);
                    if (null == dependencies)
                    {
                        continue;
                    }

                    if (
                        dependencies.Where(
                            p =>
                            String.Compare(p.FullName, testAssembly.FullName, StringComparison.OrdinalIgnoreCase) == 0)
                            .Count() > 0)
                    {
                        referringAssemblies.Add(binary.Remove(0, baseDirPathLength));
                    }

                    this.errors.AddRange(loadErrors);
                }
                catch (ArgumentException)
                {
                }
                catch (FileLoadException)
                {
                }
                catch (FileNotFoundException)
                {
                }
                catch (BadImageFormatException)
                {
                }
            }

            return referringAssemblies.OrderBy(p => p);
        }
Beispiel #4
0
        public IEnumerable <string> FindReferringAssemblies(Assembly testAssembly, string directory, bool recursive)
        {
            List <string> referringAssemblies = new List <string>();
            List <string> binaries            = new List <string>();

            try
            {
                ReferringAssemblyStatusChanged(this,
                                               new ReferringAssemblyStatusChangeEventArgs
                {
                    StatusText = "Finding all binaries"
                });
                FindAssemblies(new DirectoryInfo(directory), binaries, recursive);
            }
            catch (Exception ex)
            {
                UpdateProgress(Resource.FailedToListBinaries, -2);
                return(null);
            }

            if (binaries.Count == 0)
            {
                return(referringAssemblies);
            }
            int baseDirPathLength = directory.Length;

            if (!directory.EndsWith("\\"))
            {
                baseDirPathLength++;
            }

            int i = 0;

            foreach (var binary in binaries)
            {
                string message  = String.Format(Resource.AnalyzingAssembly, Path.GetFileName(binary));
                int    progress = (i++ *100) / binaries.Count;
                if (progress == 100)
                {
                    progress = 99;
                }
                if (!UpdateProgress(message, progress))
                {
                    return(referringAssemblies);
                }

                try
                {
                    Assembly         assembly = Assembly.LoadFile(binary);
                    DependencyWalker dw       = new DependencyWalker();
                    List <string>    loadErrors;
                    var dependencies = dw.FindDependencies(assembly, false, out loadErrors);
                    if (null == dependencies)
                    {
                        continue;
                    }
                    if (dependencies.Where(p => String.Compare(p.FullName, testAssembly.FullName, StringComparison.OrdinalIgnoreCase) == 0).Count() > 0)
                    {
                        referringAssemblies.Add(binary.Remove(0, baseDirPathLength));
                    }
                    errors.AddRange(loadErrors);
                }
                catch (ArgumentException) { }
                catch (FileLoadException) { }
                catch (FileNotFoundException) { }
                catch (BadImageFormatException) { }
            }

            return(referringAssemblies.OrderBy(p => p));
        }