Пример #1
0
        /// <summary>
        /// Creates a new instance of a type by invoking its constructor.
        /// </summary>
        /// <param name="type">The type to instantiate.</param>
        /// <param name="context">ScriptContext to be passed to the <c>type</c> constructor.</param>
        /// <param name="caller">DTypeDesc to be passed to the <c>type</c> constructor.</param>
        /// <returns>New instance of <c>type</c> created using specified constructor.</returns>
        /// <exception cref="PhpException">Fatal error.</exception>
        /// <exception cref="PhpUserException">Uncaught user exception.</exception>
        /// <exception cref="ScriptDiedException">Script died or exit.</exception>
        /// <exception cref="TargetInvocationException">An internal error thrown by the target.</exception>
        internal static DObject InvokeConstructor(DTypeDesc /*!*/ type, ScriptContext context, DTypeDesc caller)
        {
            Debug.Assert(type != null);

            try
            {
                var newobj = type.RealTypeCtor_ScriptContext_DTypeDesc;
                if (newobj == null)
                {
                    lock (type)
                        if ((newobj = type.RealTypeCtor_ScriptContext_DTypeDesc) == null)
                        {
                            // emit the type creation:
                            newobj = type.RealTypeCtor_ScriptContext_DTypeDesc = (DTypeDesc.Ctor_ScriptContext_DTypeDesc)BuildNewObj <DTypeDesc.Ctor_ScriptContext_DTypeDesc>(type.RealType, Emit.Types.ScriptContext_DTypeDesc);
                        }
                }

                return(ClrObject.Wrap(newobj(context, caller)));
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is PhpException ||
                    e.InnerException is PhpUserException ||
                    e.InnerException is ScriptDiedException ||
                    e.InnerException is System.Threading.ThreadAbortException)
                {
                    throw e.InnerException;
                }

                throw;
            }
        }
Пример #2
0
        public static EventHandler RunSilverlightApplication(System.Windows.Controls.Canvas c, string source)
        {
            ApplicationContext app_context = ApplicationContext.Default;

            // try to preload configuration (to prevent exceptions during InitApplication)
            Configuration.Load(app_context);
            ApplicationConfiguration app_config = Configuration.Application;


            string url       = HtmlPage.Document.DocumentUri.AbsoluteUri;
            int    lastSlash = url.Replace('\\', '/').LastIndexOf('/');

            app_config.Compiler.SourceRoot = new FullPath(url.Substring(0, lastSlash), false);

            int    sourcelastSlash = source.Replace('\\', '/').LastIndexOf('/');
            string sourceRelPath   = source.Substring(lastSlash + 1);



            // Silverlight language features
            app_config.Compiler.LanguageFeatures = LanguageFeatures.PhpClr;

            // ..
            ScriptContext context = InitApplication(app_context);

            Debug.Fail("Update versions below!");
            ConfigurationContext.AddLibrary("mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            ConfigurationContext.AddLibrary("System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", null, "");
            //ConfigurationContext.AddLibrary("System.SilverLight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null, "");
            //ConfigurationContext.AddLibrary("agclr, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null, "");

            ConfigurationContext.AddLibrary("PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb", null, "");

            //
            Configuration.Application.Compiler.Debug = true;

            // ..
            Dictionary <string, object> vars = new Dictionary <string, object>();

            currentContext.AutoGlobals.Canvas.Value = ClrObject.Wrap(c);
            currentContext.AutoGlobals.Addr.Value   = ClrObject.Wrap(app_config.Compiler.SourceRoot.ToString());

            //Operators.SetVariableRef(currentContext, vars, "_CANVAS", Operators.GetItemRef("_CANVAS", ref currentContext.AutoGlobals.Globals.value));
            //Operators.SetVariable(currentContext, vars, "_CANVAS", ClrObject.Wrap(c));


            context.DynamicInclude(source, sourceRelPath, vars, null, null, InclusionTypes.RunSilverlight);

            return(new EventHandler(delegate(object sender, EventArgs e)
            {
                if (context.ResolveFunction("OnLoad", null, true) != null)
                {
                    PhpCallback load = new PhpCallback("OnLoad");
                    load.Invoke(sender, e);
                }
            }));
        }