Esempio n. 1
0
        /// <summary>
        /// Recreates the repository with only the built-in descriptors (no plugins).
        /// </summary>
        public void Recreate()
        {
            Descriptors.Clear();

            // Add custom block descriptors
            Descriptors["Keycheck"]    = new KeycheckBlockDescriptor();
            Descriptors["HttpRequest"] = new HttpRequestBlockDescriptor();
            Descriptors["Parse"]       = new ParseBlockDescriptor();
            Descriptors["Script"]      = new ScriptBlockDescriptor();

            AddFromExposedMethods(Assembly.GetExecutingAssembly());
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a block by <paramref name="id"/> and casts it to the requested type.
        /// </summary>
        public static T GetBlock <T>(string id) where T : BlockInstance
        {
            if (!Globals.DescriptorsRepository.Descriptors.TryGetValue(id, out BlockDescriptor descriptor))
            {
                throw new Exception($"Invalid block id: {id}");
            }

            BlockInstance instance = descriptor switch
            {
                AutoBlockDescriptor x => new AutoBlockInstance(x),
                KeycheckBlockDescriptor x => new KeycheckBlockInstance(x),
                HttpRequestBlockDescriptor x => new HttpRequestBlockInstance(x),
                ParseBlockDescriptor x => new ParseBlockInstance(x),
                ScriptBlockDescriptor x => new ScriptBlockInstance(x),
                _ => throw new NotImplementedException()
            };

            return(instance as T);
        }
    }