示例#1
0
        public async Task <TypeAnalysisResult> Start(AnalysisEventArgs analysisEventArgs)
        {
            cancellationSource = new CancellationTokenSource();

            var analyzer     = GetAnalyzerFactory(analysisEventArgs.TypeToAnalyze, analysisEventArgs.Engine, cancellationSource.Token);
            var epaGenerator = new EpaGenerator(analyzer, -1);

            var selectedMethods = from m in analysisEventArgs.SelectedMethods select m.ToString();

            var epaBuilder = new EpaBuilder(analysisEventArgs.TypeToAnalyze);

            OnInitialStateAdded(this, epaBuilder);
            var epaBuilderObservable = new ObservableEpaBuilder(epaBuilder);

            epaBuilderObservable.TransitionAdded += OnTransitionAdded;

            return(await epaGenerator.GenerateEpa(analysisEventArgs.TypeToAnalyze, selectedMethods, epaBuilderObservable));
        }
示例#2
0
        protected static TypeAnalysisResult GenerateEpa(CciAssembly inputAssembly, ITypeDefinition typeToAnalyze, Options options)
        {
            System.Console.WriteLine("Starting analysis for type {0}", typeToAnalyze);

            var cancellationSource = new CancellationTokenSource();

            var workingDir = CreateOrCleanupWorkingDirectory();

            var queryGenerator = new CciQueryGenerator();

            IAnalyzerFactory analyzerFactory;

            switch (options.Backend)
            {
            case "CodeContracts":
                var codeContracts = Environment.GetEnvironmentVariable("CodeContractsInstallDir");
                if (string.IsNullOrEmpty(codeContracts))
                {
                    var msg = new StringBuilder();
                    msg.AppendLine("The environment variable %CodeContractsInstallDir% does not exist.");
                    msg.AppendLine("Please make sure that Code Contracts is installed correctly.");
                    msg.AppendLine("This might be because the system was not restarted after Code Contracts installation.");

                    throw new DirectoryNotFoundException(msg.ToString());
                }
                var cccheckArgs = ConfigurationManager.AppSettings["CccheckArgs"];
                Contract.Assert(cccheckArgs != null);
                var cccheck = new FileInfo(ConfigurationManager.AppSettings["CccheckFullName"]);
                Contract.Assert(cccheck.Exists);
                analyzerFactory = new CodeContractsAnalyzerFactory(workingDir, cccheckArgs, string.Empty, queryGenerator, inputAssembly,
                                                                   options.InputAssembly,
                                                                   typeToAnalyze, cancellationSource.Token);
                break;

            case "Corral":
                var corralDefaultArgs = ConfigurationManager.AppSettings["CorralDefaultArgs"];
                Contract.Assert(corralDefaultArgs != null);
                analyzerFactory = new CorralAnalyzerFactory(corralDefaultArgs, workingDir, queryGenerator, inputAssembly,
                                                            options.InputAssembly, typeToAnalyze, cancellationSource.Token);
                break;

            default:
                throw new NotSupportedException();
            }

            var generator = new EpaGenerator(analyzerFactory, options.Cutter);

            var epaBuilder = new EpaBuilder(typeToAnalyze);

            var epaBuilderObservable = new ObservableEpaBuilder(epaBuilder);

            epaBuilderObservable.TransitionAdded += OnTransitionAdded;
            TypeAnalysisResult analysisResult;

            if (!options.Methods.Equals("All"))
            {
                var selectedMethods = options.Methods.Split(';');
                analysisResult = generator.GenerateEpa(typeToAnalyze, selectedMethods, epaBuilderObservable).Result;
            }
            else
            {
                analysisResult = generator.GenerateEpa(typeToAnalyze, epaBuilderObservable).Result;
            }

            return(analysisResult);
        }