public IDictionary <int, object> LoadRecords(RecordProviderConfiguration configuration, OnStatusUpdate onStatus = null) { Dictionary <int, object> returnValue = new Dictionary <int, object>(); String fileContent = System.IO.File.ReadAllText(this.FileInput); for (int i = 0; i < configuration.RecordCount; i++) { returnValue.Add(i, fileContent); } return(returnValue); }
/// <summary> /// Return a list of objects that match your API input. This one returns a simple JSON object for an image detection /// API. /// /// There are currently two options in the RecordProviderConfiguration : "storage" or "local", but in reality in the check /// below, if we don't find storage, we assume local. /// /// "storage" in this case means records will be loaded from Azure Storage using the information in RecordProviderConfiguration.Storage /// object. /// </summary> public IDictionary <int, object> LoadRecords(RecordProviderConfiguration configuration, OnStatusUpdate onStatus = null) { Dictionary <int, object> returnObjects = new Dictionary <int, object>(); if (String.Compare(configuration.ExecutionType, "storage", true) == 0) { onStatus?.Invoke($"Loading {configuration.RecordCount} records from storage."); AzureStorageUtility storageUtility = new AzureStorageUtility(configuration.Storage); List <String> blobList = storageUtility.ListBlobs( configuration.RecordCount, configuration.Storage.StorageAccountContainer, configuration.Storage.BlobPrefix, configuration.Storage.FileType); foreach (String blob in blobList) { String content = storageUtility.GetBlobBase64(configuration.Storage.StorageAccountContainer, blob); returnObjects.Add(RecordId++, PackageRecord(System.IO.Path.GetFileName(blob), content)); } onStatus?.Invoke($"Loaded {returnObjects.Count} records from storage."); } else { onStatus?.Invoke($"Creating {configuration.RecordCount} records from local system."); // Loading from file - String fileToLoad = configuration.Local.LocalFile; if (System.IO.File.Exists(fileToLoad)) { byte[] fileData = System.IO.File.ReadAllBytes(fileToLoad); String content = Convert.ToBase64String(fileData); String name = System.IO.Path.GetFileName(fileToLoad); for (int i = 0; i < configuration.RecordCount; i++) { returnObjects.Add(RecordId++, PackageRecord(String.Format("{0}_{1}", i, name), content)); } onStatus?.Invoke($"Created {returnObjects.Count} records from local system."); } } return(returnObjects); }
/// <summary> /// Populates the cache from the IRecordProvider based on the number of messages /// identified in the configuration/context. /// </summary> private void PopulateRecordList() { // Determine how many messages are required. RecordProviderConfiguration configuration = this.Configuration.RecordConfiguration; if (this.Provider.GetType().IsAssignableFrom(typeof(DefaultRecordProvider))) { configuration = new RecordProviderConfiguration() { RecordCount = this.Configuration.DefaultProvider.RecordCount }; } // Reset counters for GetNextBatch() and populate the cache if the record count // differs from the cache count. ThreadRecordSupplier.LastItem = 0; ThreadRecordSupplier.ServedBatches = 0; ThreadRecordSupplier.UnevenBatch = 0; if (ThreadRecordSupplier.Cache.Count != configuration.RecordCount) { ThreadRecordSupplier.Cache = new Dictionary <int, object>(this.Provider.LoadRecords(configuration, this.OnStatus)); } }