Example #1
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;
        }
Example #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;
        }
Example #3
0
        /// <summary>
        /// Load the entity DM.
        /// </summary>
        /// <param name="sim">the loaded simulator.</param>
        /// <param name="info">the DM information/</param>
        /// <param name="type">the type of DM.</param>
        /// <returns>DMDescriptor</returns>
        private static DMDescriptor LoadEntityDM(WrappedSimulator sim, DMModuleInfo info, string type)
        {
            DMDescriptor desc = null;
            try
            {
                Trace.WriteLine("  Checking properties for " + info.ModuleName);
                string id = Util.BuildFullID(type, "/", info.ModuleName);
                sim.CreateEntity(info.ModuleName, id);

                // Get PropertyDescriptors
                Dictionary<string, PropertyDescriptor> pdescs = GetEntityPropertyDescriptors(sim, id);

                // Check DynamicProperty
                bool dynamic = CheckDynamicProperty(sim, id, pdescs);
                desc = new DMDescriptor(info.ModuleName, info.Path, type, dynamic, pdescs);
                desc.Description = info.Description;

            }
            catch (Exception)
            {
                Trace.WriteLine("Failed to load " + info.ModuleName);
                //Trace.WriteLine(e.StackTrace);
            }
            return desc;
        }