Esempio n. 1
0
        public override void Execute()
        {
            StorageDescriptor pluginCache = new StorageDescriptor(Application.CacheDirectory, PluginCacheFileName, path.Name);

            if (pluginCache.Load())
            {
                foreach (StorageContainer node in pluginCache.Nodes.Values)
                {
                    if (!node.Validate())
                    {
                        pluginCache.Clear();
                        break;
                    }
                }
            }
            StorageContainer assemblyNode; if (!pluginCache.TryGetNode(PluginAssemblyStorageAlias, out assemblyNode))

            {
                List <FileSystemDescriptor> files = Application.GetPluginFiles(path);
                if (files.Count > 0)
                {
                    FileDescriptor assemblyFile = Compile(files);
                    assemblyNode = pluginCache.Store(assemblyFile, PluginAssemblyStorageAlias);

                    foreach (FileDescriptor mixin in files)
                    {
                        pluginCache.Store(mixin);
                    }
                    pluginCache.Save();
                }
                else
                {
                    Application.Warning(SeverityFlags.None, "Plugin '{0}' has no code files to compile", path.Name);
                }
                files = null;
            }
            if (assemblyNode != null && assemblyNode.Element.Exists())
            {
                Assembly assembly = Assembly.LoadFrom(assemblyNode.Element.GetAbsolutePath());
                Type     type     = assembly.GetType <IPlugin>();
                if (type != null)
                {
                    instance = type.CreateInstance <IPlugin>();

                    if (instance != null)
                    {
                        instance.Load();
                        return;
                    }
                }
                Application.Warning(SeverityFlags.None, "'{0}' is not a plugin", path.GetAbsolutePath());
            }
        }
Esempio n. 2
0
        private static void LoadMixins()
        {
            StorageDescriptor mixinCache = new StorageDescriptor(Application.CacheDirectory, ModuleCacheFileName);

            if (mixinCache.Load())
            {
                foreach (StorageContainer node in mixinCache.Nodes.Values)
                {
                    if (!node.Validate())
                    {
                        mixinCache.Clear();
                        break;
                    }
                }
            }
            StorageContainer assemblyNode; if (!mixinCache.TryGetNode(MixinAssemblyStorageAlias, out assemblyNode))

            {
                Filter filter = new Filter();

                SetMixinFilter(filter);
                List <FileSystemDescriptor> mixins = Application.SdkDirectory.FindFiles(filter);
                if (mixins.Count > 0)
                {
                    FileDescriptor assemblyFile = Compile(mixins);
                    assemblyNode = mixinCache.Store(assemblyFile, MixinAssemblyStorageAlias);

                    foreach (FileDescriptor mixin in mixins)
                    {
                        mixinCache.Store(mixin);
                    }
                    mixinCache.Save();
                }
                filter = null;
                mixins = null;
            }
            MixinManager.RegisterMixins(Assembly.GetExecutingAssembly());
            if (assemblyNode != null && assemblyNode.Element.Exists())
            {
                MixinManager.RegisterMixins(Assembly.LoadFrom(assemblyNode.Element.GetAbsolutePath()));
            }
        }