Пример #1
0
        /// <summary>Initializes a new instance of the <see cref="AssemblyPropertiesInfo"/> class.</summary>
        /// <param name="assemblyPath">The assembly file path.</param>
        public AssemblyPropertiesInfo(string assemblyPath) : this()
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The file name cannot be null or empty.");
            }

            if (!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException(@"The assembly file name cannot be found!", assemblyPath);
            }

            if (!AsmUtil.IsAssembly(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The file name is not an assembly file (*.DLL;*.EXE).");
            }

            Location          = assemblyPath;
            AssemblyDirectory = new DirectoryInfo(Path.GetDirectoryName(assemblyPath));

            if (File.Exists(assemblyPath))
            {
                // Update the assembly file version information.
                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assemblyPath);
                ProductName      = fileVersionInfo.ProductName;
                FileDescription  = fileVersionInfo.FileDescription;
                CompanyName      = fileVersionInfo.CompanyName;
                LegalCopyright   = fileVersionInfo.LegalCopyright;
                LegalTrademarks  = fileVersionInfo.LegalTrademarks;
                OriginalFileName = fileVersionInfo.OriginalFilename;
                ProductVersion   = fileVersionInfo.ProductVersion;
                FileVersion      = fileVersionInfo.FileVersion;
            }
        }
Пример #2
0
        /// <summary>Initializes a new instance of the <see cref="AssemblyAnalyzer"/> class.</summary>
        /// <param name="assemblyPath">The assembly file path.</param>
        public AssemblyAnalyzer(string assemblyPath) : this()
        {
            // Validate the assembly path
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The file name cannot be null or empty.");
            }

            if (!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException(@"The assembly file name cannot be found!", assemblyPath);
            }

            if (!AsmUtil.IsAssembly(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The file name is not an assembly file (*.DLL;*.EXE).");
            }

            // Initialize
            Location = assemblyPath;
            AssemblyPropertiesInfo = new AssemblyPropertiesInfo(assemblyPath);
            HierarchyTree          = new HierarchyTree(assemblyPath);
            AssemblyReport         = new MarkdownReport(AssemblyPropertiesInfo, HierarchyTree, Settings);
            Settings = new ReportSettings(AssemblyPropertiesInfo, HierarchyTree);
        }
Пример #3
0
        private static void InitLogApender(XmlHelper xml)
        {
            IList <XmlNode> list = xml.GetChildNodesFromCriteria("//log");

            foreach (XmlNode item in list)
            {
                string nodename = item.Attributes["name"].Value;
                string type     = item.Attributes["type"].Value;

                string asmfile = "";
                if (item.Attributes["asmfile"] != null && !string.IsNullOrWhiteSpace(item.Attributes["asmfile"].Value))
                {
                    asmfile = item.Attributes["asmfile"].Value;
                }


                Type logtype;
                if (!string.IsNullOrEmpty(asmfile))
                {
                    logtype = CreateType(type, asmfile);
                }
                else
                {
                    logtype = Type.GetType(type);
                }
                if (logtype == null)
                {
                    throw new Exception("logtype=" + type + "不存在");
                }

                object logObj = Activator.CreateInstance(logtype);

                IList <XmlNode> paramlist = XmlHelper.GetChildNodesFromCriteria(item,
                                                                                "//log[@name='" + nodename + "']//param");
                //Console.WriteLine(value);

                //AppDomain.CurrentDomain.BaseDirectory


                foreach (XmlNode param in paramlist)
                {
                    string propertyName  = param.Attributes["name"].Value;
                    string propertyValue = param.Attributes["value"].Value;

                    if (AsmUtil.ExistPropertyName(logObj, propertyName))
                    {
                        AsmUtil.SetPropertyValue(logObj, propertyName, propertyValue, null);
                    }

                    //var pros = logObj.GetType().GetProperties();
                }

                SingletonLogger.Instance.Attach((ILog)logObj);
            }
        }
Пример #4
0
        /// <summary>Loads the assembly.</summary>
        /// <param name="assemblyLocation">The assembly location.</param>
        private void LoadAssembly(string assemblyLocation)
        {
            if (string.IsNullOrEmpty(assemblyLocation))
            {
                throw new ArgumentNullException(nameof(assemblyLocation), @"The assembly location cannot be null or empty.");
            }

            if (!File.Exists(assemblyLocation))
            {
                throw new FileNotFoundException(@"The assembly location cannot be found.", assemblyLocation);
            }

            if (!AsmUtil.IsAssembly(assemblyLocation))
            {
                throw new ArgumentNullException(nameof(assemblyLocation), @"The assembly location doesn't link to a valid assembly file type.");
            }

            // BUG: Validate the assembly is same '.NET Framework' version or below and not a '.NET Core' or '.NET Standard'. To validate the input and provider better feedback.

            UpdateStatus(string.Format(Resources.Analyzer_Parsing, Path.GetFileNameWithoutExtension(Tb_Location.Text)));

            // Stop any currently loaded progress and restart.
            if (assemblyWorker.IsBusy)
            {
                assemblyWorker.CancelAsync();
            }

            // Reset assembly explorer grids
            assemblyExplorer.ResetAssemblyExplorerPropertyGrid();

            // Disable buttons
            Btn_Browse.Enabled = false;
            Btn_Build.Enabled  = false;

            // Set the assembly location.
            Tb_Location.Text = assemblyLocation;

            // Show the status bar progress information.
            Tspb_ProgressBar.Visible       = true;
            Tssl_ProgressPercent.Visible   = true;
            Tssl_Separator0Divider.Visible = true;
            Tssl_Separator1Divider.Visible = true;
            Tssl_Elapsed.Visible           = true;

            // Start counting the process duration from the start.
            duration.Reset();
            duration.Start();

            // Start the assembly loading process in separate thread.
            assemblyWorker.RunWorkerAsync(assemblyLocation);
        }
Пример #5
0
        public static Type CreateType(string typeName, string AsmPath)
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AsmPath);

            path = Path.GetFullPath(path);

            Assembly asm = AsmUtil.GetAssemblyFromCurrentDomain(path);

            Type type = asm.GetType(typeName);



            return(type);
        }
Пример #6
0
        /// <summary>Resolves the specified input to a <see cref="Type"/>.</summary>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <param name="namespacePath">The namespace path.</param>
        /// <param name="typeName">Name of the type.</param>
        /// <returns>The <see cref="Type"/>.</returns>
        public static Type ResolveType(string assemblyPath, string namespacePath, string typeName)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The assembly path cannot be null or empty when resolving a Type.");
            }

            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException(nameof(typeName), @"The type name cannot be null or empty when resolving a Type.");
            }

            if (!AsmUtil.IsAssembly(assemblyPath))
            {
                throw new ArgumentNullException(nameof(assemblyPath), @"The assembly path doesn't link to an Assembly executable type file path.");
            }

            return(ResolveType(Assembly.LoadFile(assemblyPath), namespacePath, typeName));
        }