Exemple #1
0
        public AjaxResult DoProcess(AjaxReceive receive)
        {
            AjaxResult result = new AjaxResult {
                IsSuccess = true
            };

            try
            {
                if (string.IsNullOrEmpty(receive.ClassName) || string.IsNullOrEmpty(receive.MethodName))
                {
                    throw AjaxException.ToException(ErrorCode.PErrorCode, "参数解析出错!");
                }
                AjaxMethod method = AjaxServer.GetAjaxMethod(receive.FullClassName, receive.MethodName);
                result.Method = method;
                ParameterInfo[] parameters = method.MethodInfo.GetParameters();
                object[]        objArray   = Ajaxhelper.ParseParams(receive.Data, parameters);
                object          r          = method.MethodInfo.Invoke(AjaxServer.GetInstance(method.FullClassName), objArray);
                if (r != null)
                {
                    result.Data   = r;
                    result.Result = Ajaxhelper.ToJson(r);
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                HandleException(ex, result);
            }
            finally
            {
                receive.Clear();
            }
            result.FillResponseText();
            return(result);
        }
Exemple #2
0
        public UserResult Login(string userID, string password)
        {
            UserResult result  = null;
            string     pwd     = SafeHelper.EncryptDES(password, userID);
            bool       isExist = SqlHelper.Exists <HrEmploy>(H => H.UserID == userID && H.PassWord == pwd);

            if (!isExist)
            {
                throw AjaxException.ToException(ErrorCode.VErrorCode, "用户名或密码错误!");
            }
            Core.Server.ISessionServer sessionServer = SessionFactory.GetSessionServer();
            sessionServer.RegSession(userID, password);
            HrEmploy userInfo = (DbFactory.DbSession.DbContext as CrmEntities).HrEmploy.FirstOrDefault(H => H.UserID == userID && H.PassWord == pwd);
            int      timeOut  = sessionServer.Timeout;
            DateTime expires  = DateTime.Now;

            expires = expires.AddMinutes(timeOut);
            if (userInfo != null)
            {
                result = new UserResult
                {
                    id      = userInfo.UserID,
                    User    = userInfo.ToAjaxResult(),
                    Expires = expires
                };
            }

            return(result);
        }
Exemple #3
0
 /// <summary>
 /// 解析参数
 /// </summary>
 /// <param name="jsonStr"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public static object[] ParseParams(string jsonStr, ParameterInfo[] parameters)
 {
     if (parameters != null && parameters.Length > 0)
     {
         JsonSerializerSettings settings = new JsonSerializerSettings();
         foreach (JsonConverter converter in Ajaxhelper.converters)
         {
             settings.Converters.Add(converter);
         }
         JsonSerializer serializer = JsonSerializer.Create(settings);
         int            index      = 0;
         object[]       obj        = new object[parameters.Length];
         JsonReader     reader     = new JsonTextReader(new StringReader(jsonStr));
         if (reader.Read() && (reader.TokenType == JsonToken.StartObject))
         {
             while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
             {
                 reader.Read();
                 if (index >= parameters.Length)
                 {
                     throw AjaxException.ToException(ErrorCode.PErrorCode, "参数解析出错!");
                 }
                 obj[index] = serializer.Deserialize(reader, parameters[index].ParameterType);
                 index++;
             }
         }
         return(obj);
     }
     return(null);
 }
Exemple #4
0
        /// <summary>
        /// 获取类的实例
        /// </summary>
        /// <param name="fullClassName">类的完全限定名称</param>
        public static object GetInstance(string fullClassName)
        {
            Type type = Type.GetType(fullClassName);

            if (type == null)
            {
                throw AjaxException.ToException(ErrorCode.PErrorCode, "无效的类方法[{0}]", fullClassName);
            }
            object instance = Activator.CreateInstance(type);

            return(instance);
        }
Exemple #5
0
            public AjaxException(System.Exception exception)
            {
                // Recursion is bad - create own LIFO-structure and loop
                System.Collections.Generic.Stack <System.Exception> stack =
                    new System.Collections.Generic.Stack <System.Exception>();
                System.Exception ex = exception;
                ;
                while (ex != null)
                {
                    stack.Push(ex);
                    ex = ex.InnerException;
                } // Whend


                AjaxException thisException = this;

                while (stack.Count > 0)
                {
                    ex = stack.Pop();
                    thisException.Message = ex.Message;
                    thisException.Stack   = ex.StackTrace;

                    this.Source   = ex.Source;
                    this.HResult  = ex.HResult;
                    this.HelpLink = ex.HelpLink;


                    System.Type t = ex.GetType();
                    this.ShortType = t.Name;
                    this.LongType  = t.AssemblyQualifiedName;

                    this.Data = ex.Data;


                    if (stack.Count > 0)
                    {
                        thisException.Error = new AjaxException();
                        thisException       = thisException.Error;
                    } // End if (stack.Count > 0)
                }     // Whend
            }         // End Constructor
Exemple #6
0
        /// <summary>
        /// 获取请求的Ajax 的方法的信息
        /// </summary>
        /// <param name="className"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public static AjaxMethod GetAjaxMethod(string className, string methodName)
        {
            string key = string.Format("{0}.{1}", className, methodName);

            if (!methodList.Contains(key))
            {
                lock (lockObject)
                {
                    AjaxMethod method = new AjaxMethod();
                    Type       type   = Type.GetType(className);
                    if (type == null)
                    {
                        throw AjaxException.ToException(ErrorCode.PErrorCode, "无效的类方法[{0}]", className);
                    }
                    method.MethodInfo = Ajaxhelper.GetMethodInfo(type, methodName);
                    SetAjaxMethod(method, method.MethodInfo);
                    methodList.Add(key, method);
                }
            }
            return((AjaxMethod)methodList[key]);
        }
Exemple #7
0
        /// <summary>
        /// 根据SessionID获取session中存储的数据
        /// </summary>
        /// <param name="sessionID"></param>
        /// <returns></returns>
        public SessionMode GetSessionMode(string sessionID)
        {
            SessionMode mode = null;

            if (this.sessions.ContainsKey(sessionID))
            {
                mode = this.sessions[sessionID] as SessionMode;
            }
            else if (HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                var r = HttpContext.Current.Session[sessionID];
                if (r != null)
                {
                    mode = (r as SessionMode);
                }
            }
            if (mode == null)
            {
                throw AjaxException.ToException(ErrorCode.SErrorCode, "您的会话已超时, 请重新登录本系统.");
            }
            return(mode);
        }