private void btnOpenVoice_Click(object sender, EventArgs e) { if (null == lbxDecisionMakers.SelectedItem) { MessageBox.Show("Please select an owner for the voice channel."); return; } if ((null == lbxVoiceMembers.SelectedItems) || (lbxVoiceMembers.SelectedItems.Count < 2)) { MessageBox.Show("Please select at least two members for the voice channel."); return; } if ("" == txtOpenVoiceName.Text) { MessageBox.Show("Please provide a name for the voice channel."); return; } SimulationEvent openVoice = SimulationEventFactory.BuildEvent(ref simModelInfo, "RequestVoiceChannelCreate"); openVoice["ChannelName"] = DataValueFactory.BuildString(txtOpenVoiceName.Text); openVoice["SenderDM_ID"] = DataValueFactory.BuildString((string)lbxDecisionMakers.SelectedItem); StringListValue voiceMembers = new StringListValue(); for (int i = 0; i < lbxVoiceMembers.SelectedItems.Count; i++) voiceMembers.strings.Add((string)lbxVoiceMembers.SelectedItems[i]); openVoice["MembershipList"] = DataValueFactory.BuildFromDataValue(voiceMembers); EventListener.Network.PutEvent(openVoice); }
/// <summary> /// Takes an xml string, and returns a DataValue object. /// Returns null if the xml doesn't represent a DataValue. /// </summary> /// <param name="xml"></param> /// <returns></returns> public static DataValue XMLDeserialize(string xml) { Match m = typeregex.Match(xml); if (m.Success) { Group g = m.Groups[1]; string dataType = g.ToString(); switch (dataType) { case "StringType": StringValue sv = new StringValue(); sv.FromXML(xml); return sv; case "DoubleType": DoubleValue dv = new DoubleValue(); dv.FromXML(xml); return dv; case "IntegerType": IntegerValue iv = new IntegerValue(); iv.FromXML(xml); return iv; case "BooleanType": BooleanValue bv = new BooleanValue(); bv.FromXML(xml); return bv; case "LocationType": LocationValue lv = new LocationValue(); lv.FromXML(xml); return lv; case "VelocityType": VelocityValue vv = new VelocityValue(); vv.FromXML(xml); return vv; case "AttributeCollectionType": AttributeCollectionValue av = new AttributeCollectionValue(); av.FromXML(xml); return av; case "CustomAttributesType": CustomAttributesValue cav = new CustomAttributesValue(); cav.FromXML(xml); return cav; case "StringListType": StringListValue slv = new StringListValue(); slv.FromXML(xml); return slv; case "PolygonType": PolygonValue polyv = new PolygonValue(); polyv.FromXML(xml); return polyv; case "StateTableType": StateTableValue stv = new StateTableValue(); stv.FromXML(xml); return stv; case "CapabilityType": CapabilityValue cv = new CapabilityValue(); cv.FromXML(xml); return cv; case "VulnerabilityType": VulnerabilityValue vv2 = new VulnerabilityValue(); vv2.FromXML(xml); return vv2; case "ConeType": ConeValue cv2 = new ConeValue(); cv2.FromXML(xml); return cv2; case "SensorType": SensorValue sv2 = new SensorValue(); sv2.FromXML(xml); return sv2; case "SensorArrayType": SensorArrayValue sav = new SensorArrayValue(); sav.FromXML(xml); return sav; case "EmitterType": EmitterValue ev = new EmitterValue(); ev.FromXML(xml); return ev; case "RangeRingDisplayType": RangeRingDisplayValue rrdv = new RangeRingDisplayValue(); rrdv.FromXML(xml); return rrdv; case "AttackCollectionType": AttackCollectionValue attCV = new AttackCollectionValue(); attCV.FromXML(xml); return attCV; case "WrapperType": WrapperValue wrapper = new WrapperValue(); wrapper.FromXML(xml); return wrapper; case "ClassificationDisplayRulesType": ClassificationDisplayRulesValue cdrv = new ClassificationDisplayRulesValue(); cdrv.FromXML(xml); return cdrv; default: return null; } } else { return null; } }
/// <summary> /// This method extracts an objects attributes from DetectedValues in an ACV, and then sends /// out the appropriate info to a specified player. /// </summary> /// <param name="destinationPlayerID"></param> /// <param name="objectsAttributes"></param> /// <param name="time"></param> private void SendViewProAttributeUpdate(string destinationPlayerID, AttributeCollectionValue objectsAttributes) { if (!activeDMs.Contains(destinationPlayerID)) return; SimulationEvent vpu = null; objectsAttributes = ExtractDetectedValuesFromACV(objectsAttributes); AddCapabilitiesAndWeaponsList(ref objectsAttributes); if (objectsAttributes.attributes.ContainsKey("Vulnerability")) { List<string> vulnerabilityList = new List<string>(); foreach (VulnerabilityValue.Transition t in ((VulnerabilityValue)objectsAttributes["Vulnerability"]).transitions) { foreach (VulnerabilityValue.TransitionCondition tc in t.conditions) { if (!vulnerabilityList.Contains(tc.capability)) { vulnerabilityList.Add(tc.capability); } } } // objectsAttributes.attributes.Remove("Vulnerability"); StringListValue sl = new StringListValue(); sl.strings = vulnerabilityList; objectsAttributes.attributes.Add("VulnerabilityList", sl as DataValue); } if (objectsAttributes.attributes.ContainsKey("Sensors")) { List<string> sensorList = new List<string>(); foreach (SensorValue sv in ((SensorArrayValue)objectsAttributes["Sensors"]).sensors) { if (!sensorList.Contains(sv.sensorName)) { sensorList.Add(sv.sensorName); } } // objectsAttributes.attributes.Remove("Sensors"); StringListValue sl = new StringListValue(); sl.strings = sensorList; objectsAttributes.attributes.Add("SensorList", sl as DataValue); } objectsAttributes["DockedObjects"] = new StringListValue(); List<string> strList = new List<string>(); //if (((StringValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["ParentObjectID"].GetDataValue()).value != string.Empty) //{ // strList.Add("Dock To Parent"); //} strList.AddRange(((StringListValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["DockedObjects"].GetDataValue()).strings); ((StringListValue)objectsAttributes["DockedObjects"]).strings = strList; vpu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProAttributeUpdate"); if (!objectsAttributes.attributes.ContainsKey("MaximumSpeed")) { DoubleValue dv = new DoubleValue(); dv.value = ((DoubleValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["MaximumSpeed"].GetDataValue()).value * ((DoubleValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["ActiveRegionSpeedMultiplier"].GetDataValue()).value; objectsAttributes.attributes.Add("MaximumSpeed", dv as DataValue); } String classification = GetClassificationForDM(((StringValue)objectsAttributes["ID"]).value, destinationPlayerID); objectsAttributes["CurrentClassification"] = DataValueFactory.BuildString(classification); String overrideIcon = GetClassificationBasedIcon(((StringValue)objectsAttributes["ID"]).value, classification); if (overrideIcon != String.Empty) { objectsAttributes["IconName"] = DataValueFactory.BuildString(overrideIcon); } else { SimulationObjectProxy ob = objectProxies[((StringValue)objectsAttributes["ID"]).value]; objectsAttributes["IconName"] = DataValueFactory.BuildString(((StringValue)ob["IconName"].GetDataValue()).value); } vpu["TargetPlayer"] = DataValueFactory.BuildString(destinationPlayerID); vpu["ObjectID"] = objectsAttributes["ID"]; vpu["OwnerID"] = objectsAttributes["OwnerID"]; //RANGE RING LOGIC string ownerId = ((StringValue)objectsAttributes["OwnerID"]).value; if (( (destinationPlayerID == ownerId || selectedRangeRingLevel == RangeRingLevels.FULL) || (selectedRangeRingLevel == RangeRingLevels.SENSORNETWORK && AreDecisionMakersInSharedNetwork(destinationPlayerID, ownerId)) ) && selectedRangeRingLevel != RangeRingLevels.DISABLED) //this needs to be based on ownership, etc. { SimulationObjectProxy objProxy = null; if (objectProxies.ContainsKey(((StringValue)objectsAttributes["ID"]).value)) { objProxy = objectProxies[((StringValue)objectsAttributes["ID"]).value]; AddRangeRings(ref objectsAttributes, ref objProxy); } else { //if not, something's wrong Console.WriteLine("HELP"); } } else { objectsAttributes.attributes.Remove("Vulnerability"); objectsAttributes.attributes.Remove("Sensors"); objectsAttributes.attributes.Remove("Capability"); } // //if (objectsAttributes.attributes.ContainsKey("MaximumSpeed")) //{ // Console.Out.Write(String.Format("{0} moving at {1}", ((StringValue)objectsAttributes["ID"]).value, ((DoubleValue)objectsAttributes["MaximumSpeed"]).value)); // //foreach (string s in objectsAttributes.attributes.Keys) // //{ // // Console.Out.Write(String.Format("{0}, ", s)); // //} // Console.Out.WriteLine(); //} vpu["Attributes"] = objectsAttributes; vpu["Time"] = DataValueFactory.BuildInteger(currentTick); string xml = DataValueFactory.XMLSerialize(objectsAttributes); AttributeCollectionValue temp = new AttributeCollectionValue(); temp.FromXML(xml); distClient.PutEvent(vpu); }
private void ChangeCanOwn(StringListValue newValue, string objectID) { SimulationObjectProxy obj = objectProxies[objectID]; if (obj == null) return; obj["CanOwn"].SetDataValue(newValue); }
/// <summary> /// /// </summary> /// <exclude/> /// <param name="dv"></param> /// <returns></returns> public static DataValue BuildFromDataValue(DataValue dv) { DataValue returnDV; switch (dv.dataType) { case "WrapperType": returnDV = DataValueFactory.BuildWrapper(((WrapperValue)dv).value); return returnDV; break; case "StringType": returnDV = DataValueFactory.BuildString(((StringValue)dv).value); return returnDV; break; case "IntegerType": returnDV = DataValueFactory.BuildInteger(((IntegerValue)dv).value); return returnDV; break; case "DoubleType": returnDV = DataValueFactory.BuildDouble(((DoubleValue)dv).value); return returnDV; break; case "LocationType": returnDV = DataValueFactory.BuildLocation(((LocationValue)dv).X, ((LocationValue)dv).Y, ((LocationValue)dv).Z, ((LocationValue)dv).exists); return returnDV; break; case "VelocityType": returnDV = DataValueFactory.BuildVelocity(((VelocityValue)dv).VX, ((VelocityValue)dv).VY, ((VelocityValue)dv).VZ); return returnDV; break; case "StringListType": returnDV = new StringListValue(); foreach (string s in ((StringListValue)dv).strings) { ((StringListValue)returnDV).strings.Add(s); } return returnDV; break; case "RangeRingDisplayType": returnDV = DataValueFactory.BuildRangeRingDisplayValue(((RangeRingDisplayValue)dv).name, ((RangeRingDisplayValue)dv).type, ((RangeRingDisplayValue)dv).isWeapon, ((RangeRingDisplayValue)dv).rangeIntensities); return returnDV; break; case "AttackCollectionType": returnDV = new AttackCollectionValue(); String errMsg = String.Empty; foreach (AttackCollectionValue.AttackValue av in ((AttackCollectionValue)dv).GetCurrentAttacks()) { AttackCollectionValue.AttackValue newAttack = new AttackCollectionValue.AttackValue(av.attackStartTime, av.attackTimeWindow, av.targetObjectId, av.attackingObjectId, av.capabilityName, av.percentageApplied, av.isSelfdefense); ((AttackCollectionValue)returnDV).AddAttack(newAttack, out errMsg); } return returnDV; break; default: returnDV = new DataValue(); returnDV = dv; return returnDV; } return null; }
private static void SendUpdateTagEvent(UpdateTagType incoming) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo,"UpdateTag"); try { e["UnitID"]=DataValueFactory.BuildString(incoming.UnitID); e["Tag"]=DataValueFactory.BuildString(incoming.NewTag); StringListValue teamMembers = new StringListValue(); teamMembers.strings = incoming.TeamMembers; e["TeamMembers"]=(DataValue)teamMembers; } catch { throw new Exception("Error updating tag '"+incoming.NewTag+"'"); } server.PutEvent(e); }
/// <summary> /// This method takes in a dictionary that represents the SimulationModel parameters, and a Dictionary /// that is to be used to populate a DataValue dictionary given the Simulation Model. Foreach entry /// in the SimModel dictionary, if the same key (witch is converted from SimCoreKey to ScenConKey) /// exists in the given DataValue dictionary, then that value is used rather than a default DataValue. /// The newly created DataValue dictionary represents every member in the SimModel dictionary, and uses /// the available data from the given DataValue dictionary. /// </summary> /// <param name="objectAttributes"> /// This Dictionary is indexed by a string that is the parameter name, and the value is an AttributeInfo /// object that contains the name and type of the parameter. /// </param> /// <param name="SendingEventAttributes"> /// This dictionary contains attributes given from the ScenCon, to be passed on to the SimCore. The /// data is copied over to the correct entry in the resulting dictionary. /// </param> /// <returns></returns> private static Dictionary<string, DataValue> ParseAttributesList(Dictionary<string, AttributeInfo> objectAttributes, Dictionary<string, object> SendingEventAttributes) { Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>(); DataValue dv; string scenConKey, simCoreKey, attributeType; foreach (KeyValuePair<string, AttributeInfo> pair in objectAttributes) { if (!simModelIgnoreList.Contains(pair.Key)) { simCoreKey = pair.Key; scenConKey = convertSimCoreToScenCon(simCoreKey); if (SendingEventAttributes.ContainsKey(scenConKey)) {//Copy over the data attributeType = pair.Value.dataType; switch (attributeType) { //attribute type will be either the system defined name, or Dennis' type case "StringType": if (SendingEventAttributes.ContainsKey(scenConKey)) { myAtt.Add(simCoreKey, DataValueFactory.BuildString(Convert.ToString(SendingEventAttributes[scenConKey]))); }/*ConvertString(Convert.ToString(SendingEventAttributes[scenConKey])*/ else { myAtt.Add(simCoreKey, DataValueFactory.BuildString(string.Empty)); }/*ConvertString(String.Empty)*/ break; case "IntegerType": dv = new IntegerValue(); if (SendingEventAttributes.ContainsKey(scenConKey)) { dv = DataValueFactory.BuildInteger(Convert.ToInt32(SendingEventAttributes[scenConKey]));//ConvertInteger(Convert.ToInt32(SendingEventAttributes[scenConKey])); } myAtt.Add(simCoreKey, dv); break; case "BooleanType": dv = new BooleanValue(); if (SendingEventAttributes.ContainsKey(scenConKey)) { dv = DataValueFactory.BuildBoolean(Convert.ToBoolean(SendingEventAttributes[scenConKey]));//ConvertBoolean(Convert.ToBoolean(SendingEventAttributes[scenConKey])); } myAtt.Add(simCoreKey, dv); break; case "DoubleType": dv = new DoubleValue(); if (SendingEventAttributes.ContainsKey(scenConKey)) { dv = DataValueFactory.BuildDouble(Convert.ToDouble(SendingEventAttributes[scenConKey]));//ConvertDouble(Convert.ToDouble(SendingEventAttributes[scenConKey])); } myAtt.Add(simCoreKey, dv); break; case "LocationType": dv = new LocationValue(); ((LocationValue)dv).exists = false; if (SendingEventAttributes.ContainsKey(scenConKey)) { LocationType lt = SendingEventAttributes[scenConKey] as LocationType; dv = DataValueFactory.BuildLocation(lt.X, lt.Y, lt.Z, true);//ConvertLocation((LocationType)SendingEventAttributes[scenConKey], true); } myAtt.Add(simCoreKey, dv); break; case "VelocityType": dv = new VelocityValue(); if (SendingEventAttributes.ContainsKey(scenConKey)) { VelocityType vt = SendingEventAttributes[scenConKey] as VelocityType; dv = DataValueFactory.BuildVelocity(vt.VX, vt.VY, vt.VZ);//ConvertVelocity((VelocityType)SendingEventAttributes[scenConKey]); } myAtt.Add(simCoreKey, dv); break; case "StringListType": dv = new StringListValue(); if (SendingEventAttributes.ContainsKey(scenConKey)) { ((StringListValue)dv).strings = (List<string>)SendingEventAttributes[scenConKey]; } break; default: break; } } } } return myAtt; }
/// <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; } }
private static void SendOpenVoiceChannelEvent(OpenVoiceChannelType incoming) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "CreateVoiceChannel"); try { e["Time"] = DataValueFactory.BuildInteger(incoming.Time); e["ChannelName"] = DataValueFactory.BuildString(incoming.Channel); // ... //e["SenderDM_ID"] = DataValueFactory.BuildString(incoming.Owner); List<string> members = new List<string>(incoming.InitialMembers.ToArray()); //for (int i = 0; i < incoming.InitialMembers.Count;i++) // members.Add(incoming.InitialMembers[i]); StringListValue listOfMembers = new StringListValue(); listOfMembers.strings = members; e["MembershipList"] = (DataValue)listOfMembers; } catch (SystemException ev) { throw new Exception("Missing a required attribute for OpenVoiceChannel.", ev); } server.PutEvent(e); }
/// <summary> /// This method sends a command to open a whiteboardroom after the command has been validated /// </summary> /// <param name="incoming">The definition of the room, giving the name, the members and the requestor</param> private static void SendOpenWhiteboardRoomEvent(OpenWhiteboardRoomType incoming) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "CreateWhiteboardRoom"); try { e["Time"] = DataValueFactory.BuildInteger(incoming.Time); e["RoomName"] = DataValueFactory.BuildString(incoming.Room); // ... e["SenderDM_ID"] = DataValueFactory.BuildString(incoming.Owner); List<string> members = new List<string>(); for (int i = 0; i < incoming.Members.Count; i++) { members.Add(incoming.Members[i]); } StringListValue listOfMembers = new StringListValue(); listOfMembers.strings = members; e["MembershipList"] = (DataValue)listOfMembers; } catch (SystemException ev) { throw new Exception("Missing a required attribute for OpenWhiteboardRoom.", ev); } server.PutEvent(e); }