Пример #1
0
        private string RejectTag(DynamicDictionary _parameters)
        {
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                if (user != null &&
                    (user.UserType == UserTypes.SuperUser ||
                     user.UserType == UserTypes.Administrator))
                {
                    HydrantWikiManager hwManager = new HydrantWikiManager();

                    string sTagGuid = _parameters["tagGuid"];
                    Guid   tagGuid;

                    if (Guid.TryParse(sTagGuid, out tagGuid))
                    {
                        Tag tag = hwManager.GetTag(tagGuid);

                        if (tag != null)
                        {
                            if (tag.Status == TagStatus.Pending)
                            {
                                tag.Status = TagStatus.Rejected;
                                hwManager.Persist(tag);

                                return(@"{ ""Result"":""Success"" }");
                            }
                        }
                    }
                }
            }

            return(@"{ ""Result"":""Failure"" }");
        }
Пример #2
0
        public string CreateYoTag(DynamicDictionary _parameters)
        {
            string username = Request.Query["username"];
            string location = Request.Query["location"];

            if (username != null &&
                location != null)
            {
                GeoPoint geoPoint       = null;
                string[] locationParams = location.Split(";".ToCharArray());
                if (locationParams.Length > 1)
                {
                    geoPoint = new GeoPoint(Convert.ToDouble(locationParams[1]),
                                            Convert.ToDouble(locationParams[0]));
                }

                if (geoPoint != null)
                {
                    HydrantWikiManager hwm = new HydrantWikiManager();
                    User user = hwm.GetUser(UserSources.Yo, username);

                    if (user == null)
                    {
                        user = new User
                        {
                            UserSource = UserSources.Yo,
                            UserType   = UserTypes.User,
                            Username   = username,
                            Active     = true
                        };

                        hwm.Persist(user);
                    }

                    Tag tag = new Tag
                    {
                        UserGuid           = user.Guid,
                        Status             = TagStatus.Pending,
                        DeviceDateTime     = DateTime.UtcNow,
                        ExternalIdentifier = null,
                        ExternalSource     = null,
                        Position           = geoPoint
                    };

                    hwm.Persist(tag);

                    string url = Config.GetSettingValue("SystemUrl") + string.Format("/rest/yotag/{0}", tag.Guid);

                    YoHelper.SendYo(username, url);
                }
            }

            return("");
        }
Пример #3
0
        private string AcceptTag(DynamicDictionary _parameters)
        {
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                if (user != null &&
                    (user.UserType == UserTypes.SuperUser ||
                     user.UserType == UserTypes.Administrator))
                {
                    HydrantWikiManager hwManager = new HydrantWikiManager();

                    string sTagGuid = _parameters["tagGuid"];
                    Guid   tagGuid;

                    if (Guid.TryParse(sTagGuid, out tagGuid))
                    {
                        Tag tag = hwManager.GetTag(tagGuid);

                        if (tag != null)
                        {
                            if (tag.Status == TagStatus.Pending)
                            {
                                Hydrant hydrant = new Hydrant
                                {
                                    Active                   = true,
                                    CreationDateTime         = tag.DeviceDateTime,
                                    LastModifiedBy           = tag.LastModifiedBy,
                                    LastModifiedDateTime     = tag.LastModifiedDateTime,
                                    LastReviewerUserGuid     = user.Guid,
                                    OriginalReviewerUserGuid = user.Guid,
                                    OriginalTagDateTime      = tag.DeviceDateTime,
                                    OriginalTagUserGuid      = tag.UserGuid,
                                    Position                 = tag.Position,
                                    PrimaryImageGuid         = tag.ImageGuid
                                };

                                hwManager.Persist(hydrant);

                                tag.Status      = TagStatus.Approved;
                                tag.HydrantGuid = hydrant.Guid;
                                hwManager.Persist(tag);

                                return(@"{ ""Result"":""Success"" }");
                            }
                        }
                    }
                }
            }

            return(@"{ ""Result"":""Failure"" }");
        }
Пример #4
0
        private string MatchTagWithHydrant(DynamicDictionary _parameters)
        {
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                if (user != null &&
                    (user.UserType == UserTypes.SuperUser ||
                     user.UserType == UserTypes.Administrator))
                {
                    HydrantWikiManager hwManager = new HydrantWikiManager();

                    string sTagGuid = _parameters["tagGuid"];
                    Guid   tagGuid;

                    if (Guid.TryParse(sTagGuid, out tagGuid))
                    {
                        Tag tag = hwManager.GetTag(tagGuid);

                        if (tag != null)
                        {
                            if (tag.Status == TagStatus.Pending)
                            {
                                string sHydrantGuid = _parameters["hydrantGuid"];
                                Guid   hydrantGuid;

                                if (Guid.TryParse(sHydrantGuid, out hydrantGuid))
                                {
                                    Hydrant hydrant = hwManager.GetHydrant(hydrantGuid);

                                    if (hydrant != null)
                                    {
                                        tag.Status      = TagStatus.Approved;
                                        tag.HydrantGuid = hydrantGuid;
                                        hwManager.Persist(tag);

                                        //TODO - Probably need to reaverage all tag positions and assign back to hydrant
                                        hydrant.LastReviewerUserGuid = user.Guid;
                                        hwManager.Persist(hydrant);

                                        return(@"{ ""Result"":""Success"" }");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(@"{ ""Result"":""Failure"" }");
        }
Пример #5
0
        public YoModule()
        {
            Get["/rest/yotagcallback"] = _parameters =>
            {
                CreateYoTag(_parameters);

                Response response = @"{ ""Result"":""Success"" }";
                response.ContentType = "application/json";
                return(response);
            };

            Get["/rest/yotag/{TagGuid}"] = _parameters =>
            {
                string sGuid = _parameters["TagGuid"];

                Guid tagGuid;

                if (Guid.TryParse(sGuid, out tagGuid))
                {
                    HydrantWikiManager hwm = new HydrantWikiManager();
                    Tag tag = hwm.GetTag(tagGuid);

                    Context.ViewBag.MapBoxMap = Config.GetSettingValue("MapBoxMap");
                    Context.ViewBag.MapBoxKey = Config.GetSettingValue("MapBoxKey");

                    return(View["yotag.sshtml", tag]);
                }

                return(null);
            };

            Post["/rest/yotag/{TagGuid}"] = _parameters =>
            {
                return(null);
            };
        }
Пример #6
0
        private string HandlePost(DynamicDictionary _parameters)
        {
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                HydrantWikiManager hwManager = new HydrantWikiManager();

                string sLatitude       = Request.Form["latitudeInput"];
                string sLongitude      = Request.Form["longitudeInput"];
                string sAccuracy       = Request.Form["accuracyInput"];
                string sDeviceDateTime = Request.Form["positionDateTimeInput"];

                double lat      = 0.0;
                double lon      = 0.0;
                double accuracy = -1;

                DateTime deviceDateTime = DateTime.MinValue;
                GeoPoint geoPoint       = null;

                if (Double.TryParse(sLatitude, out lat))
                {
                    if (Double.TryParse(sLongitude, out lon))
                    {
                        //Ignore positions that are 0.0 and 0.0 exactly
                        if (!(lat.Equals(0) &&
                              lon.Equals(0)))
                        {
                            geoPoint = new GeoPoint {
                                X = lon, Y = lat
                            };
                        }
                    }
                }

                Double.TryParse(sAccuracy, out accuracy);
                DateTime.TryParse(sDeviceDateTime, out deviceDateTime);

                //If we got a timestamp that was a zero date, ignore it and use now.
                if (deviceDateTime == DateTime.MinValue)
                {
                    deviceDateTime = DateTime.UtcNow;
                }

                //We will accept a tag without a photo, but not one without a position.
                if (geoPoint != null)
                {
                    Tag tag = new Tag
                    {
                        Active               = true,
                        DeviceDateTime       = deviceDateTime,
                        LastModifiedDateTime = DateTime.UtcNow,
                        UserGuid             = user.Guid,
                        VersionTimeStamp     = DateTime.UtcNow.ToString("u"),
                        Position             = geoPoint,
                        Status               = TagStatus.Pending
                    };

                    if (Request.Files.Any())
                    {
                        tag.ImageGuid = Guid.NewGuid();
                    }
                    else
                    {
                        tag.ImageGuid = null;
                    }

                    try
                    {
                        hwManager.Persist(tag);
                        hwManager.LogVerbose(user.Guid, "Tag Saved");

                        if (tag.ImageGuid != null)
                        {
                            HttpFile file = Request.Files.First();

                            long fileSize = file.Value.Length;

                            try
                            {
                                byte[] data = new byte[fileSize];

                                file.Value.Read(data, 0, (int)fileSize);

                                hwManager.PersistOriginal(tag.ImageGuid.Value, ".jpg", "image/jpg", data);
                                hwManager.LogVerbose(user.Guid, "Tag Image Saved");

                                Image original = ImageHelper.GetImage(data);

                                data = ImageHelper.GetThumbnailBytesOfMaxSize(original, 800);
                                hwManager.PersistWebImage(tag.ImageGuid.Value, ".jpg", "image/jpg", data);

                                data = ImageHelper.GetThumbnailBytesOfMaxSize(original, 100);
                                hwManager.PersistThumbnailImage(tag.ImageGuid.Value, ".jpg", "image/jpg", data);
                            }
                            catch (Exception ex)
                            {
                                hwManager.LogException(user.Guid, ex);
                            }
                        }

                        return(@"{ ""Result"":""Success"" }");
                    }
                    catch (Exception ex)
                    {
                        hwManager.LogException(user.Guid, ex);
                    }
                }
                else
                {
                    //No position
                    hwManager.LogWarning(user.Guid, "No position");

                    return(@"{ ""Result"":""Failure - No position"" }");
                }
            }

            return(@"{ ""Result"":""Failure"" }");
        }
Пример #7
0
        public BaseResponse HandleRejectTag(DynamicDictionary _parameters)
        {
            User               user;
            string             message = null;
            HydrantWikiManager hwm     = new HydrantWikiManager();

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                if (user.UserType == UserTypes.SuperUser ||
                    user.UserType == UserTypes.Administrator)
                {
                    Guid?tagId = _parameters["tagid"];

                    if (tagId != null)
                    {
                        Tag tag = hwm.GetTag(tagId.Value);

                        if (tag != null)
                        {
                            //Set the tag to approved
                            tag.Status = TagStatus.Rejected;
                            hwm.Persist(tag);

                            //Update the stats
                            Guid      userGuid = tag.UserGuid;
                            UserStats stats    = hwm.GetUserStats(userGuid);
                            if (stats == null)
                            {
                                stats             = new UserStats();
                                stats.UserGuid    = userGuid;
                                stats.DisplayName = user.DisplayName;
                                stats.Active      = true;
                            }
                            stats.RejectedTagCount++;
                            hwm.Persist(stats);

                            hwm.LogInfo(user.Guid, string.Format("Tag Rejected ({0})", tagId));

                            return(new ReviewTagResponse {
                                Success = true
                            });
                        }
                        else
                        {
                            message = "Tag not found";
                        }
                    }
                    else
                    {
                        message = "TagId not specified";
                    }
                }

                hwm.LogWarning(user.Guid, string.Format("Tag Reject Error ({0})", message));
            }
            else
            {
                LogUnauthorized(Request);
            }

            return(new ReviewTagResponse {
                Success = false, Message = message
            });
        }
Пример #8
0
        public BaseResponse HandleApproveTag(DynamicDictionary _parameters)
        {
            User               user;
            string             message = null;
            HydrantWikiManager hwm     = new HydrantWikiManager();

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                if (user.UserType == UserTypes.SuperUser ||
                    user.UserType == UserTypes.Administrator)
                {
                    Guid?tagId = _parameters["tagid"];

                    if (tagId != null)
                    {
                        Tag tag = hwm.GetTag(tagId.Value);

                        if (tag != null)
                        {
                            if (tag.Status == TagStatus.Pending)
                            {
                                //Create hydrant
                                Hydrant hydrant = new Hydrant
                                {
                                    Guid                     = Guid.NewGuid(),
                                    Active                   = true,
                                    CreationDateTime         = tag.DeviceDateTime,
                                    LastModifiedBy           = tag.LastModifiedBy,
                                    LastModifiedDateTime     = tag.LastModifiedDateTime,
                                    LastReviewerUserGuid     = user.Guid,
                                    OriginalReviewerUserGuid = user.Guid,
                                    OriginalTagDateTime      = tag.DeviceDateTime,
                                    OriginalTagUserGuid      = tag.UserGuid,
                                    Position                 = tag.Position,
                                    PrimaryImageGuid         = tag.ImageGuid
                                };
                                hwm.Persist(hydrant);

                                //Set the tag to approved
                                tag.Status = TagStatus.Approved;
                                hwm.Persist(tag);

                                //Update the stats
                                Guid      userGuid = tag.UserGuid;
                                UserStats stats    = hwm.GetUserStats(userGuid);
                                if (stats == null)
                                {
                                    stats             = new UserStats();
                                    stats.UserGuid    = userGuid;
                                    stats.DisplayName = user.DisplayName;
                                    stats.Active      = true;
                                }
                                stats.ApprovedTagCount++;
                                hwm.Persist(stats);

                                hwm.LogInfo(user.Guid, string.Format("Tag Approved ({0})", tagId));

                                return(new ReviewTagResponse {
                                    Success = true
                                });
                            }
                            else
                            {
                                message = "Tag already reviewed";
                            }
                        }
                        else
                        {
                            message = "Tag not found";
                        }
                    }
                    else
                    {
                        message = "Tag not specified";
                    }
                }

                hwm.LogWarning(user.Guid, string.Format("Tag Approve Error ({0})", message));
            }
            else
            {
                LogUnauthorized(Request);
            }

            return(new ReviewTagResponse {
                Success = false, Message = message
            });
        }
Пример #9
0
        public HydrantQueryModule()
        {
            Get["/rest/hydrants/csv/{east}/{west}/{north}/{south}"] = _parameters =>
            {
                Response response = GetGeoboxCSVData(_parameters);
                response.ContentType = "text/csv";
                return(response);
            };

            Get["/rest/nearbyhydrants/csv/{latitude}/{longitude}/{distance}"] = _parameters =>
            {
                Response response = GetCenterRadiusCSVData(_parameters);
                response.ContentType = "text/csv";
                return(response);
            };

            Get["/rest/nearbyhydrants/table/{latitude}/{longitude}/{distance}"] = _parameters =>
            {
                Response response = GetCenterRadiusCSVData(_parameters);
                response.ContentType = "application/json";
                return(response);
            };


            Get["/rest/nearbyhydrantsbytag/csv/{guid}"] = _parameters =>
            {
                string sTagGuid = _parameters["guid"];
                Guid   tagGuid;

                if (Guid.TryParse(sTagGuid, out tagGuid))
                {
                    HydrantWikiManager hwm = new HydrantWikiManager();
                    Tag tag = hwm.GetTag(tagGuid);

                    if (tag != null &&
                        tag.Position != null)
                    {
                        Response response = GetCenterRadiusCSVData(tag.Position.Y, tag.Position.X, 200, true);
                        response.ContentType = "text/csv";
                        return(response);
                    }
                }

                return(null);
            };

            Get["/rest/nearbyhydrantsbytag/table/{guid}"] = _parameters =>
            {
                string sTagGuid = _parameters["guid"];
                Guid   tagGuid;

                if (Guid.TryParse(sTagGuid, out tagGuid))
                {
                    HydrantWikiManager hwm = new HydrantWikiManager();
                    Tag tag = hwm.GetTag(tagGuid);

                    if (tag != null &&
                        tag.Position != null)
                    {
                        Response response = GetCenterRadiusJsonData(tag.Position.Y, tag.Position.X, 200);
                        response.ContentType = "application/json";
                        return(response);
                    }
                }

                return(null);
            };
        }