protected static TBaseStatus[] Convert <TStatus>(TStatus[] statuses) where TStatus : struct { if (statuses == null) { return(null); } var result = new TBaseStatus[statuses.Length]; for (int i = 0; i < statuses.Length; ++i) { result[i] = BaseStatusSystem <TObject, TBaseStatus> .Convert(statuses[i]); } return(result); }
internal BaseStatusTracker(TObject obj, BaseStatusSystem <TObject, TBaseStatus> rules) { this.obj = obj; this.rules = rules; if (rules != null) { rules.TrackerCreated = true; } currentActualValues = new DefaultValueDictionary <TBaseStatus, int>(); currentRaw = new Dictionary <SourceType, DefaultValueDictionary <TBaseStatus, int> >(); sources = new Dictionary <SourceType, MultiValueDictionary <TBaseStatus, Source <TObject, TBaseStatus> > >(); internalFeeds = new Dictionary <SourceType, Dictionary <TBaseStatus, Dictionary <TBaseStatus, int> > >(); changeStack = new List <DefaultValueDictionary <StatusChange <TBaseStatus>, OnChangedHandler <TObject, TBaseStatus> > >(); foreach (SourceType type in Enum.GetValues(typeof(SourceType))) { currentRaw[type] = new DefaultValueDictionary <TBaseStatus, int>(); sources[type] = new MultiValueDictionary <TBaseStatus, Source <TObject, TBaseStatus> >(); internalFeeds[type] = new Dictionary <TBaseStatus, Dictionary <TBaseStatus, int> >(); } }
/// <summary> /// Open "<paramref name="filename"/>" and parse its text as rules. Apply the parsed rules to "<paramref name="rules"/>". /// </summary> public static BaseStatusSystem <TObject, TBaseStatus> ParseRulesText <TObject, TBaseStatus>( this BaseStatusSystem <TObject, TBaseStatus> rules, string filename) where TBaseStatus : struct { if (!File.Exists(filename)) { throw new FileNotFoundException($"{filename} cannot be found here."); } List <string> text = new List <string>(); using (StreamReader stream = new StreamReader(filename)) { while (true) { string line = stream.ReadLine(); if (line == null) { break; } text.Add(line); } } return(rules.ParseRulesText(text)); }
internal StatusParserInternal(BaseStatusSystem <TObject, TBaseStatus> rules, List <string> tokens) { this.rules = rules; this.tokens = tokens; extraEnums = rules.extraEnumTypes; if (rules.DefaultValueAggregator == rules.Total) { rulesDefaultAggregator = "total"; } else if (rules.DefaultValueAggregator == rules.Bool) { rulesDefaultAggregator = "bool"; } else if (rules.DefaultValueAggregator == rules.MaximumOrZero) { rulesDefaultAggregator = "max"; } else { rulesDefaultAggregator = null; } parserDefaultAggregator = rulesDefaultAggregator; parserDefaultSourceLimit = "multiple"; }
/// <summary> /// Parse "<paramref name="text"/>" as rules. Apply the parsed rules to "<paramref name="rules"/>". /// </summary> public static BaseStatusSystem <TObject, TBaseStatus> ParseRulesText <TObject, TBaseStatus>( this BaseStatusSystem <TObject, TBaseStatus> rules, IEnumerable <string> text) where TBaseStatus : struct { new StatusParserInternal <TObject, TBaseStatus>(rules, Tokenize(text)).Parse(); return(rules); }
internal StatusRules(BaseStatusSystem <TObject, TBaseStatus> rules, TBaseStatus status) : base(rules, status, status) { this.rules = rules; this.status = status; }
protected static TBaseStatus Convert <TStatus>(TStatus status) where TStatus : struct { return(BaseStatusSystem <TObject, TBaseStatus> .Convert(status)); }
internal RuleChecker(BaseStatusSystem <TObject, TStatus> rules) { visitedRps = new DefaultHashSet <List <TStatus> >(new IEnumValueEquality <TStatus>()); // Compare lists with value equality! this.rules = rules; CheckRules(); }
internal StatusTracker(TObject obj, BaseStatusSystem <TObject, int> rules) : base(obj, rules) { }