Esempio n. 1
0
        /// <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;
            }

        }
Esempio n. 2
0
        public void SendNewObjectEvent(String objectID, String objectType, String ownerID, Dictionary<String, DataValue> attributes, StateTableValue stv)
        {
            SimulationEvent e = SimulationEventFactory.BuildEvent(ref m_simModel, "NewObject");


            e["Time"] = DataValueFactory.BuildInteger(0);
            e["ObjectType"] = DataValueFactory.BuildString(objectType);
            e["ID"] = DataValueFactory.BuildString(objectID);
            e["Attributes"] = DataValueFactory.BuildAttributeCollection(attributes);

            e["StateTable"] = stv;

            ((AttributeCollectionValue)e["Attributes"]).attributes.Add("OwnerID", DataValueFactory.BuildString(ownerID));
            //((AttributeCollectionValue)e["Attributes"]).attributes.Add("ClassName", DataValueFactory.BuildString(objectType));


            SendSimEvent(e);
        }
Esempio n. 3
0
        /// <summary>
        /// This method takes in a Create_EventType (ScenCon defined object), and retrieves
        /// the data from the object, packages up the data into a SimulationEvent (SimCore defined
        /// object), and then sends the event to the network server.  This method was pulled out of
        /// the main block of code to simplify sending the event and code readability.
        /// </summary>
        /// <param name="incoming">The Create_EventType object whose data is packaged
        /// into an outgoing SimulationEvent.</param>
        private static void SendCreateEvent(Create_EventType incoming)
        {
            SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject");
            Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>();
            Dictionary<string, object> DictionaryOfStates;
            DataValue dv;
            ObjectInfo myObject;
            string objectType = incoming.Genus.ToString();
            myObject = simModelInfo.objectModel.objects[objectType];
            dv = new StateTableValue();

            try
            {
                e["Time"] = DataValueFactory.BuildInteger(incoming.Time);//ConvertInteger(incoming.Timer);
                e["ObjectType"] = DataValueFactory.BuildString(objectType); //ConvertString(objectType);
                e["ID"] = DataValueFactory.BuildString(incoming.UnitID);//ConvertString(incoming.UnitID);

                /*********** Define the State Table ***********************/
                DictionaryOfStates = incoming.Parameters.GetDictionary();
            }
            catch
            {
                throw new Exception("Missing Required Data for Create Event");
            }
            Dictionary<string, DataValue> SimCoreStateTable = new Dictionary<string, DataValue>();

            foreach (KeyValuePair<string, object> kvp in DictionaryOfStates)
            {
                DataValue capabilities,
                          vulnerabilities,
                          currentSimCoreState;

                capabilities = new CapabilityValue();
                vulnerabilities = new VulnerabilityValue();
                currentSimCoreState = new AttributeCollectionValue();
                ExtendedStateBody currentScenConState = new ExtendedStateBody();

                currentScenConState = (ExtendedStateBody)incoming.Parameters[kvp.Key];

                capabilities = DefineCapabilityValue(currentScenConState.Capabilities);
                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Capability", capabilities);

                vulnerabilities = DefineVulnerabilityValue(currentScenConState.Vulnerabilities, currentScenConState.Combinations);
                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Vulnerability", vulnerabilities);

                DataValue sensorArray = DataValueFactory.BuildValue("SensorArrayType");
                DataValue sensor;

                Dictionary<string, SensorType> sensors = new Dictionary<string, SensorType>();

                Dictionary<string, List<ConeValue>> ranges;
                sensors = currentScenConState.Sensors;

                foreach (string sensorKind in sensors.Keys)
                {
                    ranges = new Dictionary<string, List<ConeValue>>();
                    sensor = DataValueFactory.BuildValue("SensorType");
                    SensorType typeOfSensor = sensors[sensorKind];
                    string attributeSensed = typeOfSensor.Attribute;
                    List<Cone> cones = typeOfSensor.Cones;
                    double maxRange = 0.0;

                    ((SensorValue)sensor).attIsEngram[attributeSensed] = sensors[sensorKind].IsEngram;
                    List<ConeValue> simCoreCones = new List<ConeValue>();

                    foreach (Cone aCone in sensors[sensorKind].Cones)
                    {
                        LocationValue direction = new LocationValue();
                        direction.X = aCone.Direction.X;
                        direction.Y = aCone.Direction.Y;
                        direction.Z = aCone.Direction.Z;
                        direction.exists = true;
                        ConeValue cv = new ConeValue();
                        cv.direction = direction;
                        cv.extent = aCone.Extent;
                        if (aCone.Extent > maxRange)
                            maxRange = aCone.Extent;
                        cv.level = aCone.Level;
                        cv.spread = aCone.Spread;
                        simCoreCones.Add(cv);
                    }

                    ranges.Add(attributeSensed, simCoreCones);
                    ((SensorValue)sensor).ranges = ranges;
                    ((SensorValue)sensor).sensorName = sensorKind;
                    if (((SensorValue)sensor).maxRange < maxRange)
                    {
                        ((SensorValue)sensor).maxRange = maxRange;
                    }
                    ((SensorArrayValue)sensorArray).sensors.Add((SensorValue)sensor);
                }


                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Sensors", sensorArray);

                //Emitters
                DataValue emitter = DataValueFactory.BuildValue("EmitterType");

                Dictionary<string, EmitterType> scenConEmitters = currentScenConState.Emitters;
                EmitterType emission;
                foreach (string s in scenConEmitters.Keys)
                {
                    emission = scenConEmitters[s].DeepCopy();
                    string attributeName = s;
                    ((EmitterValue)emitter).attIsEngram[s] = emission.IsEngram;
                    // string level;
                    //        double variance;
                    Dictionary<string, double> levels = new Dictionary<string, double>();
                    foreach (string level in emission.Levels.Keys)
                    {
                        //           levels.Add(level, (double)(emission[level]));
                        double dublet = Double.Parse((emission.Levels[level].ToString()));
                        levels.Add(level, dublet);
                    }
                    ((EmitterValue)emitter).emitters.Add(attributeName, levels);
                }

                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Emitters", emitter);

                foreach (AttributeInfo attr in myObject.attributes.Values)
                {
                    string attrType = attr.dataType;
                    string simCoreName = attr.name;
                    string scenConKey = convertSimCoreToScenCon(simCoreName);

                    if (currentScenConState.Parameters.ContainsKey(scenConKey))
                    {
                        switch (attrType)
                        {
                            case "StringType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildString(Convert.ToString(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertString(Convert.ToString(currentScenConState.Parameters[scenConKey])*/

                            case "IntegerType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildInteger(Convert.ToInt32(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertInteger(Convert.ToInt32(currentScenConState.Parameters[scenConKey])*/

                            case "DoubleType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildDouble(Convert.ToDouble(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertDouble(Convert.ToDouble(currentScenConState.Parameters[scenConKey])*/

                            case "LocationType":
                                LocationType lt = currentScenConState.Parameters[scenConKey] as LocationType;
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildLocation(lt.X, lt.Y, lt.Z, false));
                                break;/*ConvertLocation((LocationType)currentScenConState.Parameters[scenConKey])*/

                            case "VelocityType":
                                VelocityType vt = currentScenConState.Parameters[scenConKey] as VelocityType;
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildVelocity(vt.VX, vt.VY, vt.VZ));
                                break;/*ConvertVelocity((VelocityType)currentScenConState.Parameters[scenConKey])*/
                            case "BooleanType":
                                if (currentScenConState.Parameters.ContainsKey(attr.name))
                                {
                                    string booleanVal = currentScenConState.Parameters[attr.name].ToString();
                                    bool value = false;
                                    if (booleanVal == "true" || booleanVal == "True" || booleanVal == "TRUE")
                                    {
                                        value = true;
                                    }
                                    ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildBoolean(value));
                                }/*ConvertBoolean(value)*/
                                break;
                            case "StringListType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildStringList((List<String>)currentScenConState.Parameters[scenConKey]));
                                break;
                            case "ClassificationDisplayRulesType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, (DataValue)currentScenConState.Parameters[scenConKey]);
                                break;
                            default:
                                break;
                        }
                    }
                }

                SimCoreStateTable.Add(kvp.Key, currentSimCoreState);
            }
            dv = new StateTableValue();
            ((StateTableValue)dv).states = SimCoreStateTable;
            e["StateTable"] = dv;

            ((AttributeCollectionValue)e["Attributes"]).attributes.Add("OwnerID", DataValueFactory.BuildString(incoming.Owner));/*ConvertString(    .Owner)*/
            ((AttributeCollectionValue)e["Attributes"]).attributes.Add("ClassName", DataValueFactory.BuildString(incoming.UnitBase));/*ConvertString(incoming.UnitBase)*/


            server.PutEvent(e);
        }