public async Task ArmaUpdateMarkersPosition(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkersPosition"); return; } var msg = new UpdateMarkersMessagePosition() { Timestamp = message.Timestamp, Makers = new List <MarkerPosition>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var id = (string)data[0]; var pos = ((object[])data[1]).Cast <double?>().ToArray(); var dir = (double)data[2]; msg.Makers.Add(new MarkerPosition() { Id = id, X = pos[0] ?? 0, Y = pos[1] ?? 0, Heading = dir }); } var lastUpdate = state.LastUpdateMarkers; if (lastUpdate != null) { foreach (var marker in lastUpdate.Makers) { var updated = msg.Makers.FirstOrDefault(m => m.Id == marker.Id); if (updated != null) { marker.X = updated.X; marker.Y = updated.Y; marker.Heading = updated.Heading; } } } try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMarkersPosition", msg); } catch (Exception e) { _logger.LogWarning(e, "UpdateMarkersPosition failed"); } }
public async Task ArmaUpdateMarkers(ArmaMessage message) { //Console.WriteLine("ArmaUpdateMarkers " + string.Join(", ", message.Args)); var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkers"); return; } var msg = new UpdateMarkersMessage() { Timestamp = message.Timestamp, Makers = new List <Marker>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var kind = (string)data[0]; var id = (string)data[1]; var iconA = (string)data[2]; var iconB = (string)data[3]; var text = (string)data[4]; var textDetail = (string)data[5]; var pos = ((object[])data[6]).Cast <double?>().ToArray(); var dir = (double)data[7]; var vehicle = data.Length > 8 ? (string)data[8] : null; msg.Makers.Add(new Marker() { Kind = kind, Id = id, X = pos[0] ?? 0, Y = pos[1] ?? 0, Heading = dir, Symbol = GetMilSymbol(iconA, iconB), Name = text, Vehicle = vehicle }); } msg.Makers.Sort((a, b) => a.Name.CompareTo(b.Name)); state.LastUpdateMarkers = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMarkers", state.LastUpdateMarkers); } catch (Exception e) { _logger.LogWarning(e, "UpdateMarkers failed"); } }
public async Task ArmaUpdateMessages(ArmaMessage message) { //Console.WriteLine("ArmaUpdateMarkers " + string.Join(", ", message.Args)); var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMarkers"); return; } var msg = new UpdateMessagesMessage() { Timestamp = message.Timestamp, Messages = new List <Message>() }; foreach (var entry in message.Args) { var data = ArmaSerializer.ParseMixedArray(entry); var title = (string)data[0]; var body = (string)data[1]; var msgState = (int)((double?)data[2]); var id = (string)data[3]; msg.Messages.Add(new Message() { Id = id, Title = title, State = msgState, Body = body }); } state.LastUpdateMessages = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMessages", state.LastUpdateMessages); } catch (Exception e) { _logger.LogWarning(e, "UpdateMessages failed"); } }
public async Task ArmaUpdateMapMarkers(ArmaMessage message) { var state = GetState(ConnectionKind.Arma); if (state == null) { _logger.LogWarning($"No state for ArmaUpdateMapMarkers"); return; } var msg = new UpdateMapMarkersMessage() { Simples = new List <SimpleMapMarker>(), Icons = new List <IconMapMarker>(), Polylines = new List <PolylineMapMarker>() }; var simple = ArmaSerializer.ParseMixedArray(message.Args[0]); foreach (object[] simpleMarker in simple) { var shape = (string)simpleMarker[3]; if (string.Equals(shape, "ICON", StringComparison.OrdinalIgnoreCase)) { Arma3MarkerType type; if (Enum.TryParse((string)simpleMarker[2], true, out type)) { msg.Icons.Add(new IconMapMarker() { Name = ShorterName((string)simpleMarker[0]), Pos = ((object[])simpleMarker[1]).Cast <double>().Take(2).Select(p => Math.Round(p, 1)).ToArray(), Icon = ToIcon(type, (string)simpleMarker[7]), Size = ((object[])simpleMarker[4]).Cast <double>().ToArray(), Dir = (double)simpleMarker[5], Label = (string)simpleMarker[8], Alpha = (double)simpleMarker[9] }); } } else { msg.Simples.Add(new SimpleMapMarker() { Name = ShorterName((string)simpleMarker[0]), Pos = ((object[])simpleMarker[1]).Cast <double>().Take(2).Select(p => Math.Round(p, 1)).ToArray(), Shape = shape.ToLowerInvariant(), Size = ((object[])simpleMarker[4]).Cast <double>().ToArray(), Dir = (double)simpleMarker[5], Brush = (string)simpleMarker[6], Color = ToHtmlColor((string)simpleMarker[7]), Alpha = (double)simpleMarker[9] }); } } var poly = ArmaSerializer.ParseMixedArray(message.Args[1]); foreach (object[] polyMarker in poly) { msg.Polylines.Add(new PolylineMapMarker() { Name = ShorterName((string)polyMarker[0]), Points = ((object[])polyMarker[1]).Cast <double>().Select(p => Math.Round(p, 1)).ToArray(), Brush = (string)polyMarker[2], Color = ToHtmlColor((string)polyMarker[3]), Alpha = (double)polyMarker[4] }); } state.LastUpdateMapMarkers = msg; try { await Clients.Group(state.WebChannelName).SendAsync("UpdateMapMarkers", state.LastUpdateMapMarkers); } catch (Exception e) { _logger.LogWarning(e, "UpdateMapMarkers failed"); } }