public bool UpdateStructure(NodeUpdateList list) { if (list == null) { return(false); } bool modified = false; foreach (NodeUpdate item in list.SubList) { if (UpdateBilancio(item)) { modified = true; } } return(modified); }
//public string CreateNewRendiconto(RendicontoHeaderDTO header, string dir) //{ // if (string.IsNullOrEmpty(dir)) // return CreateNewRendiconto(header); // //per prima cosa verifico la validità del percorso di directory fornito // string path = dir; // if (!Directory.Exists(path)) // throw new ArgumentException("Il percorso specificato per il salvataggio non esiste!"); // //verifico l'estensione del file // if (!header.FileName.Contains(".")) // header.FileName += ".xml"; // //verifico che il file non esista // path = Path.Combine(path, header.FileName); // if (File.Exists(path)) // throw new ArgumentException("Esiste già un file denominato: " + path + "!"); // //A questo punto posso creare il bilancio e salvarlo // bool isProvinciale = !header.IsRegionale; // Rendiconto r = RendicontoFactory.CreateRendiconto(isProvinciale, header.Provincia, header.Anno, header.Regione); // r.Proprietario = header.Proprietario; // _mapper.SaveRendiconto(r, path); // return path; //} public void UpdateRendicontoStructure() { string updateFile = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", ""); FileInfo i = new FileInfo(updateFile); updateFile = i.DirectoryName; if (_current.SendableTag == "FENEAL") { if (_current.IsRegionale) { updateFile += @"\Updates\updatefenealregionale.xml"; } else { updateFile += @"\Updates\updatefenealprovinciale.xml"; } } else if (_current.SendableTag == "RLST") { updateFile += @"\Updates\updaterlst.xml"; } else { updateFile += @"\Updates\update.xml"; } UpdateFileMapper m = new UpdateFileMapper(); NodeUpdateList l = m.LoadUpdateFileByPath(updateFile); if (_current.UpdateStructure(l)) { //Inoltro fgli eventi di notifica del cambiamento ChangeRendiconto_Change(this, EventArgs.Empty); } }
static void Main() { Console.OutputEncoding = Encoding.UTF8; var random = Rand.GetRandom(); var logger = new ConsoleLogger { Take = LoggerSeverity.Error }; var randomLoot = new RandomLoot <string, string>(random) { Logger = logger }; var partition = new PartitionLoot <string, string>(random) { Logger = logger }; var fpl = new FirstPickLoot <string, string>(); LootTree <string, string> tree = new LootTree <string, string>(partition, logger); ILootable <string, string>[] convertPath(params string[] s) => s.Select(x => { if (!x.Contains(':')) { return(new DefaultLoot <string, string>(50, x, x)); } var parts = x.Split(':'); return(new DefaultLoot <string, string>(int.Parse(parts[1]), parts[0], parts[0])); }) .ToArray(); var bonusPath = convertPath("Bonus:5"); var defaultPath = convertPath("Default:95"); var genPath = convertPath("Default", "Generation"); var miscPath = convertPath("Default", "Generation", "Useful", "Misc:70"); var weaponPath = convertPath("Default", "Generation", "Useful", "Gear:25", "Weapon:35"); var legendaryWeaponPath = convertPath("Default", "Generation", "Useful", "Gear", "LegendaryWeapon:5"); var armorPath = convertPath("Default", "Generation", "Useful", "Gear", "Armor:60"); var crapPath = convertPath("Default", "Generation", "Crap"); var legacyPath = convertPath("LegacyGeneration:10"); var prov = new LootProvider(); var miscNode = tree.AddPath(miscPath).AddRangeAsLeafs(prov.Misc); var crapNode = tree.AddPath(crapPath).AddLeaf(prov.Crap); var defaultNode = tree.AddPath(defaultPath); var legacyHalfRoot = tree.AddHalfRoot("Legacy"); var legacyNode = tree .AddPath(legacyHalfRoot, legacyPath) .AddRangeAsLeafs(prov.Armor) .AddRangeAsLeafs(prov.Weapons) .AddLeaf(prov.LegendaryWeapon); var genNode = tree.AddPath(genPath); var bonusNode = tree.AddPath(bonusPath); var armorNode = tree.AddPath(armorPath).AddRangeAsLeafs(prov.Armor); var weaponNode = tree.AddPath(weaponPath).AddRangeAsLeafs(prov.Weapons); var legyNode = tree.AddPath(legendaryWeaponPath).AddLeaf(prov.LegendaryWeapon); NodeUpdateList <string, string> nodes = tree.AutoList; nodes.OnDetachedNodeRemoved += n => Console.WriteLine($"registered node {n} being removed"); armorNode.SetFallback(weaponNode); weaponNode.SetFallback(legyNode); nodes.First(x => x.Key == "Gear").SetFallback(legacyHalfRoot); tree.Connect(bonusNode, (genNode, 1)); legacyHalfRoot.AddChildNodes((crapNode, 90)); legacyNode.IgnoreAvailability = true; legacyHalfRoot.Algorithm = fpl; bonusNode.Algorithm = fpl; defaultNode.Algorithm = fpl; crapNode.Algorithm = fpl; nodes.ForEach(Console.WriteLine); for (int i = 0; i < 100; i++) { Console.WriteLine(tree.GetResult()); } nodes.ForEach(Console.WriteLine); Console.ReadKey(); }