ProcessChangeShipStatus(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.ChangeShipStatus css = p as ANWI.Messaging.ChangeShipStatus; bool success = false; Datamodel.UserShip ship = null; if (Datamodel.UserShip.FetchById(ref ship, css.shipId)) { ship.status = (int)css.status; if (Datamodel.UserShip.StoreUpdateStatus(ship)) { success = true; logger.Info($"Updated ship {css.shipId} status" + $" to {css.status}"); } else { logger.Error("Failed to update status for " + $"ship {css.shipId}"); } } else { logger.Error($"Failed to fetch ship {css.shipId} " + "to update status"); } return(new ANWI.Messaging.ConfirmUpdate(p, success, css.shipId)); }
/// <summary> /// Message router. Sends messages to correct processor function /// </summary> /// <param name="e"></param> protected sealed override void OnMessage(MessageEventArgs e) { ANWI.Messaging.Message msg = ANWI.Messaging.Message.Receive(e.RawData); logger.Info($"Message received #{msg.sequence} from " + $"{GetLogIdentifier()}. {msg.payload.ToString()}"); Func <ANWI.Messaging.IMessagePayload, ANWI.Messaging.IMessagePayload> processor = msgProcessors[msg.payload.GetType()]; if (processor != null) { ANWI.Messaging.IMessagePayload p = processor(msg.payload); if (p != null) { ANWI.Messaging.Message response = new ANWI.Messaging.Message(msg.sequence, p); Send(response); } } else { logger.Error("No message processor found for payload type " + msg.payload.GetType()); } }
ProcessNewAssignment(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.NewAssignment ns = p as ANWI.Messaging.NewAssignment; Datamodel.Assignment a = null; bool success = Datamodel.Assignment.Create( ref a, ns.userId, ns.shipId, ns.roleId); if (success) { logger.Info($"Started assignment for user {ns.userId} role" + $" {ns.roleId} on ship {ns.shipId}"); } else { logger.Error("Failed to start assignment for user" + $" {ns.userId} on ship {ns.shipId}"); } if (ns.userId == GetUser().profile.id) { GetUser().RefreshProfile(); } return(new ANWI.Messaging.ConfirmUpdate(p, success, ns.shipId)); }
/// <summary> /// Handles the EndAssignment message /// </summary> /// <param name="p"></param> /// <returns></returns> private ANWI.Messaging.IMessagePayload ProcessEndAssignment( ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.EndAssignment es = p as ANWI.Messaging.EndAssignment; bool success = Datamodel.Assignment.EndAssignment( es.userId, es.assignmentId); if (success) { logger.Info($"Ended assignment {es.assignmentId} for" + $" user {es.userId}"); } else { logger.Error($"Failed to end assignment {es.assignmentId}" + $" for user {es.userId}"); } if (es.userId == GetUser().profile.id) { GetUser().RefreshProfile(); } return(new ANWI.Messaging.ConfirmUpdate(p, success, es.shipId)); }
private void ProcessUpdateOOBBoats(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateUnitsBoats ub = p as ANWI.Messaging.Ops.UpdateUnitsBoats; if (ub.added != null) { foreach (Boat add in ub.added) { fleet.AddUnit(add); } } if (ub.removed != null) { foreach (string rem in ub.removed) { fleet.DeleteUnit(rem); } } RebuildC2(); NotifyPropertyChanged(string.Empty); }
private void ProcessUpdateWing(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateWing upw = p as ANWI.Messaging.Ops.UpdateWing; switch (upw.type) { case ANWI.Messaging.Ops.UpdateWing.Type.SetName: fleet.SetWingName(upw.wingUUID, upw.str); break; case ANWI.Messaging.Ops.UpdateWing.Type.SetCallsign: fleet.SetWingCallsign(upw.wingUUID, upw.str); break; case ANWI.Messaging.Ops.UpdateWing.Type.ChangeWingCommander: fleet.SetWingCommander(upw.boatUUID); break; case ANWI.Messaging.Ops.UpdateWing.Type.ChangeRole: fleet.ChangeWingRole(upw.wingUUID, (Wing.Role)upw.integer); break; } RebuildC2(); NotifyPropertyChanged(string.Empty); }
private void ProcessUpdateOOBShips(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateUnitsShips us = p as ANWI.Messaging.Ops.UpdateUnitsShips; if (us.addedShips != null) { foreach (Ship s in us.addedShips) { fleet.AddUnit(s); } } if (us.removedShips != null) { foreach (string s in us.removedShips) { fleet.DeleteUnit(s); } } RebuildC2(); NotifyPropertyChanged("fleetComp"); }
private void ProcessUpdateOOBWings(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateUnitsWings uw = p as ANWI.Messaging.Ops.UpdateUnitsWings; if (uw.addedWings != null) { foreach (Wing w in uw.addedWings) { fleet.AddUnit(w); } } if (uw.removedWings != null) { foreach (string w in uw.removedWings) { fleet.DeleteUnit(w); } } RebuildC2(); NotifyPropertyChanged("fleetComp"); }
ProcessAddOOBElement(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.AddOOBUnit add = p as ANWI.Messaging.Ops.AddOOBUnit; ActiveOperation op = GetOperation(add.opUUID); if (op != null) { if (add.type == ANWI.Messaging.Ops.AddOOBUnit.Type.FleetShip) { op.AddFleetShip(add.shipId); } else if (add.type == ANWI.Messaging.Ops.AddOOBUnit.Type.Wing) { op.AddWing(); } else if (add.type == ANWI.Messaging.Ops.AddOOBUnit.Type.Boat) { op.AddBoat(add.wingUUID, add.hullId); } } return(null); }
private void ProcessOpSnapshot(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.FullOperationSnapshot snap = p as ANWI.Messaging.Ops.FullOperationSnapshot; operationName = snap.op.name; type = snap.op.type; status = snap.op.status; freeMove = snap.op.freeMove; C2Unified = snap.op.C2Unified; AddParticipants(snap.op.roster); if (snap.op.fleet != null) { foreach (FleetUnit f in snap.op.fleet) { fleet.AddUnit(f); } } working = false; RebuildC2(); NotifyPropertyChanged(string.Empty); }
/// <summary> /// When an update is confirmed, requests a refresh of the vessel /// </summary> /// <param name="m"></param> private void ProcessConfirmUpdate(ANWI.Messaging.IMessagePayload m) { ANWI.Messaging.ConfirmUpdate cu = m as ANWI.Messaging.ConfirmUpdate; if (cu.originalRequest == typeof(ANWI.Messaging.NewShip).ToString()) { if (cu.success) { FetchVesselDetail(cu.updatedId); FetchVesselList(); } else { MessageBox.Show( "Failed to create new ship: " + cu.errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (cu.originalRequest == typeof(ANWI.Messaging.ChangeShipStatus).ToString()) { if (cu.success) { FetchVesselDetail(cu.updatedId); FetchVesselList(); } } }
/// <summary> /// Called when the vessel details are received /// Loads the details into the detail pane /// </summary> /// <param name="m"></param> private void LoadVesselDetail(ANWI.Messaging.IMessagePayload m) { this.Dispatcher.Invoke(() => { Spinner_Detail.Visibility = Visibility.Hidden; Button_ViewShip.IsEnabled = true; }); ANWI.Messaging.FullVessel fvd = m as ANWI.Messaging.FullVessel; currentVessel = fvd.vessel; }
ProcessCreateOp(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.CreateNewOp cno = p as ANWI.Messaging.Ops.CreateNewOp; string uuid = OperationManager.Instance.CreateNew( cno.name, cno.type, cno.userId); return(new ANWI.Messaging.Ops.NewOpCreated(uuid)); }
private void ProcessUpdateSettings(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateSettings ups = p as ANWI.Messaging.Ops.UpdateSettings; freeMove = ups.freeMove; C2Unified = ups.C2Unified; RebuildC2(); NotifyPropertyChanged(string.Empty); }
/// <summary> /// Opens the ops window with the new operation /// </summary> /// <param name="p"></param> private void ProcessNewOpCreated(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.NewOpCreated noc = p as ANWI.Messaging.Ops.NewOpCreated; this.Dispatcher.Invoke(() => { opDet = new OperationDetails(account.profile, noc.uuid); opDet.OnClose += (a) => { opDet = null; }; opDet.Show(); Button_NewOp.IsEnabled = true; }); }
/// <summary> /// Fills the list of available personnel /// </summary> /// <param name="p"></param> public void ProcessRoster(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.FullRoster roster = p as ANWI.Messaging.FullRoster; _unassignedPersonnel = new ObservableCollection <LiteProfile>(roster.members); NotifyPropertyChanged("unassignedPersonnel"); this.Dispatcher.Invoke(() => { Spinner_Roster.Visibility = Visibility.Hidden; }); }
private void ProcessUpdateShip(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateShip ups = p as ANWI.Messaging.Ops.UpdateShip; switch (ups.type) { case ANWI.Messaging.Ops.UpdateShip.Type.SetFlagship: fleet.SetFlagship(ups.shipUUID); break; } NotifyPropertyChanged(string.Empty); }
/// <summary> /// Fills in appropriate text based on code /// </summary> /// <param name="resp"></param> private void Register_Response(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.RegisterResponse resp = p as ANWI.Messaging.RegisterResponse; if (resp.code == ANWI.Messaging.RegisterResponse.Code.OK) { Register_EndWorkingSucceeded(); } else { Register_EndWorkingFailed(Register_GetFailedText(resp.code)); } }
ProcessSetC2Type(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.SetC2Type sc2 = p as ANWI.Messaging.Ops.SetC2Type; ActiveOperation op = GetOperation(sc2.opUUID); if (op != null) { op.SetC2Type(sc2.unified); } return(null); }
ProcessModifyUnit(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.ModifyUnit mod = p as ANWI.Messaging.Ops.ModifyUnit; ActiveOperation op = GetOperation(mod.opUUID); if (op != null) { op.ModifyUnit(mod); } return(null); }
ProcessSetFreeMove(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.SetFreeMove sfm = p as ANWI.Messaging.Ops.SetFreeMove; ActiveOperation op = GetOperation(sfm.opUUID); if (op != null) { op.SetFreeMove(sfm.freeMove); } return(null); }
ProcessDeletePosition(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.DeletePosition del = p as ANWI.Messaging.Ops.DeletePosition; ActiveOperation op = GetOperation(del.opUUID); if (op != null) { op.DeletePosition(del.posUUID); } return(null); }
ProcessSetPositionCritical(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.SetPositionCritical set = p as ANWI.Messaging.Ops.SetPositionCritical; ActiveOperation op = GetOperation(set.opUUID); if (op != null) { op.SetPositionCritical(set.posUUID, set.critical); } return(null); }
ProcessAddPosition(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.AddPosition add = p as ANWI.Messaging.Ops.AddPosition; ActiveOperation op = GetOperation(add.opUUID); if (op != null) { op.AddPosition(add.unitUUID, add.roleID); } return(null); }
ProcessAssignUser(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.AssignUser au = p as ANWI.Messaging.Ops.AssignUser; ActiveOperation op = GetOperation(au.opUUID); if (op != null) { op.ChangeAssignment(au.positionUUID, au.userId); } return(null); }
ProcessDeleteOOBElement(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.DeleteOOBElement del = p as ANWI.Messaging.Ops.DeleteOOBElement; ActiveOperation op = GetOperation(del.opUUID); if (op != null) { op.DeleteFleetUnit(del.elementUUID); } return(null); }
private void ProcessUpdateRoster(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.Ops.UpdateRoster up = p as ANWI.Messaging.Ops.UpdateRoster; if (up.addedUsers != null) { AddParticipants(up.addedUsers); } if (up.removedUsers != null) { RemoveParticipants(up.removedUsers); } }
private void PushToAll(ANWI.Messaging.IMessagePayload p) { MemoryStream stream = new MemoryStream(); MessagePackSerializer.Get <ANWI.Messaging.Message>().Pack( stream, new ANWI.Messaging.Message(uuid, p)); byte[] array = stream.ToArray(); foreach (KeyValuePair <string, ConnectedUser> user in subscribed) { if (user.Value.socket != null) { user.Value.socket.Send(array); } } }
/// <summary> /// If the login was successful this closes the window and returns /// the logged in user. /// If login failed it keeps the window opened /// </summary> /// <param name="resp"></param> private void Login_Response(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.LoginResponse resp = p as ANWI.Messaging.LoginResponse; if (resp.code == ANWI.Messaging.LoginResponse.Code.OK) { Login_EndWorkingSucceeded(); MessageRouter.Instance.Disconnect(MessageRouter.Service.Auth); returnuser(resp.account); this.Dispatcher.Invoke(Close); } else { Login_EndWorkingFailed(Login_GetFailedText(resp.code)); } }
ProcessAddRate(ANWI.Messaging.IMessagePayload p) { ANWI.Messaging.AddRate ar = p as ANWI.Messaging.AddRate; bool success = false; Datamodel.StruckRate sr = null; if (Datamodel.StruckRate.FetchByUserRateId( ref sr, ar.userId, ar.rateId)) { sr.rank = ar.rank; if (Datamodel.StruckRate.Store(sr)) { logger.Info($"Updated rate {ar.rateId} to rank {ar.rank}" + $" to user {ar.userId}"); success = true; } else { logger.Error($"Failed to update rate {ar.rateId} for user" + $" {ar.userId}"); } } else { if (Datamodel.StruckRate.Create( ref sr, ar.userId, ar.rateId, ar.rank)) { logger.Info($"Added rate {ar.rateId} at rank {ar.rank} " + $"to user {ar.userId}"); success = true; } else { logger.Error($"Failed to add rate {ar.rateId} to " + $"user {ar.userId}"); } } if (ar.userId == GetUser().profile.id) { GetUser().RefreshProfile(); } return(new ANWI.Messaging.ConfirmUpdate(p, success, ar.userId)); }