Esempio n. 1
0
 protected void SetResponseWithFileData(string filePath, ulong avatarTimeStamp, uint requiredDimension)
 {
     byte[] fileBinary = MediaUtility.ResizeImage(filePath, Convert.ToInt32(requiredDimension), Convert.ToInt32(requiredDimension));
     _httpContext.Response.ClearContent();
     _httpContext.Response.ClearHeaders();
     _httpContext.Response.AppendHeader("ts", avatarTimeStamp.ToString());
     _httpContext.Response.Buffer      = true;
     _httpContext.Response.ContentType = "image/jpeg";
     _httpContext.Response.BinaryWrite(fileBinary);
     _httpContext.Response.Flush();
     _httpContext.Response.End();
 }
Esempio n. 2
0
        public async Task <HttpResponseMessage> Get([FromUri] AvatarRequest avatarRequest)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request"));
            }
            try
            {
                return(await Task <HttpResponseMessage> .Factory.StartNew(() =>
                {
                    NeeoFileInfo fileInfo = null;
                    ulong avatarUpdatedTimeStamp = 0;
                    int dimension = Convert.ToInt32(avatarRequest.Dimension);
                    NeeoUser user = new NeeoUser(avatarRequest.Uid);
                    switch (user.GetAvatarState(avatarRequest.Timestamp, false, out avatarUpdatedTimeStamp, out fileInfo))
                    {
                    case AvatarState.Modified:
                        var response = Request.CreateResponse(HttpStatusCode.OK);
                        response.Headers.Add("ts", avatarUpdatedTimeStamp.ToString());
                        response.Content =
                            new ByteArrayContent(MediaUtility.ResizeImage(fileInfo.FullPath, dimension, dimension));
                        //response.Content = new StreamContent(new FileStream(fileInfo.FullPath,FileMode.Open));
                        response.Content.Headers.ContentType =
                            new MediaTypeHeaderValue(
                                MimeTypeMapping.GetMimeType(fileInfo.Extension).GetDescription());
                        return response;

                    case AvatarState.NotModified:
                        return Request.CreateResponse(HttpStatusCode.NotModified);

                    default:
                        return Request.CreateResponse(HttpStatusCode.BadRequest);
                    }
                }));
            }
            catch (AggregateException aggregateException)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, aggregateException.Message, aggregateException, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
            }
            catch (Exception exception)
            {
                Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
            }
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
        }