Storage Provider Events

The IStorageProvider class uses an event-based framework to allow for asyncrhonous processing of record uploads. The event is an instance of the DataStoreFinishedEventHandler delegate, which takes in DataStoreFinishedEventArgs. The DataStoreFinishedEventArgs contains the record and data store that finished upload. The IStorageProvider interface (and the implementation) have the following property:

  event DataStoreFinishedEventHandler DataStoreFinished;

Consumers of the class can register a method to be called when the event fires as follows:

  myStorageProvider.DataStoreFinished += new DataStoreFinishedEventHandler(MyRecordFinishedMethod);

where the MyRecordFinishedMethod would need to have the signature:

        void MyRecordFinishedMethod(object sender, DataStoreFinishedEventArgs e)
        {
             // code that executes when each data store receives the record
             Console.WriteLine("Record {0} finished at time {1}. Data store is {2}.", 
                               e.Record.Id, DateTime.Now, e.DataStore);
        }

The actual storage provider method should be executed in a separate thread so whatever the caller is can remain repsonsive. For example:

        private IStorageProvider _sp;
        private Stream _inStream;

        // other code omitted

        public void CreateRecordAsync(byte[] recordBytes) {
            _inStream = new MemoryStream(recordBytes);
            Thread t = new Thread(new ThreadStart(CreateRecordHelper));
            t.SetApartmentState(ApartmentState.MTA);
            t.Start();
            // return control to the user here
        }

        private void CreateRecordHelper()
        {
            _sp.CreateRecord(_inStream, true);
        }

Currently the event only fires when records are being uploaded.