private void AnalyzeButton_Click(object sender, RoutedEventArgs e)
 {
     NoPhotos = false;
     if (this.DeviceName.Text.Equals("") || this.DeviceName.Text.Equals("Enter Test Name Here"))
     {
         MessageBox.Show(Properties.Resources.IncorrectName, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Warning);
     }
     else
     {
         RemoveAllPlaceHolders();
         this.result.Name = this.DeviceName.Text;
         if (IsMethodologyFollowed())
         {
             NavigationService navigationService = NavigationService.GetNavigationService(this);
             if (this.result.AllAnalyzed())
             {
                 //Either no change made to result, or a photo was deleted. Save the result and go directly to the Results Page
                 ResultStore.SaveResult(this.result);
                 navigationService.Navigate(new ResultPage(this.result, 1));
             }
             else
             {
                 //Some photos havent been analyzed, so go to ResultDetailPage
                 navigationService.Navigate(new ResultDetailPage(this.result));
             }
         }
         else
         {
             AddAllPlaceHolders();
             MessageBox.Show(Properties.Resources.NoPhotosSelected, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
 private async void DeleteAllButton_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show(Properties.Resources.DeleteTestsConfirmationMessage, Properties.Resources.DeleteMultipleItems, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
     {
         while (this.ResultsListView.Items.Count > 0)
         {
             this.resultBrowserPageItems.RemoveAt(0);
             await Task.Delay(50);
         }
         ResultStore.DeleteAllResults();
         UpdateButtonVisibility();
     }
 }
        private async void DeleteSelectedButton_Click(object sender, RoutedEventArgs e)
        {
            while (this.ResultsListView.SelectedItems.Count > 0)
            {
                int selectedIndex = this.ResultsListView.SelectedIndex;

                List <Result> resultList = ResultStore.GetResultList();
                if (selectedIndex < resultList.Count)
                {
                    Result result = resultList.ElementAt(selectedIndex);
                    this.resultBrowserPageItems.RemoveAt(selectedIndex);
                    ResultStore.DeleteResult(result);
                    await Task.Delay(50);
                }
            }
            UpdateButtonVisibility();
        }
        private void EditTestButton_Click(object sender, RoutedEventArgs e)
        {
            int           selectedIndex = this.ResultsListView.SelectedIndex;
            List <Result> resultList    = ResultStore.GetResultList();

            if (selectedIndex >= 0 && selectedIndex < resultList.Count)
            {
                Result result = resultList.ElementAt(selectedIndex);
                if (result != null && File.Exists(result.FilePath))
                {
                    NavigationService navigationService = NavigationService.GetNavigationService(this);
                    navigationService.Navigate(new SelectPhotosPage(result));
                }
                else
                {
                    MessageBox.Show(Properties.Resources.ResultDoesntExistError, Properties.Resources.ResultDeletedError);
                    DisplayResults();
                }
            }
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (!this.result.AllAnalyzed())
            {
                this.photoAnalyzerCancellationTokenSource = new CancellationTokenSource();

                bool success = await Analyze(this.categoryListViewItems, this.deviceName, this.photoAnalyzerCancellationTokenSource.Token);

                NavigationService navigationService = NavigationService.GetNavigationService(this);
                if (success)
                {
                    navigationService.Navigate(new ResultPage(this.result, 2));
                    ResultStore.SaveResult(this.result);
                }
                else
                {
                    navigationService.GoBack();
                }
            }
        }
        private void DisplayResults()
        {
            List <Result> resultList = ResultStore.GetResultList();

            this.resultBrowserPageItems = new ObservableCollection <ResultBrowserPageItem>();
            foreach (Result result in resultList)
            {
                ResultBrowserPageItem resultDetailPageItem = new ResultBrowserPageItem();

                //Get Name
                resultDetailPageItem.Name = result.Name;

                //Get Photo Count
                resultDetailPageItem.PhotoCount = result.PhotoCount();

                //Get MOS
                FeatureDetail overallMOSDetail = result.GetOverallMOS();
                resultDetailPageItem.OverallMOS = double.IsNaN(overallMOSDetail.Value)? Properties.Resources.NA : overallMOSDetail.Value.ToString("0.0");

                //Get Category MOS
                foreach (Category category in result.outputCategoryList)
                {
                    resultDetailPageItem.CategoryMOSList.Add(category.MOSValue);
                }

                resultBrowserPageItems.Add(resultDetailPageItem);
            }
            this.ResultsListView.DataContext = resultBrowserPageItems;

            //Update Header
            if (resultList != null && resultList.Count > 0)
            {
                ObservableCollection <string> resultsHeaderItems = new ObservableCollection <string>();
                foreach (Category category in resultList[0].outputCategoryList)
                {
                    resultsHeaderItems.Add(category.Name);
                }
                this.ResultsHeaderListView.DataContext = resultsHeaderItems;
            }
        }