public void SetupInfrastructure() { var metadata = new ScenarioMetadata { FeatureName = FeatureContext.FeatureInfo.Title, ScenarioName = ScenarioContext.ScenarioInfo.Title }; Register(metadata); var factory = new PossumLabs.Specflow.Core.Variables.ObjectFactory(); Register(factory); Register(new PossumLabs.Specflow.Core.Variables.Interpeter(factory)); var logger = new DefaultLogger(new DirectoryInfo(Environment.CurrentDirectory)); Register((PossumLabs.Specflow.Core.Logging.ILog)logger); Register(new PossumLabs.Specflow.Core.Exceptions.ActionExecutor(logger)); Register(new FileManager(new DatetimeManager() { Now = () => DateTime.Now })); FileManager.Initialize(FeatureContext.FeatureInfo.Title, ScenarioContext.ScenarioInfo.Title, null /*Specflow limitation*/); var templateManager = new PossumLabs.Specflow.Core.Variables.TemplateManager(); templateManager.Initialize(Assembly.GetExecutingAssembly()); Register(templateManager); Log.Message($"feature: {FeatureContext.FeatureInfo.Title} scenario: {ScenarioContext.ScenarioInfo.Title} \n" + $"Tags: {FeatureContext.FeatureInfo.Tags.LogFormat()} {ScenarioContext.ScenarioInfo.Tags.LogFormat()}"); }
/// <summary> /// Loads a unit type definition from the given XML node. /// </summary> /// <param name="unitTypeElem">The XML node to load from.</param> /// <param name="metadata">The metadata object being constructed.</param> private static void LoadUnitType(XElement unitTypeElem, ScenarioMetadata metadata) { XAttribute nameAttr = unitTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Unit type name not defined!"); } UnitType unitType = new UnitType(nameAttr.Value, metadata); LoadScenarioElementType(unitTypeElem, unitType, metadata); XElement createdInElem = unitTypeElem.Element(XmlMetadataConstants.CREATEDIN_ELEM); if (createdInElem != null) { Tuple <string, string> createdIn = ParseBuildingAddonStr(createdInElem.Value); unitType.SetCreatedIn(createdIn.Item1); if (createdIn.Item2 != null) { unitType.SetNecessaryAddonName(createdIn.Item2); } } metadata.AddUnitType(unitType); }
public MovieLogger(MovieLoggerConfig movieLoggerConfig, ScenarioMetadata scenarioMetadata) { ScenarioMetadata = scenarioMetadata; MovieLoggerConfig = movieLoggerConfig; Stopwatch = Stopwatch.StartNew(); StepLogger = new SrtLogger("step"); OtherLogger = new SrtLogger("other"); Images = new List <Tuple <TimeSpan, byte[]> >(); }
/// <summary> /// Loads a missile type definition from the given XML node. /// </summary> /// <param name="missileTypeElem">The XML node to load from.</param> /// <param name="metadata">The metadata object being constructed.</param> private static void LoadMissileType(XElement missileTypeElem, ScenarioMetadata metadata) { XAttribute nameAttr = missileTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Missile type name not defined!"); } MissileType missileType = new MissileType(nameAttr.Value, metadata); LoadScenarioElementType(missileTypeElem, missileType, metadata); XElement launchAnimElem = missileTypeElem.Element(XmlMetadataConstants.LAUNCHANIMATION_ELEM); if (launchAnimElem != null) { XAttribute launchDelayAttr = launchAnimElem.Attribute(XmlMetadataConstants.LAUNCH_DELAY_ATTR); if (launchDelayAttr == null) { throw new SimulatorException("Launch delay not defined for missile type!"); } int launchDelay = XmlHelper.LoadInt(launchDelayAttr.Value); missileType.SetLaunchAnimation(launchAnimElem.Value, launchDelay); } XElement flyingAnimElem = missileTypeElem.Element(XmlMetadataConstants.FLYINGANIMATION_ELEM); if (flyingAnimElem != null) { missileType.SetFlyingAnimation(flyingAnimElem.Value); } XElement trailAnimElem = missileTypeElem.Element(XmlMetadataConstants.TRAILANIMATION_ELEM); if (trailAnimElem != null) { XAttribute trailAnimFreqAttr = trailAnimElem.Attribute(XmlMetadataConstants.TRAILANIMATION_FREQUENCY_ATTR); if (trailAnimFreqAttr == null) { throw new SimulatorException("Trail animation frequency not defined for missile type!"); } int trailAnimFreq = XmlHelper.LoadInt(trailAnimFreqAttr.Value); missileType.SetTrailAnimation(trailAnimElem.Value, trailAnimFreq); } XElement impactAnimElem = missileTypeElem.Element(XmlMetadataConstants.IMPACTANIMATION_ELEM); if (impactAnimElem != null) { missileType.SetImpactAnimation(impactAnimElem.Value); } metadata.AddMissileType(missileType); }
/// <summary> /// Loads an upgrade effect definition from the given XML node. /// </summary> /// <param name="effectElem">The XML node to load from.</param> /// <param name="metadata">The metadata object.</param> /// <returns>The constructed upgrade effect definition.</returns> private static UpgradeEffectBase LoadUpgradeEffect(XElement effectElem, ScenarioMetadata metadata) { string actionName = effectElem.Name.ToString(); XAttribute targetTypeAttr = effectElem.Attribute(XmlMetadataConstants.EFFECT_TARGETTYPE_ATTR); if (targetTypeAttr == null) { throw new SimulatorException("Target type not defined for an upgrade effect!"); } return(UpgradeEffectFactory.CreateUpgradeEffect(actionName, effectElem.Value, targetTypeAttr.Value, metadata)); }
/// <summary> /// Loads a building type definition from the given XML node. /// </summary> /// <param name="buildingTypeElem">The XML node to load from.</param> /// <param name="metadata">The metadata object being constructed.</param> private static void LoadBuildingType(XElement buildingTypeElem, ScenarioMetadata metadata) { XAttribute nameAttr = buildingTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Building type name not defined!"); } BuildingType buildingType = new BuildingType(nameAttr.Value, metadata); LoadScenarioElementType(buildingTypeElem, buildingType, metadata); metadata.AddBuildingType(buildingType); }
public void SetupInfrastructure() { var metadata = new ScenarioMetadata { FeatureName = FeatureContext.FeatureInfo.Title, ScenarioName = ScenarioContext.ScenarioInfo.Title }; Register(metadata); var factory = new PossumLabs.Specflow.Core.Variables.ObjectFactory(); Register(factory); Register(new PossumLabs.Specflow.Core.Variables.Interpeter(factory)); var logger = new DefaultLogger(new DirectoryInfo(Environment.CurrentDirectory)); Register((PossumLabs.Specflow.Core.Logging.ILog)logger); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); var configFactory = new ConfigurationFactory(config); ObjectContainer.RegisterInstanceAs(configFactory.Create <MovieLoggerConfig>()); ObjectContainer.RegisterInstanceAs(configFactory.Create <ImageLoggingConfig>()); Register <ElementFactory>(new ElementFactory()); Register <XpathProvider>(new XpathProvider()); Register <SelectorFactory>(new SelectorFactory(ElementFactory, XpathProvider).UseBootstrap()); Register(new PossumLabs.Specflow.Selenium.WebDriverManager( this.Interpeter, this.ObjectFactory, new PossumLabs.Specflow.Selenium.Configuration.SeleniumGridConfiguration())); Log.Message($"feature: {FeatureContext.FeatureInfo.Title} scenario: {ScenarioContext.ScenarioInfo.Title} \n" + $"Tags: {FeatureContext.FeatureInfo.Tags.LogFormat()} {ScenarioContext.ScenarioInfo.Tags.LogFormat()}"); WebDriverManager.Initialize(BuildDriver); }
/// <summary> /// Loads an upgrade type definition from the given XML node. /// </summary> /// <param name="upgradeTypeElem">The XML node to load from.</param> /// <param name="metadata">The metadata object being constructed.</param> private static void LoadUpgradeType(XElement upgradeTypeElem, ScenarioMetadata metadata) { XAttribute nameAttr = upgradeTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Upgrade type name not defined!"); } UpgradeType upgradeType = new UpgradeType(nameAttr.Value, metadata); LoadScenarioElementType(upgradeTypeElem, upgradeType, metadata); XElement researchedInElem = upgradeTypeElem.Element(XmlMetadataConstants.RESEARCHEDIN_ELEM); if (researchedInElem != null) { upgradeType.SetResearchedIn(researchedInElem.Value); } XElement previousLevelElem = upgradeTypeElem.Element(XmlMetadataConstants.PREVIOUSLEVEL_ELEM); if (previousLevelElem != null) { upgradeType.SetPreviousLevelName(previousLevelElem.Value); } XElement effectsElem = upgradeTypeElem.Element(XmlMetadataConstants.EFFECTS_ELEM); if (effectsElem != null) { foreach (XElement effectElem in effectsElem.Elements()) { upgradeType.AddEffect(LoadUpgradeEffect(effectElem, metadata)); } } metadata.AddUpgradeType(upgradeType); }
public void SetupInfrastructure() { var metadata = new ScenarioMetadata { FeatureName = FeatureContext.FeatureInfo.Title, ScenarioName = ScenarioContext.ScenarioInfo.Title }; Register(metadata); var factory = new PossumLabs.Specflow.Core.Variables.ObjectFactory(); Register(factory); Register(new PossumLabs.Specflow.Core.Variables.Interpeter(factory)); var logger = new DefaultLogger(new DirectoryInfo(Environment.CurrentDirectory)); Register((PossumLabs.Specflow.Core.Logging.ILog)logger); var templateManager = new PossumLabs.Specflow.Core.Variables.TemplateManager(); templateManager.Initialize(Assembly.GetExecutingAssembly()); Register(templateManager); }
/// <summary> /// Loads an addon type definition from the given XML node. /// </summary> /// <param name="addonTypeElem">The XML node to load from.</param> /// <param name="metadata">The metadata object being constructed.</param> private static void LoadAddonType(XElement addonTypeElem, ScenarioMetadata metadata) { XAttribute nameAttr = addonTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Addon type name not defined!"); } AddonType addonType = new AddonType(nameAttr.Value, metadata); LoadScenarioElementType(addonTypeElem, addonType, metadata); XElement mainBuildingElem = addonTypeElem.Element(XmlMetadataConstants.MAINBUILDING_ELEM); if (mainBuildingElem == null) { throw new SimulatorException("Main building not found for addon type!"); } addonType.SetMainBuilding(mainBuildingElem.Value); metadata.AddAddonType(addonType); }
/// <summary> /// Loads a missile definition from the given XML node. /// </summary> /// <param name="missileElem">The XML node to load from.</param> /// <param name="metadata">The metadata object.</param> /// <returns>The constructed missile definition.</returns> private static MissileData LoadMissileData(XElement missileElem, ScenarioMetadata metadata) { XAttribute missileTypeAttr = missileElem.Attribute(XmlMetadataConstants.WPN_MISSILE_TYPE_ATTR); if (missileTypeAttr == null) { throw new SimulatorException("Missile type not defined!"); } MissileData missile = new MissileData(missileTypeAttr.Value, metadata); foreach (XElement launchElem in missileElem.Elements(XmlMetadataConstants.WPN_MISSILE_LAUNCH_ELEM)) { XAttribute directionAttr = launchElem.Attribute(XmlMetadataConstants.WPN_MISSILE_LAUNCH_DIR_ATTR); XAttribute positionAttr = launchElem.Attribute(XmlMetadataConstants.WPN_MISSILE_LAUNCH_POS_ATTR); if (directionAttr == null) { throw new SimulatorException("Direction not defined for missile data launch position!"); } if (positionAttr == null) { throw new SimulatorException("Relative position not defined for missile data launch position!"); } MapDirection direction; if (!EnumMap <MapDirection, string> .TryDemap(directionAttr.Value, out direction)) { throw new SimulatorException(string.Format("Unexpected MapDirection '{0}' defined in missile data!", directionAttr.Value)); } RCNumVector relativePosition = XmlHelper.LoadNumVector(positionAttr.Value); missile.AddRelativeLaunchPosition(direction, relativePosition); } return(missile); }
public ActionExecutor(ILog logger, ScenarioMetadata metadata) { Logger = logger; Metadata = metadata; IgnoredExceptions = new List <Exception>(); }
/// <summary> /// Loads the weapon data of a building/unit type from the given element. /// </summary> /// <param name="weaponDataElem">The XML element to load from.</param> /// <param name="metadata">The metadata object.</param> private static WeaponData LoadWeaponData(XElement weaponDataElem, ScenarioMetadata metadata) { XAttribute nameAttr = weaponDataElem.Attribute(XmlMetadataConstants.WPN_NAME_ATTR); XAttribute displayedNameAttr = weaponDataElem.Attribute(XmlMetadataConstants.WPN_DISPLAYEDNAME_ATTR); XElement cooldownElem = weaponDataElem.Element(XmlMetadataConstants.WPN_COOLDOWN_ELEM); XElement damageElem = weaponDataElem.Element(XmlMetadataConstants.WPN_DAMAGE_ELEM); XElement damageTypeElem = weaponDataElem.Element(XmlMetadataConstants.WPN_DAMAGETYPE_ELEM); XElement incrementElem = weaponDataElem.Element(XmlMetadataConstants.WPN_INCREMENT_ELEM); XElement rangeMaxElem = weaponDataElem.Element(XmlMetadataConstants.WPN_RANGEMAX_ELEM); XElement rangeMinElem = weaponDataElem.Element(XmlMetadataConstants.WPN_RANGEMIN_ELEM); XElement splashTypeElem = weaponDataElem.Element(XmlMetadataConstants.WPN_SPLASHTYPE_ELEM); if (nameAttr == null) { throw new SimulatorException("Weapon name not defined!"); } WeaponTypeEnum weaponType; if (!EnumMap <WeaponTypeEnum, string> .TryDemap(weaponDataElem.Name.LocalName, out weaponType)) { throw new SimulatorException(string.Format("Unexpected weapon type '{0}' defined in weapon data!", weaponDataElem.Name.LocalName)); } WeaponData weaponData = new WeaponData(nameAttr.Value, metadata, weaponType); if (cooldownElem != null) { weaponData.SetCooldown(XmlHelper.LoadInt(cooldownElem.Value)); } if (damageElem != null) { weaponData.SetDamage(XmlHelper.LoadInt(damageElem.Value)); } if (rangeMaxElem != null) { weaponData.SetRangeMax(XmlHelper.LoadInt(rangeMaxElem.Value)); } if (damageTypeElem != null) { DamageTypeEnum damageType; if (!EnumMap <DamageTypeEnum, string> .TryDemap(damageTypeElem.Value, out damageType)) { throw new SimulatorException(string.Format("Unexpected damage type '{0}' defined in weapon data!", damageTypeElem.Value)); } weaponData.SetDamageType(damageType); } if (displayedNameAttr != null) { weaponData.SetDisplayedName(displayedNameAttr.Value); } if (incrementElem != null) { weaponData.SetIncrement(XmlHelper.LoadInt(incrementElem.Value)); } if (rangeMinElem != null) { weaponData.SetRangeMin(XmlHelper.LoadInt(rangeMinElem.Value)); } if (splashTypeElem != null) { SplashTypeEnum splashType; if (!EnumMap <SplashTypeEnum, string> .TryDemap(splashTypeElem.Value, out splashType)) { throw new SimulatorException(string.Format("Unexpected splash type '{0}' defined in weapon data!", splashTypeElem.Value)); } weaponData.SetSplashType(splashType); } foreach (XElement missileElem in weaponDataElem.Elements(XmlMetadataConstants.WPN_MISSILE_ELEM)) { weaponData.AddMissile(LoadMissileData(missileElem, metadata)); } return(weaponData); }
/// <summary> /// Loads an animation palette definition from the given XML node. /// </summary> /// <param name="animPaletteElem">The XML node to load from.</param> /// <param name="metadata">The metadata object.</param> /// <param name="spritePalette">The sprite palette that the animation palette is based on.</param> /// <returns>The constructed animation palette definition.</returns> private static AnimationPalette LoadAnimationPalette(XElement animPaletteElem, ISpritePalette <MapDirection> spritePalette, ScenarioMetadata metadata) { /// Create the animation palette object. AnimationPalette animPalette = new AnimationPalette(metadata); /// Load the animations. foreach (XElement animElem in animPaletteElem.Elements(XmlMetadataConstants.ANIMATION_ELEM)) { Animation animation = LoadAnimation(animElem, animPalette.Count, spritePalette); animPalette.AddAnimation(animation); } return(animPalette); }
/// <summary> /// Loads the necessary data of a scenario element type. /// </summary> /// <param name="elementTypeElem">The XML node to load from.</param> /// <param name="elementType">The scenario element type being constructed.</param> /// <param name="metadata">The metadata object.</param> private static void LoadScenarioElementType(XElement elementTypeElem, ScenarioElementType elementType, ScenarioMetadata metadata) { /// Load the displayed name of the element type. XAttribute displayedNameAttr = elementTypeElem.Attribute(XmlMetadataConstants.TYPE_DISPLAYEDNAME_ATTR); if (displayedNameAttr != null) { elementType.SetDisplayedName(displayedNameAttr.Value); } /// Load the has owner flag of the element type. XAttribute hasOwnerAttr = elementTypeElem.Attribute(XmlMetadataConstants.TYPE_HASOWNER_ATTR); elementType.SetHasOwner(hasOwnerAttr != null && XmlHelper.LoadBool(hasOwnerAttr.Value)); /// Load the sprite palette of the element type. XElement spritePaletteElem = elementTypeElem.Element(XmlMetadataConstants.SPRITEPALETTE_ELEM); ISpritePalette <MapDirection> spritePalette = null; if (spritePaletteElem != null) { spritePalette = XmlHelper.LoadSpritePalette(spritePaletteElem, MapDirection.Undefined, tmpImageDir); elementType.SetSpritePalette(spritePalette); } /// Load the HP indicator icon palette of this element type. XElement hpIconPaletteElem = elementTypeElem.Element(XmlMetadataConstants.HPICONPALETTE_ELEM); if (hpIconPaletteElem != null) { ISpritePalette hpIconPalette = XmlHelper.LoadSpritePalette(hpIconPaletteElem, tmpImageDir); elementType.SetHPIconPalette(hpIconPalette); } /// Load the animation palette of the element type. XElement animPaletteElem = elementTypeElem.Element(XmlMetadataConstants.ANIMPALETTE_ELEM); if (animPaletteElem != null) { if (spritePalette == null) { throw new SimulatorException("Animation palette definition requires a sprite palette definition!"); } elementType.SetAnimationPalette(LoadAnimationPalette(animPaletteElem, spritePalette, metadata)); } /// Load the cost data of the element type. XElement costsDataElem = elementTypeElem.Element(XmlMetadataConstants.COSTS_ELEM); if (costsDataElem != null) { LoadCostsData(costsDataElem, elementType); } /// Load the general data of the element type. XElement genDataElem = elementTypeElem.Element(XmlMetadataConstants.GENERALDATA_ELEM); if (genDataElem != null) { LoadGeneralData(genDataElem, elementType); } /// Load the shadow data of the element type. XElement shadowDataElem = elementTypeElem.Element(XmlMetadataConstants.SHADOWDATA_ELEM); if (shadowDataElem != null) { LoadShadowData(shadowDataElem, elementType); } /// Load the ground weapon definitions of the element type. foreach (XElement gndWeaponElem in elementTypeElem.Elements(XmlMetadataConstants.GROUNDWEAPON_ELEM)) { elementType.AddWeapon(LoadWeaponData(gndWeaponElem, metadata)); } /// Load the air weapon definitions of the element type. foreach (XElement airWeaponElem in elementTypeElem.Elements(XmlMetadataConstants.AIRWEAPON_ELEM)) { elementType.AddWeapon(LoadWeaponData(airWeaponElem, metadata)); } /// Load the air-ground weapon definitions of the element type. foreach (XElement airGroundWeaponElem in elementTypeElem.Elements(XmlMetadataConstants.AIRGROUNDWEAPON_ELEM)) { elementType.AddWeapon(LoadWeaponData(airGroundWeaponElem, metadata)); } /// Load the custom weapon definitions of the element type. foreach (XElement customWeaponElem in elementTypeElem.Elements(XmlMetadataConstants.CUSTOMWEAPON_ELEM)) { elementType.AddWeapon(LoadWeaponData(customWeaponElem, metadata)); } /// Load the requirements of the element type. XElement requiresElem = elementTypeElem.Element(XmlMetadataConstants.REQUIRES_ELEM); if (requiresElem != null) { string reqListStr = requiresElem.Value.Trim(); string[] requirementStrings = reqListStr.Split(','); foreach (string reqStr in requirementStrings) { Tuple <string, string> buildingAddonPair = ParseBuildingAddonStr(reqStr); elementType.AddRequirement(new Requirement(buildingAddonPair.Item1, buildingAddonPair.Item2, metadata)); } } }
/// <summary> /// Reads metadata from the given XML document and loads it to the given metadata object. /// </summary> /// <param name="xmlStr">The string that contains the XML document to read.</param> /// <param name="imageDir">The directory where the referenced images can be found. (TODO: this is a hack!)</param> /// <param name="metadata">Reference to the metadata object being constructed.</param> public static void Read(string xmlStr, string imageDir, ScenarioMetadata metadata) { if (xmlStr == null) { throw new ArgumentNullException("xmlStr"); } if (imageDir == null) { throw new ArgumentNullException("imageDir"); } if (metadata == null) { throw new ArgumentNullException("metadata"); } tmpImageDir = imageDir; /// Load the XML document. XDocument xmlDoc = XDocument.Parse(xmlStr); /// Load the scenario element type definitions. foreach (XElement metadataElement in xmlDoc.Root.Elements()) { if (metadataElement.Name == XmlMetadataConstants.BUILDINGTYPE_ELEM) { LoadBuildingType(metadataElement, metadata); } else if (metadataElement.Name == XmlMetadataConstants.UNITTYPE_ELEM) { LoadUnitType(metadataElement, metadata); } else if (metadataElement.Name == XmlMetadataConstants.ADDONTYPE_ELEM) { LoadAddonType(metadataElement, metadata); } else if (metadataElement.Name == XmlMetadataConstants.UPGRADETYPE_ELEM) { LoadUpgradeType(metadataElement, metadata); } else if (metadataElement.Name == XmlMetadataConstants.MISSILETYPE_ELEM) { LoadMissileType(metadataElement, metadata); } else if (metadataElement.Name == XmlMetadataConstants.CUSTOMTYPE_ELEM) { XAttribute nameAttr = metadataElement.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR); if (nameAttr == null) { throw new SimulatorException("Custom type name not defined!"); } ScenarioElementType elementType = new ScenarioElementType(nameAttr.Value, metadata); LoadScenarioElementType(metadataElement, elementType, metadata); metadata.AddCustomType(elementType); } else if (metadataElement.Name == XmlMetadataConstants.SHADOWPALETTE_ELEM) { metadata.SetShadowPalette(XmlHelper.LoadSpritePalette(metadataElement, imageDir)); } } }
/// <summary> /// Helper to get the <see cref="Scenario"/> Name (defined in <see cref="ScenarioMetadata"/>) /// </summary> /// <returns></returns> public string GetName() => ScenarioMetadata.GetName(this.GetType());
/// <summary> /// Helper to get the <see cref="Scenario"/> Description (defined in <see cref="ScenarioMetadata"/>) /// </summary> /// <returns></returns> public string GetDescription() => ScenarioMetadata.GetDescription(this.GetType());