Example #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;
            }

        }
Example #2
0
 /// <summary>
 /// Given a boolean, a new DataValue is created, and assigned as an 
 /// BooleanValue.  This BooleanValue's value setting is set to the input
 /// bool, and then the BooleanValue is returned as a DataValue.
 /// </summary>
 /// <param name="input">
 /// An bool to be assigned to a BooleanValue.
 /// </param>
 /// <returns>
 ///</returns>
 private static DataValue ConvertBoolean(bool input)
 {//Replaced by method in DataValueFactory...
     DataValue dv = new BooleanValue();
     ((BooleanValue)dv).value = input;
     return dv;
 }
Example #3
0
 private void ChangeRemoveOnDestruction(BooleanValue newValue, string objectID)
 {
     SimulationObjectProxy obj = objectProxies[objectID];
     if (obj == null)
         return;
     obj["RemoveOnDestruction"].SetDataValue(newValue);
 }
Example #4
0
        /// <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;
        }