public static Dictionary <string, object> Build(IExtensionReader extensionReader, IRobotTemplateRelations robotTemplateRelations, EntityDefault ed) { var info = ed.ToDictionary(); try { Entity entity = null; var robotTemplate = robotTemplateRelations.GetRelatedTemplate(ed); if (robotTemplate != null) { entity = robotTemplate.Build(); } if (entity == null) { entity = Entity.Factory.CreateWithRandomEID(ed); } var item = entity as Item; item?.Initialize(); var builder = new InfoBuilder(extensionReader, info); entity.AcceptVisitor(builder); } catch (Exception ex) { Logger.Error($"troubled definition: {ed.Definition} {ex.Message}"); Logger.Error($"{ex}\n{ex.Message}\n{ex.Source}\n{ex.InnerException?.Message}\n{ex.StackTrace}\n"); } return(info); }
public void ContributeAddsToBuilder() { // Uses git.properties file in test project var contrib = new GitInfoContributor(); var builder = new InfoBuilder(); contrib.Contribute(builder); var result = builder.Build(); Assert.NotNull(result); var gitDict = result["git"] as Dictionary<string, object>; Assert.NotNull(gitDict); Assert.Equal(7, gitDict.Count); Assert.True(gitDict.ContainsKey("build")); Assert.True(gitDict.ContainsKey("branch")); Assert.True(gitDict.ContainsKey("commit")); Assert.True(gitDict.ContainsKey("closest")); Assert.True(gitDict.ContainsKey("dirty")); Assert.True(gitDict.ContainsKey("remote")); Assert.True(gitDict.ContainsKey("tags")); // Verify times are correctly converted var gitDict2 = gitDict["build"] as Dictionary<string, object>; Assert.NotNull(gitDict2); Assert.True(gitDict2.ContainsKey("time")); var time = gitDict2["time"]; Assert.Equal(1499884839000, time); // Verify times are correctly converted var gitDict3 = gitDict["commit"] as Dictionary<string, object>; Assert.NotNull(gitDict3); Assert.True(gitDict3.ContainsKey("time")); time = gitDict3["time"]; Assert.Equal(1496926022000, time); }
public void ContributeAddsToBuilder() { appSettings.Add("info:NET:ASPNET:type", "Core"); appSettings.Add("info:NET:ASPNET:version", "2.0.0"); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appSettings); var config = configurationBuilder.Build(); var settings = new AppSettingsInfoContributor(config); InfoBuilder builder = new InfoBuilder(); settings.Contribute(builder); Dictionary <string, object> info = builder.Build(); Assert.NotNull(info); Assert.Equal(2, info.Count); Assert.True(info.ContainsKey("application")); Assert.True(info.ContainsKey("NET")); var appNode = info["application"] as Dictionary <string, object>; Assert.NotNull(appNode); Assert.Equal("foobar", appNode["name"]); var netNode = info["NET"] as Dictionary <string, object>; Assert.NotNull(netNode); Assert.Equal("Core", netNode["type"]); Assert.NotNull(netNode["ASPNET"]); }
public void WhenCallingAddAssemblyVersionDescriptionItShouldSetupTheAssemblyVersionDescription() { var ib = new InfoBuilder("1", "title").AddAssemblyVersionDescription(); var expectedVersion = GetType().Assembly.GetName().Version; ib.GetType().GetField("_description", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ib).Should().Be($"AssemblyVersion: {expectedVersion}"); }
public void Should_AbleToSetTermsOfService(string title, string version, string termsOfService) { var info = new InfoBuilder(title, version).TermsOfService(termsOfService).Build(); Assert.Equal(title, info.Title); Assert.Equal(version, info.Version); Assert.Equal(termsOfService, info.TermsOfService); }
public void Should_AbleToSetDescription(string title, string version, string descrption) { var info = new InfoBuilder(title, version).Description(descrption).Build(); Assert.Equal(title, info.Title); Assert.Equal(version, info.Version); Assert.Equal(descrption, info.Description); }
public void ReturnsEmptyDictionary() { var builder = new InfoBuilder(); var built = builder.Build(); Assert.NotNull(built); Assert.Empty(built); }
public static InfoBuilder AddAssemblyVersionDescription(this InfoBuilder source) { var version = GetCallingAssembly() .GetName() .Version; return(source.Description($"AssemblyVersion: {version}")); }
private static void AddNewResources(InfoBuilder info, IEnumerable <Type> itemTypes, TechTreeSimData data) { foreach (var itemType in itemTypes) { data.AddItem(itemType); info.AppendLineLoc($" - New Resource: {Item.Get(itemType).DisplayName}"); } }
public void ContributeAddsToBuilder() { var appsettings = @" { 'info': { 'application': { 'name': 'foobar', 'version': '1.0.0', 'date': '5/1/2008', 'time' : '8:30:52 AM' }, 'NET': { 'type': 'Core', 'version': '1.1.0', 'ASPNET' : { 'type': 'Core', 'version': '1.1.0' } } } }"; var path = TestHelpers.CreateTempFile(appsettings); string directory = Path.GetDirectoryName(path); string fileName = Path.GetFileName(path); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.SetBasePath(directory); configurationBuilder.AddJsonFile(fileName); var config = configurationBuilder.Build(); var settings = new AppSettingsInfoContributor(config); InfoBuilder builder = new InfoBuilder(); settings.Contribute(builder); Dictionary <string, object> info = builder.Build(); Assert.NotNull(info); Assert.Equal(2, info.Count); Assert.True(info.ContainsKey("application")); Assert.True(info.ContainsKey("NET")); var appNode = info["application"] as Dictionary <string, object>; Assert.NotNull(appNode); Assert.Equal("foobar", appNode["name"]); var netNode = info["NET"] as Dictionary <string, object>; Assert.NotNull(netNode); Assert.Equal("Core", netNode["type"]); Assert.NotNull(netNode["ASPNET"]); }
public void WithInfoSingleValueAddsValue() { var builder = new InfoBuilder(); builder.WithInfo("foo", "bar"); var built = builder.Build(); Assert.NotNull(built); Assert.Single(built); Assert.Equal("bar", built["foo"]); }
public void ConstributeWithConfigNull() { var contributor = new AppSettingsInfoContributor(null); InfoBuilder builder = new InfoBuilder(); contributor.Contribute(builder); var result = builder.Build(); Assert.NotNull(result); Assert.Equal(0, result.Count); }
public async Task ObjectConstantsAsync() { var builder = new InfoBuilder(1); var v1 = await((from p in db.Products select builder.GetItemValue(p)).FirstAsync()); builder = new InfoBuilder(2); var v2 = await((from p in db.Products select builder.GetItemValue(p)).FirstAsync()); Assert.That(v1, Is.EqualTo(1), "v1"); Assert.That(v2, Is.EqualTo(2), "v2"); }
public void BuildAddsVersionInfo() { var contributor = new BuildInfoContributor(); var builder = new InfoBuilder(); contributor.Contribute(builder); var results = builder.Build(); Assert.True(results.ContainsKey("applicationVersionInfo")); Assert.NotNull(results["applicationVersionInfo"]); Assert.True(results.ContainsKey("steeltoeVersionInfo")); Assert.NotNull(results["steeltoeVersionInfo"]); }
public void ObjectConstants() { var builder = new InfoBuilder(1); var v1 = (from p in db.Products select builder.GetItemValue(p)).First(); builder = new InfoBuilder(2); var v2 = (from p in db.Products select builder.GetItemValue(p)).First(); Assert.That(v1, Is.EqualTo(1), "v1"); Assert.That(v2, Is.EqualTo(2), "v2"); }
private static void ReportMissingIngredients(InfoBuilder recipeFamilyInfo, Recipe recipe, TechTreeSimData data) { var missingIngredientsInfo = new InfoBuilder(); foreach (var ingredient in recipe.Ingredients) { if (!data.HasIngredient(ingredient)) { missingIngredientsInfo.AppendLine(ingredient.StackObject.DisplayName); } } recipeFamilyInfo.AddSectionLocStr("- missing ingredients:", missingIngredientsInfo); }
private static void UpdateRecipesFromSkills(InfoBuilder info, TechTreeSimData data) { while (data.SkillsToEvaluate.Any()) { var skill = data.SkillsToEvaluate.Dequeue(); data.CurSkills.Add(skill); info.AppendLineLocStr("Adding Skill: " + skill.Name); foreach (var recipe in RecipeFamily.GetRecipesBySkill(skill)) { data.UnusableRecipes.AddRange(recipe.Recipes); } UpdateRecipes(info, data); } }
private static bool CheckStatus(InfoBuilder info, TechTreeSimData data) { var s = new LocStringBuilder(); if (!data.CraftingTables.Contains(typeof(LaserObject))) { s.AppendLineLocStr("Error: Laser Unobtainable"); } if (data.UnusableRecipes.Any()) { s.AppendLineLocStr("Error: Visible Recipes Uncraftable"); } info.AppendLine(s.ToLocString()); return(s.ToLocString().Length <= 0); }
public void Should_AbleToSetLicense() { string title = "title"; string version = "1.0"; var license = new License(); var licenseWithBuilder = new LicenseBuilder("name").Build(); var info = new InfoBuilder(title, version).License(license).Build(); var infoWithBuilder = new InfoBuilder(title, version).License(licenseWithBuilder).Build(); Assert.Equal(title, info.Title); Assert.Equal(version, info.Version); Assert.Equal(license, info.License); Assert.Equal(licenseWithBuilder, infoWithBuilder.License); }
public void Should_AbleToSetContact() { string title = "title"; string version = "1.0"; var contact = new Contact(); var contactWithBuilder = new ContactBuilder().Build(); var info = new InfoBuilder(title, version).Contact(contact).Build(); var infoWithBuilder = new InfoBuilder(title, version).Contact(contactWithBuilder).Build(); Assert.Equal(title, info.Title); Assert.Equal(version, info.Version); Assert.Equal(contact, info.Contact); Assert.Equal(contactWithBuilder, infoWithBuilder.Contact); }
public void ReturnsPodInfoInsideCluster() { var builder = new InfoBuilder(); var contributor = new KubernetesInfoContributor(new FakePodUtilities(FakePodUtilities.SamplePod)); contributor.Contribute(builder); var info = builder.Build()["kubernetes"] as Dictionary <string, object>; Assert.True(bool.Parse(info["inside"].ToString())); Assert.Equal("mynamespace", info["namespace"].ToString()); Assert.Equal("mypod", info["podName"].ToString()); Assert.Equal("mypodip", info["podIp"].ToString()); Assert.Equal("myserviceaccount", info["serviceAccount"].ToString()); Assert.Equal("mynode", info["nodeName"].ToString()); Assert.Equal("myhostip", info["hostIp"].ToString()); }
public void WithInfoDictionaryAddsValues() { var builder = new InfoBuilder(); Dictionary <string, object> items = new Dictionary <string, object>() { { "foo", "bar" }, { "bar", 100 } }; builder.WithInfo(items); var built = builder.Build(); Assert.NotNull(built); Assert.Equal(2, built.Count); Assert.Equal("bar", built["foo"]); Assert.Equal(100, built["bar"]); }
public void ReturnsNoPodInfoOutsideCluster() { var builder = new InfoBuilder(); var contributer = new KubernetesInfoContributor(new FakePodUtilities(null)); contributer.Contribute(builder); var info = builder.Build()["kubernetes"] as Dictionary <string, object>; Assert.True(info.ContainsKey("inside")); Assert.False(bool.Parse(info["inside"].ToString())); Assert.False(info.ContainsKey("namespace")); Assert.False(info.ContainsKey("podName")); Assert.False(info.ContainsKey("podIp")); Assert.False(info.ContainsKey("serviceAccount")); Assert.False(info.ContainsKey("nodeName")); Assert.False(info.ContainsKey("hostIp")); }
protected InfoResponse BuildInfoResponse() { // TODO complete info InfoResponse infoResponse = null; Container container = GetContainer(); if (container == null) { infoResponse = new InfoResponse(); } else { var infoBuilder = new InfoBuilder(container); infoResponse = infoBuilder.GetInfoResponse(); } return infoResponse; }
protected InfoResponse BuildInfoResponse() { // TODO complete info InfoResponse infoResponse = null; Container container = GetContainer(); if (container == null) { infoResponse = new InfoResponse(); } else { var infoBuilder = new InfoBuilder(container); infoResponse = infoBuilder.GetInfoResponse(); } return(infoResponse); }
public void ContributeAddsToBuilder() { // Uses git.properties file in test project var contrib = new GitInfoContributor(); var builder = new InfoBuilder(); contrib.Contribute(builder); var result = builder.Build(); Assert.NotNull(result); var gitDict = result["git"] as Dictionary <string, object>; Assert.NotNull(gitDict); Assert.Equal(7, gitDict.Count); Assert.True(gitDict.ContainsKey("build")); Assert.True(gitDict.ContainsKey("branch")); Assert.True(gitDict.ContainsKey("commit")); Assert.True(gitDict.ContainsKey("closest")); Assert.True(gitDict.ContainsKey("dirty")); Assert.True(gitDict.ContainsKey("remote")); Assert.True(gitDict.ContainsKey("tags")); var gitBuildDict = gitDict["build"] as Dictionary <string, object>; Assert.NotNull(gitBuildDict); Assert.True(gitBuildDict.ContainsKey("time")); // Verify that datetime values are normalized correctly var gitBuildTime = gitBuildDict["time"]; Assert.Equal(DateTime.Parse("2017-07-12T18:40:39Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal), gitBuildTime); var gitCommitDict = gitDict["commit"] as Dictionary <string, object>; Assert.NotNull(gitCommitDict); Assert.True(gitCommitDict.ContainsKey("time")); // Verify that datetime values are normalized correctly var gitCommitTime = gitCommitDict["time"]; Assert.Equal(DateTime.Parse("2017-06-08T12:47:02Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal), gitCommitTime); }
public void ContributeAddsToBuilder() { var appsettings = new Dictionary <string, string> { ["info:application:name"] = "foobar", ["info:application:version"] = "1.0.0", ["info:application:date"] = "5/1/2008", ["info:application:time"] = "8:30:52 AM", ["info:NET:type"] = "Core", ["info:NET:version"] = "1.1.0", ["info:NET:ASPNET:type"] = "Core", ["info:NET:ASPNET:version"] = "1.1.0" }; var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appsettings); var config = configurationBuilder.Build(); var settings = new AppSettingsInfoContributor(config); var builder = new InfoBuilder(); settings.Contribute(builder); var info = builder.Build(); Assert.NotNull(info); Assert.Equal(2, info.Count); Assert.True(info.ContainsKey("application")); Assert.True(info.ContainsKey("NET")); var appNode = info["application"] as Dictionary <string, object>; Assert.NotNull(appNode); Assert.Equal("foobar", appNode["name"]); var netNode = info["NET"] as Dictionary <string, object>; Assert.NotNull(netNode); Assert.Equal("Core", netNode["type"]); Assert.NotNull(netNode["ASPNET"]); }
private static void UpdateRecipes(InfoBuilder info, TechTreeSimData data) { var numRemoved = 1; while (numRemoved != 0) { numRemoved = 0; var toRemove = new List <Recipe>(); foreach (var recipe in data.UnusableRecipes) { if (data.CraftableItems.ContainsAll(recipe.Items.Select(x => x.Item.Type))) { toRemove.Add(recipe); } else if (recipe.Ingredients.All(data.HasIngredient) && CraftingComponent.TablesForRecipe(recipe.Family.GetType()).Intersect(data.CraftingTables).Any()) { foreach (var product in recipe.Items.Select(x => x.Item)) { data.AddItem(product.Type); info.AppendLineLocStr(" - New Craftable Items: " + product); if (product is WorldObjectItem) { data.CraftingTables.AddUnique((product as WorldObjectItem).WorldObjectType); //will need to specify power items } if (product is SkillBook) { data.AddSkill((product as SkillBook).Skill.Type); } } toRemove.Add(recipe); numRemoved++; } } toRemove.ForEach(x => { data.UnusableRecipes.Remove(x); data.CurRecipes.Add(x); }); } }
public GetEntityDefaults(IExtensionReader extensionReader, IEntityDefaultReader entityDefaultReader, IRobotTemplateRelations robotTemplateRelations) { var cachedEntityDefaultsInfo = entityDefaultReader.GetAll().ToDictionary("d", ed => InfoBuilder.Build(extensionReader, robotTemplateRelations, ed)); _message = Message.Builder.SetCommand(Commands.GetEntityDefaults).WithData(cachedEntityDefaultsInfo).Build(); }
public static void TechTreeSimulation(User user) { var info = new InfoBuilder(); var data = new TechTreeSimData(); info.AppendLineLocStr("Starting Tech Tree Sim"); info.AppendLineLocStr("Getting Starting Skills..."); var introSkills = PlayerDefaults.GetDefaultSkills().ToList(); introSkills.ForEach(x => data.AddSkill(x)); info.AppendLineLocStr("Getting Initial Tables..."); data.CraftingTables.Add(typeof(CampsiteObject)); info.AppendLineLocStr("Getting Recipes with No Skills..."); data.UnusableRecipes.AddRange(RecipeFamily.AllRecipes.SelectMany(x => x.Recipes).Where(x => !x.Family.RequiredSkills.Any() && x.Ingredients.Any())); info.AppendLineLocStr("Getting World Resources..."); //manually defined for now since theres no easy way of checking for these data.AddItems(new List <Type> { typeof(DirtItem), typeof(SandItem), typeof(IronOreItem), typeof(CopperOreItem), typeof(GoldOreItem), typeof(CoalItem), typeof(ClayItem) }); // Add all items with "Rock" tag data.AddItems(TagManager.TagToTypes[TagManager.Tag("Rock")]); info.AppendLineLocStr("Getting Species Resources..."); var resourceless = new List <Species>(); EcoSim.AllSpecies.ForEach(x => { var speciesInfo = new InfoBuilder(); AddNewResources(speciesInfo, x.ResourceList.Select(x => x.ResourceType), data); if (x is TreeSpecies treeSpecies) { AddNewResources(speciesInfo, treeSpecies.TrunkResources.Keys, data); AddNewResources(speciesInfo, treeSpecies.DebrisResources.Keys, data); } if (speciesInfo.IsEmpty) { resourceless.Add(x); speciesInfo.AppendLineLocStr("No resources"); } info.AddSectionLoc($"Adding Species: {x.DisplayName}", speciesInfo); }); info.AppendLine(); info.AppendLineLocStr("Simulating..."); info.AppendLine(); UpdateRecipes(info, data); UpdateRecipesFromSkills(info, data); info.AppendLine(); info.AppendLineLocStr("Tech Tree Sim Complete"); ChatManager.SendChat(CheckStatus(info, data) ? "Tech Tree Complete" : "Tech Tree Failed, check the TechTreeSimulation.txt for more information.", user); //get issues with complete //PLANT DATA info.AppendLineLocStr("Plants Missing Resources"); info.AppendLine(Localizer.NotLocalizedStr(string.Join(",", resourceless))); //CRAFTABLES var uncraftableAccessed = new InfoBuilder(); foreach (var recipe in data.UnusableRecipes) { var recipeInfo = new InfoBuilder(); ReportMissingIngredients(recipeInfo, recipe, data); if (!CraftingComponent.TablesForRecipe(recipe.Family.GetType()).Intersect(data.CraftingTables).Any()) { recipeInfo.AppendLineLocStr("- missing crafting table"); } uncraftableAccessed.AddSection(recipe.DisplayName, recipeInfo); } info.AppendLine(); info.AddSectionLocStr("Uncraftable Accessed", uncraftableAccessed); var uncraftableUnaccessed = new InfoBuilder(); foreach (var recipe in RecipeFamily.AllRecipes.SelectMany(x => x.Recipes).Except(data.CurRecipes)) { var recipeInfo = new InfoBuilder(); var missingSkillsInfo = new InfoBuilder(); foreach (var skill in recipe.Family.RequiredSkills) { if (!data.CurSkills.Contains(skill.SkillType)) { missingSkillsInfo.AppendLine(skill.SkillItem.DisplayName); } } recipeInfo.AddSectionLocStr("- missing skills:", missingSkillsInfo); ReportMissingIngredients(recipeInfo, recipe, data); // notify about missing crafting table if (!CraftingComponent.TablesForRecipe(recipe.Family.GetType()).Intersect(data.CraftingTables).Any()) { recipeInfo.AppendLineLocStr("- missing crafting table"); } uncraftableUnaccessed.AddSection(recipe.DisplayName, recipeInfo); } info.AppendLine(); info.AddSectionLocStr("Uncraftable Unaccessed", uncraftableUnaccessed); //ALL UNOBTAINABLE ITEMS info.AppendLine(); info.AppendLineLocStr("Unobtainable Items"); foreach (var item in Item.AllItems .Where(x => !(x is Skill) && !(x is ActionbarItem) && !(x is SkillScroll) && !x.Hidden) .Select(x => x.Type) .Except(data.CraftableItems)) { info.AppendLineLocStr(" " + item.Name); } using var sw = new StreamWriter("TechTreeSimulation.txt"); sw.Write(info.ToLocString()); }