Пример #1
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;
 }
Пример #2
0
        private void TestDMDescriptor(string type, string dmName)
        {
            DMDescriptor module;
            Trace.WriteLine("");

            PropertyDescriptor dmd = new PropertyDescriptor("Name", false, false, false, false, false, false, new Ecell.Objects.EcellValue(1));

            try
            {
                module = _unitUnderTest.GetDMDescriptor(type, dmName);
                Assert.IsFalse(module.ContainsProperty("hoge"));
                Assert.IsNotNull(module);
                module.Equals(_unitUnderTest.GetDMDescriptor("Process", "ExpressionFluxProcess"));
                Assert.AreEqual(module, module);
                Assert.AreNotEqual(module, new object());
                Assert.AreEqual(module.Name, dmName);
                Assert.AreNotEqual(module.Path, "");
                Assert.IsNotNull(((IEnumerable)module).GetEnumerator());
                Assert.IsNotNull(module.Properties);

                Trace.WriteLine("DynamicModule:" + module.Name);
                foreach (PropertyDescriptor prop in module)
                {
                    Trace.WriteLine("PropertyName:" + prop.Name);
                    Trace.WriteLine("IsGettable  :" + prop.Gettable);
                    Trace.WriteLine("IsLoadable  :" + prop.Loadable);
                    Trace.WriteLine("IsLogable  :" + prop.Logable);
                    Trace.WriteLine("IsSavable   :" + prop.Saveable);
                    Trace.WriteLine("IsSettable  :" + prop.Settable);
                    Trace.WriteLine("IsDynamic  :" + prop.Dynamic);
                    if (prop.DefaultValue == null)
                        Trace.WriteLine("DefaultValue: null");
                    else
                        Trace.WriteLine("DefaultValue:" + prop.DefaultValue);
                    Trace.WriteLine("HashCode :" + prop.GetHashCode());
                    Trace.WriteLine("");
                    Assert.AreEqual(false, prop.Equals(null));
                    Assert.AreEqual(false, prop.Equals(dmd));
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Type:" + type + " Name:" + dmName);
                Trace.WriteLine(e.StackTrace);
                Assert.Fail();
            }
        }
Пример #3
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;
        }