コード例 #1
0
ファイル: MainForm.cs プロジェクト: pepe3197/audipoi
        /// <summary>
        /// Do Work event Handler
        /// </summary>
        /// <param name="sender">Sender Argument</param>
        /// <param name="e">Event Argument</param>
        private void BuildDatabaseBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Tuple <string, string, bool> settings = (Tuple <string, string, bool>)e.Argument;

            if (Directory.Exists(settings.Item1) && File.Exists(this.gpxFilenameTextBox.Text))
            {
                // Load existing POIs
                buildDatabaseBackgroundWorker.ReportProgress(1, "Loading existing POIs");
                Collection <PointOfInterestCategory> currentPois = PointOfInterestDatabase.LoadPois(settings.Item1);

                buildDatabaseBackgroundWorker.ReportProgress(2, "Loading GPX POIs");
                Collection <PointOfInterestCategory> gpxPois = GPX.ProcessGpxFile(this.gpxFilenameTextBox.Text, settings.Item2, settings.Item3);

                buildDatabaseBackgroundWorker.ReportProgress(3, "Merging new POIs");
                Collection <PointOfInterestCategory> pointsOfInterest = PointOfInterestDatabase.MergePointsOfInterest(currentPois, gpxPois);

                buildDatabaseBackgroundWorker.ReportProgress(4, "Building Database");
                int loadedWaypoints = PointOfInterestDatabase.SavePois(pointsOfInterest, settings.Item1, this.buildDatabaseBackgroundWorker);

                e.Result = loadedWaypoints;
            }
            else
            {
                e.Result = -1;
                MessageBox.Show(
                    Resources.FileNotFoundError,
                    Resources.ErrorTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.RightAlign);
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: pepe3197/audipoi
        private void BuildDatabaseBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            CameraSettings settings = (CameraSettings)e.Argument;

            LoggingClient logger = new LoggingClient(App.Configuration);

            logger.Log(settings.Username, "Invoked");

            if (Directory.Exists(settings.TargertDrive))
            {
                // Load POIs from PocketGPSWorld
                this.buildDatabaseBackgroundWorker.ReportProgress(1, "Loading Cameras from PocketGPSWorld.com");

                byte[] camerasZip = null;

                try
                {
                    camerasZip = SpeedCameras.Load(settings.Username, settings.Password);
                }
                catch (WebException webException)
                {
                    logger.Log(settings.Username, $"Exception (Load) - {webException.Message}");

                    // Offer the user to build from manual download
                    if (MessageBox.Show(webException.Message + "\r\r" + Properties.Resources.ManualDownloadPrompt, Properties.Resources.ErrorTitle, MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        MessageBox.Show(Properties.Resources.ManualDownloadGuidance, Properties.Resources.ManualDownloadGuidanceTitle, MessageBoxButton.OK, MessageBoxImage.Information);
                        Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog
                        {
                            DefaultExt = ".zip",
                            Filter     = "Zip Files|*.zip"
                        };

                        bool?dialogResult = fileDialog.ShowDialog();
                        if (dialogResult == true)
                        {
                            string filename = fileDialog.FileName;
                            camerasZip = File.ReadAllBytes(filename);
                        }
                    }
                }

                if (camerasZip == null)
                {
                    return;
                }

                SpeedCameras.UploadCameras(settings.Username, camerasZip);

                Collection <PointOfInterestCategory> cameras = null;

                try
                {
                    cameras = SpeedCameras.Filter(
                        SpeedCameras.SortCameras(
                            SpeedCameras.UnpackCameras(camerasZip)),
                        settings);
                }
                catch (FileFormatException fileFormatException)
                {
                    logger.Log(settings.Username, $"Exception (Unpack) - {fileFormatException.Message}");
                    MessageBox.Show(fileFormatException.Message, Properties.Resources.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }

                // Check we got some Cameras from the PocketGPSWorld
                if (cameras != null && cameras.Count > 0)
                {
                    // Load existing POIs from card
                    this.buildDatabaseBackgroundWorker.ReportProgress(2, "Load existing POIs from Card");
                    Collection <PointOfInterestCategory> existingCategories = PointOfInterestDatabase.LoadPois(settings.TargertDrive);

                    // We need to do a merge
                    Collection <PointOfInterestCategory> mergedPois = PointOfInterestDatabase.MergePointsOfInterest(existingCategories, cameras);

                    // Build the SD card
                    this.buildDatabaseBackgroundWorker.ReportProgress(3, "Building Database");
                    int loadedWaypoints = PointOfInterestDatabase.SavePois(mergedPois, settings.TargertDrive, this.buildDatabaseBackgroundWorker);

                    e.Result = loadedWaypoints;
                    logger.Log(settings.Username, "Complete");
                }
            }
            else
            {
                e.Result = -1;
                MessageBox.Show(
                    Properties.Resources.FileNotFoundError,
                    Properties.Resources.ErrorTitle,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK,
                    MessageBoxOptions.RightAlign);
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: pepe3197/audipoi
        /// <summary>
        /// Do Work event Handler
        /// </summary>
        /// <param name="sender">Sender Argument</param>
        /// <param name="e">Event Argument</param>
        private void BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Tuple <int, string, string> settings = (Tuple <int, string, string>)e.Argument;

            int    categoriesFlag = settings.Item1;
            string targetDrive    = settings.Item2;
            string username       = settings.Item3;

            LoggingClient logger = new LoggingClient(App.Configuration);

            logger.Log(username, $"POI Loader - Requested {categoriesFlag}");

            if (Directory.Exists(targetDrive))
            {
                this.buildDatabaseBackgroundWorker.ReportProgress(1, "Loading POIs");

                // Get the POIs
                string response = Azure.InvokeFunction(string.Format(App.Configuration.Get("POIsFunctionPath"), categoriesFlag), string.Empty);
                Collection <PointOfInterestCategory> poiCategories = JsonConvert.DeserializeObject <Collection <PointOfInterestCategory> >(response);

                // Get the Category icons
                response = Azure.InvokeFunction(string.Format(App.Configuration.Get("CategoryImagesFunctionPath"), categoriesFlag), string.Empty);
                Dictionary <int, string> categoryIcons = JsonConvert.DeserializeObject <Dictionary <int, string> >(response);

                // Update the category to include the correct icons
                foreach (PointOfInterestCategory poiCategory in poiCategories)
                {
                    poiCategory.Icon = this.BitmapFromBase64(categoryIcons[poiCategory.Id]);
                }

                // Check we got some Pois
                if (poiCategories != null && poiCategories.Count > 0)
                {
                    // Load existing POIs from card
                    this.buildDatabaseBackgroundWorker.ReportProgress(2, "Load existing POIs from Target Drive");
                    Collection <PointOfInterestCategory> existingCategories = PointOfInterestDatabase.LoadPois(targetDrive);

                    if (existingCategories.Count > 0)
                    {
                        List <string> categories = new List <string>();
                        foreach (PointOfInterestCategory category in existingCategories)
                        {
                            categories.Add(category.Name);
                        }

                        logger.Log(username, $"POI Loader - Already had {JsonConvert.SerializeObject(categories)}");
                    }

                    // We need to do a merge
                    Collection <PointOfInterestCategory> mergedPois = PointOfInterestDatabase.MergePointsOfInterest(existingCategories, poiCategories);

                    // Build the SD card
                    this.buildDatabaseBackgroundWorker.ReportProgress(3, "Building Database");
                    int loadedWaypoints = PointOfInterestDatabase.SavePois(mergedPois, targetDrive, this.buildDatabaseBackgroundWorker);

                    e.Result = loadedWaypoints;

                    logger.Log(username, $"POI Loader - Complete");
                }
            }
            else
            {
                e.Result = -1;
                MessageBox.Show(
                    Properties.Resources.FileNotFoundError,
                    Properties.Resources.ErrorTitle,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK,
                    MessageBoxOptions.RightAlign);
            }
        }