Exemple #1
0
        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);
            }
        }
Exemple #2
0
        public void CopyTo(AbstractSource outputSource)
        {
            outputSource.SetMetaData(this.MetaData);

            outputSource.SetProviderID(this.ProviderID);
            outputSource.SetSourceName(this.SourceName);
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
     }
 }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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;
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 protected abstract void DoUpdateSource(AbstractSource source);
Exemple #11
0
 /// <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);
 }
Exemple #13
0
 public abstract void RemoveFromDataStore(AbstractSource source);
 internal List <AbstractItem> SupportGetNewItems(AbstractSource source)
 {
     return(GetNewItems(source));
 }
 protected abstract List <AbstractItem> GetNewItems(AbstractSource source);
Exemple #16
0
 private bool IsEqual(AbstractSource that)
 {
     return(this.ProviderID == that.ProviderID &&
            this.SourceName == that.SourceName);
 }
Exemple #17
0
 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));
 }
Exemple #18
0
 public GenericItem(int id, AbstractSource source, string title, string meta, bool isNew,
                    DateTime addedDate)
     : base(source, title, meta, id, isNew, addedDate)
 {
 }