private void InitBlock (EcmaScript.NET.ICallable callable, EcmaScript.NET.IScriptable thisObj, object [] args, SecurityController enclosingInstance)
 {
     this.callable = callable;
     this.thisObj = thisObj;
     this.args = args;
     this.enclosingInstance = enclosingInstance;
 }
Exemple #2
0
        public static void Init(EcmaScript energy)
        {
            EcmaHeadObject obj = new EcmaHeadObject();

            obj.Class = "MysqlConnector";
            obj.Put("connect", EcmaValue.Object(new NativeFunctionInstance(4, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                MySqlConnection connection = new MySqlConnection("SERVER=" + arg[0].ToString(energy.State) + ";UID=" + arg[1].ToString(energy.State) + ";PASSWORD="******";DATABASE=" + arg[3].ToString(energy.State) + ";");
                try
                {
                    connection.Open();
                    return(EcmaValue.Object(new MysqlValue(energy.State, connection)));
                }
                catch (MySqlException)
                {
                    return(EcmaValue.Null());
                }
            })));
            energy.CreateVariable("MysqlConnector", EcmaValue.Object(obj));

            obj       = new EcmaHeadObject();
            obj.Class = "Mysql";
            obj.Put("escape", EcmaValue.Object(new NativeFunctionInstance(1, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                return(EcmaValue.String(MySqlHelper.EscapeString(arg[0].ToString(energy.State))));
            })));
        }
        /// <summary>
        /// Invoke method on given type
        /// </summary>
        internal protected void InvokeMethod(Type hostType)
        {
            string methodName = base["method"];
            string result     = string.Empty;

            if (string.IsNullOrEmpty(methodName))
            {
                this.Response.AddError("No method specified for \"{0}\"", hostType.Name);
                this.Response.Abort();
                return;
            }
            MethodInfo methodInfo = WebInvokable.GetMethod(hostType, methodName);

            if (methodInfo == null)
            {
                this.Response.AddError("Invokable method \"{0}()\" not found in type \"{1}\"", methodName, hostType.Name);
                this.Response.Abort();
                return;
            }

            // convert parameter types
            string value;

            ParameterInfo[] info      = methodInfo.GetParameters();
            List <object>   arguments = new List <object>();

            try {
                foreach (ParameterInfo p in info)
                {
                    value = this.Parameters[p.Name];
                    arguments.Add(EcmaScript.ToType(value, p.ParameterType, this.Context));
                }
            } catch (System.Exception ex) {
                Idaho.Exception.Log(ex);
                this.Response.Error(ex);
                return;
            }

            try {
                object instance = methodInfo.IsStatic ? null : this.CreateInstance(hostType);
                result = methodInfo.Invoke(instance, arguments.ToArray()).ToJSON();
            } catch (System.Exception ex) {
                Idaho.Exception.Log(ex);
                this.Response.Error(ex);
            } finally {
                this.Response.Complete(result, false);
            }
        }
Exemple #4
0
        private EcmaValue LoadScriptFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new EcmaRuntimeException("Unknown script path: " + path);
            }

            EcmaScript script = new EcmaScript();

            script.BuildStandartLibary();
            new DefaultScript(script);
            EcmaComplication com = script.RunCode(File.OpenText(path));

            if (com.Type != EcmaComplicationType.Return)
            {
                throw new EcmaRuntimeException("A included file must return a value!");
            }

            return(com.Value);
        }
        /// <summary>
        /// Infer constructor parameter values
        /// </summary>
        /// <remarks>
        /// If unable to infer a parameter, return null. Note that this will need
        /// to be evaluated differently from a constructor with no parameters,
        /// which will be an empty list rather than null.
        /// </remarks>
        private object[] InferParameters(ConstructorInfo i)
        {
            List <object> parameters = new List <object>();

            ParameterInfo[] info  = i.GetParameters();
            object          value = null;

            foreach (ParameterInfo p in info)
            {
                value = EcmaScript.ToType(string.Empty, p.ParameterType, this.Context);
                if (value != null)
                {
                    parameters.Add(value);
                }
                else
                {
                    return(null);
                }
            }
            return(parameters.ToArray());
        }
Exemple #6
0
        /// <summary>
        /// Use reflection to render requested control
        /// </summary>
        internal override void Process()
        {
            if (!this.Response.WriteCache(this.Key))
            {
                string         typeName = base["type"];
                StringBuilder  sb       = new StringBuilder();
                HtmlTextWriter writer   = new HtmlTextWriter(new StringWriter(sb));
                IAjaxControl   control;
                PropertyInfo[] properties;
                System.Type    controlType;

                if (string.IsNullOrEmpty(typeName))
                {
                    this.Response.AddError("No control specified");
                    return;
                }

                // expand abbreviated type names
                typeName = AjaxBase.Expand(typeName);

                // get control type and validate
                if (Handlers.AjaxHandler.KnownType.ContainsKey(typeName))
                {
                    controlType = Handlers.AjaxHandler.KnownType[typeName];
                }
                else
                {
                    controlType = System.Type.GetType(typeName);
                }
                if (controlType == null)
                {
                    this.Response.AddError("Control \"{0}\" could not found", typeName);
                    return;
                }
                if (!this.ValidType(controlType))
                {
                    this.Response.AddError("Control \"{0}\" cannot be called asynchronously", typeName);
                    return;
                }

                // now that validated, create instance and set properties
                using (Page page = new Page(this.Context)) {
                    control = (IAjaxControl)page.LoadControl(controlType, null);
                }
                properties = WebBindable.Properties(controlType);

                try {
                    foreach (PropertyInfo p in properties)
                    {
                        // only set properties for which a value has been passed
                        if (!string.IsNullOrEmpty(this.Parameters[p.Name]))
                        {
                            p.SetValue(control, EcmaScript.ToType(
                                           this.Parameters[p.Name], p.PropertyType, this.Context), null);
                        }
                    }
                    // set ID so generated JavaScript references are equivalent
                    if (!string.IsNullOrEmpty(this.Parameters["id"]))
                    {
                        control.ID = this.Parameters["id"];
                    }
                    if (!string.IsNullOrEmpty(this.Parameters["style"]))
                    {
                        control.CssStyle = this.Parameters["style"];
                    }
                    if (!string.IsNullOrEmpty(this.Parameters["cssClass"]))
                    {
                        control.CssClass = this.Parameters["cssClass"];
                    }
                    control.Ajax.Context = this.Context;
                    // any control rendered by this method is isolated from
                    // the normal page life cycle
                    control.Ajax.RenderState = AjaxBase.RenderStates.Isolation;
                    control.Ajax.RenderMode  = AjaxBase.RenderModes.Asynchronous;
                    control.RenderControl(writer);
                } catch (System.Exception ex) {
                    Idaho.Exception.Log(ex);
                    control.Ajax.Cacheable = false;
                    this.Response.Error(ex);
                } finally {
                    this.Response.Cacheable         = control.Ajax.Cacheable;
                    this.Response.CacheDependencies = control.Ajax.DependsOnType;
                    this.Response.CacheKey          = this.Key;
                    this.Response.Complete(sb.ToString(), true);
                }
            }
        }
 public AnonymousClassScript (EcmaScript.NET.ICallable callable, EcmaScript.NET.IScriptable thisObj, object [] args, SecurityController enclosingInstance)
 {
     InitBlock (callable, thisObj, args, enclosingInstance);
 }
Exemple #8
0
 public DefaultScript(EcmaScript e)
 {
     state = e.State;
     e.CreateVariable("include", EcmaValue.Object(new NativeFunctionInstance(1, state, Include)));
 }