Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
 void Initialize()
 {
     if (!_fileHelper.FileExists(_fileName))
     {
         downloadNewXmlFile();
     }
     else
     {
         Repository = new CodeCampRepository(_fileHelper.ReadFile(_fileName));
         MessageHub.Instance.Publish(new FinishedLoadingScheduleFromStorage(this));
     }
 }
Ejemplo n.º 4
0
        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));
                }
            });
        }
Ejemplo n.º 5
0
 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());
     }
 }
Ejemplo n.º 6
0
		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));
				}
			});
		}