public SimulationEvent MoveDoneReceived(SimulationEvent e, SimulationModelInfo model, SimulationEvent theTick) { //Should receieve a MoveDone event, and create a new move event and send //it to the Queue Manager with time ticks + 1. SimulationEvent ee = SimulationEventFactory.BuildEvent(ref model, "MoveObject"); ee.eventType = "MoveObject"; DataValue myDV = new IntegerValue(); myDV = e["ObjectID"]; ee["ObjectID"] = myDV; myDV = new LocationValue(); ((LocationValue)(myDV)).X = 150; ((LocationValue)(myDV)).Y = 150; ((LocationValue)(myDV)).Z = 50; ee["DestinationLocation"] = myDV; myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = .5; ee["Throttle"] = myDV; myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = ((IntegerValue)theTick.parameters["Time"]).value + 1000; ee["Time"] = myDV; return ee; }
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 "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); default: return(null); } } else { return(null); } }
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; DataValue dv; bool hasAtt = false; string attName = null, attSettingType = null; switch (eventType) { /******************Very Basic Event Type Creation*******************************/ case "RootEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "BaseEvent"); dv = new IntegerValue(); ((IntegerValue)dv).value = sendingEvent.Timer; e.parameters["Time"] = dv; break; /******************Base Scenario Event Type Creation****************************/ case "ScenarioEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "BaseEvent"); dv = new IntegerValue(); ((IntegerValue)dv).value = sendingEvent.Timer; e.parameters["Time"] = dv; break; /******************New Object Event Type Creation ******************************/ case "Create_EventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject"); Dictionary<string, DataValue> myAtt; myAtt = new Dictionary<string, DataValue>(); dv = new IntegerValue(); ((IntegerValue)dv).value = sendingEvent.Timer; e.parameters["Time"] = dv; //((StringValue)e.parameters["ObjectType"]).value = "PhysicalObject"; //Replaced by Kind from Scenario file ((StringValue)e.parameters["ObjectType"]).value = ((Create_EventType)sendingEvent).UnitKind.ToString(); // Attribute Insertion // if (((Create_EventType)sendingEvent).UnitID != null) { dv = new StringValue(); ((StringValue)dv).value = ((Create_EventType)sendingEvent).UnitID.ToString(); myAtt.Add("ID", dv); hasAtt = true; } List<ParameterSettingType> eventsList = ((Create_EventType)sendingEvent).Parameters; foreach (ParameterSettingType key in eventsList) { attName = key.Name; attSettingType = key.Setting.GetType().Name; if (attSettingType == "VectorType") { dv = new LocationValue(); ((LocationValue)dv).X = ((VectorType)key.Setting).X; ((LocationValue)dv).Y = ((VectorType)key.Setting).Y; ((LocationValue)dv).Z = ((VectorType)key.Setting).Z; myAtt.Add(attName, dv); } else if (attSettingType == "String") { switch (attName) { case "ID": //this shouldn't occur? dv = new StringValue(); ((StringValue)dv).value = key.Setting.ToString(); myAtt.Add(attName, dv); break; case "ObjectName": dv = new StringValue(); ((StringValue)dv).value = key.Setting.ToString(); myAtt.Add(attName, dv); break; case "ObjectState": dv = new StringValue(); ((StringValue)dv).value = key.Setting.ToString(); myAtt.Add(attName, dv); break; case "ClassName": dv = new StringValue(); ((StringValue)dv).value = key.Setting.ToString(); myAtt.Add(attName, dv); break; case "MaximumSpeed": dv = new DoubleValue(); ((DoubleValue)dv).value = Convert.ToDouble(key.Setting.ToString()); myAtt.Add(attName, dv); break; case "Throttle": dv = new DoubleValue(); ((DoubleValue)dv).value = Convert.ToDouble(key.Setting.ToString()); myAtt.Add(attName, dv); break; default: break; } } else ; //Should be a vector type or a string, if not... do nothing. } if (hasAtt) ((AttributeCollectionValue)e.parameters["Attributes"]).attributes = myAtt; break; /******************Move Object Event Type Creation******************************/ case "Move_EventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "MoveObject"); if (((Move_EventType)sendingEvent).UnitID != null) { dv = new StringValue(); ((StringValue)dv).value = ((Move_EventType)sendingEvent).UnitID.ToString(); e.parameters["ObjectID"] = dv; } if (((Move_EventType)sendingEvent).Location != null) { dv = new LocationValue(); ((LocationValue)dv).X = ((VectorType)((Move_EventType)sendingEvent).Location).X; ((LocationValue)dv).Y = ((VectorType)((Move_EventType)sendingEvent).Location).Y; ((LocationValue)dv).Z = ((VectorType)((Move_EventType)sendingEvent).Location).Z; e.parameters["DestinationLocation"] = dv; } dv = new DoubleValue(); ((DoubleValue)dv).value = ((Double)((Move_EventType)sendingEvent).Throttle); e.parameters["Throttle"] = dv; dv = new IntegerValue(); ((IntegerValue)dv).value = sendingEvent.Timer; e.parameters["Time"] = dv; break; /******************Tick Event Type Creation*************************************/ case "TickEventType": e = SimulationEventFactory.BuildEvent(ref simModelInfo, "TimeTick"); dv = new IntegerValue(); ((IntegerValue)dv).value = sendingEvent.Timer; e.parameters["Time"] = dv; break; /******************No valid event entered***************************************/ default: //What should it do in this case? Nothing? break; } if (e != null) server.PutEvent(e); }
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 "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; default: return null; } } else { return null; } }
private static SimulationEvent populateQueue3() { SimulationEvent ee = new SimulationEvent(); Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>(); ee.eventType = "NewObject"; DataValue myDV = new StringValue(); ((StringValue)(myDV)).value = "PhysicalObject"; ee.parameters.Add("ObjectType", myDV); // START OF ATTRIBUTE DEFINITIONS // myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 1; myAtt.Add("ID", myDV); myDV = new StringValue(); ((StringValue)(myDV)).value = "Second Object"; myAtt.Add("ObjectName", myDV); myDV = new StringValue(); ((StringValue)(myDV)).value = "flying"; myAtt.Add("ObjectState", myDV); myDV = new StringValue(); ((StringValue)(myDV)).value = "NoClassesYet"; myAtt.Add("ClassName", myDV); myDV = new LocationValue(); ((LocationValue)(myDV)).X = 100; ((LocationValue)(myDV)).Y = 100; ((LocationValue)(myDV)).Z = 0; myAtt.Add("Location", myDV); myDV = new VelocityValue(); ((VelocityValue)(myDV)).VX = 0; ((VelocityValue)(myDV)).VY = 0; ((VelocityValue)(myDV)).VZ = 0; myAtt.Add("Velocity", myDV); myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = 1; myAtt.Add("MaximumSpeed", myDV); myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = 0.0; myAtt.Add("Throttle", myDV); myDV = new LocationValue(); ((LocationValue)(myDV)).X = 0; ((LocationValue)(myDV)).Y = 0; ((LocationValue)(myDV)).Z = 0; myAtt.Add("DestinationLocation", myDV); // END OF ATTRIBUTE DEFINITIONS // myDV = new AttributeCollectionValue(); ((AttributeCollectionValue)(myDV)).attributes = myAtt; ee.parameters.Add("Attributes", myDV); myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 5000; ee.parameters.Add("Time", myDV); return ee; }
private static SimulationEvent populateQueue4() { SimulationEvent ee = new SimulationEvent(); Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>(); ee.eventType = "MoveObject"; DataValue myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 1; ee.parameters.Add("ObjectID", myDV); myDV = new LocationValue(); ((LocationValue)(myDV)).X = 100; ((LocationValue)(myDV)).Y = 100; ((LocationValue)(myDV)).Z = 100; ee.parameters.Add("DestinationLocation", myDV); myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = .5; ee.parameters.Add("Throttle", myDV); myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 10000; ee.parameters.Add("Time", myDV); return ee; }