Ejemplo n.º 1
0
        /// <summary>
        /// Instantiates a MMU  from file
        /// </summary>
        /// <param name="folderPath"></param>
        /// <param name="mmuDescription"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        private static MMUDescription GetDescriptionFromClass(Type classType)
        {
            if (classType != null)
            {
                //Get all defined attributes
                List <object> attributes = GetAttributes(classType);


                MMUDescriptionAttribute mmuDescriptionAttr = attributes.Find(s => s is MMUDescriptionAttribute) as MMUDescriptionAttribute;
                var mParamterAttr = attributes.Where(s => s is MParameterAttribute);
                var simEvents     = attributes.Where(s => s is MSimulationEventAttribute);


                //Create the mmu description
                MMUDescription mmuDescription = new MMUDescription()
                {
                    Name             = mmuDescriptionAttr.Name,
                    Author           = mmuDescriptionAttr.Author,
                    Version          = mmuDescriptionAttr.Version,
                    MotionType       = mmuDescriptionAttr.MotionType,
                    LongDescription  = mmuDescriptionAttr.LongDescription,
                    ShortDescription = mmuDescriptionAttr.ShortDescription,
                    AssemblyName     = "debug",

                    //Language can be automatically set
                    Language = "C#",

                    //Auto-generate an ID
                    ID = Guid.NewGuid().ToString(),
                };


                //Add all parameters
                if (mParamterAttr != null)
                {
                    mmuDescription.Parameters = new System.Collections.Generic.List <MParameter>();
                    foreach (MParameterAttribute param in mParamterAttr)
                    {
                        mmuDescription.Parameters.Add(new MParameter(param.Name, param.Type, param.Description, param.Required));
                    }
                }


                //Add all events (if defined)
                if (simEvents != null)
                {
                    mmuDescription.Events = new System.Collections.Generic.List <string>();
                    foreach (MSimulationEventAttribute param in simEvents)
                    {
                        mmuDescription.Events.Add(param.Type);
                    }
                }

                //Return the created MMU Description
                return(mmuDescription);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a MMU  from file
        /// </summary>
        /// <param name="folderPath"></param>
        /// <param name="mmuDescription"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        private static MMUDescription GetDescriptionFromClass(string path)
        {
            //Load the mmu from filesystem and instantiate
            Assembly assembly = Assembly.LoadFrom(path);

            //Get the specific type of the class which implementd the IMotionModelUnitDev interface
            Type classType = GetMMUClassType(assembly);

            if (classType != null)
            {
                //Get all defined attributes
                List <object> attributes = GetAttributes(classType);


                MMUDescriptionAttribute mmuDescriptionAttr = attributes.Find(s => s is MMUDescriptionAttribute) as MMUDescriptionAttribute;
                var mParamterAttr = attributes.Where(s => s is MParameterAttribute);
                var simEvents     = attributes.Where(s => s is MSimulationEventAttribute);


                //Create the mmu description
                MMUDescription mmuDescription = new MMUDescription()
                {
                    Name             = mmuDescriptionAttr.Name,
                    Author           = mmuDescriptionAttr.Author,
                    Version          = mmuDescriptionAttr.Version,
                    MotionType       = mmuDescriptionAttr.MotionType,
                    LongDescription  = mmuDescriptionAttr.LongDescription,
                    ShortDescription = mmuDescriptionAttr.ShortDescription,

                    //Language can be automatically set
                    Language = "C#",

                    //Auto-generate an ID
                    ID = Guid.NewGuid().ToString(),

                    //Use the assembly name from the path
                    AssemblyName = System.IO.Path.GetFileName(path)
                };


                //Add all parameters
                if (mParamterAttr != null)
                {
                    mmuDescription.Parameters = new System.Collections.Generic.List <MParameter>();
                    foreach (MParameterAttribute param in mParamterAttr)
                    {
                        mmuDescription.Parameters.Add(new MParameter(param.Name, param.Type, param.Description, param.Required));
                    }
                }


                //Add all events (if defined)
                if (simEvents != null)
                {
                    mmuDescription.Events = new System.Collections.Generic.List <string>();
                    foreach (MSimulationEventAttribute param in simEvents)
                    {
                        mmuDescription.Events.Add(param.Type);
                    }
                }

                //Return the created MMU Description
                return(mmuDescription);
            }

            return(null);
        }