Exemplo n.º 1
0
 private void WriteFeedItem(IFeedItem item)
 {
     this.XmlWriter.WriteStartElement("item");
     if (!string.IsNullOrEmpty(item.Title))
     {
         this.XmlWriter.WriteElementString("title", item.Title);
     }
     if (item.Uri != null)
     {
         this.XmlWriter.WriteElementString("link", item.Uri.AbsoluteUri);
         this.XmlWriter.WriteStartElement("guid");
         this.XmlWriter.WriteAttributeString("isPermaLink", "true");
         this.XmlWriter.WriteString(item.Uri.AbsoluteUri);
         this.XmlWriter.WriteEndElement();
     }
     if (!string.IsNullOrEmpty(item.Description))
     {
         this.XmlWriter.WriteElementString("description", item.Description);
     }
     if (!item.PublishDate.Equals(DateTime.MinValue))
     {
         DateTime universalPublishDate = item.PublishDate.ToUniversalTime();
         this.XmlWriter.WriteElementString("pubDate", universalPublishDate.ToString("r", DateTimeFormatInfo.InvariantInfo));
     }
     if (item.Author != null)
     {
         string author = !string.IsNullOrEmpty(item.Author.Email) ? string.Format("{0} ({1})", item.Author.Email, item.Author.Name) : item.Author.Name;
         this.XmlWriter.WriteElementString("author", author);
     }
     this.XmlWriter.WriteEndElement();
 }
Exemplo n.º 2
0
        private IntranetActivityPreviewModelBase GetBaseModel(IFeedItem feedItem, bool isGroupFeed)
        {
            if (feedItem is IntranetActivity activity)
            {
                var baseModel = new IntranetActivityPreviewModelBase
                {
                    Id            = feedItem.Id,
                    Links         = _linkService.GetLinks(feedItem.Id),
                    Type          = _localizationService.Translate(activity.Type.ToString()),
                    CommentsCount = _commentsService.GetCount(feedItem.Id),
                    Likes         = _likesService.GetLikeModels(activity.Id),
                    GroupInfo     = isGroupFeed ? null : _feedActivityHelper.GetGroupInfo(feedItem.Id),
                    ActivityType  = feedItem.Type,
                };
                if (feedItem is Social social)
                {
                    baseModel.LinkPreviewId = social.LinkPreviewId;
                    baseModel.LinkPreview   = social.LinkPreview;
                }
                _lightboxHelper.FillGalleryPreview(baseModel, activity.MediaIds);

                return(baseModel);
            }

            _logger.Warn <FeedPresentationService>("Feed item is not IntranetActivity (id={0};type={1})", feedItem.Id, feedItem.Type.ToInt());

            return(null);
        }
        public static string ToApprovalString(this IFeedItem feeditem)
        {
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("Title: {0}", feeditem.Title));
            sb.AppendLine(string.Format("Published: {0}", feeditem.DatePublished));
            sb.AppendLine(string.Format("URL: {0}", feeditem.Link));
            sb.AppendLine(string.Format("Author: {0}", feeditem.Author));
            sb.AppendLine(string.Format("Id: {0}", feeditem.Id));
            sb.AppendLine(string.Format("Content: {0}", feeditem.Content));
            var categories = string.Empty;

            foreach (var category in feeditem.Categories)
            {
                categories += category + " ";
            }
            sb.AppendLine(string.Format("Categories: {0}", categories));

            if (feeditem.GetType() == typeof(Rss20FeedItem))
            {
                var temp = (Rss20FeedItem)feeditem;
                sb.AppendLine(string.Format("Comments: {0}", temp.Comments));
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
		private void WriteFeedItem(IFeedItem item) {
			this.XmlWriter.WriteStartElement("entry");
			this.XmlWriter.WriteElementString("id", item.Id);
			if(!string.IsNullOrEmpty(item.Title)) {
				this.XmlWriter.WriteElementString("title", item.Title);
			}
			if(item.Uri != null) {
				this.XmlWriter.WriteStartElement("link");
				this.XmlWriter.WriteAttributeString("href", item.Uri.AbsoluteUri);
				this.XmlWriter.WriteEndElement();
			}
			if(item.Author != null) {
				this.XmlWriter.WriteStartElement("author");
				this.XmlWriter.WriteElementString("name", item.Author.Name);
				if(item.Author.Email != null) {
					this.XmlWriter.WriteElementString("email", item.Author.Email);
				}
				this.XmlWriter.WriteEndElement();
			}
			string summary = !string.IsNullOrEmpty(item.Description) ? item.Description : item.Title;
			if(ContainsHtml(summary)) {
				this.XmlWriter.WriteStartElement("summary");
				this.XmlWriter.WriteAttributeString("type", "html");
				this.XmlWriter.WriteCData(summary);
				this.XmlWriter.WriteEndElement();
			} else {
				this.XmlWriter.WriteElementString("summary", summary);
			}
			if(!item.PublishDate.Equals(DateTime.MinValue)) {
				DateTime universalPublishDate = item.PublishDate.ToUniversalTime();
				this.XmlWriter.WriteElementString("updated", universalPublishDate.ToString("o", DateTimeFormatInfo.InvariantInfo));
			}
			this.XmlWriter.WriteEndElement();
		}
Exemplo n.º 5
0
		private void WriteFeedItem(IFeedItem item) {
			this.XmlWriter.WriteStartElement("item");
			if(!string.IsNullOrEmpty(item.Title)) {
				this.XmlWriter.WriteElementString("title", item.Title);
			}
			if(item.Uri != null) {
				this.XmlWriter.WriteElementString("link", item.Uri.AbsoluteUri);
				this.XmlWriter.WriteStartElement("guid");
				this.XmlWriter.WriteAttributeString("isPermaLink", "true");
				this.XmlWriter.WriteString(item.Uri.AbsoluteUri);
				this.XmlWriter.WriteEndElement();
			}
			if(!string.IsNullOrEmpty(item.Description)) {
				this.XmlWriter.WriteElementString("description", item.Description);
			}
			if(!item.PublishDate.Equals(DateTime.MinValue)) {
				DateTime universalPublishDate = item.PublishDate.ToUniversalTime();
				this.XmlWriter.WriteElementString("pubDate", universalPublishDate.ToString("r", DateTimeFormatInfo.InvariantInfo));
			}
			if(item.Author != null) {
				string author = !string.IsNullOrEmpty(item.Author.Email) ? string.Format("{0} ({1})", item.Author.Email, item.Author.Name) : item.Author.Name;
				this.XmlWriter.WriteElementString("author", author);
			}
			this.XmlWriter.WriteEndElement();
		}
Exemplo n.º 6
0
 private int FreshFirstOrderer(IFeedItem a, IFeedItem b)
 {
     if (a.DatePublished > b.DatePublished)
         return -1;
     else
         return 1;
 }
Exemplo n.º 7
0
        protected override bool ItemExists(string path)
        {
            path = NormalizePath(path);

            if (PathIsDrive(path))
            {
                return(true);
            }

            if (FeedsManager.ExistsFolder(path) || FeedsManager.ExistsFeed(path))
            {
                return(true);
            }

            string[] chunks = ChunkPath(path);
            if (chunks.Length > 0)
            {
                int id;
                if (int.TryParse(chunks[chunks.Length - 1], out id))
                {
                    path = GetParentPath(path, "");

                    if (FeedsManager.ExistsFeed(path))
                    {
                        IFeed     feed     = FeedsManager.GetFeed(path) as IFeed;
                        IFeedItem feedItem = feed.GetItem(id) as IFeedItem;
                        return(feedItem != null);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 8
0
 private static FeedItem CreateFeedItem(IFeedItem feedItem)
 {
     return(new FeedItem
     {
         Title = HtmlConvert.ToPlainText(feedItem.Title),
         Content = HtmlConvert.ToPlainText(feedItem.Description)
     });
 }
Exemplo n.º 9
0
 public static FeedItemSummary SummarizeFeedItem(IFeedItem feedItem)
 {
     return new FeedItemSummary
                {
                    ItemTitle = feedItem.Title,
                    ItemUri = new Uri(feedItem.Link)
                };
 }
Exemplo n.º 10
0
        } // GetChildItems

        protected override string GetChildName(string path)
        {
            path = NormalizePath(path);

            WriteDebug("Getting name for " + path);

            // Checks if the path represented is a drive
            if (PathIsDrive(path))
            {
                return("");
            }// if (PathIsDrive...

            if (FeedsManager.ExistsFolder(path))
            {
                IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder;
                return(folder.Name);
            }

            if (FeedsManager.ExistsFeed(path))
            {
                IFeed feed = FeedsManager.GetFeed(path) as IFeed;
                return(feed.Name);
            }

            WriteDebug("Couldn't find drive, folder or feed - checking for item.");
            string[] chunks = ChunkPath(path);
            if (chunks.Length > 0)
            {
                WriteDebug("Chunks:");
                foreach (string chk in chunks)
                {
                    WriteDebug("chunk: " + chk);
                }

                int id;
                if (int.TryParse(chunks[chunks.Length - 1], out id))
                {
                    path = GetParentPath(path, "");

                    WriteDebug("Looking for feed " + path);
                    if (FeedsManager.ExistsFeed(path))
                    {
                        WriteDebug("Found feed - looking for item");

                        IFeed     feed     = FeedsManager.GetFeed(path) as IFeed;
                        IFeedItem feedItem = feed.GetItem(id) as IFeedItem;
                        if (feedItem != null)
                        {
                            WriteDebug("Found item - returning " + feedItem.LocalId);
                            return(feedItem.LocalId.ToString());
                        }
                    }
                }
            }
            return(base.GetChildName(path));
        }
Exemplo n.º 11
0
 private FrontPageArticle(IFeedItem item) : this()
 {
     this.Title = item.Title;
     this.Author = item.Author;
     this.Categories = item.Categories;
     this.Content = item.Content;
     this.DatePublished = item.DatePublished;
     this.Id = item.Id;
     this.Link = item.Link;
 }
Exemplo n.º 12
0
        protected virtual FeedItemViewModel MapFeedItemToViewModel(IFeedItem i, Dictionary <int, FeedSettings> settings)
        {
            ActivityFeedOptions options = GetActivityFeedOptions(i.Id);

            return(new FeedItemViewModel()
            {
                Activity = i,
                Options = options,
                ControllerName = settings[i.Type.ToInt()].Controller
            });
        }
Exemplo n.º 13
0
        public Feed AddFromIFeedItem(IFeedItem entity)
        {
            var  dateTimeNow = DateTime.UtcNow;
            Feed feed        = new Feed()
            {
                Description      = entity.Description,
                CreationDateTime = entity.CreationDateTime,
                ModifiedDateTime = entity.ModifiedDateTime,
                Privacy          = entity.Privacy
            };

            base.Add(feed);
            return(feed);
        }
Exemplo n.º 14
0
        } // GetChildNames

        protected override void GetItem(string path)
        {
            path = NormalizePath(path);

            // Checks if the path represented is a drive
            if (PathIsDrive(path))
            {
                WriteItemObject(FeedsManager.RootFolder, PSDriveInfo.Name + ':', true);
                return;
            }// if (PathIsDrive...

            if (FeedsManager.ExistsFolder(path))
            {
                IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder;
                WriteItemObject(folder, folder.Path, true);
                return;
            }

            if (FeedsManager.ExistsFeed(path))
            {
                IFeed feed = FeedsManager.GetFeed(path) as IFeed;
                WriteItemObject(feed, feed.Path, true);
                return;
            }

            string[] chunks = ChunkPath(path);
            if (chunks.Length > 0)
            {
                int id;
                if (int.TryParse(chunks[chunks.Length - 1], out id))
                {
                    path = GetParentPath(path, "");

                    if (FeedsManager.ExistsFeed(path))
                    {
                        IFeed     feed     = FeedsManager.GetFeed(path) as IFeed;
                        IFeedItem feedItem = feed.GetItem(id) as IFeedItem;
                        if (feedItem != null)
                        {
                            WriteItemObject(feedItem, feed.Path + _pathSeparator + feedItem.LocalId, false);
                            return;
                        }
                    }
                }
            }

            base.GetItem(path);
        } // GetItem
Exemplo n.º 15
0
        internal RssItem(IFeedItem item)
        {
            title = StripHTMLTags(item.Title);
            link  = item.Link;

            try
            {
                description = StripHTMLTags(item.Description);
            }
            catch (ArgumentException)
            {
                description = "<<<Item text too long.>>>";
            }

            IFeedEnclosure enclosure = (IFeedEnclosure)item.Enclosure;

            if (enclosure != null)
            {
                string filename = GetLocalPath(enclosure);

                try
                {
                    // Let's make sure we only add pictures
                    string extension = "*" + Path.GetExtension(filename);
                    extension = extension.ToUpperInvariant();
                    if (FeedList.imageExtensions.Contains(extension))
                    {
                        // Set enclosure without checking for existence, since enclosure might
                        // not be on disk yet (BITS still getting it)
                        this.enclosure = new FileInfo(filename);
                    }
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Debug.Print("Illegal character in filename.");
                    // 'Illegal character in filename' is one possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
                catch (NotSupportedException)
                {
                    System.Diagnostics.Debug.Print("The given path's format is not supported.");
                    // 'Message="The given path's format is not supported."' is another possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
            }
        }
Exemplo n.º 16
0
        public void Update(Feed feed, IFeedItem entity)
        {
            var objFromDb = _db.Feed.FirstOrDefault(s => s.Id == feed.Id);

            if (objFromDb == null)
            {
                throw new SafeException("An error ocurred.", new Exception(string.Format("Object not found Feed.Update() Feed ID: {0}", feed.Id)));
            }

            feed.Privacy               = entity.Privacy;
            objFromDb.Privacy          = entity.Privacy;
            objFromDb.Name             = entity.Name;
            objFromDb.Description      = entity.Description;
            objFromDb.ModifiedDateTime = entity.ModifiedDateTime;
            dbSet.Update(objFromDb);
        }
Exemplo n.º 17
0
        internal RssItem(IFeedItem item)
        {
            title = StripHTMLTags(item.Title);
            link = item.Link;

            try
            {
                description = StripHTMLTags(item.Description);
            }
            catch (ArgumentException)
            {
                description = "<<<Item text too long.>>>";
            }

            IFeedEnclosure enclosure = (IFeedEnclosure)item.Enclosure;
            if (enclosure != null)
            {
                string filename = GetLocalPath(enclosure);

                try
                {
                    // Let's make sure we only add pictures
                    string extension = "*" + Path.GetExtension(filename);
                    extension = extension.ToUpperInvariant();
                    if (FeedList.imageExtensions.Contains(extension))
                    {
                        // Set enclosure without checking for existence, since enclosure might
                        // not be on disk yet (BITS still getting it)
                        this.enclosure = new FileInfo(filename);
                    }
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Debug.Print("Illegal character in filename.");
                    // 'Illegal character in filename' is one possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
                catch (NotSupportedException)
                {
                    System.Diagnostics.Debug.Print("The given path's format is not supported.");
                    // 'Message="The given path's format is not supported."' is another possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
            }
        }
Exemplo n.º 18
0
        public bool Equals(IFeedItem other)
        {
            if (other == null)
            {
                return false;
            }

            if (other.GetType() != GetType()) return false;
            if (Id != other.Id) return false;
            if (Title != other.Title) return false;
            if (Description != other.Description) return false;
            if (Interaction != other.Interaction) return false;
            if (Dismissable != other.Dismissable) return false;
            if (Importance != other.Importance) return false;

            return true;
        }
Exemplo n.º 19
0
        public string Post(IFeedItem item)
        {
            String result = "";

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(this.AssociatedAccount.EventsUrl + this.Id.ToString());
                req.Method      = "PUT";
                req.ContentType = "application/json";
                req.UserAgent   = "NetduinoPlus";
                req.Headers.Add("X-PachubeApiKey", this.AssociatedAccount.ApiKey);
                req.Timeout = 1000;
                if (this.AssociatedAccount.HttpProxy != null)
                {
                    req.Proxy = this.AssociatedAccount.HttpProxy;
                }

                string content = item.ToJson(this.Id);
                Logging.GetLogger("PowerShell").AddToLog("Post Content : " + content, false);


                byte[] postdata = System.Text.Encoding.UTF8.GetBytes(content);
                req.ContentLength = postdata.Length;

                using (Stream s = req.GetRequestStream())
                {
                    s.Write(postdata, 0, postdata.Length);
                }

                using (WebResponse resp = req.GetResponse())
                {
                    using (StreamReader respStream = new StreamReader(resp.GetResponseStream()))
                    {
                        result = respStream.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger("PowerShell").AddToLog("Post Pachube data failed : " + ex, false);
            }
            finally
            {
            }
            return(result);
        }
Exemplo n.º 20
0
        public string Post(IFeedItem item)
        {
            String result = "";
            
            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(this.AssociatedAccount.EventsUrl + this.Id.ToString());
                req.Method = "PUT";
                req.ContentType = "application/json";
                req.UserAgent = "NetduinoPlus";
                req.Headers.Add("X-PachubeApiKey", this.AssociatedAccount.ApiKey);
                req.Timeout = 1000;
                if (this.AssociatedAccount.HttpProxy != null)
                    req.Proxy = this.AssociatedAccount.HttpProxy;

                string content = item.ToJson(this.Id);
                Logging.GetLogger("PowerShell").AddToLog("Post Content : " + content, false);


                byte[] postdata = System.Text.Encoding.UTF8.GetBytes(content);
                req.ContentLength = postdata.Length;

                using (Stream s = req.GetRequestStream())
                {
                    s.Write(postdata, 0, postdata.Length);
                }

                using (WebResponse resp = req.GetResponse())
                {
                    using (StreamReader respStream = new StreamReader(resp.GetResponseStream()))
                    {
                        result = respStream.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger("PowerShell").AddToLog("Post Pachube data failed : " + ex, false);
            }
            finally
            {
                
            }
            return result;
        }        
Exemplo n.º 21
0
        public IntranetActivityPreviewModelBase GetPreviewModel(IFeedItem feedItem, bool isGroupFeed)
        {
            var baseModel = GetBaseModel(feedItem, isGroupFeed);

            switch (feedItem)
            {
            case News news:
                return(ApplyNewsSpecific(news, baseModel));

            case Social social:
                return(ApplySocialSpecific(social, baseModel));

            case Event @event:
                return(ApplyEventSpecific(@event, baseModel));
            }

            return(baseModel);
        }
Exemplo n.º 22
0
        private void WriteFeedItem(IFeedItem item)
        {
            this.XmlWriter.WriteStartElement("entry");
            this.XmlWriter.WriteElementString("id", item.Id);
            if (!string.IsNullOrEmpty(item.Title))
            {
                this.XmlWriter.WriteElementString("title", item.Title);
            }
            if (item.Uri != null)
            {
                this.XmlWriter.WriteStartElement("link");
                this.XmlWriter.WriteAttributeString("href", item.Uri.AbsoluteUri);
                this.XmlWriter.WriteEndElement();
            }
            if (item.Author != null)
            {
                this.XmlWriter.WriteStartElement("author");
                this.XmlWriter.WriteElementString("name", item.Author.Name);
                if (item.Author.Email != null)
                {
                    this.XmlWriter.WriteElementString("email", item.Author.Email);
                }
                this.XmlWriter.WriteEndElement();
            }
            string summary = !string.IsNullOrEmpty(item.Description) ? item.Description : item.Title;

            if (ContainsHtml(summary))
            {
                this.XmlWriter.WriteStartElement("summary");
                this.XmlWriter.WriteAttributeString("type", "html");
                this.XmlWriter.WriteCData(summary);
                this.XmlWriter.WriteEndElement();
            }
            else
            {
                this.XmlWriter.WriteElementString("summary", summary);
            }
            if (!item.PublishDate.Equals(DateTime.MinValue))
            {
                DateTime universalPublishDate = item.PublishDate.ToUniversalTime();
                this.XmlWriter.WriteElementString("updated", universalPublishDate.ToString("o", DateTimeFormatInfo.InvariantInfo));
            }
            this.XmlWriter.WriteEndElement();
        }
Exemplo n.º 23
0
		public Feed(string title, string id, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items, IAuthor author, Dictionary<XmlQualifiedName, string> customElements) {
			if(title == null) {
				throw new ArgumentNullException("title");
			}
			if(uri == null) {
				throw new ArgumentNullException("uri");
			}
			this.title = title;
			this.uri = uri;
			this.feedUri = feedUri ?? uri; //Feed Uri is mandatory if the feed shall be 100% standard compliant. But some older implementations does not have such value and therefor we accept null at the moment, shall probably be removed and cast an exeption. Maybe changed later.
			this.description = description;
			this.publishDate = publishDate;
			this.language = language;
			this.image = image;
			this.items = items;
			this.author = author;
			this.id = !string.IsNullOrEmpty(id) ? id : uri.AbsoluteUri;
			this.customElements = customElements ?? new Dictionary<XmlQualifiedName, string>();
		}
Exemplo n.º 24
0
        public void UpdateIfOwner(string currentUserId, Feed feed, IFeedItem entity)
        {
            var objFromDb = (from r in _db.Feed
                             join a in _db.ApplicationUserFeed on r.Id equals a.ObjectId
                             where a.ApplicationUserId.Equals(currentUserId) && r.Id == feed.Id
                             select r).FirstOrDefault();

            if (objFromDb == null)
            {
                throw new SafeException("An error ocurred.", new Exception(string.Format("Ownership relationship not found on record. currentUserId {0},  recipe.Id {1}", currentUserId, feed.Id)));
            }

            feed.Privacy               = entity.Privacy;
            objFromDb.Privacy          = entity.Privacy;
            objFromDb.Name             = entity.Name;
            objFromDb.Description      = entity.Description;
            objFromDb.ModifiedDateTime = entity.ModifiedDateTime;
            dbSet.Update(objFromDb);
        }
Exemplo n.º 25
0
        public LatestActivitiesItemViewModel Convert(IFeedItem item)
        {
            if (item is IntranetActivity activity)
            {
                var latestActivityModel = new LatestActivitiesItemViewModel
                {
                    Id          = activity.Id,
                    Type        = _intranetLocalizationService.Translate(activity.Type.ToString()),
                    Title       = activity.Title,
                    Description = activity.Description,
                    Owner       = _intranetMemberService.Get(item.OwnerId).ToViewModel(),
                    Links       = _linkService.GetLinks(activity.Id),
                    Dates       = item.PublishDate.ToDateTimeFormat().ToEnumerable()
                };
                return(latestActivityModel);
            }

            _logger.Warn <LatestActivitiesPanelViewModelConverter>("Feed item is not IntranetActivity (id={0};type={1})", item.Id, item.Type.ToInt());
            return(null);
        }
Exemplo n.º 26
0
        private IFeedEnclosure GetEnclosure(IFeedItem item)
        {
            try
            {
                System.Diagnostics.Debug.Print("Enclosure is null={0}",item.Enclosure == null);

                return (IFeedEnclosure)item.Enclosure;
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147023728)    
                {
                    // "Element not found. (Exception from HRESULT: 0x80070490)"
                    // ignore exception
                    System.Diagnostics.Debug.Print("Enclosure element not found exception.");
                    return null;
                }
                else
                    throw;
            }
        }
Exemplo n.º 27
0
	    public RssItem(IFeedItem source)
	    {

            // ** IFeedMetadata

            // ID
            _guid = new RssGuid
            {
                Value = source.ID.ToString()
            };

            // Title
            string title = source.Title;
            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;
            if (!string.IsNullOrEmpty(description))
            {
                Description = description;
            }

            // Author
            string author = source.Author;
            if (!string.IsNullOrEmpty(author))
            {
                Author = new RssPerson
                {
                    Name = author
                };
            }

            // Published
            DateTime? published = source.Published;
            if (published.HasValue)
            {
                PubDate = new RssDate(published.Value);
            }

            // Updated
            DateTime? updated = source.Updated;
            if (updated.HasValue)
            {
                PubDate = new RssDate(updated.Value);
            }

            // Link
            Uri link = source.Link;
            if (link != null)
            {
                Link = link.ToString();
            }

            // ImageLink
	        Uri imageLink = source.ImageLink;
	        if (imageLink != null)
	        {
	            _enclosure = new RssEnclosure
	            {
	                Url = imageLink.ToString(),
	                Type = "image"
	            };
	        }

            // ** IFeedItem

            // Content
            string content = source.Content;
            if (!string.IsNullOrEmpty(content))
            {
                ContentEncoded = content;
            }

            // ThreadLink
            Uri threadLink = source.ThreadLink;
            if (threadLink != null)
            {
                _wfwCommentRss = threadLink;
            }

            // ThreadCount
            int? threadCount = source.ThreadCount;
            if (threadCount.HasValue)
            {
                SlashComments = threadCount.Value;
            }

            // ThreadUpdated
            // Not in RDF
        }
Exemplo n.º 28
0
		public Feed(string title, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items) : this(title, string.Empty, uri, feedUri, description, publishDate, language, image, items, null, null) { }
Exemplo n.º 29
0
        private static IFeed PopulateFeed(Uri url, XmlReader reader, string namespaceUri, FeedType feedType, string language)
        {
            List <IFeedItem> items            = new List <IFeedItem>();
            string           link             = null;
            string           selfLink         = null;
            string           title            = null;
            string           description      = null;
            string           id               = null;
            IAuthor          author           = null;
            DateTime         channelBuildDate = DateTime.MinValue;
            Dictionary <XmlQualifiedName, string> customElements = new Dictionary <XmlQualifiedName, string>();
            bool nodeRead = false;

            while (nodeRead || reader.Read())
            {
                nodeRead = false;
                if (!reader.NodeType.Equals(XmlNodeType.Element))
                {
                    continue;
                }
                if (reader.NamespaceURI.Equals(namespaceUri) || reader.NamespaceURI.Equals(String.Empty))
                {
                    if (reader.LocalName.Equals("title"))
                    {
                        if (!reader.IsEmptyElement)
                        {
                            title = ReadElementString(reader);
                        }
                        continue;
                    }
                    if (feedType.Equals(FeedType.Rdf) || feedType.Equals(FeedType.Rss))
                    {
                        if (reader.IsEmptyElement)
                        {
                            continue;
                        }
                        if (reader.LocalName.Equals("description"))
                        {
                            description = ReadElementString(reader);
                            continue;
                        }
                        if (reader.LocalName.Equals("link"))
                        {
                            link = ReadElementString(reader);
                            continue;
                        }
                        if (reader.LocalName.Equals("language"))
                        {
                            language = ReadElementString(reader);
                            continue;
                        }
                        if (reader.LocalName.Equals("lastBuildDate"))
                        {
                            DateTime.TryParse(ReadElementString(reader), out channelBuildDate);
                            continue;
                        }
                        if (reader.LocalName.Equals("pubDate") && channelBuildDate.Equals(DateTime.MinValue))
                        {
                            DateTime.TryParse(ReadElementString(reader), out channelBuildDate);
                            continue;
                        }
                        if (reader.LocalName.Equals("item"))
                        {
                            IFeedItem rssItem = PopulateFeedItem(reader, feedType, url);
                            if (rssItem != null)
                            {
                                items.Add(rssItem);
                            }
                            continue;
                        }
                    }
                    else if (feedType.Equals(FeedType.Atom))
                    {
                        if (reader.LocalName.Equals("subtitle"))
                        {
                            if (!reader.IsEmptyElement)
                            {
                                description = ReadElementString(reader);
                            }
                            continue;
                        }
                        if (reader.LocalName.Equals("id"))
                        {
                            if (!reader.IsEmptyElement)
                            {
                                id = ReadElementString(reader);
                            }
                            continue;
                        }
                        if (reader.LocalName.Equals("link"))
                        {
                            string rel  = reader.GetAttribute("rel");
                            string href = reader.GetAttribute("href");
                            if (string.IsNullOrEmpty(link))
                            {
                                if (rel != null && href != null)
                                {
                                    if (rel.Equals("alternate"))
                                    {
                                        link = href;
                                    }
                                    if (rel.Equals("self"))
                                    {
                                        selfLink = href;
                                    }
                                }
                            }
                            continue;
                        }
                        if (reader.LocalName.Equals("author"))
                        {
                            author = PopulateAuthor(reader, feedType);
                            continue;
                        }
                        if (reader.LocalName.Equals("updated") || reader.LocalName.Equals("modified"))
                        {
                            if (!reader.IsEmptyElement)
                            {
                                DateTime.TryParse(ReadElementString(reader), out channelBuildDate);
                            }
                            continue;
                        }
                        if (reader.LocalName.Equals("entry") && !reader.IsEmptyElement)
                        {
                            IFeedItem rssItem = PopulateFeedItem(reader, feedType, url);
                            if (rssItem != null)
                            {
                                items.Add(rssItem);
                            }
                            continue;
                        }
                    }
                }

                XmlQualifiedName qname        = new XmlQualifiedName(reader.LocalName, reader.NamespaceURI);
                string           optionalNode = reader.ReadOuterXml();
                nodeRead = true;
                if (!customElements.ContainsKey(qname))
                {
                    customElements.Add(qname, optionalNode);
                }
            }
            Uri feedUrl     = GetUrl(link, url);
            Uri selfFeedUrl = GetUrl(selfLink, url);

            return(new Feed(title, id, feedUrl, selfFeedUrl, description, channelBuildDate, language, null, items.ToArray(), author, customElements));
        }
Exemplo n.º 30
0
	    public AtomEntry(IFeedItem source)
        {
            // ** IFeedMetadata

            // ID
            Id = source.ID.ToString();

            // Title
            string title = source.Title;
            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;
            if (!string.IsNullOrEmpty(description))
            {
                Summary = description;
            }

            // Author
            string author = source.Author;
            if (!string.IsNullOrEmpty(author))
            {
                Authors.Add(new AtomPerson
                {
                    Name = author
                });
            }

            // Published
            DateTime? published = source.Published;
            if (published.HasValue)
            {
                Updated = published.Value;
            }

            // Updated
            DateTime? updated = source.Updated;
            if (updated.HasValue)
            {
                Updated = updated.Value;
            }

            // Link
            Uri link = source.Link;
            if (link != null)
            {
                Links.Add(new AtomLink(link.ToString()));
            }

            // ImageLink
            Uri imageLink = source.ImageLink;
            if (imageLink != null)
            {
                Links.Add(new AtomLink
                {
                    Type = "image",
                    Href = imageLink.ToString(),
                    Relation = AtomLinkRelation.Enclosure
                });
            }

            // ** IFeedItem

            // Content
	        string content = source.Content;
	        if (!string.IsNullOrEmpty(content))
	        {
	            Content = new AtomContent(content);
	        }

            // ThreadLink
	        Uri threadLink = source.ThreadLink;
	        AtomLink replies = null;
	        if (threadLink != null)
	        {
	            replies = new AtomLink
	            {
	                Href = threadLink.ToString(),
                    Relation = AtomLinkRelation.Replies
	            };
                Links.Add(replies);
	        }

            // ThreadCount
	        int? threadCount = source.ThreadCount;
	        if (threadCount.HasValue && replies != null)
	        {
	            replies.ThreadCount = threadCount.Value;
	        }

            // ThreadUpdated
	        DateTime? threadUpdated = source.ThreadUpdated;
	        if (threadUpdated.HasValue && replies != null)
	        {
	            replies.ThreadUpdated = threadUpdated.Value;
	        }
        }
Exemplo n.º 31
0
 /// <summary>
 /// FeedItem から Status に無理矢理変換
 /// </summary>
 private Status ToTwitterStatus(IFeedItem item)
 {
     return new Status()
     {
         CreatedAt = item.PublishDate,
         Source = item.Link.ToString(),
         Text = item.Description,
         User = new User()
         {
             Name = item.Title,
             ScreenName = item.Author,
         },
     };
 }
Exemplo n.º 32
0
        /// <summary>
        /// 書式付き文字列を値で置き換える
        /// </summary>
        private String ReplaceFormattedString(String str, IFeedDocument doc, IFeedItem item)
        {
            Func<Object, String> conv = obj =>
            {
                var s = obj != null ? obj.ToString() : String.Empty;
                if (String.IsNullOrEmpty(s))
                    return String.Empty;

                // 改行コードを削除
                if (EnableRemoveLineBreak)
                    s = BindUtility.RemoveLineBreak(s);

                // HTMLタグを削除
                if (EnableRemoveHtmlTag)
                    s = BindUtility.RemoveHtmlTag(s);

                // HTML デコード
                return Utility.UnescapeCharReference(s);
            };

            if (doc != null)
            {
                str = ReplacePlaceholder(str, "feed_title", conv(doc.Title));
                str = ReplacePlaceholder(str, "feed_link", conv(doc.Link));
                str = ReplacePlaceholder(str, "feed_description", conv(doc.Description));
            }
            if (item != null)
            {
                str = ReplacePlaceholder(str, "author", conv(item.Author));
                str = ReplacePlaceholder(str, "link", conv(item.Link));
                str = ReplacePlaceholder(str, "title", conv(item.Title));
                str = ReplacePlaceholder(str, "description", conv(item.Description));
                str = ReplacePlaceholder(str, "publish_date", conv(item.PublishDate));
            }

            return str;
        }
Exemplo n.º 33
0
 public void AddItem(IFeedItem item)
 {
     AddChild <IFeedItem>(() => items.Add(item), item, x => x.Items);
 }
Exemplo n.º 34
0
        private String ReplaceFormattedString(String str, FeedReaderUrlConfiguration config, IFeedDocument doc, IFeedItem item)
        {
            Func<String, String> conv = s =>
            {
                if (String.IsNullOrEmpty(s))
                    return String.Empty;

                if (config.EnableRemoveLineBreak)
                {
                    // 改行コードを削除
                    s = _regexLineBreak.Replace(s, String.Empty);
                }
                else
                {
                    // 改行コードを LF(\n) に統一
                    s = _regexLineBreak.Replace(s, "\n");
                }

                // HTMLタグを削除
                if (config.EnableRemoveHtmlTag)
                {
                    s = _regexHtmlTag.Replace(s, String.Empty);
                }

                // HTML デコード
                s = Utility.UnescapeCharReference(s);

                return s;
            };

            // ${...} にすればよかった...
            StringBuilder sb = new StringBuilder(str);
            if (doc != null)
            {
                sb.Replace("#{feed_title}", conv(doc.Title));
                sb.Replace("#{feed_link}", conv(doc.Link.ToString()));
                sb.Replace("#{feed_description}", conv(doc.Description));
            }
            if (item != null)
            {
                sb.Replace("#{author}", conv(item.Author));
                sb.Replace("#{link}", conv(item.Link.ToString()));
                sb.Replace("#{title}", conv(item.Title));
                sb.Replace("#{description}", conv(item.Description));
                sb.Replace("#{publish_date}", conv(item.PublishDate.ToString()));
            }

            return sb.ToString();
        }
Exemplo n.º 35
0
 public FeedReceiveEventArgs(IFeedDocument doc, IFeedItem item)
 {
     Document = doc;
     Item = item;
 }
Exemplo n.º 36
0
 public void UseItems <TMap>() where TMap : FeedItem <T>, new()
 {
     _itemConfiguration = new TMap();
 }
Exemplo n.º 37
0
 public Feed UpdateFeed(string currentApplicationUserId, Feed feed, IFeedItem item)
 {
     _unitOfWork.Feed.UpdateIfOwner(currentApplicationUserId, feed, item);
     return(feed);
 }
Exemplo n.º 38
0
        public RdfItem(IFeedItem source)
        {
            // ** IFeedMetadata

            // ID
            Link = source.ID.ToString();

            // Title
            string title = source.Title;

            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;

            if (!string.IsNullOrEmpty(description))
            {
                Description = description;
            }

            // Author
            string author = source.Author;

            if (!string.IsNullOrEmpty(author))
            {
                DublinCore[DublinCore.TermName.Creator] = author;
            }

            // Published
            DateTime?published = source.Published;

            if (published.HasValue)
            {
                DublinCore[DublinCore.TermName.Date] = ConvertToString(published.Value);
            }

            // Updated
            DateTime?updated = source.Updated;

            if (updated.HasValue)
            {
                DublinCore[DublinCore.TermName.Date] = ConvertToString(updated.Value);
            }

            // Link
            Uri link = source.Link;

            if (link != null)
            {
                Link = link.ToString();
            }

            // ImageLink
            // Not in RDF

            // ** IFeedItem

            // Content
            string content = source.Content;

            if (!string.IsNullOrEmpty(content))
            {
                ContentEncoded = content;
            }

            // ThreadLink
            Uri threadLink = source.ThreadLink;

            if (threadLink != null)
            {
                _wfwCommentRss = threadLink;
            }

            // ThreadCount
            int?threadCount = source.ThreadCount;

            if (threadCount.HasValue)
            {
                SlashComments = threadCount.Value;
            }

            // ThreadUpdated
            // Not in RDF
        }
Exemplo n.º 39
0
        public async Task <Feed> AddFeedWithRelationship(string currentApplicationUserId, IFeedItem feedItem, bool saveOnRelationshipInsert = true)
        {
            var feed = _unitOfWork.Feed.AddFromIFeedItem(feedItem);
            await _unitOfWork.SaveAsync();

            _unitOfWork.Feed.AddOwnerRelationship(currentApplicationUserId, feed, new ApplicationUserFeed());

            if (saveOnRelationshipInsert == true)
            {
                await _unitOfWork.SaveAsync();
            }

            return(feed);
        }
Exemplo n.º 40
0
 private bool IsGroupActivity(Guid groupId, IFeedItem item) =>
 IsGroupActivity(List(groupId), item);
Exemplo n.º 41
0
 public void RemoveItem(IFeedItem item)
 {
     RemoveChild <IFeedItem>(() => items.Remove(item), item, x => x.Items);
 }
Exemplo n.º 42
0
		public Feed(string title, Guid id, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items, IAuthor author, Dictionary<XmlQualifiedName, string> customElements) : this(title, "urn:uuid:" + id, uri, feedUri, description, publishDate, language, image, items, author, customElements) { }
Exemplo n.º 43
0
        public RdfItem(IFeedItem source)
        {
            // ** IFeedMetadata

            // ID
            Link = source.ID.ToString();

            // Title
            string title = source.Title;
            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;
            if (!string.IsNullOrEmpty(description))
            {
                Description = description;
            }

            // Author
            string author = source.Author;
            if (!string.IsNullOrEmpty(author))
            {
                DublinCore[DublinCore.TermName.Creator] = author;
            }

            // Published
            DateTime? published = source.Published;
            if (published.HasValue)
            {
                DublinCore[DublinCore.TermName.Date] = ConvertToString(published.Value);
            }

            // Updated
            DateTime? updated = source.Updated;
            if (updated.HasValue)
            {
                DublinCore[DublinCore.TermName.Date] = ConvertToString(updated.Value);
            }

            // Link
            Uri link = source.Link;
            if (link != null)
            {
                Link = link.ToString();
            }

            // ImageLink
            // Not in RDF

            // ** IFeedItem

            // Content
            string content = source.Content;
            if (!string.IsNullOrEmpty(content))
            {
                ContentEncoded = content;
            }

            // ThreadLink
            Uri threadLink = source.ThreadLink;
            if (threadLink != null)
            {
                _wfwCommentRss = threadLink;
            }

            // ThreadCount
            int? threadCount = source.ThreadCount;
            if (threadCount.HasValue)
            {
                SlashComments = threadCount.Value;
            }

            // ThreadUpdated
            // Not in RDF
        }
Exemplo n.º 44
0
 private bool IsCentralFeedActivity(IFeedItem item) =>
 (item as IGroupActivity)?.GroupId == null;
Exemplo n.º 45
0
		public Feed(string title, string id, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items, Dictionary<XmlQualifiedName, string> customElements) : this(title, id, uri, feedUri, description, publishDate, language, image, items, null, customElements) { }
Exemplo n.º 46
0
        public RssItem(IFeedItem source)
        {
            // ** IFeedMetadata

            // ID
            _guid = new RssGuid
            {
                Value = source.ID.ToString()
            };

            // Title
            string title = source.Title;

            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;

            if (!string.IsNullOrEmpty(description))
            {
                Description = description;
            }

            // Author
            string author = source.Author;

            if (!string.IsNullOrEmpty(author))
            {
                Author = new RssPerson
                {
                    Name = author
                };
            }

            // Published
            DateTime?published = source.Published;

            if (published.HasValue)
            {
                PubDate = new RssDate(published.Value);
            }

            // Updated
            DateTime?updated = source.Updated;

            if (updated.HasValue)
            {
                PubDate = new RssDate(updated.Value);
            }

            // Link
            Uri link = source.Link;

            if (link != null)
            {
                Link = link.ToString();
            }

            // ImageLink
            Uri imageLink = source.ImageLink;

            if (imageLink != null)
            {
                _enclosure = new RssEnclosure
                {
                    Url  = imageLink.ToString(),
                    Type = "image"
                };
            }

            // ** IFeedItem

            // Content
            string content = source.Content;

            if (!string.IsNullOrEmpty(content))
            {
                ContentEncoded = content;
            }

            // ThreadLink
            Uri threadLink = source.ThreadLink;

            if (threadLink != null)
            {
                _wfwCommentRss = threadLink;
            }

            // ThreadCount
            int?threadCount = source.ThreadCount;

            if (threadCount.HasValue)
            {
                SlashComments = threadCount.Value;
            }

            // ThreadUpdated
            // Not in RDF
        }
Exemplo n.º 47
0
		public Feed(string title, string id, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items, IAuthor author) : this(title, id, uri, feedUri, description, publishDate, language, image, items, author, null) { }
 public bool Equals(IFeedItem other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 49
0
		public Feed(string title, Guid id, Uri uri, Uri feedUri, string description, DateTime publishDate, string language, IFeedImage image, IFeedItem[] items) : this(title, "urn:uuid:" + id, uri, feedUri, description, publishDate, language, image, items, null, null) { }
Exemplo n.º 50
0
        /// <summary>
        /// フィードのエントリを送信する。
        /// </summary>
        private void Send(IFeedDocument doc, IFeedItem item, Boolean isFirstTime)
        {
            String replacedSender = ReplaceFormattedString(SenderNick, doc, item);
            String replacedContent = ReplaceFormattedString(ContentFormat, doc, item);
            replacedContent = AddIn.ApplyTypableMap(replacedContent, ToTwitterStatus(item));
            replacedContent = AddIn.ApplyDateTime(replacedContent, item.PublishDate, isFirstTime);
            SendMessage(replacedSender, replacedContent, isFirstTime);

            AddIn.SleepClientMessageWait();
        }
Exemplo n.º 51
0
        private bool IsGroupActivity(IEnumerable <Guid> groupIds, IFeedItem item)
        {
            var assignedGroupId = _groupActivityService.GetGroupId(item.Id);

            return(assignedGroupId.HasValue && groupIds.Contains(assignedGroupId.Value) && !_groupService.Get(assignedGroupId.Value).IsHidden);
        }
Exemplo n.º 52
0
        public AtomEntry(IFeedItem source)
        {
            // ** IFeedMetadata

            // ID
            Id = source.ID.ToString();

            // Title
            string title = source.Title;

            if (!string.IsNullOrWhiteSpace(title))
            {
                Title = title;
            }

            // Description
            string description = source.Description;

            if (!string.IsNullOrEmpty(description))
            {
                Summary = description;
            }

            // Author
            string author = source.Author;

            if (!string.IsNullOrEmpty(author))
            {
                Authors.Add(new AtomPerson
                {
                    Name = author
                });
            }

            // Published
            DateTime?published = source.Published;

            if (published.HasValue)
            {
                Updated = published.Value;
            }

            // Updated
            DateTime?updated = source.Updated;

            if (updated.HasValue)
            {
                Updated = updated.Value;
            }

            // Link
            Uri link = source.Link;

            if (link != null)
            {
                Links.Add(new AtomLink(link.ToString()));
            }

            // ImageLink
            Uri imageLink = source.ImageLink;

            if (imageLink != null)
            {
                Links.Add(new AtomLink
                {
                    Type     = "image",
                    Href     = imageLink.ToString(),
                    Relation = AtomLinkRelation.Enclosure
                });
            }

            // ** IFeedItem

            // Content
            string content = source.Content;

            if (!string.IsNullOrEmpty(content))
            {
                Content = new AtomContent(content);
            }

            // ThreadLink
            Uri      threadLink = source.ThreadLink;
            AtomLink replies    = null;

            if (threadLink != null)
            {
                replies = new AtomLink
                {
                    Href     = threadLink.ToString(),
                    Relation = AtomLinkRelation.Replies
                };
                Links.Add(replies);
            }

            // ThreadCount
            int?threadCount = source.ThreadCount;

            if (threadCount.HasValue && replies != null)
            {
                replies.ThreadCount = threadCount.Value;
            }

            // ThreadUpdated
            DateTime?threadUpdated = source.ThreadUpdated;

            if (threadUpdated.HasValue && replies != null)
            {
                replies.ThreadUpdated = threadUpdated.Value;
            }
        }
Exemplo n.º 53
0
 private bool IsGroupActivity(Guid groupId, IFeedItem item) =>
 IsGroupActivity(groupId.ToEnumerable(), item);