Grofit
June 30th, 2009, 04:17 AM
Hey,
Im porting over a library i wrote for one of my apps but im just wondering the best way to go about doing it...
Originally there were 2 main loaders, lets say CollageLoader and ImageReferenceLoader, the first one being ImageReferenceLoader acted like a palette of images. It was an XML file with a list of images and a few other bits and bobs. Then it would load up all the images and store them internally within the object.
CollageLoader loaded up an object that contained many ImageReference objects, and it basically indexed them, so it would have a list of reference_images giving an image reference object id (the image reference object to lookup) then an index, which was the index within that object that the image was stored.
Now this was fairly straight forward using non async methods:
ImageReferenceLoader
- Load XML
- Parse XML
- Load Images referenced
- Populate internal images with loaded ones
- return populated ImageReference
CollageLoader
- Load XML
- Parse XML
- Load ImageReferences via ImageReferenceLoader
- Populate internal ImageReferences with loaded ones
- return populated Collage
Now with Async methods (im using WebClient and OpenReadAsync/DownloadStringAsync) it is a whole new ballgame, so im currently thinking:
ImageReferenceLoader
- Start async string download
- download complete event fires
- Parse XML
- Start async open of images
- download event fires for each image (need some way of linking images to indexes, could use UserState with an index)
- Somehow check that all images have loaded
- fire CompletedEvent containing the populated object
CollageLoader
- Start async string download
- download complete event fires
- Parse XML
- Start ImageReferenceLoader for each ImageReference (need some way of linking these ImageReferences to the internal objects)
- Somehow check that all imagereferences have loaded
- fire CompletedEvent containing the populated object
Now as you can see i still have a few bits where im not quite sure how is the best way to proceed, so does anyone have any nuggets of greatness that could point me in the right direction?
Loading the ImageReferences shouldnt be too hard but im not sure how im going to load the CollageLoader as i wont know what ImageReference goes where, unless i give it a tag of some kind, but then im breaking the model for this bit of logic, or i give each loader an internal count to keep adding to as things load, but although i can tell when things load that way, i wont know which order they loaded...
Any advice would be great!
Im porting over a library i wrote for one of my apps but im just wondering the best way to go about doing it...
Originally there were 2 main loaders, lets say CollageLoader and ImageReferenceLoader, the first one being ImageReferenceLoader acted like a palette of images. It was an XML file with a list of images and a few other bits and bobs. Then it would load up all the images and store them internally within the object.
CollageLoader loaded up an object that contained many ImageReference objects, and it basically indexed them, so it would have a list of reference_images giving an image reference object id (the image reference object to lookup) then an index, which was the index within that object that the image was stored.
Now this was fairly straight forward using non async methods:
ImageReferenceLoader
- Load XML
- Parse XML
- Load Images referenced
- Populate internal images with loaded ones
- return populated ImageReference
CollageLoader
- Load XML
- Parse XML
- Load ImageReferences via ImageReferenceLoader
- Populate internal ImageReferences with loaded ones
- return populated Collage
Now with Async methods (im using WebClient and OpenReadAsync/DownloadStringAsync) it is a whole new ballgame, so im currently thinking:
ImageReferenceLoader
- Start async string download
- download complete event fires
- Parse XML
- Start async open of images
- download event fires for each image (need some way of linking images to indexes, could use UserState with an index)
- Somehow check that all images have loaded
- fire CompletedEvent containing the populated object
CollageLoader
- Start async string download
- download complete event fires
- Parse XML
- Start ImageReferenceLoader for each ImageReference (need some way of linking these ImageReferences to the internal objects)
- Somehow check that all imagereferences have loaded
- fire CompletedEvent containing the populated object
Now as you can see i still have a few bits where im not quite sure how is the best way to proceed, so does anyone have any nuggets of greatness that could point me in the right direction?
Loading the ImageReferences shouldnt be too hard but im not sure how im going to load the CollageLoader as i wont know what ImageReference goes where, unless i give it a tag of some kind, but then im breaking the model for this bit of logic, or i give each loader an internal count to keep adding to as things load, but although i can tell when things load that way, i wont know which order they loaded...
Any advice would be great!