Пример #1
0
        public override void ProcessRequest(HttpContext context)
        {
            YZRequest request = new YZRequest(context);

            try
            {
                string method = request.GetString("Method", "Download");

                if (!YZNameChecker.IsValidMethodName(method))
                {
                    throw new Exception("Invalid method name");
                }

                Type type = this.GetType();
                System.Reflection.MethodInfo methodcall = type.GetMethod(method, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
                if (methodcall == null)
                {
                    throw new Exception(String.Format(Resources.YZStrings.Aspx_UnknowCommand, method));
                }

                try
                {
                    methodcall.Invoke(this, new object[] { context });
                }
                catch (Exception exp)
                {
                    throw exp.InnerException;
                }
            }
            catch (Exception e)
            {
                JObject rv = new JObject();
                rv["success"]      = false;
                rv["errorMessage"] = HttpUtility.HtmlEncode(YZSetting.Debug ? String.Format("{0}.{1}\n{2}", this.GetType().FullName, context.Request.Params["method"], e.Message) : e.Message);
                context.Response.Write(rv.ToString(Formatting.Indented, request.Converters));
            }
        }
Пример #2
0
    public virtual void ProcessRequest(HttpContext context)
    {
        YZAuthHelper.AshxAuthCheck();
        YZRequest request = new YZRequest(context);

        context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
        try
        {
            string method = request.GetString("Method");
            if (!YZNameChecker.IsValidMethodName(method))
            {
                throw new Exception("Invalid method name");
            }
            Type type = this.GetType();
            System.Reflection.MethodInfo methodcall = type.GetMethod(method, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, new Type[] { typeof(HttpContext) }, null);
            if (methodcall == null)
            {
                throw new Exception(String.Format(Resources.YZStrings.Aspx_UnknowCommand, method));
            }
            object rv;
            try
            {
                rv = methodcall.Invoke(this, new object[] { context });
            }
            catch (Exception exp)
            {
                throw exp.InnerException;
            }
            if (rv is JsonItem || rv is JsonItemCollection)
            {
                throw new Exception("JsonItem/JsonItemCollection is Obsoleted, please replace with JObject/JArray");
            }
            JToken jToken;
            if (rv == null)
            {
                jToken = new JObject();
            }
            else if (rv is JToken)
            {
                jToken = rv as JToken;
            }
            else
            {
                if (rv is string)
                {
                    jToken = JValue.FromObject(rv);
                }
                else if (rv is IEnumerable)
                {
                    jToken = JArray.FromObject(rv);
                }
                else
                {
                    jToken = JValue.FromObject(rv);
                }
            }
            jToken["code"] = 0;



            if (context.Request.Params["DateFormat"] == "text")
            {
                context.Response.Write(jToken.ToString(Formatting.Indented));
            }
            else
            {
                context.Response.Write(jToken.ToString(Formatting.Indented, request.Converters));
            }
        }
        catch (Exception e)
        {
            JObject rv = new JObject();
            rv["code"] = -1;
            rv["msg"]  = HttpUtility.HtmlEncode(e.Message);
            context.Response.Write(rv.ToString(Formatting.Indented, request.Converters));
        }
    }
Пример #3
0
    public virtual void ProcessRequest(HttpContext context)
    {
        YZAuthHelper.AshxAccessCheck(context);
        this.AuthCheck(context);

        YZRequest request = new YZRequest(context);

        //模拟仿真信息
        string simulateAuthcookie = request.GetString("stk", null);

        if (!String.IsNullOrEmpty(simulateAuthcookie))
        {
            try
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(simulateAuthcookie);
                this.SimulateAccount = ticket.Name;
                this.Simulate        = true;
            }
            catch
            {
            }
        }

        try
        {
            string method = request.GetString("Method");

            if (!YZNameChecker.IsValidMethodName(method))
            {
                throw new Exception("Invalid method name");
            }

            Type type = this.GetType();
            System.Reflection.MethodInfo methodcall = type.GetMethod(method, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, new Type[] { typeof(HttpContext) }, null);
            if (methodcall == null)
            {
                throw new Exception(String.Format(Resources.YZStrings.Aspx_UnknowCommand, method));
            }

            object rv;
            try
            {
                rv = methodcall.Invoke(this, new object[] { context });
            }
            catch (Exception exp)
            {
                throw exp.InnerException;
            }

            if (rv is JsonItem || rv is JsonItemCollection)
            {
                throw new Exception("JsonItem/JsonItemCollection is Obsoleted, please replace with JObject/JArray");
            }

            JToken jToken;
            if (rv == null)
            {
                jToken            = new JObject();
                jToken["success"] = true;
            }
            else if (rv is JToken)
            {
                jToken = rv as JToken;
            }
            else
            {
                if (rv is string)
                {
                    jToken = JValue.FromObject(rv);
                }
                else if (rv is IEnumerable)
                {
                    jToken = JArray.FromObject(rv);
                }
                else
                {
                    jToken = JValue.FromObject(rv);
                }
            }
            jToken["code"] = 0;
            if (context.Request.Params["DateFormat"] == "text")
            {
                context.Response.Write(jToken.ToString(Formatting.Indented));
            }
            else
            {
                context.Response.Write(jToken.ToString(Formatting.Indented, request.Converters));
            }
        }
        catch (Exception e)
        {
            JObject rv = new JObject();
            rv["code"]    = 1;
            rv["success"] = false;
            rv["msg"]     = HttpUtility.HtmlEncode(YZSetting.Debug ? String.Format("{0}.{1}\n{2}", this.GetType().FullName, context.Request.Params["method"], e.Message) : e.Message);
            context.Response.Write(rv.ToString(Formatting.Indented, request.Converters));
        }
    }
Пример #4
0
        public virtual void ProcessRequest(HttpContext context)
        {
            YZAuthHelper.AshxAccessCheck(context);
            YZAuthHelper.AshxAuthCheck();

            //如果是自己管理语言,需要放出以下2行
            //System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(1033);
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(1033);

            //if (String.Compare(YZAuthHelper.LoginUserAccount, "usera06", true) == 0)
            //{
            //using (FileStream fs = new FileStream("e:\\abc.xml", FileMode.Create, FileAccess.Write))
            //{
            //    byte[] bytes = new byte[context.Request.InputStream.Length];
            //    context.Request.InputStream.Read(bytes, 0, (int)context.Request.InputStream.Length);
            //    fs.Write(bytes, 0, bytes.Length);
            //}
            //context.Request.InputStream.Seek(0, SeekOrigin.Begin);
            //}

            try
            {
                JArray         tables     = new JArray();
                JsonSerializer serializer = new JsonSerializer();
                StreamReader   reader     = new StreamReader(context.Request.InputStream);
                using (JsonTextReader streamReader = new JsonTextReader(reader))
                {
                    JArray requests = serializer.Deserialize(streamReader) as JArray;
                    using (BPMConnection cn = new BPMConnection())
                    {
                        cn.WebOpen();

                        for (int requestIndex = 0; requestIndex < requests.Count; requestIndex++)
                        {
                            JObject request = (JObject)requests[requestIndex];

                            string method = (string)request["Method"];

                            if (!YZNameChecker.IsValidMethodName(method))
                            {
                                throw new Exception("Invalid method name");
                            }

                            Type type = this.GetType();
                            System.Reflection.MethodInfo methodcall = type.GetMethod(method, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
                            if (methodcall == null)
                            {
                                throw new Exception(String.Format(Resources.YZStrings.Aspx_UnknowCommand, method));
                            }

                            try
                            {
                                object mrv = methodcall.Invoke(this, new object[] { cn, request });
                                if (mrv is JObject)
                                {
                                    (mrv as JObject)["Index"] = requestIndex;
                                    tables.Add(mrv);
                                }
                                else
                                {
                                    JArray rvs = mrv as JArray;
                                    foreach (JObject jTable in rvs)
                                    {
                                        jTable["Index"] = requestIndex;
                                        tables.Add(jTable);
                                    }
                                }
                            }
                            catch (Exception exp)
                            {
                                throw exp.InnerException;
                            }
                        }
                    }
                }

                JObject rv = new JObject();
                rv[YZJsonProperty.success] = true;
                rv["Tables"] = tables;
                context.Response.Write(rv.ToString());
            }
            catch (Exception e)
            {
                JObject rv = new JObject();
                rv[YZJsonProperty.success]      = false;
                rv[YZJsonProperty.errorMessage] = HttpUtility.HtmlEncode(e.Message);
                context.Response.Write(rv.ToString(Newtonsoft.Json.Formatting.Indented, YZJsonHelper.Converters));
            }
        }
Пример #5
0
        public override void ProcessRequest(HttpContext context)
        {
            YZRequest request = new YZRequest(context);

            try
            {
                if (!YZAuthHelper.IsAuthenticated)
                {
                    string account     = request.GetString("UploadAuthorAccount", null);
                    string uploadToken = request.GetString("UploadAuthorToken", null);

                    if (!String.IsNullOrEmpty(account) && !String.IsNullOrEmpty(uploadToken))
                    {
                        if (YZSecurityHelper.CheckUploadToken(account, uploadToken))
                        {
                            YZAuthHelper.SetAuthCookie(account);
                        }
                    }
                }

                if (!YZAuthHelper.IsAuthenticated)
                {
                    JObject rv = new JObject();
                    rv["success"]      = false;
                    rv["errorMessage"] = Resources.YZStrings.Aspx_Upload_NoAuth;
                    context.Response.Write(rv.ToString());
                    return;
                }

                HttpFileCollection files = context.Request.Files;
                if (files.Count > 0 && files[0].ContentLength > 0)
                {
                    HttpPostedFile file     = files[0];
                    string         fileName = System.IO.Path.GetFileName(file.FileName);
                    long           fileSize = file.ContentLength;
                    string         fileExt  = System.IO.Path.GetExtension(fileName).ToLower();
                    string         method   = request.GetString("Method", "SaveAttachment");

                    if (!YZNameChecker.IsValidMethodName(method))
                    {
                        throw new Exception("Invalid method name");
                    }

                    Type type = this.GetType();
                    System.Reflection.MethodInfo methodcall = type.GetMethod(method, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
                    if (methodcall == null)
                    {
                        throw new Exception(String.Format(Resources.YZStrings.Aspx_UnknowCommand, method));
                    }

                    object rv;
                    try
                    {
                        rv = methodcall.Invoke(this, new object[] { context, file, fileName, fileSize, fileExt });
                    }
                    catch (Exception exp)
                    {
                        throw exp.InnerException;
                    }

                    JToken jToken;
                    if (rv == null)
                    {
                        jToken            = new JObject();
                        jToken["success"] = true;
                    }
                    else if (rv is JToken)
                    {
                        jToken = rv as JToken;
                    }
                    else
                    {
                        if (rv is string)
                        {
                            jToken = JValue.FromObject(rv);
                        }
                        else if (rv is IEnumerable)
                        {
                            jToken = JArray.FromObject(rv);
                        }
                        else
                        {
                            jToken = JValue.FromObject(rv);
                        }
                    }

                    context.Response.Write(jToken.ToString(Formatting.Indented, request.Converters));
                }
                else
                {
                    JObject rv = new JObject();
                    rv[YZJsonProperty.success]      = false;
                    rv[YZJsonProperty.errorMessage] = Resources.YZStrings.Aspx_Invalid_File;
                    context.Response.Write(rv.ToString(Formatting.Indented, request.Converters));
                }
            }
            catch (Exception exp)
            {
                JObject rv = new JObject();
                rv[YZJsonProperty.success]      = false;
                rv[YZJsonProperty.errorMessage] = HttpUtility.HtmlEncode(exp.Message) /* + exp.StackTrace*/;
                context.Response.Write(rv.ToString(Formatting.Indented, request.Converters));
            }
        }