示例#1
0
        /// <summary>
        /// Loads all scripts from the compiled folder.
        /// </summary>
        /// <returns>Returns a list of scripts.</returns>
        internal List <ScriptItem> LoadScripts()
        {
            var dir            = BotDirectories.compiledDir;
            var scriptItemList = new List <ScriptItem>();

            try
            {
                if (Directory.Exists(dir) || !Directory.EnumerateFileSystemEntries(dir).Any())
                {
                    foreach (var file in Directory.GetFiles(dir))
                    {
                        // loading assembly file
                        var            assembly   = Assembly.LoadFile(file);
                        var            types      = assembly.GetTypes();
                        var            scriptItem = new ScriptItem();
                        Attribute[]    attributes = null;
                        ScriptManifest manifest   = null;

                        // loading attributes
                        for (int i = 0; i < types.Length; i++)
                        {
                            attributes = Attribute.GetCustomAttributes(types[i]);

                            // get information from assembly file
                            for (int j = 0; j < attributes.Length; j++)
                            {
                                manifest = (ScriptManifest)attributes[j];
                                dynamic classInformation = Activator.CreateInstance(types[i]); // creates an instance of an assembly file

                                // is the class of type IScript?
                                if (classInformation is IScript)
                                {
                                    scriptItem.script = (IScript)classInformation;

                                    // exists an manifest?
                                    if (manifest != null)
                                    {
                                        scriptItem.manifest = manifest;
                                    }
                                    else
                                    {
                                        scriptItem.manifest = null;
                                    }

                                    scriptItemList.Add(scriptItem);
                                }
                            }
                        }
                    }
                }
            }
            catch (DirectoryNotFoundException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e) { }

            return((scriptItemList.Count > 0) ? scriptItemList : null);
        }
示例#2
0
 /// <summary>
 /// Initialises a new instance of the <see cref="ScriptPackage"/> class.
 /// </summary>
 public ScriptPackage(ScriptManifest manifest)
 {
     InitializeComponent();
     _manifest = manifest;
 }