public void ReadPlatformData(Action<PlatformList, Exception> callback) { Exception exception = null; try { string uri = "GamesXML/Platforms.xml"; StreamResourceInfo SRI = Application.GetResourceStream(new Uri(uri, System.UriKind.Relative)); XmlSerializer serializer = new XmlSerializer(typeof(PlatformList)); FoundPlatforms = (PlatformList)serializer.Deserialize(SRI.Stream); } catch (Exception ex) { exception = ex; } if (callback != null) { callback(FoundPlatforms, exception); } }
private static void SavePlatformData(PlatformList platformList, Exception exception) { if (exception != null) { // catch exception here } else { if (platformList.Platforms.Count > 0) { using (GameDataContext context = new GameDataContext(Constants.DBConnectionString)) { foreach (PlatformData item in platformList.Platforms) { context.Platform.InsertOnSubmit(item); } context.SubmitChanges(); } } else { // have no data } } }