Exemplo n.º 1
0
        public void ParseOpenGISText(string _wellKnownText)
        {
            string wkt = _wellKnownText.Trim();

            if (wkt.StartsWith("Point", StringComparison.InvariantCultureIgnoreCase))
            {
                int start = wkt.IndexOf("(");
                int end   = wkt.IndexOf(")");

                string inner = wkt.Substring(start + 1, end - (start + 1));

                string[] parts = inner.Split(" ".ToCharArray());

                if (parts.Length == 2)
                {
                    X = Convert.ToDouble(parts[0]);
                    Y = Convert.ToDouble(parts[1]);
                }
                else
                {
                    TraceFileHelper.Warning(string.Format("Invalid Point Definition - {0}", wkt));
                    throw new Exception("Invalid Point definition");
                }
            }
            else
            {
                TraceFileHelper.Warning(string.Format("Not a point - {0}", wkt));
                throw new Exception("Not a point");
            }
        }
Exemplo n.º 2
0
        protected override void ApplicationStartup(TinyIoCContainer _container, IPipelines _pipelines)
        {
            base.ApplicationStartup(_container, _pipelines);
            m_ApiToken = Config.GetSettingValue("ApiAccessKey", null);

            Trace.Listeners.Add(new LogglyTraceListener());

            _pipelines.BeforeRequest.AddItemToStartOfPipeline(_context =>
            {
                //Validate the API Token
                string apiToken = _context.Request.Headers["ApiAccessKey"].FirstOrDefault();

                if (apiToken != null &&
                    apiToken.Equals(m_ApiToken))
                {
                    return(null);
                }

                TraceFileHelper.Warning("Missing or invalid api access key");
                return(new Response()
                {
                    StatusCode = HttpStatusCode.BadRequest
                });
            });

            _pipelines.OnError.AddItemToStartOfPipeline((context, exception) =>
            {
                TraceFileHelper.Exception(exception);
                return(Response.NoBody);
            });
        }
Exemplo n.º 3
0
        public void ParseOpenGISText(string _wellKnownText)
        {
            string wkt = _wellKnownText.Trim();

            const string MP_REGEX    = @"MULTIPOINT \((?<Points>.+)\)";
            const string POINT_REGEX = @"(?<Point>\(.+?\))";
            const string XY_REGEX    = @"\((?<X>.+?) (?<Y>.+)\)";

            Match pointsMatch = Regex.Match(_wellKnownText, MP_REGEX);

            if (pointsMatch != null)
            {
                string points = pointsMatch.Groups["Points"].Value;

                MatchCollection mc = Regex.Matches(points, POINT_REGEX);

                if (mc != null &&
                    mc.Count > 0)
                {
                    foreach (Match pointMatch in mc)
                    {
                        string point = pointMatch.Groups[""].Value;

                        Match xyMatch = Regex.Match(point, XY_REGEX);

                        if (xyMatch != null)
                        {
                            double x = Convert.ToDouble(xyMatch.Groups["X"].Value);
                            double y = Convert.ToDouble(xyMatch.Groups["Y"].Value);

                            GeoPoint gp = new GeoPoint(x, y);
                            Add(gp);
                        }
                    }
                }
            }
            else
            {
                TraceFileHelper.Warning(string.Format("Not a point - {0}", wkt));
                throw new Exception("Not a point");
            }
        }
Exemplo n.º 4
0
        public void ParseOpenGISText(string _wellKnownText)
        {
            string wkt = _wellKnownText.Trim();

            if (wkt.StartsWith("LineString", StringComparison.InvariantCultureIgnoreCase))
            {
                int start = wkt.IndexOf("(");
                int end   = wkt.IndexOf(")");

                string inner = wkt.Substring(start + 1, end - (start + 1));

                string[] points = inner.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                foreach (string point in points)
                {
                    string[] parts = point.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    if (parts.Length == 2)
                    {
                        GeoPoint gp = new GeoPoint
                        {
                            X = Convert.ToDouble(parts[0]),
                            Y = Convert.ToDouble(parts[1])
                        };

                        Points.Add(gp);
                    }
                    else
                    {
                        TraceFileHelper.Warning(string.Format("Invalid Point Definition - {0}", wkt));
                        throw new Exception("Invalid Line definition");
                    }
                }
            }
            else
            {
                TraceFileHelper.Warning(string.Format("Not a line - {0}", wkt));
                throw new Exception("Not a line");
            }
        }
Exemplo n.º 5
0
        public bool SendCannedEmail(TGUser _tgUser,
                                    string _cannedEmailName,
                                    NameValueCollection _additionParameters)
        {
            try
            {
                CannedEmail cannedEmail = GetCannedEmail(_cannedEmailName);

                if (cannedEmail != null)
                {
                    SystemEmail email = new SystemEmail(cannedEmail.Guid);

                    TGSerializedObject tgso = _tgUser.GetTGSerializedObject();
                    foreach (string key in _additionParameters.Keys)
                    {
                        string value = _additionParameters.Get(key);
                        tgso.Add(key, value);
                    }

                    CannedEmailHelper.PopulateEmail(cannedEmail, email, tgso);

                    SESHelper.SendMessage(email);
                    Persist(email);

                    return(true);
                }

                TraceFileHelper.Warning("Canned email not found");
            }
            catch (Exception ex)
            {
                TraceFileHelper.Exception(ex);
            }

            return(false);
        }
Exemplo n.º 6
0
        public BaseResponse ResetPassword(DynamicDictionary _parameters)
        {
            BaseResponse response = new BaseResponse();

            string json = Request.Body.ReadAsString();

            if (json != null)
            {
                ResetPassword rr = JsonConvert.DeserializeObject <ResetPassword>(json);
                if (rr.Email != null &&
                    rr.InstallId != null &&
                    rr.Code != null &&
                    rr.NewPassword != null)
                {
                    HydrantWikiManager manager = new HydrantWikiManager();
                    User user = manager.GetUserByEmail(UserSources.HydrantWiki, rr.Email);
                    if (user != null)
                    {
                        DateTime      now = DateTime.UtcNow;
                        PasswordReset pr  = manager.GetPasswordReset(user.Guid, rr.Code);

                        if (pr != null)
                        {
                            if (pr.CreationDateTime > now.AddHours(-2))
                            {
                                TGUserPassword userPassword = TGUserPassword.GetNew(
                                    user.Guid,
                                    user.Username,
                                    rr.NewPassword);
                                manager.Persist(userPassword);

                                pr.Active = false;
                                manager.Persist(pr);

                                manager.LogInfo(user.Guid, "Password successfully reset");

                                response.Success = true;
                                response.Message = "Password successfully reset.";
                            }
                            else
                            {
                                manager.LogWarning(user.Guid, "Password Reset request has expired");
                                response.Success = false;
                                response.Message = "Password Reset request has expired";
                            }
                        }
                        else
                        {
                            manager.LogWarning(user.Guid, "Invalid reset code");
                            response.Success = false;
                            response.Message = "Invalid reset code.";
                        }
                    }
                    else
                    {
                        TraceFileHelper.Warning("User not found ({0})", rr.Email);
                        response.Success = false;
                        response.Message = "User not found.";
                    }
                }
                else
                {
                    response.Message = "Invalid information supplied";
                }
            }
            else
            {
                response.Message = "Body not supplied";
            }

            return(response);
        }
Exemplo n.º 7
0
        private void LogUnauthorized(Request _request)
        {
            string username = _request.Headers["Username"].First();

            TraceFileHelper.Warning("{0} - {1} ({2})", _request.UserHostAddress, _request.Url, username);
        }
Exemplo n.º 8
0
        public static LoginResult Authorize(OpenFormGraphManager _manager,
                                            string _username, string _password, out TGUser _user)
        {
            LoginResult result = new LoginResult();

            _user = _manager.GetUser(_username);

            if (_user != null)
            {
                if (_user.Active)
                {
                    if (_manager.ValidateUser(_user, _password))
                    {
                        string token = _manager.GetAuthorizationToken(_user.Guid, _password);

                        result.Result    = "Success";
                        result.AuthToken = token;
                        result.Username  = _username;

                        if (_manager.HasUserRole(_user.Guid, UserRoles.UserAdmin))
                        {
                            result.IsUserAdmin = true;
                        }
                        else
                        {
                            result.IsUserAdmin = false;
                        }

                        if (_manager.HasUserRole(_user.Guid, UserRoles.DataAdmin))
                        {
                            result.IsDataAdmin = true;
                        }
                        else
                        {
                            result.IsDataAdmin = false;
                        }
                    }
                    else
                    {
                        //Bad password or username
                        TraceFileHelper.Warning("User not found");
                        _user = null;

                        result.Result = "BadUserOrPassword";
                    }
                }
                else
                {
                    //user not active
                    //Todo - Log Something
                    TraceFileHelper.Warning("User Not Active");
                    _user = null;

                    result.Result = "NotActive";
                }
            }
            else
            {
                //User not found
                TraceFileHelper.Warning("User not found");
                result.Result = "BadUserOrPassword";
            }

            return(result);
        }
Exemplo n.º 9
0
 public void LogWarning(Guid _userGuid, string _message)
 {
     TraceFileHelper.Warning(_message + "|UserGuid - {0}", _userGuid);
 }