示例#1
0
        public void TestAccessors()
        {
            string name = "TestData";
            EcellValue value = new EcellValue(0.001);
            string entityPath = "Variable:/:V0:TestData";

            EcellData data = new EcellData();
            data.Name = name;
            data.Value = value;
            data.EntityPath = entityPath;
            Assert.IsNotNull(data, "Constructor of type, EcellData failed to create instance.");
            Assert.AreEqual(name, data.Name, "Name is not expected value.");
            Assert.AreEqual(entityPath, data.EntityPath, "EntityPath is not expected value.");
            Assert.AreEqual(value, data.Value, "Value is not expected value.");
            Assert.IsTrue(data.Gettable, "Gettable is not expected value.");
            Assert.IsTrue(data.Loadable, "Loadable is not expected value.");
            Assert.IsFalse(data.Logable, "Logable is not expected value.");
            Assert.IsFalse(data.Logged, "Logged is not expected value.");
            Assert.IsTrue(data.Saveable, "Saveable is not expected value.");
            Assert.IsTrue(data.Settable, "Settable is not expected value.");
            Assert.IsTrue(data.IsInitialized(), "IsInitialized is not expected value.");

            data.Settable = false;
            Assert.IsFalse(data.Settable, "Settable is not expected value.");
            Assert.IsFalse(data.IsInitialized(), "IsInitialized is not expected value.");

            data.Gettable = false;
            data.Loadable = false;
            data.Logable = false;
            data.Logged = false;
            data.Saveable = false;
            Assert.IsFalse(data.Gettable, "Gettable is not expected value.");
            Assert.IsFalse(data.Loadable, "Loadable is not expected value.");
            Assert.IsFalse(data.Logable, "Logable is not expected value.");
            Assert.IsFalse(data.Logged, "Logged is not expected value.");
            Assert.IsFalse(data.Saveable, "Saveable is not expected value.");

            data.Gettable = true;
            data.Loadable = true;
            data.Logable = true;
            data.Logged = true;
            data.Saveable = true;
            Assert.IsTrue(data.Gettable, "Gettable is not expected value.");
            Assert.IsTrue(data.Loadable, "Loadable is not expected value.");
            Assert.IsTrue(data.Logable, "Logable is not expected value.");
            Assert.IsTrue(data.Logged, "Logged is not expected value.");
            Assert.IsTrue(data.Saveable, "Saveable is not expected value.");
            Assert.IsFalse(data.Settable, "Settable is not expected value.");
            Assert.IsFalse(data.IsInitialized(), "IsInitialized is not expected value.");

            data.Settable = true;
            Assert.IsTrue(data.Settable, "Settable is not expected value.");
            Assert.IsTrue(data.IsInitialized(), "IsInitialized is not expected value.");
        }
示例#2
0
        public void TestAccessor()
        {
            string str = "string"; ;
            EcellValue value = new EcellValue(str);
            Assert.AreEqual("string", value.Value);

            Type type = value.GetType();
            FieldInfo info = type.GetField("m_value", BindingFlags.NonPublic | BindingFlags.Instance);
            info.SetValue(value, new object());
            try
            {
                ValueType vtype = value.Type;
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
示例#3
0
        /// <summary>
        /// Initialize the simulator before it starts.
        /// </summary>
        public void Initialize(bool flag)
        {
            string simParam = m_currentProject.Info.SimulationParam;
            Dictionary<string, List<EcellObject>> stepperList = m_currentProject.StepperDic;
            WrappedSimulator simulator = null;
            Dictionary<string, Dictionary<string, double>> initialCondition = m_currentProject.InitialCondition[simParam];

            m_currentProject.Simulator = m_currentProject.CreateSimulatorInstance();
            simulator = m_currentProject.Simulator;
            //
            // Loads steppers on the simulator.
            //
            List<EcellObject> newStepperList = new List<EcellObject>();
            List<string> modelIDList = new List<string>();
            Dictionary<string, Dictionary<string, object>> setStepperPropertyDic
                = new Dictionary<string, Dictionary<string, object>>();
            foreach (string modelID in stepperList.Keys)
            {
                //foreach (EcellObject stepper in stepperList[modelID])
                //{
                //    if (m_currentProject.IsUsedStepper(stepper.Key))
                //    {
                //        newStepperList.Add(stepper);
                //    }
                //}
                newStepperList.AddRange(stepperList[modelID]);
                modelIDList.Add(modelID);
            }
            if (newStepperList.Count > 0)
                LoadStepper(
                simulator,
                newStepperList,
                setStepperPropertyDic);

            //
            // Loads systems on the simulator.
            //
            List<string> allLoggerList = new List<string>();
            List<EcellObject> systemList = new List<EcellObject>();
            m_currentProject.LogableEntityPathDic.Clear();
            Dictionary<string, object> setSystemPropertyDic = new Dictionary<string, object>();
            foreach (string modelID in modelIDList)
            {
                List<string> loggerList = new List<string>();
                if (flag)
                {
                    LoadSystem(
                        simulator,
                        m_currentProject.SystemDic[modelID],
                        loggerList,
                        initialCondition[modelID],
                        setSystemPropertyDic);
                }
                else
                {
                    LoadSystem(
                        simulator,
                        m_currentProject.SystemDic[modelID],
                        loggerList,
                        null,
                        setSystemPropertyDic);
                }
                foreach (string logger in loggerList)
                {
                    m_currentProject.LogableEntityPathDic[logger] = modelID;
                }
                allLoggerList.AddRange(loggerList);
            }

            //
            // Initializes
            //
            simulator.Initialize();

            //
            // Sets the "Settable" and "Not Savable" properties
            //
            foreach (string key in setStepperPropertyDic.Keys)
            {
                foreach (string path in setStepperPropertyDic[key].Keys)
                {
                    simulator.SetStepperProperty(key, path, setStepperPropertyDic[key][path]);
                }
            }
            foreach (string path in setSystemPropertyDic.Keys)
            {
                try
                {
                    EcellValue storedEcellValue = new EcellValue(simulator.GetEntityProperty(path));
                    EcellValue newEcellValue = new EcellValue(setSystemPropertyDic[path]);
                    if (storedEcellValue.Type.Equals(newEcellValue.Type)
                        && storedEcellValue.Value.Equals(newEcellValue.Value))
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                    // do nothing
                }
                simulator.SetEntityProperty(path, setSystemPropertyDic[path]);
            }
            //
            // Set the initial condition property.
            //
            foreach (string modelID in modelIDList)
            {
                foreach (string fullPN in initialCondition[modelID].Keys)
                {
                    EcellValue storedValue = null;
                    if (fullPN.StartsWith(Constants.xpathStepper))
                    {
                        string name;
                        string type;
                        string propName;
                        Util.ParseFullPN(fullPN, out type, out name, out propName);
                        storedValue = new EcellValue(simulator.GetStepperProperty(name, propName));
                    }
                    else
                    {
                        storedValue = new EcellValue(simulator.GetEntityProperty(fullPN));
                    }
                    double initialValue = initialCondition[modelID][fullPN];
                    object newValue = null;
                    if (storedValue.IsInt)
                    {
                        int initialValueInt = Convert.ToInt32(initialValue);
                        if (storedValue.Value.Equals(initialValueInt))
                        {
                            continue;
                        }
                        newValue = initialValueInt;
                    }
                    else
                    {
                        if (storedValue.Value.Equals(initialValue))
                        {
                            continue;
                        }
                        newValue = initialValue;
                    }
                    if (fullPN.StartsWith(Constants.xpathStepper))
                    {
                        string name;
                        string type;
                        string propName;
                        Util.ParseFullPN(fullPN, out type, out name, out propName);
                        simulator.SetStepperProperty(name, propName, newValue);
                    }
                    else
                    {
                        simulator.SetEntityProperty(fullPN, newValue);
                    }
                }
            }
            //
            // Reinitializes
            //
            // this.m_simulatorDic[m_currentProject.Name].Initialize();
            //
            // Creates the "Logger" only after the initialization.
            //
            m_loggerEntry.Clear();
            if (allLoggerList != null && allLoggerList.Count > 0)
            {
                LoggerPolicy loggerPolicy = this.GetCurrentLoggerPolicy();
                foreach (string logger in allLoggerList)
                {
                    CreateLogger(logger, true, simulator, loggerPolicy);
                }
            }
            ClearSteppingModel();
        }
示例#4
0
 /// <summary>
 /// GetValueFromDMM
 /// </summary>
 /// <param name="dmm">DMDescriptorKeeper</param>
 /// <param name="type">DM type.</param>
 /// <param name="className">the class name,</param>
 /// <param name="name">the property name.</param>
 /// <returns></returns>
 private static EcellValue GetValueFromDMM(DMDescriptorKeeper dmm, string type, string className, string name)
 {
     EcellValue value = null;
     try
     {
         if (dmm.ContainsDescriptor(type, className))
         {
             DMDescriptor desc = dmm.GetDMDescriptor(type, className);
             if (desc.ContainsProperty(name))
             {
                 PropertyDescriptor prop = desc[name];
                 value = new EcellValue(prop.DefaultValue);
             }
             else
             {
                 value = new EcellValue(0.0);
             }
         }
         else
         {
             value = new EcellValue("");
         }
     }
     catch(Exception e)
     {
         Trace.WriteLine(e.StackTrace);
     }
     return value;
 }
示例#5
0
        /// <summary>
        /// Stores the "EcellObject" 4 the "System".
        /// </summary>
        /// <param name="simulator">The simulator</param>
        /// <param name="ecellObject">The stored "System"</param>
        /// <param name="initialCondition">The initial condition.</param>
        internal static void DataStored4System(
            WrappedSimulator simulator,
            EcellObject ecellObject,
            Dictionary<string, double> initialCondition)
        {
            // Creates an entityPath.
            string parentPath = ecellObject.ParentSystemID;
            string childPath = ecellObject.LocalID;
            string key = Constants.xpathSystem + Constants.delimiterColon +
                parentPath + Constants.delimiterColon +
                childPath;
            // Property List
            IList<string> wrappedPolymorph = simulator.GetEntityPropertyList(key);
            //
            // Checks the stored "EcellData"
            //
            List<EcellData> systemEcellDataList = new List<EcellData>();
            Dictionary<string, EcellData> storedEcellDataDic
                    = new Dictionary<string, EcellData>();
            if (ecellObject.Value != null && ecellObject.Value.Count > 0)
            {
                foreach (EcellData storedEcellData in ecellObject.Value)
                {
                    storedEcellDataDic[storedEcellData.Name] = storedEcellData;
                    systemEcellDataList.Add(storedEcellData);

                }
            }
            foreach (string name in wrappedPolymorph)
            {
                string entityPath = key + Constants.delimiterColon + name;
                PropertyAttributes flag = simulator.GetEntityPropertyAttributes(entityPath);

                if (!flag.Gettable)
                {
                    continue;
                }

                object value = null;
                if (name.Equals(Constants.xpathSize))
                {
                    value = new EcellValue(EcellSystem.DefaultSize);
                }
                else
                {
                    try
                    {
                        value = new EcellValue(simulator.GetEntityProperty(entityPath));
                    }
                    catch (WrappedException ex)
                    {
                        Trace.WriteLine(ex);
                        if (storedEcellDataDic.ContainsKey(name))
                        {
                            IEnumerable val = storedEcellDataDic[name].Value as IEnumerable;
                            object firstItem = null;
                            {
                                IEnumerator i = val.GetEnumerator();
                                if (i.MoveNext())
                                    firstItem = i.Current;
                            }
                            if (firstItem is IEnumerable)
                            {
                                value = val;
                            }
                            else
                            {
                                value = firstItem;
                            }
                        }
                        else
                        {
                            value = "";
                        }
                    }
                }

                EcellData ecellData = CreateEcellData(name, new EcellValue(value), entityPath, flag);
                if (ecellData.Value != null)
                {
                    ecellData.Logable = ecellData.Value.IsDouble;
                }
                if (storedEcellDataDic.ContainsKey(name))
                {
                    ecellData.Logged = storedEcellDataDic[name].Logged;
                    systemEcellDataList.Remove(storedEcellDataDic[name]);
                }
                systemEcellDataList.Add(ecellData);
            }

            ecellObject.SetEcellDatas(systemEcellDataList);
        }
示例#6
0
        /// <summary>
        /// Stores the "EcellObject" 4 the "Process".
        /// </summary>
        /// <param name="simulator">The simulator</param>
        /// <param name="dmm">The "DMDescriptorKeeper"</param>
        /// <param name="ecellObject">The stored "Process"</param>
        /// <param name="initialCondition">The initial condition.</param>
        internal static void DataStored4Process(
            WrappedSimulator simulator,
            DMDescriptorKeeper dmm,
            EcellObject ecellObject,
            Dictionary<string, double> initialCondition)
        {
            string key = ecellObject.FullID;
            IList<string> wrappedPolymorph = null;
            try
            {
                wrappedPolymorph = simulator.GetEntityPropertyList(key);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                return;
            }
            //
            // Checks the stored "EcellData"
            //
            List<EcellData> processEcellDataList = new List<EcellData>();
            Dictionary<string, EcellData> storedEcellDataDic = new Dictionary<string, EcellData>();

            if (ecellObject.Value != null && ecellObject.Value.Count > 0)
            {
                foreach (EcellData storedEcellData in ecellObject.Value)
                {
                    storedEcellDataDic[storedEcellData.Name] = storedEcellData;
                    processEcellDataList.Add(storedEcellData);

                }
            }
            //
            // Stores the "EcellData"
            //
            foreach (string name in wrappedPolymorph)
            {
                string entityPath = Util.BuildFullPN(key, name);

                PropertyAttributes flag = simulator.GetEntityPropertyAttributes(entityPath);
                if (!flag.Gettable)
                {
                    continue;
                }
                EcellValue value = null;

                if (name == Constants.xpathVRL)
                {
                    // Won't restore the variable reference list from the simulator's corresponding
                    // object.
                    if (storedEcellDataDic.ContainsKey(name))
                        value = storedEcellDataDic[name].Value;
                    else
                        value = new EcellValue(new List<object>());
                }
                else if (name == Constants.xpathActivity || name == Constants.xpathMolarActivity)
                {
                    value = new EcellValue(0.0);
                }
                else
                {
                    try
                    {
                        value = new EcellValue(simulator.GetEntityProperty(entityPath));
                        if (dmm.ContainsDescriptor(ecellObject.Type, ecellObject.Classname))
                        {
                            DMDescriptor desc = dmm.GetDMDescriptor(ecellObject.Type, ecellObject.Classname);
                            if (desc.ContainsProperty(name))
                            {
                                PropertyDescriptor prop = desc[name];
                                if (prop.DefaultValue.Type == EcellValueType.List && !value.IsList)
                                    value = new EcellValue(new List<EcellValue>());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                        value = GetValueFromDMM(dmm, ecellObject.Type, ecellObject.Classname, name);
                    }
                }
                EcellData ecellData = CreateEcellData(name, value, entityPath, flag);
                if (ecellData.Value != null)
                {
                    ecellData.Logable = ecellData.Value.IsDouble &&
                        (ecellData.Settable == false || ecellData.Saveable == false);

                }

                if (storedEcellDataDic.ContainsKey(name))
                {
                    ecellData.Logged = storedEcellDataDic[name].Logged;
                    processEcellDataList.Remove(storedEcellDataDic[name]);
                }
                processEcellDataList.Add(ecellData);

            }
            ecellObject.SetEcellDatas(processEcellDataList);
        }
示例#7
0
        /// <summary>
        /// Press key on DataGridView.
        /// </summary>
        /// <param name="msg">Message.</param>
        /// <param name="keyData">Key data.</param>
        /// <returns></returns>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (m_dgv.CurrentCell != null && m_dgv.CurrentCell is DataGridViewComboBoxCell)
                return base.ProcessCmdKey(ref msg, keyData);

            // Select all
            if ((int)keyData == (int)Keys.Control + (int)Keys.A)
            {
                // Cut selected text.
                if (m_dgv.EditingControl is DataGridViewTextBoxEditingControl)
                {
                    TextBox tBox = (TextBox)m_dgv.EditingControl;
                    tBox.SelectAll();
                }
                return true;
            }
            // Copy
            if ((int)keyData == (int)Keys.Control + (int)Keys.C)
            {
                // Copy selected text.
                if (m_dgv.EditingControl is DataGridViewTextBoxEditingControl)
                {
                    TextBox tBox = (TextBox)m_dgv.EditingControl;
                    tBox.Copy();
                    return true;
                }
                // Copy cell
                else if (m_dgv.CurrentCell != null && m_dgv.CurrentCell.Value != null)
                {
                    string copytext = m_dgv.CurrentCell.Value.ToString();
                    Clipboard.SetText(copytext);
                    return true;
                }
            }
            // Cut
            if ((int)keyData == (int)Keys.Control + (int)Keys.X)
            {
                // Cut selected text.
                if (m_dgv.EditingControl is DataGridViewTextBoxEditingControl)
                {
                    TextBox tBox = (TextBox)m_dgv.EditingControl;
                    tBox.Cut();
                    return true;
                }
            }
            // Paste
            if ((int)keyData == (int)Keys.Control + (int)Keys.V)
            {
                // Paste to selected location.
                if (m_dgv.EditingControl is DataGridViewTextBoxEditingControl)
                {
                    TextBox tBox = (TextBox)m_dgv.EditingControl;
                    tBox.Paste();
                    return true;
                }
                // Paste
                string pastetext = Clipboard.GetText();
                if (!String.IsNullOrEmpty(pastetext) && m_dgv.CurrentCell != null &&
                    m_dgv.CurrentCell.ReadOnly == false)
                {
                    if (m_dgv.CurrentCell.Tag is EcellData)
                    {
                        EcellData tag = m_dgv.CurrentCell.Tag as EcellData;
                        EcellObject eo = m_current.Clone();
                        EcellData d = eo.GetEcellData(tag.Name);
                        EcellValue value;
                        try
                        {
                            if (tag.Name == Constants.xpathSize)
                            {
                                value = new EcellValue(Convert.ToDouble(pastetext));
                                EcellSystem system = (EcellSystem)eo;
                                system.SizeInVolume = (double)value;
                            }
                            else
                            {
                                if (d.Value.IsDouble)
                                    value = new EcellValue(Convert.ToDouble(pastetext));
                                else if (d.Value.IsInt)
                                    value = new EcellValue(Convert.ToInt32(pastetext));
                                else
                                    value = new EcellValue(pastetext);
                                d.Value = value;
                            }
                            NotifyDataChanged(eo.ModelID, eo.Key, eo);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex);
                            m_dgv.MouseLeave -= new EventHandler(this.LeaveMouse);
                            Util.ShowErrorDialog(MessageResources.ErrFormat);
                            m_dgv.MouseLeave += new EventHandler(this.LeaveMouse);
                        }
                    }
                }
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }
示例#8
0
        public void TestConvertFromEcellValue()
        {
            EcellValue value = null;
            List<EcellLayer> layers = EcellLayer.ConvertFromEcellValue(value);
            Assert.IsEmpty(layers, "ConvertFromEcellValue method returned unexpected value.");

            List<EcellValue> list = new List<EcellValue>();
            value = new EcellValue(list);
            layers = EcellLayer.ConvertFromEcellValue(value);
            Assert.IsEmpty(layers, "ConvertFromEcellValue method returned unexpected value.");

            string str = "((\"layer0\", 1), (\"Layer1\", 0))";
            layers = EcellLayer.ConvertFromString(str);
            value = EcellLayer.ConvertToEcellValue(layers);
            layers = EcellLayer.ConvertFromEcellValue(value);
            Assert.IsNotEmpty(layers, "ConvertFromEcellValue method returned unexpected value.");

            Assert.AreEqual("layer0", layers[0].Name, "Name is unexpected value.");
            Assert.AreEqual(true, layers[0].Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"layer0\", 1)", layers[0].ToString(), "ToString method returned unexpected value.");

            Assert.AreEqual("Layer1", layers[1].Name, "Name is unexpected value.");
            Assert.AreEqual(false, layers[1].Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"Layer1\", 0)", layers[1].ToString(), "ToString method returned unexpected value.");
        }
示例#9
0
        public void TestCastToInt()
        {
            int expectedInt32 = 10;
            int resultInt32 = 10;
            EcellValue value = new EcellValue(expectedInt32);
            resultInt32 = (int)value;
            Assert.IsTrue(value.IsInt, "IsInt is not expected value.");
            Assert.AreEqual(expectedInt32, resultInt32, "CastToInt method returned unexpected result.");

            value = new EcellValue(0.01);
            resultInt32 = (int)value;
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.AreEqual(0, resultInt32, "CastToInt method returned unexpected result.");

            value = new EcellValue("1");
            resultInt32 = (int)value;
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.AreEqual(1, resultInt32, "CastToInt method returned unexpected result.");

            value = new EcellValue("Test");
            try
            {
                resultInt32 = (int)value;
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            value = new EcellValue(new List<object>());
            try
            {
                resultInt32 = (int)value;
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
示例#10
0
        public void TestCastToDouble()
        {
            double expectedDouble = 0.0001;
            double resultDouble = 0.0001;
            EcellValue value = new EcellValue(expectedDouble);
            resultDouble = (double)value;
            Assert.IsTrue(value.IsDouble, "IsDouble is not expected value.");
            Assert.AreEqual(expectedDouble, resultDouble, "CastToDouble method returned unexpected result.");

            value = new EcellValue(1);
            resultDouble = (double)value;
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.AreEqual(1.0, resultDouble, "CastToDouble method returned unexpected result.");

            value = new EcellValue("0.01");
            resultDouble = (double)value;
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.AreEqual(0.01, resultDouble, "CastToDouble method returned unexpected result.");

            value = new EcellValue("Test");
            try
            {
                resultDouble = (double)value;
                Assert.Fail();
            }
            catch (Exception)
            {
            }

            value = new EcellValue(new List<object>());
            try
            {
                resultDouble = (double)value;
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
示例#11
0
 /// <summary>
 /// Get PropertyDescriptors
 /// </summary>
 /// <param name="sim">the curremt simulator.</param>
 /// <param name="stepper">the stepper name.</param>
 /// <returns></returns>
 private static Dictionary<string, PropertyDescriptor> GetStepperPropertyDescriptors(WrappedSimulator sim, string stepper)
 {
     // Get default property values.
     Dictionary<string, PropertyDescriptor> pdescs = new Dictionary<string, PropertyDescriptor>();
     foreach (string propName in sim.GetStepperPropertyList(stepper))
     {
         PropertyAttributes attrs = sim.GetStepperPropertyAttributes(stepper, propName);
         EcellValue defaultValue = null;
         if (attrs.Gettable)
         {
             try
             {
                 defaultValue = new EcellValue(sim.GetStepperProperty(stepper, propName));
             }
             catch (Exception)
             {
                 Trace.WriteLine(string.Format("    Failed to get default value of property, {0}:{1}.", stepper, propName));
             }
         }
         // Set default value.
         if (defaultValue == null)
             defaultValue = new EcellValue(0.0d);
         bool logable = defaultValue.IsDouble;
         pdescs[propName] = new PropertyDescriptor(
             propName,
             attrs.Settable, // settable
             attrs.Gettable, // gettable
             attrs.Loadable, // loadable
             attrs.Savable,  // saveable
             attrs.Dynamic,  // dynamic
             logable, // logable
             defaultValue
         );
     }
     return pdescs;
 }
示例#12
0
        /// <summary>
        /// Get PropertyDescriptors
        /// </summary>
        /// <param name="sim">the current simulator.</param>
        /// <param name="fullID">the entity fullID.</param>
        /// <returns></returns>
        private static Dictionary<string, PropertyDescriptor> GetEntityPropertyDescriptors(WrappedSimulator sim, string fullID)
        {
            // Get default property values.
            Dictionary<string, PropertyDescriptor> pdescs = new Dictionary<string, PropertyDescriptor>();
            foreach (string propName in sim.GetEntityPropertyList(fullID))
            {
                string fullPN = Util.BuildFullPN(fullID, propName);
                PropertyAttributes attrs = sim.GetEntityPropertyAttributes(fullPN);
                EcellValue defaultValue = null;
                if (attrs.Gettable)
                {
                    if (propName.Equals(Constants.xpathMolarActivity) || propName.Equals(Constants.xpathActivity))
                        defaultValue = new EcellValue(0.0);
                    if (propName.Equals(Constants.xpathMolarConc) || propName.Equals(Constants.xpathNumberConc))
                        defaultValue = new EcellValue(0.0);
                    try
                    {
                        object obj = sim.GetEntityProperty(fullPN);
                        defaultValue = new EcellValue(obj);
                    }
                    catch (Exception)
                    {
                        Trace.WriteLine(string.Format("    Failed to get default value of property, {0}:{1}.", fullID, propName));
                    }
                }
                // Set default value.
                bool isMatrix = false;
                if (defaultValue == null && !propName.Contains("Matrix"))
                    defaultValue = new EcellValue(0.0d);
                else if(propName.Contains("Matrix"))
                {
                    defaultValue = new EcellValue("");
                    isMatrix =true;
                }

                bool logable = defaultValue.IsDouble;
                if (fullID.StartsWith(EcellObject.PROCESS))
                    logable = logable && (!attrs.Settable || !attrs.Savable);

                pdescs[propName] = new PropertyDescriptor(
                    propName,
                    attrs.Settable && !isMatrix, // settable
                    attrs.Gettable, // gettable
                    attrs.Loadable && !isMatrix, // loadable
                    attrs.Savable && !isMatrix,  // saveable
                    attrs.Dynamic,  // dynamic
                    logable, // logable
                    defaultValue
                );
            }
            return pdescs;
        }
示例#13
0
文件: Eml.cs 项目: ecell/ecell3-ide
        /// <summary>
        /// Loads the "process" or "variable" element.
        /// </summary>
        /// <param name="node">The "process" or "variable" element</param>
        /// <param name="systemID">The system ID of the parent "System" element</param>
        /// <param name="flag">"Process" if this element is "Process" element; "Variable" otherwise</param>
        private EcellObject ParseText(
            XmlNode node,
            string systemID,
            string flag)
        {
            XmlNode nodeClass = node.Attributes.GetNamedItem(Constants.xpathClass);
            XmlNode nodeID = node.Attributes.GetNamedItem(Constants.xpathID.ToLower());
            if (!this.IsValidNode(nodeClass) || !this.IsValidNode(nodeID))
            {
                throw new EmlParseException("Invalid text node found");
            }
            // 4 children
            List<EcellData> ecellDataList = new List<EcellData>();
            XmlNodeList nodePropertyList = node.ChildNodes;
            foreach (XmlNode nodeProperty in nodePropertyList)
            {
                if (nodeProperty.NodeType == XmlNodeType.Whitespace)
                    continue;
                if (nodeProperty.NodeType != XmlNodeType.Element)
                    throw new EmlParseException("Unexpected node");
                if (!nodeProperty.Name.Equals(Constants.xpathProperty))
                    throw new EmlParseException(
                        string.Format(
                            "Element {0} found where {1} is expected",
                            nodeProperty.Name, Constants.xpathProperty));
                XmlNode nodePropertyName = nodeProperty.Attributes.GetNamedItem(Constants.xpathName.ToLower());
                if (!this.IsValidNode(nodePropertyName))
                    continue;

                EcellValue ecellValue = new EcellValue(nodeProperty.InnerText);
                if (ecellValue == null)
                    continue;

                // 4 "EcellCoreLib"
                string entityPath =
                    flag + Constants.delimiterColon +
                    systemID + Constants.delimiterColon +
                    nodeID.InnerText + Constants.delimiterColon +
                    nodePropertyName.InnerText;

                EcellData ecellData = new EcellData(nodePropertyName.InnerText, ecellValue, entityPath);
                ecellDataList.Add(ecellData);
            }
            // 4 "EcellLib"
            return EcellObject.CreateObject(
                    m_modelID,
                    systemID + Constants.delimiterColon + nodeID.InnerText,
                    flag,
                    nodeClass.InnerText,
                    ecellDataList);
        }
示例#14
0
 /// <summary>
 /// Load the stepping model from file.
 /// </summary>
 /// <param name="fileName">the stepping model file.</param>
 private void LoadSteppingModelInfo(string fileName)
 {
     m_steppingData = new Dictionary<string, EcellValue>();
     string line;
     string[] ele;
     StreamReader reader;
     reader = new StreamReader(fileName, Encoding.Unicode);
     while ((line = reader.ReadLine()) != null)
     {
         ele = line.Split(new char[] { ',' });
         string entPath = ele[0];
         string data = ele[1];
         if (entPath.StartsWith(Constants.xpathStepper))
         {
             ele = entPath.Split(new char[] { ':' });
             string key = ele[2];
             string name = ele[3];
             EcellValue storedValue
                     = new EcellValue(m_currentProject.Simulator.GetStepperProperty(key, name));
             if (storedValue.IsDouble)
                 m_steppingData.Add(entPath, new EcellValue(Double.Parse(data)));
             else if (storedValue.IsInt)
                 m_steppingData.Add(entPath, new EcellValue(Int32.Parse(data)));
             else
                 m_steppingData.Add(entPath, new EcellValue(data));
         }
         else
         {
             EcellValue storedValue
                     = new EcellValue(m_currentProject.Simulator.GetEntityProperty(entPath));
             if (storedValue.IsDouble)
                 m_steppingData.Add(entPath, new EcellValue(Double.Parse(data)));
             else if (storedValue.IsInt)
                 m_steppingData.Add(entPath, new EcellValue(Int32.Parse(data)));
             else
                 m_steppingData.Add(entPath, new EcellValue(data));
         }
     }
     reader.Close();
 }
示例#15
0
 /// <summary>
 /// Set the stepper property to the current simulator.
 /// </summary>
 /// <param name="key">the key of property.</param>
 /// <param name="name">the name of property.</param>
 /// <param name="value">the set data.</param>
 public void SetStepperProperty(string key, string name, string value)
 {
     if (m_currentProject.Simulator == null
         || this.GetCurrentSimulationTime() <= 0.0)
     {
         return;
     }
     EcellValue storedValue
         = new EcellValue(m_currentProject.Simulator.GetStepperProperty(key, name));
     EcellValue newValue = null;
     if (storedValue.IsDouble)
     {
         newValue = new EcellValue(XmlConvert.ToDouble(value));
     }
     else if (storedValue.IsInt)
     {
         newValue = new EcellValue(XmlConvert.ToInt32(value));
     }
     else if (storedValue.IsList)
     {
         // newValue = new EcellValue(value);
         return;
     }
     else
     {
         newValue = new EcellValue(value);
     }
     m_currentProject.Simulator.LoadStepperProperty(key, name, newValue.Value);
 }
示例#16
0
 public void SetUp()
 {
     _unitUnderTest = new EcellValue(0);
 }
示例#17
0
 public void TearDown()
 {
     _unitUnderTest = null;
 }
示例#18
0
        public void TestCastToString()
        {
            string expectedString;
            string resultString;
            EcellValue value;

            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            value = new EcellValue(er1);
            expectedString = er1.ToString();
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue(1);
            expectedString = "1";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue(0.0002);
            expectedString = "0.0002";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");

            value = new EcellValue("string");
            expectedString = "string";
            resultString = (string)value;
            Assert.AreEqual(expectedString, resultString, "CastToString method returned unexpected result.");
        }
示例#19
0
        public void TestConstructorWithEcellValue()
        {
            EcellValue value = null;
            List<object> list = null;
            EcellLayer el;
            try
            {
                el = new EcellLayer(list);
                Assert.Fail("Failed to throw EcellException.");
            }
            catch (EcellException)
            {
            }

            try
            {
                el = new EcellLayer(new object());
                Assert.Fail("Failed to throw EcellException.");
            }
            catch (Exception)
            {
            }

            try
            {
                value = new EcellValue(new EcellReference("S1", "/:S1", 0, 0));
                list = (List<object>)value.Value;
                el = new EcellLayer(list);
                Assert.Fail("Failed to throw EcellException.");
            }
            catch (Exception)
            {
            }

            list = new List<object>();
            list.Add("Name");
            list.Add(1);

            el = new EcellLayer(list);
            Assert.IsNotNull(el, "Constructor of type, object failed to create instance.");
            Assert.AreEqual("Ecell.Objects.EcellLayer", el.GetType().ToString(), "GetType method returned unexpected value.");
            Assert.AreEqual("Name", el.Name, "Name is unexpected value.");
            Assert.AreEqual(true, el.Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"Name\", 1)", el.ToString(), "ToString method returned unexpected value.");
        }
示例#20
0
        public void TestClone()
        {
            EcellValue value = new EcellValue(1);
            EcellValue clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual(value, clonedValue, "Clone method returned unexpected result.");
            Assert.IsTrue(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(1, (int)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Integer, clonedValue.Type, "Type is not expected value.");

            // double
            value = new EcellValue(0.01);
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual(value, clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsTrue(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(0.01, (double)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Double, clonedValue.Type, "Type is not expected value.");

            // string.
            value = new EcellValue("test");
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual((string)value, (string)clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsTrue(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual("test", (string)clonedValue.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.String, clonedValue.Type, "Type is not expected value.");

            // list
            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value = EcellValue.ConvertFromListString(str);
            clonedValue = value.Clone();
            Assert.IsNotNull(clonedValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.AreEqual((string)value, (string)clonedValue, "Clone method returned unexpected result.");
            Assert.IsFalse(clonedValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(clonedValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(clonedValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(clonedValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(str, clonedValue.ToString(), "ToString method returned unexpected value.");
            Assert.AreEqual(EcellValueType.List, clonedValue.Type, "Type is not expected value.");

            object obj = ((ICloneable)value).Clone();
            Assert.IsNotNull(obj, "Constructor of type, EcellValue failed to create instance.");

            try
            {
                obj = null;
                value = new EcellValue(obj);
                EcellValue newValue = value.Clone();
                Assert.Fail("Failed to throw TypeError Exception.");
            }
            catch (EcellException)
            {
            }
        }
示例#21
0
        public void TestClone()
        {
            EcellLayer el;
            List<EcellValue> list = new List<EcellValue>();
            list.Add(new EcellValue("Name"));
            list.Add(new EcellValue(1));
            EcellValue value = new EcellValue(list);

            el = new EcellLayer(value);
            Assert.IsNotNull(el, "Constructor of type, object failed to create instance.");
            Assert.AreEqual("Ecell.Objects.EcellLayer", el.GetType().ToString(), "GetType method returned unexpected value.");
            Assert.AreEqual("Name", el.Name, "Name is unexpected value.");
            Assert.AreEqual(true, el.Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"Name\", 1)", el.ToString(), "ToString method returned unexpected value.");

            EcellLayer el1 = el.Clone();
            Assert.IsNotNull(el1, "Constructor of type, object failed to create instance.");
            Assert.AreEqual("Ecell.Objects.EcellLayer", el1.GetType().ToString(), "GetType method returned unexpected value.");
            Assert.AreEqual("Name", el1.Name, "Name is unexpected value.");
            Assert.AreEqual(true, el1.Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"Name\", 1)", el1.ToString(), "ToString method returned unexpected value.");

            EcellLayer el2 = (EcellLayer)((ICloneable)el).Clone();
            Assert.IsNotNull(el2, "Constructor of type, object failed to create instance.");
            Assert.AreEqual("Ecell.Objects.EcellLayer", el2.GetType().ToString(), "GetType method returned unexpected value.");
            Assert.AreEqual("Name", el2.Name, "Name is unexpected value.");
            Assert.AreEqual(true, el2.Visible, "Name is unexpected value.");
            Assert.AreEqual("(\"Name\", 1)", el2.ToString(), "ToString method returned unexpected value.");
        }
示例#22
0
        public void TestConstructorEcellValueEr()
        {
            // EcellReference
            EcellReference er = new EcellReference("S1","Variable:/:S1",1,0);
            EcellValue testEcellValue = new EcellValue(er);
            Assert.IsNotNull(testEcellValue, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(testEcellValue.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(testEcellValue.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(testEcellValue.IsList, "IsList is not expected value.");
            Assert.IsFalse(testEcellValue.IsString, "IsString is not expected value.");
            Assert.AreEqual(EcellValueType.List, testEcellValue.Type, "Type is not expected value.");
            Assert.AreEqual(er.ToString(), testEcellValue.ToString(), "ToString() is not expected value.");

            // List
            EcellValue temp = new EcellValue(er);
            List<EcellValue> list = new List<EcellValue>();
            list.Add(temp);
            EcellValue value = new EcellValue(list);
            Assert.IsNotNull(value, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsTrue(value.IsList, "IsList is not expected value.");
            Assert.IsFalse(value.IsString, "IsString is not expected value.");
            Assert.AreEqual(EcellValueType.List, value.Type, "Type is not expected value.");
        }
示例#23
0
        /// <summary>
        /// Event when the value of cell is changed.
        /// </summary>
        /// <param name="sender">DataGridView.</param>
        /// <param name="e">DataGridViewCellEventArgs.</param>
        private void ChangeProperty(object sender, DataGridViewCellParsingEventArgs e)
        {
            e.ParsingApplied = true;
            if (m_current == null)
                return;
            if (m_env.PluginManager.Status == ProjectStatus.Running)
                return;
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
                return;
            if (m_isChanging)
                return;

            DataGridViewCell editCell = m_dgv[e.ColumnIndex, e.RowIndex];
            // Update the name of user defined Property.
            if (e.ColumnIndex == 0)
            {
                string propName = e.Value.ToString();
                string oldName = editCell.Value.ToString();
                try
                {
                    if (propName.Equals(oldName))
                        return;
                    if (m_current.IsEcellValueExists(propName)
                            || m_nonDataProps.Contains(propName))
                        throw new EcellException(MessageResources.ErrSameProp);

                    // Set value.
                    DataGridViewCell valueCell = m_dgv[1, e.RowIndex];
                    double value;
                    if (valueCell.Tag == null || valueCell.Value.Equals(""))
                    {
                        value = 0.0d;
                    }
                    else
                    {
                        value = Convert.ToDouble(valueCell.Value);
                    }
                    m_current.RemoveEcellValue(oldName);
                    m_current.SetEcellValue(propName, new EcellValue(value));
                    valueCell.Tag = m_current.GetEcellData(propName);
                    NotifyDataChanged(m_current.ModelID,
                        m_current.Key, m_current);
                }
                catch (Exception ex)
                {
                    e.Value = oldName;
                    Trace.WriteLine(ex);
                    m_dgv.MouseLeave -= new EventHandler(this.LeaveMouse);
                    Util.ShowErrorDialog(ex.Message);
                    m_dgv.MouseLeave += new EventHandler(this.LeaveMouse);
                }
                return;
            }
            // Ignore invalid index.
            if (e.ColumnIndex != 1)
                return;
            // Update property value.
            try
            {
                // Update property.
                if (editCell.Tag is EcellData)
                {
                    EcellData tag = editCell.Tag as EcellData;
                    string data = e.Value.ToString();
                    if ((m_env.PluginManager.Status == ProjectStatus.Running ||
                        m_env.PluginManager.Status == ProjectStatus.Stepping ||
                        m_env.PluginManager.Status == ProjectStatus.Suspended) &&
                        !tag.Name.Equals(Constants.xpathSize) &&
                        !tag.Name.Equals(Constants.xpathExpression) &&
                        !tag.Name.Equals(Constants.xpathActivity))
                    {
                        if (m_current.Type.Equals(Constants.xpathStepper))
                        {
                            m_env.DataManager.SetStepperProperty(m_current.Key, tag.Name, data);
                        }
                        else
                        {
                            m_env.DataManager.SetEntityProperty(tag.EntityPath, data);
                        }
                        UpdatePropForSimulation();
                    }
                    else
                    {
                        EcellObject eo = m_current.Clone();
                        EcellData d = eo.GetEcellData(tag.Name);
                        EcellValue value;
                        try
                        {
                            if (tag.Name == Constants.xpathSize)
                            {
                                value = new EcellValue(Convert.ToDouble(data));
                                EcellSystem system = (EcellSystem)eo;
                                system.SizeInVolume = (double)value;
                            }
                            else
                            {
                                if (d.Value.IsDouble)
                                    value = new EcellValue(Convert.ToDouble(data));
                                else if (d.Value.IsInt)
                                    value = new EcellValue(Convert.ToInt32(data));
                                else
                                    value = new EcellValue(data);
                                d.Value = value;
                            }
                        }
                        catch (Exception ex)
                        {
                            e.Value = editCell.Value;
                            Trace.WriteLine(ex);
                            m_dgv.MouseLeave -= new EventHandler(this.LeaveMouse);
                            Util.ShowErrorDialog(MessageResources.ErrFormat);
                            m_dgv.MouseLeave += new EventHandler(this.LeaveMouse);
                            return;
                        }
                        if (!NotifyDataChanged(m_current.ModelID, m_current.Key, eo))
                        {
                            e.Value = editCell.Value;
                        }
                    }
                }
                // Update ID.
                else if (editCell.Tag is string)
                {
                    string propName = editCell.Tag as string;
                    if (!propName.Equals("ID"))
                        return;
                    string tmpID = e.Value.ToString();
                    // Error check.
                    if (tmpID.Equals(m_current.Key))
                        return;
                    if (string.IsNullOrEmpty(tmpID) || Util.IsReservedID(tmpID) || Util.IsNGforID(tmpID))
                        throw new EcellException(MessageResources.ErrID);

                    EcellObject p = m_current.Clone();
                    if (p.Type == Constants.xpathSystem)
                    {
                        // ���[�g�̏ꍇ�A���[�g��/�ƃf�~���^��/��2�d�Ȃ�
                        if (p.ParentSystemID.Equals("/"))
                            p.Key = p.ParentSystemID + tmpID;
                        else
                            p.Key = p.ParentSystemID + Constants.delimiterPath + tmpID;
                    }
                    else if (p.Type == Constants.xpathStepper)
                    {
                        p.Key = tmpID;
                    }
                    else
                        p.Key = p.ParentSystemID + Constants.delimiterColon + tmpID;
                    if (!NotifyDataChanged(m_current.ModelID, m_current.Key, p))
                    {
                        e.Value = editCell.Value;
                    }
                }
            }
            catch (Exception ex)
            {
                e.Value = editCell.Value;
                Trace.WriteLine(ex);
                m_dgv.MouseLeave -= new EventHandler(this.LeaveMouse);
                Util.ShowErrorDialog(ex.Message);
                m_dgv.MouseLeave += new EventHandler(this.LeaveMouse);
            }
        }
示例#24
0
        public void TestConstructorEcellValueValue()
        {
            // int
            EcellValue value = null;
            value = new EcellValue(0);
            Assert.IsNotNull(value, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsTrue(value.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(value.IsList, "IsList is not expected value.");
            Assert.IsFalse(value.IsString, "IsString is not expected value.");
            Assert.AreEqual(0, (int)value.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Integer, value.Type, "Type is not expected value.");

            // double
            value = null;
            value = new EcellValue(0.01);
            Assert.IsNotNull(value, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.IsTrue(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(value.IsList, "IsList is not expected value.");
            Assert.IsFalse(value.IsString, "IsString is not expected value.");
            Assert.AreEqual(0.01, (double)value.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.Double, value.Type, "Type is not expected value.");

            // string.
            value = null;
            value = new EcellValue("test");
            Assert.IsNotNull(value, "Constructor of type, EcellValue failed to create instance.");
            Assert.IsFalse(value.IsInt, "IsInt is not expected value.");
            Assert.IsFalse(value.IsDouble, "IsDouble is not expected value.");
            Assert.IsFalse(value.IsList, "IsList is not expected value.");
            Assert.IsTrue(value.IsString, "IsString is not expected value.");
            Assert.AreEqual("test", (string)value.Value, "Value is not expected value.");
            Assert.AreEqual(EcellValueType.String, value.Type, "Type is not expected value.");
        }
示例#25
0
 /// <summary>
 /// Stores the "EcellObject" 4 the "Stepper".
 /// </summary>
 /// <param name="simulator">The simulator</param>
 /// <param name="dmm">The "DynamicModuleManager"</param>
 /// <param name="ecellObject">The stored "Stepper"</param>
 internal static void DataStored4Stepper(
     WrappedSimulator simulator,
     DMDescriptorKeeper dmm,
     EcellObject ecellObject)
 {
     string key = Constants.xpathStepper + Constants.delimiterColon + Constants.delimiterColon + ecellObject.Key;
     List<EcellData> stepperEcellDataList = new List<EcellData>();
     IList<string> wrappedPolymorph = null;
     //
     // Property List
     //
     try
     {
         wrappedPolymorph = simulator.GetStepperPropertyList(ecellObject.Key);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.StackTrace);
         return;
     }
     //
     // Sets the class name.
     //
     if (string.IsNullOrEmpty(ecellObject.Classname))
     {
         ecellObject.Classname = simulator.GetStepperClassName(ecellObject.Key);
     }
     //
     // Checks the stored "EcellData"
     //
     Dictionary<string, EcellData> storedEcellDataDic = new Dictionary<string, EcellData>();
     if (ecellObject.Value != null && ecellObject.Value.Count > 0)
     {
         foreach (EcellData storedEcellData in ecellObject.Value)
         {
             storedEcellDataDic[storedEcellData.Name] = storedEcellData;
             stepperEcellDataList.Add(storedEcellData);
         }
     }
     //
     // Stores the "EcellData"
     //
     foreach (string name in wrappedPolymorph)
     {
         string entityPath = key + Constants.delimiterColon + name;
         PropertyAttributes flag = simulator.GetStepperPropertyAttributes(ecellObject.Key, name);
         if (!flag.Gettable)
         {
             continue;
         }
         EcellValue value = null;
         try
         {
             object property = simulator.GetStepperProperty(ecellObject.Key, name);
             value = new EcellValue(property);
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex);
             value = GetValueFromDMM(dmm, ecellObject.Type, ecellObject.Classname, name);
         }
         EcellData ecellData = CreateEcellData(name, value, entityPath, flag);
         if (storedEcellDataDic.ContainsKey(name))
         {
             if (value.IsString && value.ToString().Equals(""))
             {
                 continue;
             }
             else
             {
                 stepperEcellDataList.Remove(storedEcellDataDic[name]);
             }
         }
         stepperEcellDataList.Add(ecellData);
     }
     ecellObject.SetEcellDatas(stepperEcellDataList);
 }
示例#26
0
        public void TestEquals()
        {
            // Compare int.
            EcellValue value1 = new EcellValue(1);
            EcellValue value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals(1), "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals(1.0), "Equals method returned unexpected result.");

            value2 = null;
            Assert.IsFalse(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals(new object()), "Equals method returned unexpected result.");

            // Compare double.
            value1 = new EcellValue(0.01);
            value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals(0.01), "Equals method returned unexpected result.");

            // Compare string.
            value1 = new EcellValue("test");
            value2 = value1.Clone();
            Assert.IsTrue(value1.Equals(value2), "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals("test"), "Equals method returned unexpected result.");

            string str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value1 = EcellValue.ConvertFromListString(str);
            value2 = value1.Clone();
            Assert.AreEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsTrue(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");

            str = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S3\", \"Variable:/:S3\", 1, 1))";
            value2 = EcellValue.ConvertFromListString(str);
            Assert.AreNotEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");

            str = "((\"S1\", \"Variable:/:S1\", 1, 0))";
            value2 = EcellValue.ConvertFromListString(str);
            Assert.AreNotEqual((List<object>)value1.Value, (List<object>)value2.Value, "Equals method returned unexpected result.");
            Assert.IsFalse(value1.Equals((List<object>)value2.Value), "Equals method returned unexpected result.");
        }
示例#27
0
 /// <summary>
 /// Create new EcellData.
 /// </summary>
 /// <param name="name">the entity name.</param>
 /// <param name="value">the entity value.</param>
 /// <param name="entityPath">the entity path.</param>
 /// <param name="flags">property attribute object.</param>
 /// <returns></returns>
 private static EcellData CreateEcellData(string name, EcellValue value, string entityPath, PropertyAttributes flags)
 {
     EcellData data = new EcellData(name, value, entityPath);
     data.Settable = flags.Settable;
     data.Gettable = flags.Gettable;
     data.Loadable = flags.Loadable;
     data.Saveable = flags.Savable;
     return data;
 }
示例#28
0
 public void TestGetHashCode()
 {
     EcellValue value1 = new EcellValue(1);
     EcellValue value2 = value1.Clone();
     Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "Clone method returned unexpected result.");
 }
示例#29
0
 /// <summary>
 /// GetVariableValue
 /// </summary>
 /// <param name="simulator">the current simulator.</param>
 /// <param name="name">the variable name</param>
 /// <param name="entityPath">the entity name.</param>
 /// <returns></returns>
 private static EcellValue GetVariableValue(WrappedSimulator simulator, string name, string entityPath)
 {
     EcellValue value = null;
     try
     {
         object property = simulator.GetEntityProperty(entityPath);
         value = new EcellValue(property);
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
         if (name.Equals(Constants.xpathFixed))
         {
             value = new EcellValue(0);
         }
         else
         {
             value = new EcellValue(0.0);
         }
     }
     return value;
 }
示例#30
0
        public void TestToString()
        {
            string expectedString;
            string resultString;
            EcellValue value;

            EcellReference er1 = new EcellReference("S1", "Variable:/:S1", 1, 0);
            value = new EcellValue(er1);
            expectedString = er1.ToString();
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(new List<object>());
            expectedString = "()";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            List<object> list = new List<object>();
            list.Add(0.001);
            list.Add("Test");
            value = new EcellValue(list);
            expectedString = "(0.001, \"Test\")";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(1);
            expectedString = "1";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue(0.0002);
            expectedString = "0.0002";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            value = new EcellValue("string");
            expectedString = "string";
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "ToString method returned unexpected result.");

            expectedString = "((\"S1\", \"Variable:/:S1\", 1, 0), (\"S2\", \"Variable:/:S2\", 1, 1))";
            value = EcellValue.ConvertFromListString(expectedString);
            resultString = value.ToString();
            Assert.AreEqual(expectedString, resultString, "CastToList method returned unexpected result.");
        }