/// <summary> /// Creates an instance of a RuleContainer /// </summary> /// <param name="pathToFile">Path to rule file (.cs or .dll)</param> /// <param name="containerType">Type of container: compiled or source code.</param> /// when the rule is initialized from the container. Exceptions will be thrown if compilation fails.</param> public RuleContainer(string pathToFile, RuleContainerType containerType) { if (String.IsNullOrEmpty(pathToFile)) { throw new ArgumentNullException(nameof(pathToFile)); } this.PathToFile = pathToFile; this.ContainerType = containerType; }
/// <summary> /// Creates an instance of a RuleContainer /// </summary> /// <param name="pathToFile">Path to rule file (.cs or .dll)</param> /// <param name="containerType">Type of container: compiled or source code.</param> /// <param name="filteringExpressionMethod">An optional filtering expression method.</param> public RuleContainer(string pathToFile, RuleContainerType containerType, COExpression <ClassificationObject> filteringExpressionMethod) { if (String.IsNullOrEmpty(pathToFile)) { throw new ArgumentNullException("pathToFile"); } this.PathToFile = pathToFile; this.ContainerType = containerType; this.FilteringExpressionMethod = filteringExpressionMethod; }
public CheckConfig(string name, string pathToFile, bool allLanguages, IList <CultureInfo> languages, bool allProjects, IList <string> projects, RuleContainerType containerType) { if (name == null) { throw new ArgumentNullException("name"); } if (pathToFile == null) { throw new ArgumentNullException("pathToFile"); } Name = name; PhysicalFile = pathToFile; IsEnabledForAllLanguages = allLanguages; Languages = new ReadOnlyCollection <CultureInfo>(languages ?? new CultureInfo[0]); IsEnabledForAllProjects = allProjects; Projects = new ReadOnlyCollection <string>(projects ?? new string[0]); ContainerType = containerType; }
/// <summary> /// Creates a sample Engine configuration /// </summary> /// <param name="testContext">VS Test Context</param> /// <param name="testRuleFileName">Rule to be used (.dll or .cs)</param> /// <param name="numberOfResources">Number of Resources to generate (in increments of 6)</param> /// <returns></returns> internal static EngineConfig CreateSampleConfig(TestContext testContext, string testRuleFileName, int numberOfResources) { testRuleFileName = Path.Combine(testContext.DeploymentDirectory, testRuleFileName); var configuration = new EngineConfig(); #region DataSourceProviderTypes configuration.AddDataSourceProvider(typeof(SampleDataSource)); #endregion #region PropertyAdapterTypes configuration.AddPropertyAdapter <SamplePropertyAdapter>(); configuration.AddPropertyAdapter <SampleClassificationObjectSelfPropertyAdapter>(); #endregion #region COAdatpers configuration.AddCOAdapter(typeof(SampleDataAdapter)); #endregion #region COTypes configuration.AddClassificationObject <SampleClassificationObjectType>(); #endregion #region DataSourcePackages var package = new DataSourcePackage(); // This package will contain 2 data sources package.SetCOType <SampleClassificationObjectType>(); var dataSource = new DataSourceInfo(); dataSource.SetSourceType <SampleResourceCollection>(); List <Tuple <string, string, string> > sampleResources = GenerateLargeNumberOfResources(numberOfResources); dataSource.SetSourceLocation(sampleResources); package.AddDataSource(dataSource); configuration.AddDataSourcePackage(package); #endregion #region Add rules RuleContainerType rct = new RuleContainerType(); if (testRuleFileName.EndsWith(".cs")) { rct = RuleContainerType.Source; } else { rct = RuleContainerType.Module; } configuration.AddRule(new RuleContainer(testRuleFileName, rct)); #endregion #region And some configuration for dynamic compiler configuration.AddBinaryReference("System.Core.dll"); configuration.AddBinaryReference("mscorlib.dll"); configuration.AddBinaryReference("System.dll"); configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.Core.dll"); configuration.AddBinaryReference("UnitTests.dll"); #endregion #region Configure output behavior var outputCfg = new OutputWriterConfig(); outputCfg.SetDataSourceProvider <XMLDOMOutputWriter>(); outputCfg.Schema = "ResourceStaticAnalysisOutput.xsd"; outputCfg.Path = testContext.TestRunDirectory; outputCfg.AddPropertyToIncludeInOutput("ResourceId"); outputCfg.AddPropertyToIncludeInOutput("SourceString"); outputCfg.AddPropertyToIncludeInOutput("Comments"); configuration.OutputConfigs.Add(outputCfg); #endregion return(configuration); }
/// <summary> /// Creates an engine configuration with two Data Sources. /// </summary> /// <param name="testContext">Used to store information that is provided to unit tests.</param> /// <param name="testRuleFileName">Name of the C# file that contains the Rule implementaiton.</param> /// <param name="testResourceFile">Resource File used to run the engine.</param> /// <returns>The configuration of the engine with two DataSources.</returns> internal static EngineConfig CreateSampleConfigWithTwoDataSources(TestContext testContext, string testRuleFileName, string testResourceFile) { testRuleFileName = Path.Combine(testContext.DeploymentDirectory, testRuleFileName); testResourceFile = Path.Combine(testContext.DeploymentDirectory, testResourceFile); var configuration = new EngineConfig(); #region DataSourceProviderTypes configuration.AddDataSourceProvider <ResourceFileDataSource>(); configuration.AddDataSourceProvider <ConfigDictionaryDataSource>(); #endregion #region PropertyAdapterTypes configuration.AddPropertyAdapter <ResourceFileEntryPropertyAdapter>(); configuration.AddPropertyAdapter <ConfigDictPropertyAdapter>(); configuration.AddPropertyAdapter <LocResourceSelfPropertyAdapter>(); #endregion #region COAdatpers configuration.AddCOAdapter <ResourceFileDataAdapter>(); #endregion #region COTypes configuration.AddClassificationObject <LocResource>(); #endregion #region DataSourcePackages var package = new DataSourcePackage(); // This package will contain 2 data sources package.SetCOType <LocResource>(); var dataSource = new DataSourceInfo(); dataSource.SetSourceType(typeof(ResourceFile)); dataSource.SetSourceLocation(Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, testResourceFile)); package.AddDataSource(dataSource); dataSource = new DataSourceInfo(); dataSource.SetSourceType <ConfigDictionary>(); var configDictionary = new ConfigDictionary { { "Project", "test RSA" }, }; dataSource.SetSourceLocation(configDictionary); package.AddDataSource(dataSource); configuration.AddDataSourcePackage(package); #endregion #region Add rules RuleContainerType rct = new RuleContainerType(); if (testRuleFileName.EndsWith(".cs")) { rct = RuleContainerType.Source; } else { rct = RuleContainerType.Module; } configuration.AddRule(new RuleContainer(testRuleFileName, rct)); #endregion #region And some configuration for dynamic compiler configuration.AddBinaryReference("System.Core.dll"); configuration.AddBinaryReference("mscorlib.dll"); configuration.AddBinaryReference("System.dll"); configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.Core.dll"); configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.LocResource.dll"); configuration.AddBinaryReference("Microsoft.ResourceStaticAnalysis.DataAdapter.dll"); #endregion return(configuration); }