/// <summary> /// Creates a Stump contract from a Stump data entity. /// </summary> /// <param name="serverId">The unique identifier for the server.</param> /// <param name="entity">The <see cref="StumpEntity"/> used to create the contract.</param> /// <param name="dataAccess">The data access provider used by the instance.</param> /// <returns> /// A <see cref="StumpContract"/> created from the specified <paramref name="entity"/>. /// </returns> public static StumpContract CreateContractFromEntity(string serverId, StumpEntity entity, IDataAccess dataAccess) { var contract = new StumpContract { OriginalRequest = new RecordedRequest(new HttpRequestEntityReader(serverId, entity.OriginalRequest, dataAccess), ContentDecoderHandling.DecodeNotRequired), OriginalResponse = new RecordedResponse(new HttpResponseEntityReader(serverId, entity.OriginalResponse, dataAccess), ContentDecoderHandling.DecodeNotRequired), Response = new RecordedResponse(new HttpResponseEntityReader(serverId, entity.Response, dataAccess), ContentDecoderHandling.DecodeNotRequired), Rules = new RuleContractCollection(), StumpCategory = entity.StumpName, StumpId = entity.StumpId, StumpName = entity.StumpName, }; foreach (var ruleEntity in entity.Rules) { var rule = new RuleContract { RuleName = ruleEntity.RuleName }; foreach (var value in ruleEntity.Settings) { var setting = new RuleSetting { Name = value.Name, Value = value.Value }; rule.AppendRuleSetting(setting); } contract.Rules.Add(rule); } return(contract); }
/// <summary> /// Appends a <see cref="RuleSetting"/> to the contract. /// </summary> /// <param name="setting">The <see cref="RuleSetting"/> to add to the contract.</param> public void AppendRuleSetting(RuleSetting setting) { if (setting == null || string.IsNullOrWhiteSpace(setting.Name) || setting.Value == null) { return; } _ruleSettings.Add(setting); }
/// <summary> /// Appends a <see cref="T:Stumps.RuleSetting"/> to the contract. /// </summary> /// <param name="setting">The <see cref="T:Stumps.RuleSetting"/> to add to the contract.</param> public void AppendRuleSetting(RuleSetting setting) { if (setting == null || string.IsNullOrWhiteSpace(setting.Name) || setting.Value == null) { return; } _ruleSettings.Add(setting); }
public Game(Mahjongs.Game source) { displayRoundCount = source.DisplayRoundCount; firstDealer = source.firstDealer; riichiScore = source.riichiScore; roundWindCount = source.RoundWindCount; rule = source.rule; scores = source.scoreOwners.Select(_ => _.score).ToArray(); 本場 = source.本場; 連荘 = source.連荘; }
/// <summary> /// Creates a Stump contract from a Stump data entity. /// </summary> /// <param name="serverId">The unique identifier for the server.</param> /// <param name="entity">The <see cref="T:Stumps.Server.Data.StumpEntity"/> used to create the contract.</param> /// <param name="dataAccess">The data access provider used by the instance.</param> /// <returns> /// A <see cref="T:Stumps.Server.StumpContract"/> created from the specified <paramref name="entity"/>. /// </returns> public static StumpContract CreateContractFromEntity(string serverId, StumpEntity entity, IDataAccess dataAccess) { var contract = new StumpContract { OriginalRequest = new RecordedRequest(new HttpRequestEntityReader(serverId, entity.OriginalRequest, dataAccess), ContentDecoderHandling.DecodeNotRequired), OriginalResponse = new RecordedResponse(new HttpResponseEntityReader(serverId, entity.OriginalResponse, dataAccess), ContentDecoderHandling.DecodeNotRequired), Response = new RecordedResponse(new HttpResponseEntityReader(serverId, entity.Response, dataAccess), ContentDecoderHandling.DecodeNotRequired), ResponseDelay = entity.ResponseDelay, Rules = new RuleContractCollection(), StumpCategory = entity.StumpName, StumpId = entity.StumpId, StumpName = entity.StumpName, TerminateConnection = entity.TerminateConnection }; foreach (var ruleEntity in entity.Rules) { var rule = new RuleContract { RuleName = ruleEntity.RuleName }; foreach (var value in ruleEntity.Settings) { var setting = new RuleSetting { Name = value.Name, Value = value.Value }; rule.AppendRuleSetting(setting); } contract.Rules.Add(rule); } return contract; }
private void GetRuleSettings(ParseInfo parseInfo, Scope scope, RuleContext ruleContext) { RuleSetting teamContext = null, playerContext = null; bool setEventType = false, setTeam = false, setPlayer = false; foreach (var setting in ruleContext.Settings) { // Add completion. switch (setting.Setting.Text) { case "Event": AddCompletion(parseInfo, setting.Dot, setting.Value, EventItems); break; case "Team": AddCompletion(parseInfo, setting.Dot, setting.Value, TeamItems); break; case "Player": AddCompletion(parseInfo, setting.Dot, setting.Value, PlayerItems); break; } // Get the value. if (setting.Value != null) { var alreadySet = new Diagnostic("The " + setting.Setting.Text + " rule setting was already set.", setting.Range, Diagnostic.Error); string name = setting.Value.Text; DocRange range = setting.Value.Range; switch (setting.Setting.Text) { case "Event": if (setEventType) { parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet); } EventType = GetMember <RuleEvent>("Event", name, parseInfo.Script.Diagnostics, range); setEventType = true; break; case "Team": if (setTeam) { parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet); } Team = GetMember <Team>("Team", name, parseInfo.Script.Diagnostics, range); setTeam = true; teamContext = setting; break; case "Player": if (setPlayer) { parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet); } Player = GetMember <PlayerSelector>("Player", name, parseInfo.Script.Diagnostics, range); setPlayer = true; playerContext = setting; break; default: parseInfo.Script.Diagnostics.Error("Expected an enumerator of type 'Event', 'Team', or 'Player'.", setting.Setting.Range); break; } } } // Set the event type to player if the event type was not set and player or team was changed. if (!setEventType && ((setPlayer && Player != PlayerSelector.All) || (setTeam && Team != Team.All))) { EventType = RuleEvent.OngoingPlayer; } if (setEventType && EventType == RuleEvent.OngoingGlobal) { // Syntax error if the event type is global and the team type is not default. if (Team != Team.All) { parseInfo.Script.Diagnostics.Error("Can't change rule Team type with an event type of Ongoing Global.", teamContext.Range); } // Syntax error if the event type is global and the player type is not default. if (Player != PlayerSelector.All) { parseInfo.Script.Diagnostics.Error("Can't change rule Player type with an event type of Ongoing Global.", playerContext.Range); } } }
/// <summary> /// Reads the configuration found in the given string. This method is cumulative, so calling it /// multiple times will add to the total configuration. /// </summary> /// <param name="config">A configuration string.</param> /// <exception cref="MalformedRuleConfiguration">Throw if the configuration string cannot be /// parsed.</exception> public void ReadConfiguration(string config) { var individualSettings = Regex.Split(config, "\r?\n"); foreach (var individualSetting in individualSettings) { if (individualSetting.StartsWith("#")) continue; // comment line var trimmed = individualSetting.Trim(); if ("".Equals(trimmed)) continue; // empty line var parts = Regex.Split(trimmed, "\\.|="); if (parts.Length != 3) throw new MalformedRuleConfiguration(string.Format("Setting is malformed, must be on the form Rule.Setting=Value: " + trimmed)); var rule = parts[0]; var setting = parts[1].TrimEnd(); var value = parts[2].Trim(); var rs = new RuleSetting {Name = setting, Value = value}; IList<RuleSetting> settingsList; if (!_rulesSettings.TryGetValue(rule, out settingsList)) { settingsList = new List<RuleSetting>(); _rulesSettings.Add(rule, settingsList); } if (settingsList.Where(s => s.Name.Equals(setting)).Count() > 0) throw new MalformedRuleConfiguration("Duplicate setting: " + trimmed); settingsList.Add(rs); } }