internal void Synchronize( IActivityMonitor m, IEnumerable <StackDef> expectedStacks, StackInitializeOption option, Action <LocalWorldName> addWorld) { Debug.Assert(expectedStacks.All(d => d.OriginUrl == OriginUrl)); _syncCount = _store._syncCount; _stacks = expectedStacks.ToArray(); ReadWorlds(m, option, addWorld); }
void UpdateReposFromDefinitions(IActivityMonitor m, StackInitializeOption option) { var newWorlds = new List <LocalWorldName>(); ++_syncCount; foreach (var gD in _stacks.GroupBy(d => d.OriginUrl)) { if (gD.Any(d => d.IsPublic) && gD.Any(d => !d.IsPublic)) //Filter out repos with mixed public/private { m.Error($"Repository {gD.Key} contains a mix of public and private Stacks. All stacks in this repository are ignored."); } else if (gD.Select(d => d.BranchName).Distinct().Count() > 1) //Filter { m.Error($"Repository {gD.Key} contains Stacks bound to different branches: it must be the same branch for all stacks. All stacks in this repository are ignored."); } else { EnsureRepo(gD.Key).Synchronize(m, gD, option, newWorlds.Add); } } for (int i = 0; i < _repos.Count; ++i) { if (!_repos[i].PostSynchronize(m)) { _repos[i].Dispose(); _repos.RemoveAt(i--); } } SetWorlds(m, newWorlds); StackRepo EnsureRepo(Uri u) { int idx = _repos.IndexOf(r => r.OriginUrl == u); if (idx >= 0) { return(_repos[idx]); } var newOne = new StackRepo(this, u); _repos.Add(newOne); return(newOne); } }
internal void ReadWorlds(IActivityMonitor m, StackInitializeOption option, Action <LocalWorldName> addWorld) { if (option == StackInitializeOption.OpenRepository) { EnsureOpen(m); } else if (option == StackInitializeOption.OpenAndPullRepository) { Pull(m); } if (!IsOpen) { m.Warn($"Repository '{OriginUrl}' for stacks '{_stacks.Select( s => s.StackName ).Concatenate("', '")}' is not opened. Skipping Worlds reading from them."); return; } var worldNames = Directory.GetFiles(Root, "*.World.xml") .Select(p => LocalWorldName.TryParse(m, p, _store.WorldLocalMapping)) .Where(w => w != null) .ToList(); var missing = _stacks .Where(s => !worldNames.Any(w => w.FullName.Equals(s.StackName, StringComparison.OrdinalIgnoreCase))); foreach (var s in missing) { m.Warn($"Unable to find xml file definition for '{s.StackName}'."); } for (int i = 0; i < worldNames.Count; ++i) { var w = worldNames[i]; if (w.ParallelName == null && !_stacks.Any(s => s.StackName.Equals(w.FullName, StringComparison.OrdinalIgnoreCase))) { m.Warn($"Unexpected '{w.FullName}' stack found. It is ignored."); worldNames.RemoveAt(i--); } else { addWorld(w); } } }