Beispiel #1
0
        protected virtual Assembly CreateAssembly(ScriptingScheme scheme, CodeDomProvider provider, CompilerParameters cp)
        {
            cp.GenerateInMemory = true;

            foreach (string s in scheme.ReferencedAssemblies)
            {
                cp.ReferencedAssemblies.Add(s);
            }

            var cr = provider.CompileAssemblyFromSource(cp, scheme.Source);

            if (!cr.Errors.HasErrors)
            {
                return(cr.CompiledAssembly);
            }

            foreach (var error in cr.Errors)
            {
                Console.Error.WriteLine(error);
            }

            if (scheme.ThrowOnCompileError)
            {
                throw new ArgumentException("Errors while compiling script.", "scheme");
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Binds the events.
        /// </summary>
        /// <param name="scheme">The ScriptingScheme.</param>
        protected override void BindEvents(ScriptingScheme scheme)
        {
            // create or retrieve assembly
            Assembly asm;

            this.Assemblies.TryGetValue(scheme.Source.GetHashCode(), out asm);

            if (asm == null)
            {
                asm = this.CreateAssembly(scheme);

                if (asm != null)
                {
                    this.Assemblies[scheme.Source.GetHashCode()] = asm;
                }
            }

            // bind events
            if (asm != null)
            {
                object instance = asm.CreateInstance(asm.GetTypes()[0].FullName);
                if (instance != null)
                {
                    foreach (ScriptMap emd in scheme.ScriptMaps)
                    {
                        // Iterate through events
                        foreach (KeyValuePair <string, string> kvp in emd.EventMethods)
                        {
                            // get event of control
                            EventInfo ei = emd.Target.GetType().GetEvent(kvp.Key);

                            if (ei != null)
                            {
                                ei.AddEventHandler(emd.Target, Delegate.CreateDelegate(ei.EventHandlerType, instance, kvp.Value));
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Binds the events.
 /// </summary>
 /// <param name="scheme">The ScriptingScheme.</param>
 protected abstract void BindEvents(ScriptingScheme scheme);
Beispiel #4
0
 /// <summary>
 /// Creates an assembly.
 /// </summary>
 /// <param name="scheme">The ScriptingScheme.</param>
 /// <returns>The newly created assembly.</returns>
 protected abstract Assembly CreateAssembly(ScriptingScheme scheme);
 /// <summary>
 /// Initializes a new instance of the BindEventsEventArgs class.
 /// </summary>
 /// <param name="scriptingScheme">The affected ScriptingScheme.</param>
 public BindEventsEventArgs(ScriptingScheme scriptingScheme)
 {
     this.ScriptingScheme = scriptingScheme;
 }