Пример #1
0
        /// <summary>
        /// Bind the checkboxes from Azure Data
        /// </summary>
        /// <returns>false if unable to bind the checkboxes</returns>
        private bool BindCheckBoxes()
        {
            try
            {
                string response = Azure.InvokeFunction(
                    App.Configuration.Get("CategoriesFunctionPath"),
                    string.Empty);

                Dictionary <int, string> categories = JsonConvert.DeserializeObject <Dictionary <int, string> >(response);
                foreach (int categoryId in categories.Keys)
                {
                    CheckBox dynamicCheckbox = new CheckBox
                    {
                        Content          = categories[categoryId],
                        CommandParameter = categoryId
                    };

                    poiCategories.Children.Add(dynamicCheckbox);
                }

                return(true);
            }
            catch (WebException webEx)
            {
                MessageBox.Show($"{Properties.Resources.PoiCategoryDownloadError}\r\n\r\nDetail:\r\n{webEx.Message}", Properties.Resources.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Upload a Cameras File for later inspection
        /// </summary>
        /// <param name="username">Username to record the zip against</param>
        /// <param name="camerasZip">Zip file to store in the cloud</param>
        public static async void UploadCameras(string username, byte[] camerasZip)
        {
            // Get an SAS token and path to Blob storage
            Config configuration = new Config();

            string path          = string.Format(configuration.Get("GetAccessTokenFunctionPath"), username);
            string accountName   = configuration.Get("AccountName");
            string containerName = configuration.Get("Container");

            string accessToken = Azure.InvokeFunction(path, string.Empty);

            // If we were issued a token attempt to upload the file to blob storage.
            if (!string.IsNullOrEmpty(accessToken))
            {
                // Do upload to Azure Blob Storage
                try
                {
                    // Create new storage credentials using the SAS token.
                    StorageCredentials accountSAS = new StorageCredentials(accessToken);

                    // Use these credentials and the account name to create a Blob service client.
                    CloudStorageAccount accountWithSAS    = new CloudStorageAccount(accountSAS, accountName, endpointSuffix: null, useHttps: true);
                    CloudBlobClient     blobClientWithSAS = accountWithSAS.CreateCloudBlobClient();

                    CloudBlobContainer container = blobClientWithSAS.GetContainerReference(containerName);

                    CloudBlockBlob blob = container.GetBlockBlobReference($"{DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")}_{username}");
                    await blob.UploadFromByteArrayAsync(camerasZip, 0, camerasZip.Length);
                }
                catch (Exception ex)
                {
                    LoggingClient logger = new LoggingClient(configuration);
                    logger.Log(username, $"Exception in Upload Cameras - {ex.Message}");
                }
            }

            return;
        }
Пример #3
0
        /// <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);
            }
        }