Example #1
0
        private BaseResponse HandleImagePost(DynamicDictionary _parameters)
        {
            HydrantWikiManager hwManager = new HydrantWikiManager();

            var response = new BaseResponse {
                Success = false
            };
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                try
                {
                    byte[] fileData = null;
                    string fileName = null;

                    if (Request.Files.Any())
                    {
                        HttpFile file = Request.Files.First();

                        long length = file.Value.Length;
                        fileData = new byte[(int)length];
                        file.Value.Read(fileData, 0, (int)length);
                        fileName = file.Name;
                    }

                    if (fileName != null)
                    {
                        string tempGuid = Path.GetFileNameWithoutExtension(fileName);
                        Guid   imageGuid;

                        if (Guid.TryParse(tempGuid, out imageGuid))
                        {
                            hwManager.PersistOriginal(imageGuid, ".jpg", "image/jpg", fileData);
                            hwManager.LogVerbose(user.Guid, "Tag Image Saved");

                            Image original = ImageHelper.GetImage(fileData);

                            fileData = ImageHelper.GetThumbnailBytesOfMaxSize(original, 800);
                            hwManager.PersistWebImage(imageGuid, ".jpg", "image/jpg", fileData);

                            fileData = ImageHelper.GetThumbnailBytesOfMaxSize(original, 100);
                            hwManager.PersistThumbnailImage(imageGuid, ".jpg", "image/jpg", fileData);

                            hwManager.LogInfo(user.Guid, string.Format("Saved Image ({0})", imageGuid));

                            response.Success = true;
                            return(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceFileHelper.Error("Failure to post image");
                    hwManager.LogException(user.Guid, ex);
                }
            }
            else
            {
                LogUnauthorized(Request);
                response.Error   = "Unauthorized";
                response.Message = "Reauthenticate";
            }

            return(response);
        }
Example #2
0
        private BaseResponse HandleTagPost(DynamicDictionary _parameters)
        {
            HydrantWikiManager hwManager = new HydrantWikiManager();

            var response = new TagPostResponse {
                Success = false
            };
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                try
                {
                    string json = Request.Body.ReadAsString();

                    Objects.Tag tag = JsonConvert.DeserializeObject <Objects.Tag>(json);

                    if (tag != null)
                    {
                        if (tag.Position != null)
                        {
                            if (tag.Position != null)
                            {
                                var dbTag = new HydrantWiki.Library.Objects.Tag
                                {
                                    Active               = true,
                                    DeviceDateTime       = tag.Position.DeviceDateTime,
                                    LastModifiedDateTime = DateTime.UtcNow,
                                    UserGuid             = user.Guid,
                                    VersionTimeStamp     = DateTime.UtcNow.ToString("u"),
                                    Position             = new GeoPoint(tag.Position.Longitude, tag.Position.Latitude),
                                    ImageGuid            = tag.ImageGuid,
                                    Status               = TagStatus.Pending
                                };

                                hwManager.Persist(dbTag);
                                hwManager.LogVerbose(user.Guid, "Tag Saved");

                                response.ImageUrl     = dbTag.GetUrl(false);
                                response.ThumbnailUrl = dbTag.GetUrl(true);

                                response.Success = true;
                                return(response);
                            }
                            else
                            {
                                //No position
                                hwManager.LogWarning(user.Guid, "No position");

                                response.Message = "No position";
                                return(response);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceFileHelper.Error("Failure to post tag");
                    hwManager.LogException(user.Guid, ex);
                }
            }
            else
            {
                LogUnauthorized(Request);
                response.Error   = "Unauthorized";
                response.Message = "Reauthenticate";
            }

            return(response);
        }