public void RegisterPhoto (ICacheablePhotoSource source, IPhoto photo) { if (source.CacheId == 0) { throw new Exception ("The source needs to be registered first using RegisterPhotoSource ()"); } var cache_photo = SqliteCachedPhoto.CreateFrom (photo); cache_photo.SourceId = source.CacheId; provider.Save (cache_photo); source.RegisterCachedPhoto (photo, cache_photo.CacheId); }
public void RegisterPhotoSource (ICacheablePhotoSource source) { if (source.CacheId != 0) { throw new Exception ("Can't register an already registered source!"); } var cache = new SqliteCachedPhotoSource (source); cache.AvailabilityChanged += OnCachedSourceAvailabilityChanged; source_provider.Save (cache); source.CacheId = cache.CacheId; source.Persist (); cache.Start (this); }
public SqliteCachedPhotoSource (ICacheablePhotoSource source) { instance = source; instance.AvailabilityChanged += (s, a) => UpdateAvailability (); SourceType = instance.GetType ().FullName; }
void EnsureInstance () { if (instance_create_failed) throw new PhotoSourceNotAvailableException (); lock (this) { if (instance == null) { Type type = null; if (!PhotoSourceInfoManager.Instance.PhotoSourceTypes.TryGetValue (SourceType, out type)) { instance_create_failed = true; UpdateAvailability (); throw new PhotoSourceNotAvailableException (); } instance = Activator.CreateInstance (type) as ICacheablePhotoSource; instance.CacheId = CacheId; instance.WakeUp (); instance.AvailabilityChanged += (s, a) => UpdateAvailability (); } } }