Ejemplo n.º 1
0
 /// <summary>
 /// Removes the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 public void Remove(FeedSourceEntry source)
 {
     if (source != null && _feedSources.ContainsKey(source.ID))
     {
         _feedSources.Remove(source.ID);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the source extension.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="newsFeed">The news feed.</param>
        /// <returns>Null, if <paramref name="newsFeed"/> is null, else the requested extension instance</returns>
        /// <exception cref="InvalidCastException">If extension is not implemented by the <c>newsFeed</c> source</exception>
        public T GetSourceExtension <T>(INewsFeed newsFeed)
        {
            FeedSourceEntry sid = SourceOf(newsFeed);

            if (sid != null)
            {
                object t = sid.Source;
                return((T)t);
            }
            return(default(T));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Indexer which returns feed source keyed by name
 /// </summary>
 /// <param name="name">The name of the feed source</param>
 /// <returns>The requested feed source</returns>
 /// <exception cref="KeyNotFoundException">if the name is not found in the <see cref="FeedSourceManager"/></exception>
 public FeedSourceEntry this[string name]
 {
     get {
         FeedSourceEntry fsid = _feedSources.Values.FirstOrDefault(fs => fs.Name == name);
         if (fsid != null)
         {
             return(fsid);
         }
         throw new KeyNotFoundException(name);
     }
 }
Ejemplo n.º 4
0
        static StringProperties BuildProperties(FeedSourceEntry f)
        {
            StringProperties h = new StringProperties();

            if (f.Source.SubscriptionLocation.Credentials != null &&
                !String.IsNullOrEmpty(f.Source.SubscriptionLocation.Credentials.UserName))
            {
                h.Add(PropertyKey.Domain, f.Source.SubscriptionLocation.Credentials.Domain);
                h.Add(PropertyKey.UserName, f.Source.SubscriptionLocation.Credentials.UserName);
                h.Add(PropertyKey.Password, CryptHelper.Encrypt(f.Source.SubscriptionLocation.Credentials.Password));
            }
            return(h);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns feed source keyed by name
 /// </summary>
 /// <param name="name">The name of the feed source</param>
 /// <param name="value">out parameter for storing feed source</param>
 /// <returns>
 /// The requested feed source (true) or null if not found (false)
 /// </returns>
 public bool TryGetValue(string name, out FeedSourceEntry value)
 {
     value = null;
     if (!string.IsNullOrEmpty(name))
     {
         FeedSourceEntry fsid = _feedSources.Values.FirstOrDefault(fs => fs.Name == name);
         if (fsid != null)
         {
             value = fsid;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the specified new source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If source or name are null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If name is empty</exception>
        /// <exception cref="InvalidOperationException">If source with provided name yet exists</exception>
        public FeedSourceEntry Add(FeedSource source, string name)
        {
            source.ExceptionIfNull("source");
            name.ExceptionIfNullOrEmpty("name");

            if (Contains(name))
            {
                throw new InvalidOperationException("Entry with name '" + name + "' already exists");
            }

            source.sourceID = UniqueKey;
            FeedSourceEntry fs = new FeedSourceEntry(source.sourceID, source, name, _feedSources.Count);

            _feedSources.Add(fs.ID, fs);
            return(fs);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a new source with the specified name and properties.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If name is null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If name is empty</exception>
        /// <exception cref="InvalidOperationException">If source with provided name yet exists</exception>
        public FeedSourceEntry Add(string name, FeedSourceType type, IDictionary properties)
        {
            name.ExceptionIfNullOrEmpty("name");

            if (Contains(name))
            {
                throw new InvalidOperationException("Entry with name '" + name + "' already exists");
            }

            int        id     = UniqueKey;
            FeedSource source = FeedSource.CreateFeedSource(id, type,
                                                            CreateSubscriptionLocation(id, type, properties));
            FeedSourceEntry fse = new FeedSourceEntry(id, source, name, _feedSources.Count);

            //fse.Properties =
            _feedSources.Add(fse.ID, fse);
            return(fse);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds the specified new source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If source or name are null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If name is empty</exception>
        /// <exception cref="InvalidOperationException">If source with provided name yet exists</exception>
        public FeedSourceEntry Add(FeedSource source, string name)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("message", nameof(name));
            }

            if (Contains(name))
            {
                throw new InvalidOperationException("Entry with name '" + name + "' already exists");
            }

            source.sourceID = UniqueKey;
            FeedSourceEntry fs = new FeedSourceEntry(source.sourceID, source, name, _feedSources.Count);

            _feedSources.Add(fs.ID, fs);
            return(fs);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the source type of an item.
        /// </summary>
        /// <param name="newsFeed">The news feed.</param>
        /// <returns></returns>
        public FeedSourceType SourceTypeOf(INewsFeed newsFeed)
        {
            FeedSourceEntry sid = SourceOf(newsFeed);

            return(sid != null ? sid.Source.Type : FeedSourceType.Unknown);
        }