protected AjaxResult ProcessRequest <TRequest, TResult>(TRequest request) where TRequest : Request
        {
            AjaxResult ajaxResult;
            var        commandLocator = Kernel.ServiceLocator.GetService <ICommandLocator>();
            var        logger         = Kernel.ServiceLocator.GetService <ILogger>();
            BaseCommand <TRequest, TResult> command = null;

            try
            {
                command = commandLocator.FindCommand <TRequest, TResult>();
                var result = command.Execute(request);

                switch (result.ResultType)
                {
                case ResponseTypes.Success:
                    logger.Info("Successfully Processed Request", new { request, result });
                    ajaxResult = new AjaxSuccessfulResult(result);
                    break;

                case ResponseTypes.Error:
                    logger.Error("Error Processing Request", new { request, result });
                    ajaxResult = new AjaxErrorResult("HEY REDO THIS", result);
                    break;

                case ResponseTypes.InvalidRequest:
                    logger.Error("Invalid Request", new { request, result });
                    ajaxResult = new AjaxErrorResult("HEY REDO THIS", result);
                    break;

                case ResponseTypes.Unauthorized:
                    logger.Error("Unauthorized Request", new { request, result });
                    ajaxResult = new AjaxErrorResult("HEY REDO THIS", result);
                    break;

                default:
                    ajaxResult = new AjaxErrorResult("Unknown response type", result);
                    break;
                }
            }
            catch (Exception exception)
            {
                logger.Error("Could not process request", new { request, exception, command });
                ajaxResult = new AjaxErrorResult("Could not process request", new { request, exception });
            }

            return(ajaxResult);
        }
示例#2
0
    public string Uploads()
    {
        HttpFileCollection files = Request.Files;
        AjaxErrorResult    r     = new AjaxErrorResult("error");

        try
        {
            if (files == null)
            {
                return(r.ToString());
            }

            if (files.Count == 0)
            {
                return(r.ToString());
            }

            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFile f               = files[i];
                string         ex              = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1);
                string         str_path        = "/file/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
                string         str_file_name   = Guid.NewGuid().ToString("N") + "." + ex;
                string         str_path_absult = Server.MapPath("~" + str_path);
                if (!System.IO.Directory.Exists(str_path_absult))
                {
                    System.IO.Directory.CreateDirectory(str_path_absult);
                }

                string str_file_url = str_path_absult + str_file_name;

                f.SaveAs(str_file_url);

                return(new AjaxSuccessResult(str_file_url).ToString());
            }

            return(r.ToString());
        }
        catch (Exception ex)
        {
            comm_fun.WriteLog(ex.ToString());
            return(r.ToString());
        }
    }
示例#3
0
    public void PreViewFile()
    {
        List <string> list_image_ex = new List <string>();

        list_image_ex.Add("jpg");
        list_image_ex.Add("png");
        list_image_ex.Add("bmp");
        list_image_ex.Add("jpeg");

        int      FL_ID = Convert.ToInt32(Request["FL_ID"]);
        SYS_FILE f     = db.SYS_FILE.Where(o => o.FL_ID == FL_ID).FirstOrDefault();

        if (string.IsNullOrEmpty(f.FL_ICON_S))
        {
            if (list_image_ex.Contains(f.FL_EXTENSION))
            {
                //1查询图片的绝对路径
                string str_url = Server.MapPath("~" + f.FL_URL);
                //2生成图片的预览路径
                string str_url_new = SmallImageWidth(str_url, 200);
                //3赋值给FL_EXTENSION
                f.FL_ICON_S = str_url_new;
                //返回
                string str_result = new AjaxSuccessResult(str_url_new).ToString();
                Response.Write(str_result);
            }
            else
            {
                string str_result = new AjaxErrorResult("暂时不支持缩略图").ToString();
                Response.Write(str_result);
            }
        }
        else
        {
            string str_result = new AjaxSuccessResult(f.FL_ICON_S).ToString();
            Response.Write(str_result);
        }
    }
示例#4
0
    /// <summary>
    /// 上传一个文件
    /// </summary>
    public void Upload()
    {
        HttpFileCollection files = Request.Files;
        AjaxErrorResult    r     = new AjaxErrorResult("error");

        string str_FD_ID = Request["FD_ID"];
        int    FD_ID     = 0;

        if (!string.IsNullOrEmpty(str_FD_ID))
        {
            FD_ID = Convert.ToInt32(str_FD_ID);
        }
        string BUSINESS_TYPE = Request["BUSINESS_TYPE"];

        if (string.IsNullOrEmpty(BUSINESS_TYPE))
        {
            BUSINESS_TYPE = string.Empty;
        }

        try
        {
            if (files == null)
            {
                Response.Write(r.ToString());
                return;
            }

            if (files.Count == 0)
            {
                Response.Write(r.ToString());
                return;
            }

            HttpPostedFile f             = files[0];
            string         extension     = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1);
            string         str_path_v    = "/file/upload/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
            string         str_file_name = Guid.NewGuid().ToString("N") + "." + extension;
            string         str_path_s    = Server.MapPath("~" + str_path_v);
            //string str_file_old = "";
            //Dim i_index As Int32 = str_file_url_v.LastIndexOf("/")
            //Dim str_file_name As String = comm_fun.convert_string(str_file_url_v.Substring(i_index + 1, str_file_url_v.Length - i_index - 1))

            if (!System.IO.Directory.Exists(str_path_s))
            {
                System.IO.Directory.CreateDirectory(str_path_s);
            }
            string str_file_url_s = str_path_s + str_file_name;
            f.SaveAs(str_file_url_s);
            string str_file_url_v = str_path_v + str_file_name;

            //新增文件表
            SYS_FILE f1 = new SYS_FILE();
            f1.FL_ACTIVE        = true;
            f1.FL_SIZE          = f.ContentLength;
            f1.FL_EXTENSION     = extension;
            f1.FL_NAME          = get_old_filename(f.FileName);
            f1.FL_URL           = str_file_url_v;
            f1.FL_CREATE_DATE   = DateTime.Now;
            f1.FL_FD_ID         = FD_ID;
            f1.FL_BUSINESS_TYPE = BUSINESS_TYPE;

            db.SYS_FILE.Add(f1);
            db.SaveChanges();
            Response.Write(new AjaxSuccessResult(f1.FL_ID.ToString()).ToString());
            return;
        }
        catch (Exception ex)
        {
            comm_fun.WriteLog(ex.ToString());
            Response.Write(r.ToString());
            return;
        }
    }