// GET: UEditor public ContentResult Handle(string action) { UploadConfig config = null; IUEditorHandle handle = null; action = Request["action"]; switch (action) { case "config": handle = new ConfigHandler(); break; case "uploadimage": config = new UploadConfig() { AllowExtensions = UEConfig.GetStringList("imageAllowFiles"), PathFormat = UEConfig.GetString("imagePathFormat"), SizeLimit = UEConfig.GetInt("imageMaxSize"), UploadFieldName = UEConfig.GetString("imageFieldName") }; handle = new UploadHandle(config); break; case "uploadtemplateimage": default: handle = new NotSupportedHandler(); break; } var result = handle.Process(); var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(result); return(Content(jsonString)); }
public override void Process() { try { Start = ((!string.IsNullOrEmpty(base.Request["start"])) ? Convert.ToInt32(base.Request["start"]) : 0); Size = (string.IsNullOrEmpty(base.Request["size"]) ? UEConfig.GetInt("imageManagerListSize") : Convert.ToInt32(base.Request["size"])); } catch (FormatException) { State = ResultState.InvalidParam; WriteResult(); return; } List <string> list = new List <string>(); try { string localPath = base.Server.MapPath(PathToList); list.AddRange(from x in Directory.GetFiles(localPath, "*", SearchOption.AllDirectories) where SearchExtensions.Contains(Path.GetExtension(x).ToLower()) select PathToList + x.Substring(localPath.Length).Replace("\\", "/")); Total = list.Count; FileList = (from x in list orderby x select x).Skip(Start).Take(Size).ToArray(); } catch (UnauthorizedAccessException) { State = ResultState.AuthorizError; } catch (DirectoryNotFoundException) { State = ResultState.PathNotFound; } catch (IOException) { State = ResultState.IOError; } finally { WriteResult(); } }
public override void Process() { try { this.Start = string.IsNullOrEmpty(this.Request["start"]) ? 0 : Convert.ToInt32(this.Request["start"]); this.Size = string.IsNullOrEmpty(this.Request["size"]) ? UEConfig.GetInt("imageManagerListSize") : Convert.ToInt32(this.Request["size"]); } catch (FormatException ex) { this.State = UEListFileManager.ResultState.InvalidParam; this.WriteResult(); return; } List <string> source = new List <string>(); try { string localPath = this.Server.MapPath(this.PathToList); source.AddRange(((IEnumerable <string>)Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)).Where <string>((Func <string, bool>)(x => ((IEnumerable <string>) this.SearchExtensions).Contains <string>(Path.GetExtension(x).ToLower()))).Select <string, string>((Func <string, string>)(x => this.PathToList + x.Substring(localPath.Length).Replace("\\", "/")))); this.Total = source.Count; this.FileList = source.OrderBy <string, string>((Func <string, string>)(x => x)).Skip <string>(this.Start).Take <string>(this.Size).ToArray <string>(); } catch (UnauthorizedAccessException ex) { this.State = UEListFileManager.ResultState.AuthorizError; } catch (DirectoryNotFoundException ex) { this.State = UEListFileManager.ResultState.PathNotFound; } catch (IOException ex) { this.State = UEListFileManager.ResultState.IOError; } finally { this.WriteResult(); } }