예제 #1
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);
                }
            }));
        }
예제 #2
0
        public virtual object __construct(ScriptContext context, object arg)
        {
            string name = PhpVariable.AsString(arg);
            if (!string.IsNullOrEmpty(name))
            {
                routine = context.ResolveFunction(name, null, false);
            }
            else
            {
                PhpException.InvalidArgument("arg");
            }

            if (routine == null)
                PhpException.Throw(PhpError.Error, string.Format("Function {0}() does not exist", name));
            
            return null;
        }
예제 #3
0
        /// <summary>
        /// Attempts to bind this callback to its target.
        /// </summary>
        /// <param name="quiet"><B>true</B> of no errors should be thrown, <B>false</B> otherwise.</param>
        /// <param name="nameContext">Current <see cref="NamingContext"/> for function and class name resolution.</param>
        /// <param name="caller">Current class context or a <see cref="UnknownTypeDesc"/> if the class context
        /// should be determined ad-hoc.</param>
        /// <returns><B>True</B> if the callback was successfully bound, <B>false</B> if an error occured.</returns>
        public bool Bind(bool quiet, DTypeDesc caller, NamingContext nameContext)
        {
            if (IsInvalid)
            {
                return(false);
            }

            switch (state)
            {
            case State.UnboundFunction:
            {
                if (context == null)
                {
                    context = ScriptContext.CurrentContext;
                }

                routineDesc = context.ResolveFunction(targetName, nameContext, quiet);
                if (routineDesc == null)
                {
                    return(false);
                }

                state = State.Bound;
                return(true);
            }

            case State.UnboundStaticMethod:
            {
                if (context == null)
                {
                    context = ScriptContext.CurrentContext;
                }

                if (caller != null && caller.IsUnknown)
                {
                    callingContext = PhpStackTrace.GetClassContext();
                }
                else
                {
                    callingContext = caller;
                }

                // try to find the CLR method

                // find the class according to className
                ResolveTypeFlags flags = ResolveTypeFlags.UseAutoload;
                if (!quiet)
                {
                    flags |= ResolveTypeFlags.ThrowErrors;
                }

                DTypeDesc type = context.ResolveType(className, nameContext, callingContext, null, flags);
                if (type == null)
                {
                    return(false);
                }

                // find the method
                bool is_caller_method;
                lateStaticBindType = type;
                routineDesc        = Operators.GetStaticMethodDesc(type, targetName,
                                                                   ref instance, callingContext, context, quiet, false, out is_caller_method);

                if (routineDesc == null)
                {
                    return(false);
                }

                if (instance != null)
                {
                    dummyInstance = true;
                }
                state = is_caller_method ? State.BoundToCaller : State.Bound;
                return(true);
            }

            case State.UnboundInstanceMethod:
            {
                if (caller != null && caller.IsUnknown)
                {
                    callingContext = PhpStackTrace.GetClassContext();
                }
                else
                {
                    callingContext = caller;
                }

                // ask the instance for a handle to the method
                bool is_caller_method;
                routineDesc = instance.GetMethodDesc(targetName, callingContext, quiet, out is_caller_method);
                if (routineDesc == null)
                {
                    return(false);
                }

                state = (is_caller_method ? State.BoundToCaller : State.Bound);
                return(true);
            }
            }
            return(true);
        }
예제 #4
0
        public virtual object __construct(ScriptContext context, object arg)
        {
            string name = PhpVariable.AsString(arg);
            if (!string.IsNullOrEmpty(name))
            {
                routine = context.ResolveFunction(name, null, false);
            }
            else
            {
                PhpException.InvalidArgument("arg");
            }

            return null;
        }