Ejemplo n.º 1
0
        /// <summary>
        /// Load DMDescriptions.
        /// </summary>
        /// <param name="dmPaths">DM path.</param>
        private void LoadDMs(string[] dmPaths)
        {
            m_dmPaths = dmPaths;

            // Set dictionary.
            Dictionary<string, Dictionary<string, List<DMModuleInfo>>> maps =
                    new Dictionary<string, Dictionary<string, List<DMModuleInfo>>>();
            Dictionary<string, Dictionary<string, List<DMModuleInfo>>> modulesToLookup =
                    new Dictionary<string, Dictionary<string, List<DMModuleInfo>>>();
            maps[Constants.xpathSystem] = new Dictionary<string, List<DMModuleInfo>>();
            maps[Constants.xpathStepper] = new Dictionary<string, List<DMModuleInfo>>();
            maps[Constants.xpathProcess] = new Dictionary<string, List<DMModuleInfo>>();
            maps[Constants.xpathVariable] = new Dictionary<string, List<DMModuleInfo>>();

            // Look for built-in modules
            {
                const string dmPath = "<BUILTIN>";
                Dictionary<string, List<DMModuleInfo>> perDirectoryModuleList =
                    new Dictionary<string, List<DMModuleInfo>>();
                perDirectoryModuleList[Constants.xpathSystem] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathStepper] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathProcess] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathVariable] = new List<DMModuleInfo>();

                modulesToLookup[dmPath] = perDirectoryModuleList;

                using (WrappedSimulator sim = new WrappedSimulator(new string[] { "" }))
                {
                    foreach (DMInfo entry in sim.GetDMInfo())
                    {
                        perDirectoryModuleList[entry.TypeName].Add(
                            new DMModuleInfo(dmPath, entry));
                    }
                }
            }

            // Searches the DM paths
            foreach (string dmPath in m_dmPaths)
            {
                if (!Directory.Exists(dmPath))
                    continue;

                string[] modulePaths = Directory.GetFiles(
                    dmPath,
                    Constants.delimiterWildcard + Constants.FileExtDM
                    );
                if (modulePaths.Length == 0)
                    continue;

                Dictionary<string, List<DMModuleInfo>> perDirectoryModuleList =
                    new Dictionary<string, List<DMModuleInfo>>();
                perDirectoryModuleList[Constants.xpathSystem] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathStepper] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathProcess] = new List<DMModuleInfo>();
                perDirectoryModuleList[Constants.xpathVariable] = new List<DMModuleInfo>();

                modulesToLookup[dmPath] = perDirectoryModuleList;
                using (WrappedSimulator sim = new WrappedSimulator(new string[] { dmPath }))
                {
                    foreach (string modulePath in modulePaths)
                    {
                        string moduleName = Path.GetFileNameWithoutExtension(modulePath);
                        string moduleType = GetModuleType(moduleName);

                        if (moduleType == null)
                            continue; // XXX: what are we supposed to do here?

                        List<DMModuleInfo> infoList = null;
                        maps[moduleType].TryGetValue(moduleName, out infoList);
                        if (infoList == null)
                        {
                            infoList = new List<DMModuleInfo>();
                            maps[moduleType][moduleName] = infoList;
                        }
                        string description = null;
                        try
                        {
                            description = sim.GetDescription(moduleName);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e);
                        }
                        DMModuleInfo info = new DMModuleInfo(modulePath, moduleName, description);
                        infoList.Add(info);
                        perDirectoryModuleList[moduleType].Add(info);
                    }
                }
            }

            Dictionary<string, Dictionary<string, DMDescriptor>> descs =
                new Dictionary<string, Dictionary<string, DMDescriptor>>();
            descs[Constants.xpathSystem] = new Dictionary<string, DMDescriptor>();
            descs[Constants.xpathProcess] = new Dictionary<string, DMDescriptor>();
            descs[Constants.xpathVariable] = new Dictionary<string, DMDescriptor>();
            descs[Constants.xpathStepper] = new Dictionary<string, DMDescriptor>();

            foreach (KeyValuePair<string, Dictionary<string, List<DMModuleInfo>>> kv in modulesToLookup)
            {
                using (WrappedSimulator sim = new WrappedSimulator(new string[] { kv.Key }))
                {
                    {
                        sim.CreateStepper("PassiveStepper", "tmp");
                        string id = Util.BuildFullPN(Constants.xpathSystem, "", "/", "StepperID");
                        sim.SetEntityProperty(id, "tmp");
                    }
                    Trace.WriteLine("Checking DMs in " + kv.Key);

                    // Test System DMs.
                    foreach (string kind in new String[] { Constants.xpathSystem,
                                                           Constants.xpathProcess,
                                                           Constants.xpathVariable })
                    {
                        foreach (DMModuleInfo info in kv.Value[kind])
                        {
                            descs[kind][info.ModuleName] = LoadEntityDM(sim, info, kind);
                        }
                    }

                    // Test Stepper DMs.
                    foreach (DMModuleInfo info in kv.Value[Constants.xpathStepper])
                    {
                        descs[Constants.xpathStepper][info.ModuleName] = LoadStepperDM(sim, info);
                    }
                }
            }
            m_descs = descs;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the stepper DM.
        /// </summary>
        /// <param name="sim">the loaded simulator.</param>
        /// <param name="info">DM information.</param>
        /// <returns>DMDescriptor.</returns>
        private static DMDescriptor LoadStepperDM(WrappedSimulator sim, DMModuleInfo info)
        {
            DMDescriptor desc = null;
            try
            {
                Trace.WriteLine("  Checking properties for " + info.ModuleName);
                string stepper = info.ModuleName;
                sim.CreateStepper(stepper, stepper);

                // Get PropertyDescriptors
                Dictionary<string, PropertyDescriptor> pdescs = GetStepperPropertyDescriptors(sim, stepper);

                // Check DynamicProperty
                bool dynamic = CheckDynamicProperty(sim, stepper, pdescs);
                desc = new DMDescriptor(stepper, info.Path, Constants.xpathStepper, dynamic, pdescs);
                desc.Description = info.Description;

            }
            catch (Exception)
            {
                Trace.WriteLine("Failed to load " + info.ModuleName);
                //Trace.WriteLine(e.StackTrace);
            }
            return desc;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the "Stepper" 2 the "EcellCoreLib".
        /// </summary>
        /// <param name="simulator">The simulator</param>
        /// <param name="stepperList">The list of the "Stepper"</param>
        /// <param name="setStepperDic">The list of stepper.</param>
        private static void LoadStepper(
            WrappedSimulator simulator,
            List<EcellObject> stepperList,
            Dictionary<string, Dictionary<string, object>> setStepperDic)
        {
            Debug.Assert(stepperList != null && stepperList.Count > 0);

            foreach (EcellObject stepper in stepperList)
            {
                if (stepper == null)
                    continue;

                simulator.CreateStepper(stepper.Classname, stepper.Key);

                // 4 property
                if (stepper.Value == null || stepper.Value.Count <= 0)
                    continue;

                foreach (EcellData ecellData in stepper.Value)
                {
                    if (ecellData.Name == null || ecellData.Name.Length <= 0 || ecellData.Value == null)
                        continue;
                    else if (!ecellData.Value.IsDouble && !ecellData.Value.IsInt)
                        continue;

                    // 4 MaxStepInterval == Double.MaxValue
                    EcellValue value = ecellData.Value;
                    try
                    {
                        if ((double)value == Double.PositiveInfinity || (double)value == Double.MaxValue)
                            continue;
                        XmlConvert.ToDouble(value);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                        continue;
                    }

                    if (value.IsDouble
                        && (Double.IsInfinity((double)value) || Double.IsNaN((double)value)))
                        continue;

                    if (ecellData.Saveable)
                    {
                        simulator.LoadStepperProperty(
                            stepper.Key,
                            ecellData.Name,
                            value.Value);
                    }
                    else if (ecellData.Settable)
                    {
                        if (!setStepperDic.ContainsKey(stepper.Key))
                        {
                            setStepperDic[stepper.Key] = new Dictionary<string, object>();
                        }
                        setStepperDic[stepper.Key][ecellData.Name] = value.Value;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize the model
        /// </summary>
        /// <param name="modelObject">the model object.</param>
        /// <param name="simulator">the loaded simulator.</param>
        public static void InitializeModel(EcellModel modelObject, WrappedSimulator simulator)
        {
            bool isWarn = false;
            string errMsg = MessageResources.WarnLoadDM + "\n";
            Dictionary<string, object> processPropertyDic = new Dictionary<string, object>();

            // Initialize object
            foreach (EcellObject obj in modelObject.Children)
            {
                // Initialize Stepper
                if (obj is EcellStepper)
                {
                    try
                    {
                        simulator.CreateStepper(obj.Classname, obj.Key);
                    }
                    catch (Exception e)
                    {
                        errMsg += obj.FullID + ":" + e.Message + "\n";
                        Trace.WriteLine(e.ToString());
                        isWarn = true;
                    }
                    foreach (EcellData data in obj.Value)
                    {
                        simulator.LoadStepperProperty(
                            obj.Key,
                            data.Name,
                            data.Value.Value);
                    }
                }
                else if (obj is EcellSystem)
                {
                    // Initialize System
                    if (!obj.Key.Equals(Constants.delimiterPath))
                    {
                        try
                        {
                            simulator.CreateEntity(
                                    obj.Classname,
                                    obj.FullID);
                        }
                        catch (Exception e)
                        {
                            throw new EmlParseException("Failed to create a System entity", e);
                        }
                    }
                    foreach (EcellData data in obj.Value)
                    {
                        simulator.LoadEntityProperty(
                            data.EntityPath,
                            data.Value.Value);
                    }

                    // Initialize Entity
                    foreach (EcellObject entity in obj.Children)
                    {
                        if (entity.Type.Equals(EcellObject.TEXT))
                            continue;
                        bool isCreated = true;
                        // 4 "EcellCoreLib"
                        try
                        {
                            simulator.CreateEntity(
                                entity.Classname,
                                entity.FullID);
                        }
                        catch (Exception e)
                        {
                            errMsg += entity.FullID + ":" + e.Message + "\n";
                            Trace.WriteLine(e.ToString());
                            isCreated = false;
                            isWarn = true;
                        }

                        foreach (EcellData data in entity.Value)
                        {
                            string entityPath = data.EntityPath;
                            if (obj.Type.Equals(Constants.xpathVariable))
                            {
                                if (isCreated == true)
                                    simulator.LoadEntityProperty(entityPath, data.Value.Value);
                            }
                            else
                            {
                                processPropertyDic[entityPath] = data.Value.Value;
                            }
                        }
                    }
                }
            }
            //
            List<string> removeList = new List<string>();
            foreach (KeyValuePair<string, object> pair in processPropertyDic)
            {
                try
                {
                    simulator.LoadEntityProperty(pair.Key, pair.Value);
                }
                catch (WrappedException e)
                {
                    isWarn = true;
                    errMsg += pair.Key + ":" + e.Message + "\n";
                }
                if (pair.Key.EndsWith(Constants.xpathVRL))
                    removeList.Add(pair.Key);
            }
            foreach (string entityPath in removeList)
            {
                processPropertyDic.Remove(entityPath);
            }
            if (isWarn)
            {
                modelObject.ErrMsg = errMsg;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the dummy simulator 4 property lists.
        /// </summary>
        /// <param name="simulator">The dummy simulator</param>
        /// <param name="defaultProcess">The dm name of "Process"</param>
        /// <param name="defaultStepper">The dm name of "Stepper"</param>
        private static void BuildDefaultSimulator(
            WrappedSimulator simulator, string defaultProcess, string defaultStepper)
        {
            try
            {
                // Set DefaultProcess if null
                if (defaultProcess == null)
                    defaultProcess = Constants.DefaultProcessName;
                // Set DefaultStepper if null
                if (defaultStepper == null)
                    defaultStepper = Constants.DefaultStepperName;

                //
                simulator.CreateStepper(defaultStepper, Constants.textKey);
                simulator.CreateEntity(
                    Constants.xpathVariable,
                    Constants.xpathVariable + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                    );
                simulator.CreateEntity(
                    defaultProcess,
                    Constants.xpathProcess + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                );
                simulator.LoadEntityProperty(
                    Constants.xpathSystem +  "::/:" + Constants.xpathStepperID,
                    new string[] { Constants.textKey }
                );
                simulator.LoadEntityProperty(
                    Util.BuildFullPN(
                        Constants.xpathVariable,
                        Constants.delimiterPath,
                        Constants.xpathSize.ToUpper(),
                        Constants.xpathValue
                    ),
                    new string[] { "0.1" }
                );
                simulator.Initialize();
            }
            catch (Exception ex)
            {
                throw new EcellException(
                    MessageResources.ErrCombiStepProc, ex);
            }
        }