/// <summary> /// Vrati odpoved v definovanom formate /// </summary> /// <param name="type">Typ odpovede</param> /// <param name="message">Sprava vysvetlujuca odpoved</param> /// <param name="redirectUrl">Url na ktoru sa ma redirectnut stranka</param> /// <param name="data">Data ktore sa odosielaju</param> /// <param name="behavior">JsonRequestBehavior</param> /// <returns>Navratova hodnota pre server</returns> public static JsonResult GetJsonResult(ResponseTypes type, String message, String redirectUrl, Object data, JsonRequestBehavior behavior) { if (type == ResponseTypes.RedirectToAction && String.IsNullOrWhiteSpace(redirectUrl)) { throw new Exception("redirectUrl is null or empty!"); } if (String.IsNullOrWhiteSpace(message) && WebConfiguration.OnResponseMessageDelegate != null) { message = WebConfiguration.OnResponseMessageDelegate(type); } return(WebUtility.Json(new { result = type, message = message, redirectUrl = redirectUrl, data = data }, behavior)); }
/// <summary> /// Spracuje request poziadavku na nacitanie obrazku /// </summary> /// <param name="context">HttpContext</param> public void ProcessRequest(HttpContext context) { String file = context.Request.RawUrl.Replace("/file/", String.Empty); Nullable <Guid> key = file.Replace(".data", String.Empty).ToGuidWithoutDash(); if (key.HasValue) { FileModelBase fileModel = null; if (WebConfiguration.OnFileLoadDelegate != null) { fileModel = WebConfiguration.OnFileLoadDelegate(key.Value); } if (fileModel != null) { context.Response.ContentType = fileModel.ContentType; context.Response.BinaryWrite(fileModel.Data); return; } } context.Response.StatusCode = 404; context.Response.StatusDescription = "File not found !"; context.Response.End(); }
/// <summary> /// Spracuje request poziadavku na nacitanie obrazku /// </summary> /// <param name="context">HttpContext</param> public void ProcessRequest(HttpContext context) { //nazov suboru String baseUrl = context.Request.RawUrl; String file = baseUrl.Replace(WebConfiguration.ImageConfiguration.BasUrl, String.Empty); Nullable <Guid> key = null; Nullable <int> width = null; Nullable <int> height = null; if (this.internalParseImageUrl(ref file, out key, out width, out height)) { //update file name file = !width.HasValue && !height.HasValue ? String.Format("{0}.data", key.Value.ToStringWithoutDash()) : String.Format("{0}_{1}_{2}.data", key.Value.ToStringWithoutDash(), (width.HasValue ? width.Value : 0), (height.HasValue ? height.Value : 0)); //ziskame format obrazku ImageFormat format = this.InternalGetContentType(baseUrl); String directory = context.Server.MapPath(WebImageHandler.m_directoryPath); file = context.Server.MapPath(String.Format("{0}{1}", WebImageHandler.m_directoryPath, file)); WebImage image = null; if (File.Exists(file)) { image = new WebImage(System.IO.File.ReadAllBytes(file), format); } else { if (WebConfiguration.OnImageLoadDelegate != null) { image = WebConfiguration.OnImageLoadDelegate(key.Value, format); if (image != null) { if (width.HasValue) { image.Image = image.Image.CropOrResizeImage(width, height, format); } try { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllBytes(file, image.ImageBlob); } catch (Exception ex) { Debug.WriteLine(ex); } } } } if (image != null) { context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetMaxAge(new TimeSpan(2, 0, 0, 0)); context.Response.ContentType = image.ContentType; context.Response.BinaryWrite(image.ImageBlob); return; } } context.Response.StatusCode = 404; context.Response.StatusDescription = "Image not found !"; }