private PhotoInstance?GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType[] photoTypes) { IEnumerator <photo> phEn = ni.photos.GetEnumerator(); if (!phEn.MoveNext()) { return(null); } PhotoInstance phIns = new PhotoInstance(); bool found = false; photo ph = phEn.Current; IEnumerator <photo.Instance> phIEn = ph.Instances.GetEnumerator(); while (phIEn.MoveNext()) { foreach (enumeratedTypes.enumPhotoInstanceType phType in photoTypes) { if (phIEn.Current.type == phType) { phIns.Width = phIEn.Current.width; phIns.Height = phIEn.Current.height; phIns.Url = phIEn.Current.url; phIns.Type = phIEn.Current.type; phIns.Type = phType; string cleanedUrl = phIns.Url; if (cleanedUrl.IndexOf('?') >= 0) { cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?')); } string phTypeSlug = Slugify(phType); phIns.DestinationFileName = Slugify(ni.headline) + (phTypeSlug == "" ? "" : "-" + phTypeSlug) + Path.GetExtension(cleanedUrl); found = true; break; } } if (found) { phIns.AltText = phEn.Current.htmlAlt; phIns.Caption = phEn.Current.caption; phIns.Id = phEn.Current.id; phIns.Orientation = phEn.Current.orientation; break; } } if (!found) { return(null); } return(phIns); }
private Category[] GetNewsItemCategories(newsItem ni) { List <Category> cats = new List <Category>(); IEnumerator <category> catEn = ni.categories.GetEnumerator(); while (catEn.MoveNext()) { cats.Add(new Category(catEn.Current.name, "")); } return(cats.ToArray()); }
protected NewsItem GetNewsItem(newsItem item, out bool isNew) { NewsItem news; isNew = false; var result = from n in objectScope.Extent<NewsItem>() where n.NewsID == item.id select n; if (result.Count() <= 0) { news = new NewsItem(); isNew = true; } else { news = (NewsItem)result.First(); } return news; }
private Post ConvertToPost(newsItem ni) { Post p = new Post(); p.Author = "Admin"; foreach (category c in ni.categories) { p.Categories.Add(new Category(GetCleanCategoryName(c.name), "")); } p.Content = ni.text; string importedDate = _settings.GetSingleValue("ImportedDate"); switch (importedDate) { case "Published Date": p.DateCreated = ni.publishDate; break; case "Last Modified Date": p.DateCreated = ni.lastModifiedDate; break; default: p.DateCreated = ni.createdDate; break; } p.DateModified = ni.lastModifiedDate; p.Description = ni.extract; p.Slug = Slugify(ni.headline); if (!string.IsNullOrEmpty(ni.htmlMetaKeywords)) { p.Tags.AddRange(ni.htmlMetaKeywords.Split(new char[] { ',' })); } p.Title = ni.headline.Trim(); return(p); }
protected NewsItem LoadNewsItem(newsItem newsFeed, NewsItem dataItem) { IList<Category> categories = new List<Category>(); dataItem.Categories.Clear(); bool isNew; foreach(category cat in newsFeed.categories) { Category category = GetCategory(cat, out isNew); category = LoadCategoryItem(cat, category); dataItem.Categories.Add(category); } dataItem.NewsID = newsFeed.id; dataItem.ByLine = newsFeed.byLine; dataItem.ClientQuote = newsFeed.clientQuote; dataItem.CreatedDate = newsFeed.createdDate; dataItem.Encoding = newsFeed.encoding; dataItem.Extract = newsFeed.extract; dataItem.Format = newsFeed.format; dataItem.Headline = newsFeed.headline; dataItem.HtmlMetaDescripiton = newsFeed.htmlMetaDescription; dataItem.HtmlMetaKeywords = newsFeed.htmlMetaKeywords; dataItem.HtmlMetaLanguage = newsFeed.htmlMetaLanguage; dataItem.HtmlTitle = newsFeed.htmlTitle; dataItem.LastModifiedDate = newsFeed.lastModifiedDate; dataItem.Priority = newsFeed.priority; dataItem.PublishDate = newsFeed.publishDate; dataItem.Source = newsFeed.source; dataItem.State = (int)newsFeed.state; dataItem.TweetText = newsFeed.tweetText; dataItem.Txt = newsFeed.text; dataItem.Url = Regex.Replace(newsFeed.headline.Trim().ToLower(), @"[^\p{L}\-\!\$\(\)\=\@\d_\'\.]+", "-"); dataItem.Tags = newsFeed.tags; //dataItem.Categories = categories; return dataItem; }
private PhotoInstance?GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType photoType) { return(GetPhotoInstance(ni, new enumeratedTypes.enumPhotoInstanceType[] { photoType })); }
private PhotoInstance? GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType[] photoTypes) { IEnumerator<photo> phEn = ni.photos.GetEnumerator(); if (!phEn.MoveNext()) return null; PhotoInstance phIns = new PhotoInstance(); bool found = false; photo ph = phEn.Current; IEnumerator<photo.Instance> phIEn = ph.Instances.GetEnumerator(); while (phIEn.MoveNext()) { foreach (enumeratedTypes.enumPhotoInstanceType phType in photoTypes) { if (phIEn.Current.type == phType) { phIns.Width = phIEn.Current.width; phIns.Height = phIEn.Current.height; phIns.Url = phIEn.Current.url; phIns.Type = phIEn.Current.type; phIns.Type = phType; string cleanedUrl = phIns.Url; if (cleanedUrl.IndexOf('?') >= 0) cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?')); string phTypeSlug = Slugify(phType); phIns.DestinationFileName = Slugify(ni.headline) + (phTypeSlug == "" ? "" : "-" + phTypeSlug) + Path.GetExtension(cleanedUrl); found = true; break; } } if (found) { phIns.AltText = phEn.Current.htmlAlt; phIns.Caption = phEn.Current.caption; phIns.Id = phEn.Current.id; phIns.Orientation = phEn.Current.orientation; break; } } if (!found) return null; return phIns; }
private PhotoInstance? GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType photoType) { return GetPhotoInstance(ni, new enumeratedTypes.enumPhotoInstanceType[] { photoType }); }
private Category[] GetNewsItemCategories(newsItem ni) { List<Category> cats = new List<Category>(); IEnumerator<category> catEn = ni.categories.GetEnumerator(); while (catEn.MoveNext()) cats.Add(new Category(catEn.Current.name, "")); return cats.ToArray(); }
//The constructor initialises the component, then //sets the data context to itself and sets the FeedItem //property accordingly. private void MenuItem_Click(object sender, RoutedEventArgs e) { bool ratingValid = false; //This variable sets up a loop in order to allow //for a while loop to be used while (ratingValid == false) { //The while loop allows for the rating input to be retried //by the user, or cancelled if they change their mind ratingStr = Interaction.InputBox("Please enter an importance rating from 0.0 to 10.0 to 1 decimal place" + " (Entering nothing will cancel this operation, as will pressing the cancel button) ", "Assign rating", ""); //A VisualBasic InputBox is created and displays the following message, with a suitable title and blank //default response. The input response is stored in a suitable variable, ratingStr, defined at the start of //the code for this object. if (ratingStr == "") { break; } //Pressing the cancel button on the InputBox will always return an empty string, so this if statement //is used to detect the cancellation event and break the while loop try { ratingDbl = Double.Parse(ratingStr); } //A try-catch block is used, and an attempt is made to parse the input string to a Double catch (Exception) { MessageBox.Show("Entered rating is not a valid number, please try again or cancel", "Invalid Format", MessageBoxButton.OK); continue; } //Any exception is caught here. This would be from an invalid parse, due to input of non-numeric characters. //As such, the following dialog box alerts the user of this, and continues the while loop to allow for //input to be retried. ratingDbl = Math.Round(ratingDbl, 1); //If the parsing is a success, the Double value is rounded to one decimal place if (ratingDbl >= 0.0 && ratingDbl <= 10.0) { newsItem currentItem = FeedItem; currentItem.Rating = ratingDbl; FeedItem = currentItem; ratingValid = true; } //If the rating input is between the boundaries of 0 and 10 inclusive, then the rating of the //newsItem object contained in the TickerItemEelement object is set to this input rating value //by first retrieving the stored newsItem, setting the rating value, and then storing the altered //newsItem //ratingValid is thereafter set to true, breaking the while loop. else { MessageBox.Show("Entered rating is not between 0.0 and 10.0, please try again", "Invalid Range", MessageBoxButton.OK); continue; } //If the rating value is outside of these boundaries, the following is displayed, and the //while loop continues to allow the user to retry inputting the rating } if (ratingStr == "") { } //If the input was cancelled then the while loop breaks, and so to stop //the addition of an unwanted item to the watchLater database, this if statement //detects that eventuality and ensures that no action is taken else { DataRoutines.addItem(this); } //If the if statement above is not triggered, then the TickerItemElement object //is added to the database using the DataRoutines function addItem. }
private Post ConvertToPost(newsItem ni) { Post p = new Post(); p.Author = "Admin"; foreach (category c in ni.categories) p.Categories.Add(new Category(GetCleanCategoryName(c.name), "")); p.Content = ni.text; string importedDate = _settings.GetSingleValue("ImportedDate"); switch (importedDate) { case "Published Date": p.DateCreated = ni.publishDate; break; case "Last Modified Date": p.DateCreated = ni.lastModifiedDate; break; default: p.DateCreated = ni.createdDate; break; } p.DateModified = ni.lastModifiedDate; p.Description = ni.extract; p.Slug = Slugify(ni.headline); if (!string.IsNullOrEmpty(ni.htmlMetaKeywords)) p.Tags.AddRange(ni.htmlMetaKeywords.Split(new char[] { ',' })); p.Title = ni.headline.Trim(); return p; }
public void GetNewsItemTest() { NewsServiceClient client = new NewsServiceClient(); byte[] bytes = Encoding.UTF8.GetBytes("hola mundo"); newsItem nItem = new newsItem() { title = "News Item Title", body = "News Item Body", reportedBy = "4ab87d67-db83-4364-9ded-d6dd4e616a34", picture = bytes, pictureScale = 16.9, pictureScaleSpecified = true, pictureSize = bytes.Length, pictureSizeSpecified = true, rating = 10, ratingSpecified = true, reviews = 50, reviewsSpecified = true, tags = new string[] { "tag1", "tag2", "tag3" }, categories = new newsItemEntry[] { new newsItemEntry() { key="sport", value="Sports" }, new newsItemEntry() { key="economy", value="Bussiness and Economy" } } }; string id = client.ReportNewsItem(nItem); newsItem nItemFromDB = client.GetNewsItem(id); Assert.IsNotNull(nItemFromDB.id); Assert.AreEqual<string>(id, nItemFromDB.id); Assert.AreEqual<string>("News Item Title", nItemFromDB.title); Assert.AreEqual<string>("News Item Body", nItemFromDB.body); Assert.AreEqual<string>("4ab87d67-db83-4364-9ded-d6dd4e616a34", nItemFromDB.reportedBy); client.DeleteNewsItem(id); }
public void GetLatestNewsTest() { NewsServiceClient client = new NewsServiceClient(); byte[] bytes = Encoding.UTF8.GetBytes("hola mundo"); newsItem nItem = new newsItem() { title = "News Item1 Title", body = "News Item1 Body", reportedBy = "4ab87d67-db83-4364-9ded-d6dd4e616a34", picture = bytes, pictureScale = 16.9, pictureScaleSpecified = true, pictureSize = bytes.Length, pictureSizeSpecified = true, rating = 10, ratingSpecified = true, reviews = 50, reviewsSpecified = true, tags = new string[] { "tag1", "tag2", "tag3" }, categories = new newsItemEntry[] { new newsItemEntry() { key="sport", value="Sports" }, new newsItemEntry() { key="economy", value="Bussiness and Economy" } } }; string id1 = client.ReportNewsItem(nItem); bytes = Encoding.UTF8.GetBytes("hola guapa"); nItem = new newsItem() { title = "News Item2 Title", body = "News Item2 Body", reportedBy = "4ab87d67-8888-4444-9999-d6dd4e616a34", picture = bytes, pictureScale = 16.9, pictureScaleSpecified = true, pictureSize = bytes.Length, pictureSizeSpecified = true, rating = 10, ratingSpecified = true, reviews = 50, reviewsSpecified = true, tags = new string[] { "tag4", "tag5" }, categories = new newsItemEntry[] { new newsItemEntry() { key="culture", value="Culture and Art" }, new newsItemEntry() { key="international", value="International" } } }; string id2 = client.ReportNewsItem(nItem); newsItem[] latest = client.GetLatestNews(1); Assert.IsNotNull(latest); Assert.AreEqual<int>(1, latest.Length); client.DeleteNewsItem(id1); client.DeleteNewsItem(id2); }
public void ModifyNewsItemTest() { NewsServiceClient client = new NewsServiceClient(); byte[] bytes = Encoding.UTF8.GetBytes("hola mundo"); newsItem nItem = new newsItem() { title = "News Item Title", body = "News Item Body", reportedBy = "4ab87d67-db83-4364-9ded-d6dd4e616a34", picture = bytes, pictureScale = 16.9, pictureScaleSpecified = true, pictureSize = bytes.Length, pictureSizeSpecified = true, rating = 10, ratingSpecified = true, reviews = 50, reviewsSpecified = true }; string id = client.ReportNewsItem(nItem); newsItem nItemFromDB = client.GetNewsItem(id); nItemFromDB.title = "Modified title"; nItemFromDB.body = "Modified body"; nItemFromDB.rating = 5; nItemFromDB.ratingSpecified = true; nItemFromDB.reviews = 1; nItemFromDB.reviewsSpecified = true; client.ModifyNewsItem(nItemFromDB); nItemFromDB = client.GetNewsItem(nItemFromDB.id); Assert.IsNotNull(nItemFromDB); Assert.AreEqual<string>(id, nItemFromDB.id); Assert.AreEqual<string>("Modified title", nItemFromDB.title); Assert.AreEqual<string>("Modified body", nItemFromDB.body); Assert.AreEqual<short>(5, nItemFromDB.rating); Assert.AreEqual<int>(1, nItemFromDB.reviews); client.DeleteNewsItem(id); }
private Post FindPost(newsItem ni) { return Post.Posts.Find(p => p.Title.Trim() == ni.headline.Trim()); }
private Post FindPost(newsItem ni) { return(Post.Posts.Find(p => p.Title.Trim() == ni.headline.Trim())); }
//The FeedItem property stores a newsItem which can //be set and retrieved public TickerItemElement(newsItem itemIn) { InitializeComponent(); DataContext = this; FeedItem = itemIn; }