public CodeCampService(string baseUrl, string campKey) { // ideally each app would just send in its folder path or helper instead of doing it this way // including this as a example of how to use compiler directives in shared layers #if WINDOWS_PHONE _fileHelper = new IsolatedStorageFileSystemHelper(); #elif __ANDROID__ string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "../cache"); _fileHelper = new StandardFileSystemHelper(folderPath); #else string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "../Library/Caches"); _fileHelper = new StandardFileSystemHelper(folderPath); #endif _fileName = campKey + ".xml"; Repository = new CodeCampRepository(null); _client = new CodeCampDataClient(baseUrl, campKey); if (!_fileHelper.FileExists(_fileName)) { downloadNewXmlFile(); } else { Repository = new CodeCampRepository(_fileHelper.ReadFile(_fileName)); } }
void Initialize() { if (!_fileHelper.FileExists(_fileName)) { downloadNewXmlFile(); } else { Repository = new CodeCampRepository(_fileHelper.ReadFile(_fileName)); MessageHub.Instance.Publish(new FinishedLoadingScheduleFromStorage(this)); } }
private void downloadNewXmlFile() { MessageHub.Instance.Publish(new StartedDownloadingUpdatedScheduleMessage(this)); _client.GetXml(xml => { if (string.IsNullOrEmpty(xml)) { MessageHub.Instance.Publish(new ErrorDownloadingUpdatedScheduleMessage(this)); } else { _fileHelper.WriteFile(_fileName, xml); Repository = new CodeCampRepository(xml); MessageHub.Instance.Publish(new FinishedUpdatingScheduleMessage(this)); } }); }
async void Initialize() { try { var fileExists = await _fileHelper.FileExists(_fileName); if (!fileExists) { downloadNewXmlFile(); } else { Repository = new CodeCampRepository(await _fileHelper.ReadFile(_fileName)); MessageHub.Instance.Publish(new FinishedLoadingScheduleFromStorageMessage(this)); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }