本文整理汇总了C#中RuleSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# RuleSet.Add方法的具体用法?C# RuleSet.Add怎么用?C# RuleSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RuleSet
的用法示例。
在下文中一共展示了RuleSet.Add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fire
public string Fire(Unit target)
{
string result = string.Empty;
RuleSet idealHitRules = new RuleSet();
idealHitRules.Add(new UnderMaximumIdealRangeRule(this, target));
idealHitRules.Add(new OverMinimumIdealRangeRule(this, target));
RuleSet regularHitRules = new RuleSet();
regularHitRules.Add(new UnderMaximumRangeRule(this, target));
regularHitRules.Add(new OverMinimumRangeRule(this, target));
//Fire!
if (idealHitRules.Validate())
{
result = "Ideal hit!";
}
else if (regularHitRules.Validate())
{
result = "Hit.";
}
else
{
result = regularHitRules.FailureMessages[0];
}
return result;
}
示例2: RuleSetSuccess
public void RuleSetSuccess()
{
//Assemble
RuleSet rules = new RuleSet();
rules.Add(new StringMatchRule(){ string1 = "One", string2 = "One" });
//Act
bool success = rules.Validate();
//Assert
Assert.IsTrue(success, "Strings did not match");
Assert.IsEmpty(rules.FailureMessages, "There should not be any FailureMessages");
}
示例3: RuleSetFailure
public void RuleSetFailure()
{
//Assemble
RuleSet rules = new RuleSet();
rules.Add(new StringMatchRule() { string1 = "Two", string2 = "Hats" });
//Act
bool success = rules.Validate();
//Assert
Assert.IsFalse(success, "No match should exist");
Assert.IsNotEmpty(rules.FailureMessages, "There should not be any FailureMessages");
}
示例4: PassMaxIdealRangeTest
public void PassMaxIdealRangeTest()
{
//Assemble
Unit unit1 = new Unit() { MaximumIdealRange = 10, XCoordinate = 0, YCoordinate = 0 };
Unit unit2 = new Unit() { MaximumIdealRange = 10, XCoordinate = 0, YCoordinate = 5 };
RuleSet rules = new RuleSet();
rules.Add(new UnderMaximumIdealRangeRule(unit1, unit2));
//Act
bool success = rules.Validate();
//Assert
Assert.IsTrue(success, "Unit should be inside of max ideal range");
}
示例5: FailMaxRangeTest
public void FailMaxRangeTest()
{
//Assemble
Unit unit1 = new Unit() { MaximumRange = 10, XCoordinate = 0, YCoordinate = 0 };
Unit unit2 = new Unit() { MaximumRange = 10, XCoordinate = 0, YCoordinate = 500 };
RuleSet rules = new RuleSet();
rules.Add(new UnderMaximumRangeRule(unit1, unit2));
//Act
bool success = rules.Validate();
//Assert
Assert.IsFalse(success, "Unit should be outside of max range");
}
示例6: LoadRuleSet
public void LoadRuleSet(Action<IEnumerable<RuleSet>, Exception> onComplete)
{
var list = new List<RuleSet>();
var ruleSet = new RuleSet() { Name = "Default" };
ruleSet.Add(new FileStructureRule()
{
IsEnabled = true,
Name = "Check File Structure",
Description = "Check file structure with template. ",
Template = "default.txt"
});
ruleSet.Add(new OutputPathRule()
{
IsEnabled = true,
Path = "./output/$(Configuration)/",
Name = "Check Build Output Path",
Description = "Check output path for all project files (*.csproj). "
});
ruleSet.Add(new CodeAnalysisRule()
{
IsEnabled = true,
Name = "Run Code Analysis",
Description = "Run code analysis with InspectCode. "
});
list.Add(ruleSet);
if (onComplete != null)
{
onComplete.Invoke(list, null);
}
//throw new NotImplementedException();
}
示例7: FailMinIdealRangeTest
public void FailMinIdealRangeTest()
{
//Assemble
Unit unit1 = new Unit() { MinimumIdealRange = 10, XCoordinate = 0, YCoordinate = 0 };
Unit unit2 = new Unit() { MinimumIdealRange = 10, XCoordinate = 0, YCoordinate = 5 };
RuleSet rules = new RuleSet();
rules.Add(new OverMinimumIdealRangeRule(unit1, unit2));
//Act
bool success = rules.Validate();
//Assert
Assert.IsFalse(success, "Unit should be inside of min ideal range");
}
示例8: TestEngine
public static void TestEngine()
{
TagReplacementWatchers watchers;
DataLookupTag dlt;
Rule rule;
RuleSet rules = new RuleSet();
rule = new Rule("root");
rule.Priority = 2; rule.MinPriority = 1;
rule.Output = new Content();
rule.Output.Add("Hello. ");
rule.Output.Add(new Tag("cats"));
rule.Expression = Expression.Parse("value? 2 >=");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("cats");
rule.Output = new Content();
dlt = new DataLookupTag("value");
dlt.AddWatcher(new CardinalFilter());
rule.Output.Add(dlt);
rule.Output.Add(" (");
rule.Output.Add(new DataLookupTag("value"));
rule.Output.Add(") cat");
dlt = new DataLookupTag("value");
dlt.AddWatcher(new PluraliseFilter());
rule.Output.Add(dlt);
rule.Output.Add(" in a bag, here is the ");
dlt = new DataLookupTag("value");
dlt.AddWatcher(new OrdinalFilter());
rule.Output.Add(dlt);
rule.Output.Add(" (");
dlt = new DataLookupTag("value");
dlt.AddWatcher(new OrdinalSuffixFilter());
rule.Output.Add(dlt);
rule.Output.Add(")");
rule.AddWatcher(new SentenceFilter());
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("root");
rule.Frequency = 2;
rule.Output = new Content();
rule.Output.Add("Hi ");
watchers = new TagReplacementWatchers();
watchers.Add(new AsClause("name"));
rule.Output.Add(new Tag("nickname", watchers));
rule.Output.Add("! Do you mind if I call you '");
rule.Output.Add(new DataLookupTag("name"));
rule.Output.Add("'?");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("nickname");
rule.Output = new Content();
rule.Output.Add("mate");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("nickname");
rule.Output = new Content();
rule.Output.Add("buddy");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("nickname");
rule.Output = new Content();
rule.Output.Add("dude");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("nickname");
rule.Output = new Content();
rule.Output.Add("man");
rules.Add(rule);
Console.WriteLine(rule.ToString());
rule = new Rule("nickname");
rule.Output = new Content();
rule.Output.Add("friendo");
rules.Add(rule);
Console.WriteLine(rule.ToString());
Engine engine = new Engine(rules);
Namespace data = new Namespace();
data.Set("value", 2);
string result = engine.Run("root", data);
Console.WriteLine("........................................................................");
Console.WriteLine(result);
Console.WriteLine("........................................................................");
Console.WriteLine("Final data:");
Console.WriteLine(data.ToString(" "));
}
示例9: Main
/// <summary>
/// Program entry point.
/// </summary>
/// <example>
/// -r "f:\_E_\SolutionTool" -t default.xml -b "./output/$(Configuration)/" -i "f:\_E_\jb-cl\inspectcode.exe" -l slntool.log
/// </example>
/// <param name="args"></param>
static void Main(string[] args)
{
Debug.Listeners.Add(new ConsoleTraceListener());
var options = new Options();
var parser = new Parser();
if (!Parser.Default.ParseArguments(args, options))
{
return;
}
Console.WriteLine("Begin checking " + options.Repository);
var pathOfRepository = Path.GetFullPath(options.Repository);
var pathOfTemplate = Path.GetFullPath(options.Template);
if (!Directory.Exists(pathOfRepository))
{
Console.WriteLine("Repository directory does not exist: [" + options.Repository + "]");
}
if (!File.Exists(pathOfTemplate))
{
Console.WriteLine("Template File does not exist: [" + options.Repository + "]");
}
else
{
var di = new DirectoryInfo(pathOfRepository);
var fi = new DirectoryInfo(pathOfTemplate);
var project = new Project { Name = di.Name, Path = pathOfRepository, CreateTime = DateTime.Now, };
var ruleSet = new RuleSet
{
new FileStructureRule
{
Name = "File Structure Rule",
IsEnabled = true,
Template = fi.Name,
},
new OutputPathRule
{
Name = "Output Path Rule",
IsEnabled = true,
Path = options.OutputBuildPath,
},
};
if (!string.IsNullOrWhiteSpace(options.InspectCodeExePath))
{
ruleSet.Add(new CodeAnalysisRule
{
Name = "Code Analysis Rule",
IsEnabled = true,
Path = options.InspectCodeExePath,
});
}
var ruleRunner = new RuleRunner();
project.RuleSet = ruleSet;
ruleRunner.RunProject(project, (report,log) =>
{
if (report != null)
{
Console.WriteLine(report.GetText());
}
if (!string.IsNullOrWhiteSpace(options.LogFile))
{
var logFile = Path.GetFullPath(options.LogFile);
using (var sw = File.AppendText(logFile))
{
sw.Write(report.GetText());
}
}
});
}
Console.WriteLine("Checking is done. ");
Console.ReadKey();
}