예제 #1
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));
        }
예제 #2
0
        public override void BeforeEachTest()
        {
            base.BeforeEachTest();

            avatarRequest = new AvatarRequest(UserId, Resources.SmallImage);
        }