コード例 #1
0
        public ProxyTestableViewModel()
        {
            TestProxy = AsyncCommand.Create((parameter, token) =>
            {
                Url url    = new Url(parameter as string ?? "");
                TestResult = new SiteTestResultViewModel()
                {
                    Model = new SiteProxyTestResult(HttpStatusCode.Gone, "", -1, SiteProxyTestStatus.Testing)
                };
                return(SiteProxyTester.RunTest(m_model, url, token));
            });

            TestProxy.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Execution")
                {
                    if (m_testProxyExecution != null)
                    {
                        m_testProxyExecution.PropertyChanged -= TaskCompletionNotifierPropertyChangedHandler;
                    }

                    m_testProxyExecution = TestProxy.Execution;

                    m_testProxyExecution.PropertyChanged += TaskCompletionNotifierPropertyChangedHandler;
                }
            };

            GetLocation = AsyncCommand.Create((parameter, token) =>
            {
                Location = "pending...";
                return(IpGeolocation.GetLocation(m_model, token));
            });

            GetLocation.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Execution")
                {
                    if (m_getLocationExecution != null)
                    {
                        m_getLocationExecution.PropertyChanged -=
                            GetLocationTaskCompletionNotifierPropertyChangedHandler;
                    }
                }

                m_getLocationExecution = GetLocation.Execution;

                m_getLocationExecution.PropertyChanged += GetLocationTaskCompletionNotifierPropertyChangedHandler;
            };
        }
コード例 #2
0
        public static BranchSession Create(string ipAddress, string userAgent, BranchIdentity branchIdentity, bool rememberMe)
        {
            var modernAgent = new ModernAgent(userAgent);

            var session = new BranchSession
            {
                Revoked        = false,
                Ip             = ipAddress,
                Identifier     = Guid.NewGuid(),
                Browser        = modernAgent.Browser(),
                Platform       = modernAgent.OperatingSystem(),
                UserAgent      = userAgent,
                BranchIdentity = branchIdentity,
                ExpiresAt      = rememberMe ? DateTime.UtcNow.AddYears(1) : DateTime.UtcNow.AddDays(1)
            };

            if (ipAddress == "127.0.0.1")
            {
                session.FriendlyLocation = "Unknown Location - Developer Session - Running on Local Machine";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
                return(session);
            }

            var g = IpGeolocation.Geolocate(ipAddress);

            if (g.Latitude <= -1336)
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
                return(session);
            }

            var gg = new Geocoding.Google.GoogleGeocoder().ReverseGeocode(g.Latitude, g.Longitude).ToList();

            if (gg.Any())
            {
                var ggg = gg.First();
                session.FriendlyLocation = ggg.FormattedAddress;
                session.GpsLocation      = String.Format("{0},{1}", ggg.Coordinates.Latitude, ggg.Coordinates.Longitude);
            }
            else
            {
                session.FriendlyLocation = "Unknown Location";
                session.GpsLocation      = String.Format("{0},{1}", 0, 0);
            }

            return(session);
        }