/// <summary> /// Gets events but ignores all but timer ticke /// </summary> /// <param name="r">The event</param> public void EventGetter(RootEventType r) { if (r.GetType() == typeof(TickEventType)) { thisTimer = r.Time; wait = true; } }
public static void SecondarySendBeforeStartup(RootEventType r) { secondaryImmediateQueue.Enqueue(r); }
/// <summary> /// This method receives a ScenCon event, and transforms the /// data into a valid SimCore event. At this point, the /// event is sent out to the network, and received by those /// objects subscribing to those types of events. /// Parameter: /// sendingEvent: A base ScenCon event, using GetType we can /// find out what type of event it is, and based on that info /// we can create the correct SimCore event to distribute. /// <param name="sendingEvent"> /// <br><B>Sending event</B> is a Dennis style event, whose info gets converted /// and packaged in a Gabe styled event, and then added to the outgoing queue. /// </br></param> /// </summary> public static void SendEvent(RootEventType sendingEvent) { //This will discover the RootEventType's actual Type of event, //and then based on that, will break out the information into //a simulation model event, and then putEvent to the NetworkClient string eventType; eventType = sendingEvent.GetType().Name.ToString(); SimulationEvent e = null; Dictionary<string, DataValue> myAtt; switch (eventType) { case "StartupCompleteNotice": SendStartupCompleteEvent(); break; /******************New Object Event Type Creation ******************************/ case "Create_EventType": SendCreateEvent((Create_EventType)sendingEvent); break; //Break from New Event Type /******************Move Object Event Type Creation******************************/ case "Move_EventType": SendMoveEvent((Move_EventType)sendingEvent); break; /*****************Update Tag Event Type ***************/ case "UpdateTagType": SendUpdateTagEvent((UpdateTagType)sendingEvent); break; /******************Tick Event Type Creation*************************************/ case "TickEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick"); e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//ConvertInteger(sendingEvent.Timer); e["SimulationTime"] = DataValueFactory.BuildString(((TickEventType)sendingEvent).SimulationTime); latestTick = sendingEvent.Time; server.PutEvent(e); break; /******************Attack Object Event Type Creation****************************/ case "AttackObjectEvent": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "AttackObject"); try { e["ObjectID"] = DataValueFactory.BuildString(((AttackObjectEvent)sendingEvent).UnitID);//ConvertString(((AttackObjectEvent)sendingEvent).UnitID); e["TargetObjectID"] = DataValueFactory.BuildString(((AttackObjectEvent)sendingEvent).TargetObjectID);//ConvertString(((AttackObjectEvent)sendingEvent).TargetObjectID); e["CapabilityName"] = DataValueFactory.BuildString(((AttackObjectEvent)sendingEvent).CapabilityName);//ConvertString(((AttackObjectEvent)sendingEvent).CapabilityName); e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//(sendingEvent.Timer); } catch { throw new Exception("Missing required members of Attack Object Event"); } server.PutEvent(e); break; /******************Playfield Event Entered *************************************/ case "PlayfieldEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "Playfield"); try { e["MapDataFile"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).MapFileName);//ConvertString(((PlayfieldEventType)sendingEvent).MapFileName); e["IconLibrary"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).IconLibrary);//ConvertString(((PlayfieldEventType)sendingEvent).IonLibrary); e["UTMZone"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).UTMZone); //ConvertString(((PlayfieldEventType)sendingEvent).UTMZone); //e["UTMNorthing"] = DataValueFactory.BuildDouble(((PlayfieldEventType)sendingEvent).VerticalScale); //e["UTMEasting"] = DataValueFactory.BuildDouble(((PlayfieldEventType)sendingEvent).HorizontalScale); e["VerticalScale"] = DataValueFactory.BuildDouble(((PlayfieldEventType)sendingEvent).VerticalScale); e["HorizontalScale"] = DataValueFactory.BuildDouble(((PlayfieldEventType)sendingEvent).HorizontalScale); e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//ConvertInteger(sendingEvent.Timer); e["Name"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).ScenarioName);//ConvertString(((PlayfieldEventType)sendingEvent).ScenarioName); string description = ((PlayfieldEventType)sendingEvent).Description; description = description.Replace("\n", " "); description = description.Replace("\t", " "); e["Description"] = DataValueFactory.BuildString(description);//ConvertString(description); e["DefaultDisplayLabels"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).DisplayLabels);//ConvertString(description); e["DefaultDisplayTags"] = DataValueFactory.BuildString(((PlayfieldEventType)sendingEvent).DisplayTags);//ConvertString(description); } catch { throw new Exception("Missing a required attribute for Playfield"); } server.PutEvent(e); break; /******************Decision Maker Entered **************************************/ case "DecisionMakerType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject"); myAtt = new Dictionary<string, DataValue>(); try { e["ObjectType"] = DataValueFactory.BuildString("DecisionMaker"); myAtt.Add("RoleName", DataValueFactory.BuildString(((DecisionMakerType)sendingEvent).Role)); myAtt.Add("TeamMember", DataValueFactory.BuildString(((DecisionMakerType)sendingEvent).Team)); myAtt.Add("Color", DataValueFactory.BuildInteger(((DecisionMakerType)sendingEvent).Chroma)); myAtt.Add("Briefing", DataValueFactory.BuildString(((DecisionMakerType)sendingEvent).Briefing)); myAtt.Add("CanTransfer", DataValueFactory.BuildBoolean(((DecisionMakerType)sendingEvent).HasTransferAuthority)); myAtt.Add("ReportsTo", DataValueFactory.BuildStringList(((DecisionMakerType)sendingEvent).Supervisors)); myAtt.Add("CanForceTransfer", DataValueFactory.BuildBoolean(((DecisionMakerType)sendingEvent).HasForcedTransferAuthority)); myAtt.Add("CanChat", DataValueFactory.BuildStringList(((DecisionMakerType)sendingEvent).ChatPartners)); myAtt.Add("CanWhiteboard", DataValueFactory.BuildStringList(((DecisionMakerType)sendingEvent).WhiteboardPartners)); myAtt.Add("CanSpeak", DataValueFactory.BuildStringList(((DecisionMakerType)sendingEvent).VoicePartners)); myAtt.Add("IsObserver", DataValueFactory.BuildBoolean(((DecisionMakerType)sendingEvent).IsObserver)); ////myAtt.Add("ComputerControlled", DataValueFactory.BuildBoolean(((DecisionMakerType)sendingEvent).ComputerControlled)); myAtt.Add("ComputerControlled", DataValueFactory.BuildBoolean(false)); e["ID"] = DataValueFactory.BuildString(((DecisionMakerType)sendingEvent).Identifier); e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); e["Attributes"] = DataValueFactory.BuildAttributeCollection(myAtt); } catch { throw new Exception("Missing a required attribute for Decision Maker"); } server.PutEvent(e); break; /*************** Reveal Event Entered ****************************/ case "Reveal_EventType": SendRevealEvent((Reveal_EventType)sendingEvent); break; /*************** Random Seed Event Entered ****************************/ case "RandomSeedType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "RandomSeed"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//ConvertInteger(sendingEvent.Timer); e["SeedValue"] = DataValueFactory.BuildInteger(((RandomSeedType)sendingEvent).seed);//ConvertInteger(((RandomSeedType)sendingEvent).seed); } catch { throw new Exception("Missing a required attribute for Random Seed."); } server.PutEvent(e); break; /**********************************Team Definition Event *********************/ case "TeamType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); myAtt = new Dictionary<string, DataValue>(); myAtt.Add("TeamName", DataValueFactory.BuildString(((TeamType)sendingEvent).Name)); List<string> hostilities = new List<string>(); for (int x = 0; x < ((TeamType)sendingEvent).Count(); x++) { hostilities.Add(((TeamType)sendingEvent)[x]); } StringListValue listOfHostiles = new StringListValue(); listOfHostiles.strings = hostilities; myAtt.Add("TeamHostility", (DataValue)listOfHostiles); e["Attributes"] = DataValueFactory.BuildAttributeCollection(myAtt); e["ID"] = DataValueFactory.BuildString(((TeamType)sendingEvent).Name); e["ObjectType"] = DataValueFactory.BuildString("Team"); //e["StateTable"] = DataValueFactory.BuildString(string.Empty); } catch { throw new Exception("Missing a required attribute for Team definition."); } server.PutEvent(e); break; /**********************************Network Definition Event *********************/ case "NetworkType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); myAtt = new Dictionary<string, DataValue>(); List<string> members = new List<string>(); for (int x = 0; x < ((NetworkType)sendingEvent).Count(); x++) { members.Add(((NetworkType)sendingEvent)[x]); } StringListValue listOfMembers = new StringListValue(); listOfMembers.strings = members; myAtt.Add("DMMembers", (DataValue)listOfMembers); e["Attributes"] = DataValueFactory.BuildAttributeCollection(myAtt); e["ID"] = DataValueFactory.BuildString(((NetworkType)sendingEvent).Name); e["ObjectType"] = DataValueFactory.BuildString("SensorNetwork"); //e["StateTable"] = DataValueFactory.BuildString(string.Empty); } catch { throw new Exception("Missing a required attribute for Network definition."); } server.PutEvent(e); break; /******************* Region Definition ********************************************/ case "RegionEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); myAtt = new Dictionary<string, DataValue>(); List<PolygonValue.PolygonPoint> listOfPoints = new List<PolygonValue.PolygonPoint>(); PolygonValue.PolygonPoint point; foreach (PointType pt in ((RegionEventType)sendingEvent).Vertices) { point = new PolygonValue.PolygonPoint(pt.X, pt.Y); listOfPoints.Add(point); } PolygonValue pointsList = new PolygonValue(); pointsList.points = listOfPoints; myAtt.Add("Polygon", (DataValue)pointsList); e["ObjectType"] = DataValueFactory.BuildString("LandRegion"); if (((RegionEventType)sendingEvent).End != null) { myAtt.Add("EndHeight", DataValueFactory.BuildDouble((double)((RegionEventType)sendingEvent).End)); e["ObjectType"] = DataValueFactory.BuildString("ScoringRegion"); } if (((RegionEventType)sendingEvent).Start != null) { myAtt.Add("StartHeight", DataValueFactory.BuildDouble((double)((RegionEventType)sendingEvent).Start)); } if (((RegionEventType)sendingEvent).ReferencePoint != null) { PointType refPoint = ((RegionEventType)sendingEvent).ReferencePoint; myAtt.Add("ReferencePoint", DataValueFactory.BuildLocation(refPoint.X,refPoint.Y,0,true)); } if (((RegionEventType)sendingEvent).IsDynamicRegion != null) { myAtt.Add("IsDynamicRegion", DataValueFactory.BuildBoolean((bool)((RegionEventType)sendingEvent).IsDynamicRegion)); } if (((RegionEventType)sendingEvent).SpeedMultiplier != null) { myAtt.Add("SpeedMultiplier", DataValueFactory.BuildDouble((double)((RegionEventType)sendingEvent).SpeedMultiplier)); e["ObjectType"] = DataValueFactory.BuildString("ActiveRegion"); } if (((RegionEventType)sendingEvent).BlocksMovement != null) { myAtt.Add("BlocksMovement", DataValueFactory.BuildBoolean((Boolean)((RegionEventType)sendingEvent).BlocksMovement)); } //if (((RegionEventType)sendingEvent).BlocksMovement != null) //{ // myAtt.Add("BlocksMovement", DataValueFactory.BuildBoolean((Boolean)((RegionEventType)sendingEvent).BlocksMovement)); //} List<string> sensorsBlocked = new List<string>(); if ( (((RegionEventType)sendingEvent).SensorsBlocked != null) && (((RegionEventType)sendingEvent).SensorsBlocked.Count > 0)) { // string sensorBlocked; for (int sensor = 0; sensor < ((RegionEventType)sendingEvent).SensorsBlocked.Count; sensor++) { sensorsBlocked.Add(((RegionEventType)sendingEvent).SensorsBlocked[sensor]); } } StringListValue mySensorsBlocked = new StringListValue(); mySensorsBlocked.strings = sensorsBlocked; myAtt.Add("BlocksSensorTypes", (DataValue)mySensorsBlocked); myAtt.Add("IsVisible", DataValueFactory.BuildBoolean((Boolean)((RegionEventType)sendingEvent).IsVisible)); myAtt.Add("IsActive", DataValueFactory.BuildBoolean((Boolean)((RegionEventType)sendingEvent).IsActive)); myAtt.Add("DisplayColor", DataValueFactory.BuildInteger((int)((RegionEventType)sendingEvent).Chroma)); try { if (((RegionEventType)sendingEvent).ObstructedViewImage != "" && ((RegionEventType)sendingEvent).ObstructedViewImage != null) { myAtt.Add("ObstructedViewImage", DataValueFactory.BuildString(((RegionEventType)sendingEvent).ObstructedViewImage)); } }catch(Exception ex) {} try { myAtt.Add("ObstructionOpacity", DataValueFactory.BuildString(((RegionEventType)sendingEvent).ObstructionOpacity.ToString())); }catch(Exception ex2) {} //e["BlocksSensorTypes"]= e["ID"] = DataValueFactory.BuildString(((RegionEventType)sendingEvent).UnitID); e["Attributes"] = DataValueFactory.BuildAttributeCollection(myAtt); } catch { throw new Exception("Missing a required attribute for Region definition"); } server.PutEvent(e); break; case "ActiveRegionUpdateType": SendActiveRegionUpdateEvent((ActiveRegionUpdateType)sendingEvent); break; case "WeaponLaunch_EventType": SendWeaponLaunchEvent((WeaponLaunch_EventType)sendingEvent); break; case "WeaponLaunchFailure_EventType": SendWeaponLaunchFailureEvent((WeaponLaunchFailure_EventType)sendingEvent); break; case "LaunchEventType": SendLaunchEvent((LaunchEventType)sendingEvent); break; case "WeaponLaunchEventType": SendWeaponLaunchEvent((WeaponLaunchEventType)sendingEvent); break; case "SubplatformLaunchType": SendSubplatformLaunchEvent((SubplatformLaunchType)sendingEvent); break; case "SubplatformDockType": SendSubplatformDockEvent((SubplatformDockType)sendingEvent); break; case "StateChangeEvent": SendStateChangeEvent((StateChangeEvent)sendingEvent); break; case "OpenChatRoomType": SendOpenChatRoomEvent((OpenChatRoomType)sendingEvent); break; case "CloseChatRoomType": SendCloseChatRoomType((CloseChatRoomType)sendingEvent); break; case "OpenWhiteboardRoomType": SendOpenWhiteboardRoomEvent((OpenWhiteboardRoomType)sendingEvent); break; case "OpenVoiceChannelType": SendOpenVoiceChannelEvent((OpenVoiceChannelType)sendingEvent); break; case "CloseVoiceChannelType": SendCloseVoiceChannelType((CloseVoiceChannelType)sendingEvent); break; /* case "GrantVoiceAccessType": SendAddToVoiceChannelEvent((GrantVoiceAccessType)sendingEvent); break; case "RemoveVoiceAccessType": SendRemoveFromVoiceChannelEvent((RemoveVoiceAccessType)sendingEvent); break; case "CreateChatRoomFailureType": SendCreateChatRoomFailureType((CreateChatRoomFailureType)sendingEvent); break;*/ case "TransferEvent": SendTransferEvent((TransferEvent)sendingEvent); break; case "EngramSettingType": SendEngramValue(((EngramSettingType)sendingEvent)); break; case "ChangeEngramType": SendEngramValue(((ChangeEngramType)sendingEvent)); break; case "ClientSideAssetTransferType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "ClientSideAssetTransferAllowed"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//ConvertInteger(sendingEvent.Timer); e["EnableAssetTransfer"] = DataValueFactory.BuildBoolean(((ClientSideAssetTransferType)sendingEvent).assetTransferEnabled);//ConvertInteger(((RandomSeedType)sendingEvent).seed); } catch { throw new Exception("Missing a required attribute for ClientSideAssetTransferType"); } server.PutEvent(e); break; case "ClientSideStartingLabelVisibleType": /* AD: TODO e = SimulationEventFactory.BuildEvent(ref simModelInfo, "ClientSideAssetTransferAllowed"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time);//ConvertInteger(sendingEvent.Timer); e["EnableAssetTransfer"] = DataValueFactory.BuildBoolean(((ClientSideAssetTransferType)sendingEvent).assetTransferEnabled);//ConvertInteger(((RandomSeedType)sendingEvent).seed); } catch { throw new Exception("Missing a required attribute for ClientSideAssetTransferType"); } server.PutEvent(e); */ break; case "ClientSideRangeRingVisibilityType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "ClientSideRangeRingDisplayLevel"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); e["Value"] = DataValueFactory.BuildString(((ClientSideRangeRingVisibilityType)sendingEvent).clientSideRangeRingVisibility); } catch { throw new Exception("Missing a required attribute for ClientSideRangeRingVisibilityType"); } server.PutEvent(e); break; case "SendChatMessageType": SendChatMessageType scm = (SendChatMessageType)sendingEvent; /* Done in Timer... * if (!ChatRooms.IsRoom(scm.RoomName)) break; */ try { e = SimulationEventFactory.BuildEvent(ref simModelInfo, "TextChatRequest"); e["ChatBody"] = DataValueFactory.BuildString(scm.Message); e["UserID"] = DataValueFactory.BuildString(scm.Sender); e["TargetUserID"] = DataValueFactory.BuildString(scm.RoomName); } catch { throw new Exception("Missing a required attribute for SendChatMessage"); } server.PutEvent(e); break; case "SendVoiceMessageType": SendVoiceMessageType svm = (SendVoiceMessageType)sendingEvent; try { e = SimulationEventFactory.BuildEvent(ref simModelInfo, "PlayVoiceMessage"); e["Channel"] = DataValueFactory.BuildString(svm.ChannelName); e["File"] = DataValueFactory.BuildString(svm.FilePath); e["Time"] = DataValueFactory.BuildInteger(svm.Time); } catch { throw new Exception("Missing a required attribute for SendVoiceMessage"); } server.PutEvent(e); break; case "SendVoiceMessageToUserType": SendVoiceMessageToUserType svmtu = (SendVoiceMessageToUserType)sendingEvent; try { e = SimulationEventFactory.BuildEvent(ref simModelInfo, "PlayVoiceMessageToUser"); e["DecisionMakerID"] = DataValueFactory.BuildString(svmtu.DecisionMakerID); e["File"] = DataValueFactory.BuildString(svmtu.FilePath); e["Time"] = DataValueFactory.BuildInteger(svmtu.Time); } catch { throw new Exception("Missing a required attribute for SendVoiceMessageToUser"); } server.PutEvent(e); break; case "SystemMessage": SystemMessage sm = (SystemMessage)sendingEvent; e = SimulationEventFactory.BuildEvent(ref simModelInfo, "SystemMessage"); e["PlayerID"] = DataValueFactory.BuildString(sm.Addressee); e["Message"] = DataValueFactory.BuildString(sm.Message); e["TextColor"] = DataValueFactory.BuildInteger(sm.TextColor); e["DisplayMode"] = DataValueFactory.BuildString(sm.DisplayMode); server.PutEvent(e); break; case "ClassificationsType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "InitializeClassifications"); try { e["Time"] = DataValueFactory.BuildInteger(sendingEvent.Time); e["Classifications"] = DataValueFactory.BuildStringList(((ClassificationsType)sendingEvent).classifications); } catch { throw new Exception("Missing a required attribute for ClientSideRangeRingVisibilityType"); } server.PutEvent(e); break; case "ForkReplayEventType": server.PutEvent(((ForkReplayEventType)sendingEvent).Event); break; /******************No valid event entered***************************************/ /******************Very Basic Event Type Creation*******************************/ case "RootEventType": throw new Exception("RootEventType events should not be created"); /******************Base Scenario Event Type Creation****************************/ case "ScenarioEventType": throw new Exception("ScenarioEventType events should not be created"); default: //What should it do in this case? Nothing? Console.Out.Write("In EventCommunicator: Missing event type to send: " + eventType); break; } }