コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            DTOFileUploadResult  result   = new DTOFileUploadResult();
            GenericResponseModel response = new GenericResponseModel();
            string extension = string.Empty;
            Dictionary <string, DTOFileUploadResult> dict = new Dictionary <string, DTOFileUploadResult>();

            if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE))
            {
                dict = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE);
            }
            try
            {
                HttpPostedFile file = ParseFile(context);
                if (file != null)
                {
                    extension = System.IO.Path.GetExtension(file.FileName);
                }
                if (file != null)
                {
                    if (!(dict.ContainsKey(file.FileName)))
                    {
                        // switch tipo upload
                        result = ParseMail(file);
                        dict.Add(file.FileName, result);
                        if (result.errormessage != "Upload non riuscito.")
                        {
                            // salvo in sessione
                            SessionManager <Dictionary <string, DTOFileUploadResult> > .set(SessionKeys.DTO_FILE, dict);

                            response.FileName = file.FileName;
                            response.success  = "true";
                        }
                    }
                }
            }
            catch (ManagedException mex)
            {
                _log.Error(mex);
                result.success      = false;
                result.errormessage = mex.Message;
            }
            catch (System.Web.HttpException wex)
            {
                ErrorLogInfo error = new ErrorLogInfo();
                error.freeTextDetails = wex.Message;
                error.logCode         = "ERR771";
                error.loggingAppCode  = "PEC";
                error.loggingTime     = System.DateTime.Now;
                error.uniqueLogID     = System.DateTime.Now.Ticks.ToString();
                _log.Error(error);
                result.success      = false;
                result.errormessage = wex.Message;
            }
            finally
            {
                context.Response.Write(JsonResult(response));
                context.ApplicationInstance.CompleteRequest();
            }
        }
コード例 #2
0
        private DTOFileUploadResult ParseMail(HttpPostedFile file)
        {
            byte[] btotal           = ReadFully(file.InputStream);
            DTOFileUploadResult dto = new DTOFileUploadResult();
            string Extension        = System.IO.Path.GetExtension(file.FileName);

            string[] args = Extension.Split('.');
            dto.Extension = args[1];
            dto.FileName  = file.FileName;
            if (btotal.Length > 0)
            {
                dto.CustomData   = btotal;
                dto.success      = true;
                dto.errormessage = string.Empty;
            }
            return(dto);
        }