public static RuleViolationCollection ToRuleViolationList(this ModelStateDictionary modelState) { if (modelState.IsValid) { return(new RuleViolationCollection()); } else { var ruleViolations = new RuleViolationCollection(); var modelStateErrors = modelState .Where(x => x.Value.Errors.Any()) .ToDictionary(key => key.Key, value => value.Value.Errors.Select(x => x.ErrorMessage)).ToList(); modelStateErrors.ForEach(modelStateError => { ruleViolations.AddRange(modelStateError.Value.Select(error => new RuleViolation() { Field = modelStateError.Key, ErrorMessage = error })); }); return(ruleViolations); } }
public BLLResult() { IsSuccess = false; FieldErrorList = new RuleViolationCollection(); ErrorMessage = ""; Model = null; }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCode.ToLines(); lines.ForEachWithIndex((i, line) => { if (line.Length > MaxLineLength) { var violationText = "Line {0} has {1} symbols".Formatted(i + 1, line.Length); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned .ToLines(); lines.ForEachWithIndex((i, line) => { if (Regex.Match(line, "\\s+$").Captures.Count > 0) { var violationText = "Line {0} has trailing white spaces".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned .ToLines(); lines.ForEachWithIndex((i, line) => { if (line.Contains("goto")) { var violationText = "Line {0} with use of goto".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } }); }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned.ToLines(); var nesting = 0; // Remove brackets but preserve lines lines.ForEachWithIndex((i, line) => { foreach (var ch in line) { if (ch == '{') { nesting++; } if (ch == '}') { nesting--; } if (MaxNumberOfScopesValue < nesting) { var violationText = "Too deep nesting in line {0} - {1} scopes".Formatted(i + 1, nesting); var violation = new RuleViolation(violationText); Violations.Add(violation); } else if (nesting < 0) { var violationText = "} with no matching { on line {0}".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } } }); if (nesting > 0) { var violationText = "{ with no matching } on line {0}".Formatted(lines.Count); var violation = new RuleViolation(violationText); Violations.Add(violation); } }
public void Apply(RuleContext context) { Violations = new RuleViolationCollection(); var lines = context.SourceCodeCleaned.ToLines(); var nesting = 0; // Remove brackets but preserve lines lines.ForEachWithIndex((i, line) => { foreach (var ch in line) { if (ch == '{') nesting++; if (ch == '}') nesting--; if (MaxNumberOfScopesValue < nesting) { var violationText = "Too deep nesting in line {0} - {1} scopes".Formatted(i+1,nesting); var violation = new RuleViolation(violationText); Violations.Add(violation); } else if (nesting < 0) { var violationText = "} with no matching { on line {0}".Formatted(i + 1); var violation = new RuleViolation(violationText); Violations.Add(violation); } } }); if (nesting > 0) { var violationText = "{ with no matching } on line {0}".Formatted(lines.Count); var violation = new RuleViolation(violationText); Violations.Add(violation); } }
public void Start() { dispatcher = new Dispatcher(); scheduler = new Scheduler(dispatcher); listeners = new List <Listener>(); listeners.Add(new Listener(7171, socket => new LoginConnection(this, socket))); listeners.Add(new Listener(7172, socket => new GameConnection(this, socket))); Clock = new Clock(12, 0); Logger = new Logger(); Channels = new ChannelCollection(); RuleViolations = new RuleViolationCollection(); PacketsFactory = new PacketsFactory(); using (Logger.Measure("Loading items", true)) { var otb = OtbFile.Load("data/items/items.otb"); var dat = DatFile.Load("data/items/tibia.dat"); var items = ItemsFile.Load("data/items/items.xml"); ItemFactory = new ItemFactory(otb, dat, items); } using (Logger.Measure("Loading monsters", true)) { var monsters = MonsterFile.Load("data/monsters"); MonsterFactory = new MonsterFactory(monsters); } using (Logger.Measure("Loading npcs", true)) { var npcs = NpcFile.Load("data/npcs"); NpcFactory = new NpcFactory(npcs); } using (Logger.Measure("Loading map", true)) { var otbm = OtbmFile.Load("data/map/pholium3.otbm"); Map = new Map(ItemFactory, otbm); } Pathfinding = new Pathfinding(Map); Events = new EventsCollection(); Scripts = new ScriptsCollection(); using (Logger.Measure("Loading scripts", true)) { Scripts.Start(this); } dispatcher.Start(); scheduler.Start(); foreach (var listener in listeners) { listener.Start(); } Logger.WriteLine("Server online"); }