Beispiel #1
0
        public AzureBlobSource()
            : base("AzureStorageConfiguration.json")
        {
            this.Name       = "AzureStorage";
            this.SourceType = DataSourceType.Blob;
            this.DeleteSourceFilesWhenComplete = true;

            this.CurrentImage = -1;

            // Get the configuration specific to this instance
            this.Configuration = this.LoadConfiguration();
            this.MultiClass    = this.Configuration.MultiClass;


            // Create the storage utils
            this.AzureStorageUtils = new StorageUtility(this.Configuration);

            // Prepare the UI control with the right hooks.
            AzureStorageConfigurationUi configUi = new AzureStorageConfigurationUi(this, this.Configuration);

            configUi.OnConfigurationSaved += ConfigurationSaved;
            configUi.OnSourceDataUpdated  += UpdateInformationRequested;

            this.ConfigurationControl =
                new ConfigurationControlImpl("Azure Storage - Unlabeled Dataset",
                                             configUi);

            // Load the catalogs and initialize if already configured
            this.CatalogFiles     = new List <string>(BlobPersistenceLogger.GetAcquisitionFiles(this.Configuration));
            this.CurrentContainer = this.CatalogFiles.FirstOrDefault();
            this.InitializeOnNewContainer();

            this.ContainerControl = new GenericContainerControl(this);
            this.ImageControl     = new SingleImageControl(this);
        }
Beispiel #2
0
        /// <summary>
        /// Routine called in a ThreadPool thread from the AcquireContentWindow to collect the data
        /// </summary>
        /// <param name="cancelEvent">Hooked to the UI cancel button</param>
        /// <param name="statusHandler">Ability to write to the window to show status of the request</param>
        private void DataCollectionThread(ManualResetEvent cancelEvent, Action <string> statusHandler)
        {
            statusHandler?.Invoke(String.Format("Acquiring {0} files from {1}",
                                                this.Configuration.FileCount,
                                                this.Configuration.StorageAccount));

            // Clean up current catalog data
            FileUtils.DeleteFiles(this.Configuration.RecordLocation, new string[] { "*.csv" });

            // Load data from storage
            int fileLabel                = 1;
            int recordCount              = 0;
            int totalDownloadCount       = (this.Configuration.FileCount == StorageUtility.DEFAULT_FILE_COUNT) ? StorageUtility.DEFAULT_DOWNLOAD_COUNT : this.Configuration.FileCount;
            BlobPersistenceLogger logger = new BlobPersistenceLogger(this.Configuration, fileLabel);

            try
            {
                foreach (KeyValuePair <String, String> kvp in this.AzureStorageUtils.ListBlobs(false))
                {
                    // Check cancellation
                    if (cancelEvent != null && cancelEvent.WaitOne(10))
                    {
                        statusHandler?.Invoke("Cancel recieved");
                        break;
                    }

                    logger.Record(new string[] { kvp.Value });

                    // Too many?
                    if (++recordCount >= totalDownloadCount)
                    {
                        break;
                    }

                    // Have to roll the file?
                    if (recordCount % AzureBlobSource.MAX_ENTRIES_PER_FILE == 0)
                    {
                        logger = new BlobPersistenceLogger(this.Configuration, ++fileLabel);
                    }

                    // Update any status?
                    if (recordCount % 50 == 0)
                    {
                        statusHandler?.Invoke(String.Format("Currently detected files - {0}", recordCount));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Azure Storage Exception");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Triggered when the data collection routine completes either by completion or cancel.
        /// </summary>
        private void DataCollectionJobCompleted()
        {
            this.CatalogFiles     = new List <string>(BlobPersistenceLogger.GetAcquisitionFiles(this.Configuration));
            this.CurrentContainer = this.CatalogFiles.FirstOrDefault();

            // Update containers
            this.ContainerControl?.Refresh();

            // Initialize with new data
            this.InitializeOnNewContainer();

            // Notify listeners it just happened.
            if (this.ConfigurationControl != null)
            {
                this.ConfigurationControl.Control.Dispatcher.Invoke(() =>
                {
                    this.ConfigurationControl.OnSourceDataUpdated?.Invoke(this);
                });
            }
        }