public AbstractSource AddSource(AbstractSource source) { if (sources.Contains(source)) { throw new Exception("Source already exists."); } else if (source.ID != null) { throw new Exception("Source should not have ID"); } else { try { sources.Add(source); DoInsertSource(source); if (source.ID == null) { throw new Exception("Logic error, expected DataStore to set ID"); } } catch (Exception e) { sources.RemoveAt(sources.Count - 1); throw; } return(source); } }
public void CopyTo(AbstractSource outputSource) { outputSource.SetMetaData(this.MetaData); outputSource.SetProviderID(this.ProviderID); outputSource.SetSourceName(this.SourceName); }
protected override AbstractSource DoCreateNewSource(string name, string url, List <MetaDataObject> metaData) { Dictionary <string, string> oldMetaFormat = ConvertToOldFormat(metaData); V1.AbstractSource src = provider.CreateNewSource(name, url, oldMetaFormat); return(SourceAdapter.CreateSourceAdapter(src, provider)); }
public void RemoveSource(AbstractSource source) { bool removed = sources.Remove(source); if (removed) { RemoveFromDataStore(source); } }
public List <AbstractItem> CheckForNewItems(AbstractSource source) { if (this.providerId != source.ProviderID) { return(null); //throw new Exception(String.Format("Source is not supported by this provider.")); } else { return(GetNewItems(source)); } }
public void UpdateSource(AbstractSource source) { DoUpdateSource(source); //Copy changes to active source var existing = Sources.FirstOrDefault(x => x.ID == source.ID); if (existing != null) { source.CopyTo(existing); } }
protected override List <AbstractItem> GetNewItems(AbstractSource source) { V1.AbstractSource oldSource = ConvertToOldFormat(source); var items = provider.SupportGetNewItems(oldSource); List <AbstractItem> newItems = new List <AbstractItem>(); foreach (var i in items) { newItems.Add(new ItemAdapter(i, source)); } return(newItems); }
protected AbstractItem(AbstractSource source, string title, string link, int?id = null, bool isNew = true, DateTime?addedDate = null) { this.source = source; this.SourceId = source.ID.Value; this.SourceName = source.SourceName; this.Provider = source.ProviderID; this.Name = title; this.ActionContent = link; this.AddedDate = !addedDate.HasValue? DateTime.Now : addedDate.Value; this.ID = id; this.New = isNew; }
public static SourceAdapter CreateSourceAdapter(V1.AbstractSource src, V1.AbstractProvider provider) { string strDisabled = src.GetMetaDataValue(AbstractSource.DISABLED); bool disabled = strDisabled == null ? false : Convert.ToBoolean(strDisabled); GenericSource gs = new GenericSource(src.SourceName, src.ProviderID, disabled); //Update Meta Dictionary <string, MetaDataObject> newMeta = new Dictionary <string, MetaDataObject>(); List <string> providerMeta = provider.GetMetaFields(); { foreach (string name in providerMeta) { var mdo = new MetaDataObject(name, name); if (src.GetMetaData().ContainsKey(name)) { mdo.SetValue(src.GetMetaDataValue(name)); } newMeta.Add(mdo.ID, mdo); } } gs.SetMetaData(newMeta); if (src.ID.HasValue) { gs.SetID(src.ID.Value); } var sa = new SourceAdapter(gs); return(sa); }
protected abstract void DoUpdateSource(AbstractSource source);
/// <summary> /// Insert the Source into the actual data store. /// This function should set the ID on the source object /// </summary> /// <param name="source"></param> protected abstract void DoInsertSource(AbstractSource source);
public bool CanCheck(AbstractSource source) { return(source.ProviderID == this.providerId); }
public abstract void RemoveFromDataStore(AbstractSource source);
internal List <AbstractItem> SupportGetNewItems(AbstractSource source) { return(GetNewItems(source)); }
protected abstract List <AbstractItem> GetNewItems(AbstractSource source);
private bool IsEqual(AbstractSource that) { return(this.ProviderID == that.ProviderID && this.SourceName == that.SourceName); }
public static AbstractItem CreateGenericItem(int id, AbstractSource source, string title, string meta, bool isNew, DateTime addedDate) { return(new GenericItem(id, source, title, meta, isNew, addedDate)); }
public GenericItem(int id, AbstractSource source, string title, string meta, bool isNew, DateTime addedDate) : base(source, title, meta, id, isNew, addedDate) { }