private Condition compile(string conditionText) { var settings = new ConditionSettings(conditionText, PowerStatus.Undefined, ConditionType.Regular, "", new Socket(1, "")); var compiler = new ConditionCompiler(); return(compiler.Compile(new List <ConditionSettings>() { settings }).FirstOrDefault()); }
public void Seed() { if (!Configurations.Any()) { var config = new List <ApiConfiguration> { new ApiConfiguration() { AcceptedSpeed = 2, LimitSpeed = 5, PriceThreshold = 0.04, LastNotification = DateTime.UtcNow.AddMinutes(-15), MinimalAcceptedSpeed = 0.4, AcceptedPercentThreshold = 0.1, EnableAudit = true, TotalHashThreshold = 0.8, } }; AddRange(config); } foreach (var condition in Registry.GetConditions()) { var name = condition.Name; var priority = Registry.GetPriority(condition); var dbCondition = ConditionSettings.FirstOrDefault(c => c.ConditionName == name); if (dbCondition == null) { var setting = new ConditionSetting() { ConditionID = priority, ConditionName = name, Enabled = true }; Add(setting); } else if (dbCondition.ConditionID != priority) { dbCondition.ConditionID = priority; } } SaveChanges(); }
/// <summary> /// Evaluates <see cref="AdvancedSolverSettings.PseudoAttributeConstraints"/> and converts each /// PseudoAttribute into a list of the attribute names that evaluated to true and their conversion multiplier. /// </summary> private List <ConvertedPseudoAttributeConstraint> EvalPseudoAttrConstraints() { var keystones = from node in Settings.Checked where SkillTree.Skillnodes[node].IsKeyStone select SkillTree.Skillnodes[node].Name; var conditionSettings = new ConditionSettings(Settings.Tags, Settings.OffHand, keystones.ToArray(), Settings.WeaponClass); var resolvedWildcardNames = new Dictionary <string, List <Tuple <string, string[]> > >(); var convertedPseudos = new List <ConvertedPseudoAttributeConstraint>(Settings.PseudoAttributeConstraints.Count); foreach (var pair in Settings.PseudoAttributeConstraints) { var convAttrs = new List <Tuple <string, float> >(pair.Key.Attributes.Count); foreach (var attr in pair.Key.Attributes) { var name = attr.Name; if (ContainsWildcardRegex.IsMatch(name)) { // Wildcards are resolverd by searching the skill tree attributes for each attribute // that matches the attribute name ('{number}' replaced by '(.*)' for matching) and // evaluating the attribute for each of those replacements. if (!resolvedWildcardNames.ContainsKey(name)) { var searchRegex = new Regex("^" + ContainsWildcardRegex.Replace(name, "(.*)") + "$"); resolvedWildcardNames[name] = (from a in SkillTree.AllAttributes let match = searchRegex.Match(a) where match.Success select Tuple.Create(a, ExtractGroupValuesFromGroupCollection(match.Groups))).ToList(); } convAttrs.AddRange(from replacement in resolvedWildcardNames[name] where attr.Evaluate(conditionSettings, replacement.Item2) select Tuple.Create(replacement.Item1, attr.ConversionMultiplier)); } else if (attr.Evaluate(conditionSettings)) { convAttrs.Add(Tuple.Create(name, attr.ConversionMultiplier)); } } var convPseudo = new ConvertedPseudoAttributeConstraint(convAttrs, pair.Value); convertedPseudos.Add(convPseudo); } return(convertedPseudos); }
private IEnumerable <ConditionSettings> readConditions(XElement socketNode) { var socket = new Socket( id: int.Parse(socketNode.Attribute("id").Value), name: socketNode.Attribute("name").Value); string startupAttributeValue = socketNode.Element("conditions").Attribute("startupState").Value.ToLower(); var startupStatus = new ConditionSettings( text: "", resultingStatus: convertStringToPowerStatus(startupAttributeValue), type: ConditionType.Startup, mode: "", socket: socket); string shutdownAttributeValue = socketNode.Element("conditions").Attribute("shutdownState").Value.ToLower(); var shutdownStatus = new ConditionSettings( text: "", resultingStatus: convertStringToPowerStatus(shutdownAttributeValue), type: ConditionType.Shutdown, mode: "", socket: socket); var regularConditions = socketNode.Element("conditions").Elements().Where(x => !string.IsNullOrEmpty(x.Value)).Select(x => { return(new ConditionSettings( text: x.Value, resultingStatus: convertStringToPowerStatus(x.Name.ToString()), type: ConditionType.Regular, mode: x.Attribute("mode") == null ? "" : x.Attribute("mode").Value, socket: socket)); }).ToList(); var conditions = new List <ConditionSettings>(); conditions.Add(startupStatus); conditions.Add(shutdownStatus); conditions.AddRange(regularConditions); return(conditions); }
/// <summary> /// Converts attribute constraints to pseudo attribute constraints with the set Tags, WeaponClass, /// OffHand and check-tagged keystones where possible. /// Str, Int and Dex are not removed from the attribute constraint list but still converted. /// </summary> private void ConverteAttributeToPseudoAttributeConstraints() { var keystones = from node in Tree.GetCheckedNodes() where node.Type == NodeType.Keystone select node.Name; var conditionSettings = new ConditionSettings(Tags.Value, OffHand.Value, keystones.ToArray(), WeaponClass.Value); var convertedConstraints = new List <AttributeConstraint>(); foreach (var attributeConstraint in AttributeConstraints) { var attrName = attributeConstraint.Data; // Select the pseudo attributes and the multiplier for attributes which match the given one and evaluate to true. var pseudos = from pseudo in _pseudoAttributes let matches = (from attr in pseudo.Attributes where attr.MatchesAndEvaluates(conditionSettings, attrName) select attr) where matches.Any() select new { PseudoAttribute = pseudo, Multiplier = matches.First().ConversionMultiplier }; // Add attribute target and weight to the pseudo attributes. var converted = false; foreach (var pseudo in pseudos) { var pseudoAttribute = pseudo.PseudoAttribute; converted = true; if (_addedPseudoAttributes.Contains(pseudoAttribute)) { foreach (var pseudoAttributeConstraint in PseudoAttributeConstraints) { if (pseudoAttributeConstraint.Data == pseudoAttribute) { pseudoAttributeConstraint.TargetValue += attributeConstraint.TargetValue * pseudo.Multiplier; } } } else { _addedPseudoAttributes.Add(pseudoAttribute); PseudoAttributeConstraints.Add(new PseudoAttributeConstraint(pseudoAttribute) { TargetValue = attributeConstraint.TargetValue * pseudo.Multiplier }); } } if (converted && attrName != "+# to Intelligence" && attrName != "+# to Dexterity" && attrName != "+# to Strength") { convertedConstraints.Add(attributeConstraint); } } // Update the attribute constraint related collections. foreach (var convertedConstraint in convertedConstraints) { _addedAttributes.Remove(convertedConstraint.Data); AttributeConstraints.Remove(convertedConstraint); } if (convertedConstraints.Count > 0) { AttributesView.Refresh(); NewAttributeConstraint = convertedConstraints[0]; PseudoAttributesView.Refresh(); PseudoAttributesView.MoveCurrentToFirst(); NewPseudoAttributeConstraint.Data = PseudoAttributesView.CurrentItem as PseudoAttribute; } }