当前位置: 首页>>代码示例>>C#>>正文


C# Analyzer.Invoke方法代码示例

本文整理汇总了C#中Analyzer.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Analyzer.Invoke方法的具体用法?C# Analyzer.Invoke怎么用?C# Analyzer.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Analyzer的用法示例。


在下文中一共展示了Analyzer.Invoke方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            #region OptionVariables
            string source  = "";
            string target  = "";
            string filter  = "";
            string pattern = "";
            string flags   = "";
            string theme   = "light";
            string title   = "AsmDiff.NET report";
            string filename = "";
            UInt16 maxdepth = 1;

            bool isHtml   = true;
            bool showHelp = false;
            #endregion

            options = new OptionSet
            {
                {"h|help", "show this message and exit", x => showHelp = true },
                {"s|source=", "this is the OLD version of the library. Either a path to a specific assembly or a folder which contains assemblies", src => source = src},
                {"t|target=", "this is the NEW version of the library. Either a path to a specific assembly or a folder which contains assemblies", tar => target = tar},
                {"f|filter=", "specify a filter which will exclude other classes which doesn't reference what's specified in the filter (eg. System.Reflection.Assembly) ", f => filter = f},
                {"p|pattern=", "specify a regex pattern which will exclude all files which doesn't match the regular expression ", p => pattern = p},
                {"o|output=", "specify output format, JSON or HTML. Default: HTML", h => isHtml = !String.Equals(h.ToUpperInvariant(), "JSON") },
                {"flags=",  "specify which kind of analysis you want the application to do." + Environment.NewLine +
                            "Options: (a = Addtions, c = Changes, d = Deletions)" + Environment.NewLine +
                            "Ex. `flags=ad` will only search for and include Additions and Deletions from the analysis of the assemblies." + Environment.NewLine +
                            "Default: `flags=cd`", fl => flags = fl },
                {"theme=", "specify either a filename within Assets\\Themes or a path to a CSS file. " + Environment.NewLine +
                            "Default options: light, dark" + Environment.NewLine +
                            "Default: `theme=light`", th => theme = th},
                {"title=", "the given title will be displayed at the top of the HTML report", t => { if(!String.IsNullOrEmpty(t)) title = t; } },
                {"maxdepth=", "descend at most levels (a non-negative integer) levels of directories below the current", m => { if(UInt16.TryParse(m, out maxdepth)); } },
                {"filename=", "the name the tool will use for naming the result file, excluding the file extension", f => { if(!String.IsNullOrEmpty(f)) filename = f; } }
            };


            try
            {
                options.Parse(args);

                if (showHelp)
                {
                    Help();
                    return;
                }

                #region HandleArguments
                // handle commandarguments
                bool sourceIsNull = false;
                if ((sourceIsNull = String.IsNullOrEmpty(source)) || String.IsNullOrEmpty(target))
                    throw new OptionException(String.Format("{0} cannot be empty. You have to specify a {0}", sourceIsNull ? "source" : "target"), sourceIsNull ? "source" : "target");

                // verify that the files or directory in source and target exist
                if ((sourceIsNull = !Exists(source)) || !Exists(target))
                    throw new OptionException(String.Format("the program were unable to find the path specified in {0} ({1})", sourceIsNull ? "source" : "target", sourceIsNull ? source : target),
                        sourceIsNull ? "source" : "target");

                source = Path.GetFullPath(source);
                target = Path.GetFullPath(target);

                Regex regex = null;
                if (IsValidRegex(pattern))
                    regex = new Regex(@pattern, RegexOptions.Compiled);
                else if(!String.IsNullOrEmpty(pattern))
                    throw new OptionException(String.Format("the pattern specified is not a valid regular expression {0}", Environment.NewLine + pattern), "pattern");

                var fl = !String.IsNullOrEmpty(flags) ? GetFlags(flags) : (Analyzer.AnalyzerFlags.Changes | Analyzer.AnalyzerFlags.Deletion);

                if(!Exists(theme) && !Exists(String.Format(@"{0}\Assets\Themes\{1}.css", Environment.CurrentDirectory, theme)))
                    throw new OptionException(String.Format("invalid path or file does not exists {0}", Environment.NewLine + theme), "theme");

                #endregion

                var metaData = new MetaData
                {
                    Pattern = pattern,
                    Filter = filter,
                    Flags = GetFlagsString(flags),
                    CommandArguments = String.Join(" ", args),
                    Source = new AssemblyMetaData { Path = source, AssemblyErrors = new List<string>(), AssemblySuccess = new List<string>() },
                    Target = new AssemblyMetaData { Path = target, AssemblyErrors = new List<string>(), AssemblySuccess = new List<string>() }
                };
                var analyzer = new Analyzer { Flags = fl, MaxDepth = maxdepth };
                var s = analyzer.Invoke(@source, @target, @filter, regex, metaData);

                #region RenderOutput
                // is the outputformat HTML or not
                if (isHtml)
                {
                    var htmlHelper = new HtmlHelper(theme, title);
                    var html = htmlHelper.RenderHTML(s, metaData);
                    string filepath = String.Format(@"{0}\{1}.html", Environment.CurrentDirectory, !String.IsNullOrEmpty(filename) ? filename : ("AssemblyScanReport-" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm")));
                    using (var fileStream = File.Create(filepath))
                    {
                        html.Seek(0, SeekOrigin.Begin);
                        html.CopyTo(fileStream);
                    }

//.........这里部分代码省略.........
开发者ID:KLIM8D,项目名称:AsmDiff.NET,代码行数:101,代码来源:Program.cs


注:本文中的Analyzer.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。