Esempio n. 1
0
        protected virtual void OnMethod(RunnerEventArgs e)
        {
            OnEvent(AnalyzeMethod, e);

            foreach (IMethodRule rule in method_rules)
            {
                defectCountBeforeCheck = Defects.Count;
                // stop if we reach the user defined defect limit
                if (defectCountBeforeCheck >= DefectsLimit)
                {
                    break;
                }

                // ignore if the visibility does not match user selection
                ApplicabilityScope scope = rule.ApplicabilityScope;
                if ((scope != ApplicabilityScope.All) && !VisibilityCheck(scope, e.CurrentMethod.IsVisible()))
                {
                    continue;
                }

                // ignore the rule on some user defined methods
                if (IgnoreList.IsIgnored(rule, e.CurrentMethod))
                {
                    continue;
                }

                currentRule = rule;
                rule.CheckMethod(e.CurrentMethod);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// For all assemblies, every modules in each assembly, every
        /// type in each module, every methods in each type call all
        /// applicable rules.
        /// </summary>
        public virtual void Run()
        {
            RunnerEventArgs runner_args = new RunnerEventArgs(this);

            foreach (AssemblyDefinition assembly in assemblies)
            {
                currentTarget = (IMetadataTokenProvider)assembly;
                runner_args.CurrentAssembly = assembly;
                OnAssembly(runner_args);

                foreach (ModuleDefinition module in assembly.Modules)
                {
                    currentTarget             = (IMetadataTokenProvider)module;
                    runner_args.CurrentModule = module;
                    OnModule(runner_args);

                    foreach (TypeDefinition type in module.GetAllTypes())
                    {
                        currentTarget           = (IMetadataTokenProvider)type;
                        runner_args.CurrentType = type;
                        OnType(runner_args);

                        foreach (MethodDefinition method in type.Methods)
                        {
                            currentTarget             = (IMetadataTokenProvider)method;
                            runner_args.CurrentMethod = method;
                            OnMethod(runner_args);
                        }
                    }
                }
            }
            // don't report them if we hit an exception after analysis is completed (e.g. in reporting)
            currentRule   = null;
            currentTarget = null;
        }
Esempio n. 3
0
 private void OnEvent(EventHandler <RunnerEventArgs> handler, RunnerEventArgs e)
 {
     if (handler != null)
     {
         handler(this, e);
     }
 }
Esempio n. 4
0
        protected virtual void OnModule(RunnerEventArgs e)
        {
            OnEvent(AnalyzeModule, e);

            // Since it has never been used in the previous years
            // this version of the Gendarme framework doesn't
            // support IModuleRule. Nor do we support ignore on
            // modules.
        }
Esempio n. 5
0
        // protected since a higher-level (e.g. GUI) runner might want to override
        // them to update it's user interface
        protected virtual void OnAssembly(RunnerEventArgs e)
        {
            OnEvent(AnalyzeAssembly, e);

            foreach (IAssemblyRule rule in assembly_rules)
            {
                defectCountBeforeCheck = Defects.Count;
                // stop if we reach the user defined defect limit
                if (defectCountBeforeCheck >= DefectsLimit)
                {
                    break;
                }

                // ignore the rule on some user defined assemblies
                if (IgnoreList.IsIgnored(rule, e.CurrentAssembly))
                {
                    continue;
                }

                currentRule = rule;
                rule.CheckAssembly(e.CurrentAssembly);
            }
        }
Esempio n. 6
0
		/// <summary>
		/// Update UI after analyzing an assembly.
		/// </summary>
		/// <param name="e">RunnerEventArgs that contains the Assembly being analyzed and the Runner</param>
		public void PostTypeUpdate (RunnerEventArgs e)
		{
			analyze_defect_label.Text = String.Format ("Defects Found: {0}", e.Runner.Defects.Count);
		}
Esempio n. 7
0
		public void OnAssembly (object sender, RunnerEventArgs e)
		{
			// If the assembly defines ThreadModelAttribute then we need to
			// check all of the methods within it.
			foreach (ModuleDefinition module in e.CurrentAssembly.Modules) {
				if (LookForThreadModelAttribute (module.GetAllTypes ())) {
					Log.WriteLine (this, "assembly defines ThreadModelAttribute");
					Active = true;
					return;
				} else if (LookForThreadModelAttribute (module.GetTypeReferences ())) {
					Log.WriteLine (this, "assembly references ThreadModelAttribute");
					Active = true;
					return;
				}
			}
			
			// If the assembly does not define ThreadModelAttribute then we don't
			// want to check methods but we do want to report (one) defect to inform
			// people about the rule.
			Active = false;
			
			if (!displayed_no_attribute_defect) {
				string mesg = "The assembly does not use ThreadModelAttribute (this defect will be reported only once).";
				Log.WriteLine (this, mesg);
				ReportDefect (e.CurrentAssembly, Severity.Medium, Confidence.Low, mesg);
				
				displayed_no_attribute_defect = true;
			}
		}
Esempio n. 8
0
		// protected since a higher-level (e.g. GUI) runner might want to override
		// them to update it's user interface
		protected virtual void OnAssembly (RunnerEventArgs e)
		{
			OnEvent (AnalyzeAssembly, e);

			foreach (IAssemblyRule rule in assembly_rules) {
				defectCountBeforeCheck = Defects.Count;
				// stop if we reach the user defined defect limit
				if (defectCountBeforeCheck >= DefectsLimit)
					break;

				// ignore the rule on some user defined assemblies
				if (IgnoreList.IsIgnored (rule, e.CurrentAssembly))
					continue;

				currentRule = rule;
				rule.CheckAssembly (e.CurrentAssembly);
			}
		}
Esempio n. 9
0
 /// <summary>
 /// Update UI after analyzing an assembly.
 /// </summary>
 /// <param name="e">RunnerEventArgs that contains the Assembly being analyzed and the Runner</param>
 internal void PostTypeUpdate(RunnerEventArgs e)
 {
     analyze_defect_label.Text = String.Format (CultureInfo.CurrentCulture,
         "Defects Found: {0}", e.Runner.Defects.Count);
 }
Esempio n. 10
0
		protected override void OnAssembly (RunnerEventArgs e)
		{
			if (!quiet) {
				if (local.IsRunning) {
					local.Stop ();
					Console.WriteLine (": {0}", TimeToString (local.Elapsed));
					local.Reset ();
				}
			
				// next assembly
				Console.Write (Path.GetFileName (e.CurrentAssembly.MainModule.FullyQualifiedName));
				local.Start ();
			}
			
			base.OnAssembly (e);
		}
Esempio n. 11
0
		/// <summary>
		/// For all assemblies, every modules in each assembly, every 
		/// type in each module, every methods in each type call all
		/// applicable rules.
		/// </summary>
		public virtual void Run ()
		{
			RunnerEventArgs runner_args = new RunnerEventArgs (this);

			foreach (AssemblyDefinition assembly in assemblies) {
				currentTarget = (IMetadataTokenProvider) assembly;
				runner_args.CurrentAssembly = assembly;
				OnAssembly (runner_args);

				foreach (ModuleDefinition module in assembly.Modules) {
					currentTarget = (IMetadataTokenProvider) module;
					runner_args.CurrentModule = module;
					OnModule (runner_args);

					foreach (TypeDefinition type in module.GetAllTypes ()) {
						currentTarget = (IMetadataTokenProvider) type;
						runner_args.CurrentType = type;
						OnType (runner_args);

						foreach (MethodDefinition method in type.Methods) {
							currentTarget = (IMetadataTokenProvider) method;
							runner_args.CurrentMethod = method;
							OnMethod (runner_args);
						}
					}
				}
			}
			// don't report them if we hit an exception after analysis is completed (e.g. in reporting)
			currentRule = null;
			currentTarget = null;
		}
Esempio n. 12
0
		protected virtual void OnMethod (RunnerEventArgs e)
		{
			OnEvent (AnalyzeMethod, e);

			foreach (IMethodRule rule in method_rules) {
				defectCountBeforeCheck = Defects.Count;
				// stop if we reach the user defined defect limit
				if (defectCountBeforeCheck >= DefectsLimit)
					break;

				// ignore if the visibility does not match user selection 
				ApplicabilityScope scope = rule.ApplicabilityScope;
				if ((scope != ApplicabilityScope.All) && !VisibilityCheck (scope, e.CurrentMethod.IsVisible ()))
					continue;

				// ignore the rule on some user defined methods
				if (IgnoreList.IsIgnored (rule, e.CurrentMethod))
					continue;

				currentRule = rule;
				rule.CheckMethod (e.CurrentMethod);
			}
		}
Esempio n. 13
0
		protected virtual void OnModule (RunnerEventArgs e)
		{
			OnEvent (AnalyzeModule, e);

			// Since it has never been used in the previous years 
			// this version of the Gendarme framework doesn't 
			// support IModuleRule. Nor do we support ignore on 
			// modules.
		}
Esempio n. 14
0
		protected override void OnAssembly (RunnerEventArgs e)
		{
			// update wizard UI on the main, i.e. UI, thread
			wizard.BeginInvoke ((Action) (() => wizard.PreAssemblyUpdate (e)));
			base.OnAssembly (e);
		}
Esempio n. 15
0
		/// <summary>
		/// Update UI before analyzing an assembly.
		/// </summary>
		/// <param name="e">RunnerEventArgs that contains the Assembly being analyzed and the Runner</param>
		public void PreAssemblyUpdate (RunnerEventArgs e)
		{
			progress_bar.Value = counter++;
			analyze_status_label.Text = String.Format ("Processing assembly {0} of {1}",
				counter, e.Runner.Assemblies.Count);
			analyze_assembly_label.Text = "Assembly: " + e.CurrentAssembly.Name.FullName;
		}
Esempio n. 16
0
		protected override void OnType (RunnerEventArgs e)
		{
			base.OnType (e);
			wizard.BeginInvoke ((Action) (() => wizard.PostTypeUpdate (e)));
		}
Esempio n. 17
0
		private void OnEvent (EventHandler<RunnerEventArgs> handler, RunnerEventArgs e)
		{
			if (handler != null)
				handler (this, e);
		}