private void Context_UpdateCompleted(IArkUpdateableContext sender, bool successful, bool cancelled) { // When all server contexts have completed one update successfully trigger the InitializationCompleted-event. if (!IsFullyInitialized && Servers.All(x => x.IsInitialized) && Clusters.All(x => x.IsInitialized)) { IsFullyInitialized = true; InitializationCompleted?.Invoke(); } UpdateCompleted?.Invoke(sender, successful, cancelled); }
/// <summary> /// When gamedata changes broadcast SignalR clients with serverUpdateNotification-/clusterUpdateNotification-message /// </summary> private void _contextManager_GameDataUpdated(IArkUpdateableContext sender) { if (sender is ArkServerContext) { _hubContext.Clients.All.serverUpdateNotification((sender as ArkServerContext).Config.Key); } if (sender is ArkClusterContext) { _hubContext.Clients.All.clusterUpdateNotification((sender as ArkClusterContext).Config.Key); } }
private void Context_UpdateCompleted(IArkUpdateableContext sender, bool successful, bool cancelled) { // Force an immediate garbage collection because it seems more effective (extraction process requires a great deal of memory) GC.Collect(); // When all server contexts have completed one update successfully trigger the InitializationCompleted-event. if (!IsFullyInitialized && Servers.All(x => x.IsInitialized) && Clusters.All(x => x.IsInitialized)) { IsFullyInitialized = true; InitializationCompleted?.Invoke(); } UpdateCompleted?.Invoke(sender, successful, cancelled); }
private void QueueUpdate(IArkUpdateableContext context, string type, string key) { if (_updateQueue.Any(x => x.Item1 == context)) { return; } if (_currentContext == context) { _currentCts?.Cancel(); } _progress.Report($"{type} ({key}): Update queued by watcher ({DateTime.Now:HH:mm:ss.ffff})"); _updateQueue.Add(new Tuple <IArkUpdateableContext, bool>(context, false)); }
/// <summary> /// On updates broadcast SignalR clients with serverUpdateNotification-/clusterUpdateNotification-message /// </summary> private void _contextManager_UpdateCompleted(IArkUpdateableContext sender, bool successful, bool cancelled) { if (!successful) { return; } if (sender is ArkServerContext) { _hubContext.Clients.All.serverUpdateNotification((sender as ArkServerContext).Config.Key); } if (sender is ArkClusterContext) { _hubContext.Clients.All.clusterUpdateNotification((sender as ArkClusterContext).Config.Key); } }
private void _updateManagerRun(CancellationToken ct) { try { while (!_updateQueue.IsCompleted) { Tuple <IArkUpdateableContext, bool> queueItem = null; try { queueItem = _updateQueue.Take(); } catch (InvalidOperationException) { } if (queueItem?.Item1 != null) { _currentCts = new CancellationTokenSource(); _currentContext = queueItem.Item1; queueItem.Item1.Update(queueItem.Item2, _config, _savegameBackupService, _progress, _currentCts.Token); } } } catch (OperationCanceledException) { } }
private void Context_GameDataUpdated(IArkUpdateableContext sender) { GameDataUpdated?.Invoke(sender); }
private void _contextManager_GameDataUpdated(IArkUpdateableContext sender) { if (!(sender is ArkServerContext)) { return; } var asc = sender as ArkServerContext; try { Logging.Log($"Updating Prometheus", GetType(), LogLevel.INFO); // Basics CreaturesWild.WithLabels(asc.Config.Key).Set(asc.WildCreatures.Length); CreaturesTamed.WithLabels(asc.Config.Key).Set(asc.TamedCreatures.Length); Structures.WithLabels(asc.Config.Key).Set(asc.Structures.Length); Tribes.WithLabels(asc.Config.Key).Set(asc.Tribes.Length); Players.WithLabels(asc.Config.Key).Set(asc.Players.Length); if (_config.Prometheus.CountSouls) { // Souls (non empty) var souls = new List <DinoSoul>(); var inventories = asc.Items.Where(x => x.ClassName == "SoulTrap_DS_C" && x.CustomName != null).GroupBy(x => x.OwnerInventoryId); foreach (var inventory in inventories) { var obj = asc.Structures.FirstOrDefault(x => x.InventoryId == inventory.Key); if (obj != null) { if (obj.TargetingTeam.HasValue) { var soul = souls.FirstOrDefault(x => x.TribeId == obj.TargetingTeam.Value); if (soul == null) { soul = new DinoSoul { TribeId = obj.TargetingTeam.Value }; souls.Add(soul); } soul.Amount += inventory.Count(); } } else { var p = asc.Players.FirstOrDefault(x => x.InventoryId == inventory.Key); if (p != null && p.TribeId.HasValue) { var soul = souls.FirstOrDefault(x => x.TribeId == p.TribeId.Value); if (soul == null) { soul = new DinoSoul { TribeId = p.TribeId.Value }; souls.Add(soul); } soul.Amount += inventory.Count(); } } } foreach (var soul in souls) { var tribe = asc.Tribes.FirstOrDefault(x => x.Id == soul.TribeId); if (tribe == null) { Souls.WithLabels(asc.Config.Key, $"Unknown Tribe: {soul.TribeId}").Set(soul.Amount); } else { Souls.WithLabels(asc.Config.Key, tribe.Name).Set(soul.Amount); } } } // Filesize var fi = new FileInfo(asc.Config.SaveFilePath); Filesize.WithLabels(asc.Config.Key).Set(fi.Length); } catch (Exception ex) { Logging.LogException($"Failed to update prometheus for server ({asc.Config.Key})", ex, GetType(), LogLevel.ERROR, ExceptionLevel.Ignored); } }
private void ContextManager_GameDataUpdated(IArkUpdateableContext sender) { _queue.Post(sender); }