Пример #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
 private void TaskCompletionNotifierPropertyChangedHandler(object sender, PropertyChangedEventArgs args)
 {
     if (args.PropertyName == "IsCompleted")
     {
         if (TestProxy.Execution.IsCanceled)
         {
             TestResult = null;
         }
         else if (TestProxy.Execution.IsFaulted)
         {
             TestResult = new SiteTestResultViewModel()
             {
                 Model = new SiteProxyTestResult(HttpStatusCode.Gone, $"ERROR({m_testProxyExecution.Exception.Message})", -1, SiteProxyTestStatus.Failed)
             };
         }
         else if (TestProxy.Execution.IsSuccessfullyCompleted)
         {
             TestResult = new SiteTestResultViewModel()
             {
                 Model = TestProxy.Execution.Result
             };
         }
     }
 }