Пример #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;
        }
Пример #2
0
 /// <summary>
 /// Check DynamicProperty
 /// </summary>
 /// <param name="sim">The current simulator.</param>
 /// <param name="id">The proerty name.</param>
 /// <param name="pdescs">the list of proerty.</param>
 /// <returns></returns>
 private static bool CheckDynamicProperty(WrappedSimulator sim, string id, Dictionary<string, PropertyDescriptor> pdescs)
 {
     // Check DynamicProperty
     bool dynamic = true;
     try
     {
         string randomID = null;
         do
         {
             randomID = Util.GenerateRandomID(32);
         }
         while (pdescs.ContainsKey(randomID));
         // Test Set property.
         if (id.EndsWith(EcellObject.STEPPER))
         {
             sim.SetStepperProperty(id, randomID, 0.0);
         }
         else
         {
             string fullId = Util.BuildFullPN(id, randomID);
             sim.SetEntityProperty(fullId, 0.0);
         }
     }
     catch (Exception)
     {
         dynamic = false;
     }
     return dynamic;
 }