public static Post LoadFromRow (IList row) { var result = new Post { Id = (int)row[0], Name = (string)row[1], Description = (string)row[2], Score = (int)row[3], Views = (int)row[4], Answers = (int)row[5], Tags = row[6].FromDBNull<string> (), DateAsked = (DateTime)row[7], DateFirstAnswered = row[8].FromDBNull<DateTime?> (), DateLastAnswered = row[9].FromDBNull<DateTime?> (), Asker = row[10].FromDBNull<string> (), AcceptedAnswerId = row[11].FromDBNull<int?> (), AcceptedAnswer = row[12].FromDBNull<string> (), TopAnswerId = row[13].FromDBNull<int?> (), TopAnswer = row[14].FromDBNull<string> (), Favorites = (int)row[15], }; return result; }
internal static XElement PivotizePost (Post post) { #region <Item Id="3232" Href="3232" Name="What are the best Excel tips?"> var itemNode = new XElement ("Item"); itemNode.SetAttributeValue ("Img", "#{0}".FormatInvariant(post.Id)); itemNode.SetAttributeValue ("Id", post.Id); itemNode.SetAttributeValue ("Href", post.Id); itemNode.SetAttributeValue ("Name", post.Name); #region <Description>What are your best tips/not so known features of excel?</Description> var descriptionNode = new XElement ("Description", post.Description.CleanHtml ()); itemNode.Add (descriptionNode); #endregion #region <Facets> var facetsNode = new XElement("Facets"); #region <Facet Name="Score"><Number Value="7" /></Facet> facetsNode.AddFacet (FacetType.Number, "Score", post.Score); #endregion #region <Facet Name="Views"><Number Value="761" /></Facet> facetsNode.AddFacet (FacetType.Number, "Views", post.Views); #endregion #region <Facet Name="Answers"><Number Value="27" /></Facet> facetsNode.AddFacet (FacetType.Number, "Answers", post.Answers); #endregion if (post.Tags != null) { var tags = post.Tags.ParseTags (); #region <Facet Name="Tagged"><String Value="excel" /><String Value="tips-and-tricks" /></Facet> facetsNode.AddFacet (FacetType.String, "Tagged", tags.Map (t => (object) t)); #endregion #region <Facet Name="Related Tags"><Link Href="excel.cxml" Name="excel" /></Facet> // TODO: the "related tags" files should be binned! facetsNode.AddFacetLink ("Related Tags", tags.Map (t => new Pair<string, string> (t + ".cxml", t))); #endregion } #region <Facet Name="Date asked"><DateTime Value="2009-07-15T18:41:08" /></Facet> facetsNode.AddFacet (FacetType.DateTime, "Date asked", post.DateAsked.ToString ("s")); #endregion #region <Facet Name="Is answered?"><String Value="yes" /></Facet> facetsNode.AddFacet (FacetType.String, "Is answered?", post.DateFirstAnswered.HasValue.YesNo ()); #endregion #region <Facet Name="Date first answered"><DateTime Value="2009-07-15T18:41:08" /></Facet> if (post.DateFirstAnswered.HasValue) { facetsNode.AddFacet (FacetType.DateTime, "Date first answered", post.DateFirstAnswered.Value.ToString ("s")); } #endregion #region <Facet Name="Date last answered"><DateTime Value="2010-06-16T09:46:07" /></Facet> if (post.DateLastAnswered.HasValue) { facetsNode.AddFacet (FacetType.DateTime, "Date last answered", post.DateLastAnswered.Value.ToString ("s")); } #endregion #region <Facet Name="Asker"><String Value="Bob" /></Facet> if (post.Asker != null) { facetsNode.AddFacet (FacetType.String, "Asker", post.Asker); } #endregion #region <Facet Name="Has accepted answer?"><String Value="yes" /></Facet> facetsNode.AddFacet (FacetType.String, "Has accepted answer?", post.AcceptedAnswerId.HasValue.YesNo ()); #endregion #region <Facet Name="Accepted Answer"><LongString Value="My best advice for Excel..." /></Facet> if (post.AcceptedAnswer != null) { facetsNode.AddFacet (FacetType.LongString, "Accepted Answer", post.AcceptedAnswer.CleanHtml ()); // TODO: link to accepted answer // Accepted Answer Details: Link, Author(s), Score } #endregion #region <Facet Name="Top Answer"><LongString Value="In-cell graphs..." /></Facet> if (post.TopAnswer != null) { facetsNode.AddFacet (FacetType.LongString, "Top Answer", post.TopAnswer.CleanHtml ()); // TODO: link to top answer // Top Answer Details: Link, Author(s), Score } #endregion #region <Facet Name="Is favorite?"><String Value="yes" /></Facet> facetsNode.AddFacet (FacetType.String, "Is favorite?", ( post.Favorites > 0 ).YesNo ()); #endregion #region <Facet Name="Favorites"><Number Value="10" /></Facet> facetsNode.AddFacet (FacetType.Number, "Favorites", post.Favorites); #endregion itemNode.Add (facetsNode); #endregion return itemNode; #endregion }
internal static void ImagePost (Post post, Page pageTemplate, ImageFormat imageFormat, Stream destination) { pageTemplate.DataBindAndWait (post); var imageSource = pageTemplate.ToBitmapSource (); var bitmap = imageSource.ConvertToGdiPlusBitmap (); bitmap.Save (destination, imageFormat); }