public void TestGetDescription()
        {
            string[] paths = Util.GetDMDirs();
            string desc = "";

            WrappedSimulator sim = new WrappedSimulator(paths);
            try
            {
                desc = sim.GetDescription("HogeProcess");
                Assert.AreEqual("", desc, "GetDescription method returns unexpected value.");
            }
            catch(Exception)
            {
            }

            desc = sim.GetDescription("ExpressionFluxProcess");
            Assert.IsNotEmpty(desc, "GetDescription method returns unexpected value.");
        }
Beispiel #2
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;
        }