Skip to content

Commit

Permalink
updating content
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncanma committed Apr 17, 2019
1 parent d6d5e71 commit a74df3b
Show file tree
Hide file tree
Showing 16 changed files with 2,258 additions and 2,238 deletions.
8 changes: 7 additions & 1 deletion .gitignore
@@ -1 +1,7 @@
public
public
public/index.html
public/404.html
public/index.xml
public/sitemap.xml
public/tags/index.html
public/tags/index.xml
45 changes: 20 additions & 25 deletions content/Blog/a-bug-in-my-rss-generator-but-is-it-really-invalid.md
Expand Up @@ -5,31 +5,26 @@ type: posts
---
The RSS generator for MSDN, creator of [this feed](http://msdn.microsoft.com/rss.xml), and many more ... has a small problem. Way upstream, when various people inside the company enter information about an upcoming headline, they have the ability to specify a URL to a download. The intent was for this to be a URL to an actual downloadable file, so when I generate an RSS item from that headline entry, I take that URL and turn it into an enclosure entry in the RSS file.

<pre>
&lt;item&gt;
&lt;title&gt;Read about Atlas - Ajax for ASP.NET&lt;/title&gt;
&lt;description&gt;ASP.NET "Atlas" is a package of
new Web development technologies that integrates an extensive set of
client script libraries with the rich, server-based development
platform of ASP.NET 2.0. &lt;/description&gt;
&lt;link&gt;http://msdn.microsoft.com/asp.net/future/&lt;/link&gt;
&lt;dc:creator&gt;Microsoft Corporation&lt;/dc:creator&gt;
&lt;category domain="msdndomain:ContentType"&gt;Link&lt;/category&gt;
&lt;category domain="msdndomain:Audience"&gt;Developers&lt;/category&gt;
&lt;category domain="msdndomain:Hardware"&gt;CPU&lt;/category&gt;
&lt;category domain="msdndomain:Operating Systems"&gt;Windows&lt;/category&gt;
&lt;category domain="msdndomain:Subject"&gt;Web development&lt;/category&gt;
&lt;msdn:headlineImage /&gt;
&lt;msdn:headlineIcon&gt;http://msdn.microsoft.com/msdn-online/shared/graphics/icons/offsite.gif&lt;/msdn:headlineIcon&gt;
&lt;msdn:contentType&gt;Link&lt;/msdn:contentType&gt;
&lt;msdn:simpleDate&gt;Sep 19&lt;/msdn:simpleDate&gt;
<span style="background-color: #FFFF00">&lt;enclosure url="
http://go.microsoft.com/fwlink/?LinkId=52384" length="17437" type="text/html; charset=utf-8" /&gt;</span>
&lt;guid isPermaLink="false"&gt;Titan_2519&lt;/guid&gt;
&lt;pubDate&gt;Mon, 19 Sep 2005 18:20:40 GMT&lt;/pubDate&gt;
&lt;/item&gt;

</pre>
```xml
<item>
<title>Read about Atlas - Ajax for ASP.NET</title>
<description>ASP.NET "Atlas" is a package of new Web development technologies that integrates an extensive set of client script libraries with the rich, server-based development platform of ASP.NET 2.0. </description>
<link>http://msdn.microsoft.com/asp.net/future/</link>
<dc:creator>Microsoft Corporation</dc:creator>
<category domain="msdndomain:ContentType">Link</category>
<category domain="msdndomain:Audience">Developers</category>
<category domain="msdndomain:Hardware">CPU</category>
<category domain="msdndomain:Operating Systems">Windows</category>
<category domain="msdndomain:Subject">Web development</category>
<msdn:headlineImage />
<msdn:headlineIcon>http://msdn.microsoft.com/msdn-online/shared/graphics/icons/offsite.gif</msdn:headlineIcon>
<msdn:contentType>Link</msdn:contentType>
<msdn:simpleDate>Sep 19</msdn:simpleDate>
<enclosure url="http://go.microsoft.com/fwlink/?LinkId=52384" length="17437" type="text/html;charset=utf-8" />
<guid isPermaLink="false">Titan_2519</guid>
<pubDate>Mon, 19 Sep 2005 18:20:40 GMT</pubDate>
</item>
```

This generally works fine, I make a HEAD request with that URL which gives me back the MIME type and the Content Length, both of which are needed for the enclosure element in the RSS item. Sometimes though, people put in a URL to the download's landing page, not the download itself. There are good reasons for this, as the download page often contains useful information and/or multiple localized versions of the download, but it was not what I expected. In this case, I put the enclosure in with the MIME type I get back from that URL, which ends up being 'text/html' and with a byte size that reflects the size of the landing page.

Expand Down
Expand Up @@ -14,7 +14,24 @@ This seemed really odd to me, since much of the UI of the .Text posting page, ed

If you haven't looked at the .Text source yourself, you might be wondering why adding these elements to one feed wouldn't have added them to all of the feeds, because all RSS feeds are probably running through the same code path. While this is mostly true, they are running through the same ASP.NET handler and through the same feed generation code, the category-based feeds use a different stored procedure to retrieve their entries than the feeds that I have updated, and I had to make a change to the database query to return the list of categories along with each item. What I ended up doing, (and I'm not sure about the performance of this code but it is so highly cached that I'm not particularly worried about it for this use), was using a Function to retrieve the list of categories as a semi-colon deliminated string given a PostID (note that if you host multiple blogs on your .Text instance that this function should take both a BlogID **and** a PostID... I'll have to update this for the multi-blog case).

<pre> <span class="TSql_ReservedKeyword">CREATE</span> <span class="TSql_ReservedKeyword">FUNCTION</span> blog_GetCategoryTitles (@PostID <span class="TSql_DataType">int</span>) RETURNS <span class="TSql_DataType">nvarchar</span>(4000) <span class="TSql_ReservedKeyword">BEGIN</span> <span class="TSql_ReservedKeyword">DECLARE</span> @CategoryList <span class="TSql_DataType">nvarchar</span>(4000) <span class="TSql_ReservedKeyword">SELECT</span> @CategoryList = <span class="TSql_Function">COALESCE</span>(@CategoryList + <span class="TSql_String">';'</span>, <span class="TSql_String">''</span>) + blog_LinkCategories.Title <span class="TSql_ReservedKeyword">FROM</span> blog_Content <span class="TSql_Function">LEFT</span> <span class="TSql_Operator">OUTER</span> <span class="TSql_Operator">JOIN</span> blog_Links <span class="TSql_ReservedKeyword">on</span> blog_Links.PostID = blog_Content.ID <span class="TSql_Function">LEFT</span> <span class="TSql_Operator">OUTER</span> <span class="TSql_Operator">JOIN</span> blog_LinkCategories <span class="TSql_ReservedKeyword">on</span> blog_Links.CategoryID = blog_LinkCategories.CategoryID <span class="TSql_ReservedKeyword">WHERE</span> blog_Content.ID=@PostID <span class="TSql_Operator">AND</span> blog_Content.BlogID = blog_Links.BlogID <span class="TSql_Operator">AND</span> blog_LinkCategories.Title != <span class="TSql_String">''</span> <span class="TSql_ReservedKeyword">RETURN</span> @CategoryList <span class="TSql_ReservedKeyword">END</span> </pre>
```sql
CREATE FUNCTION blog_GetCategoryTitles (@PostID int) RETURNS nvarchar(4000)
BEGIN
DECLARE @CategoryList nvarchar(4000)
SELECT @CategoryList = COALESCE
(@CategoryList + ';', '') +
blog_LinkCategories.Title
FROM blog_Content
LEFT OUTER JOIN blog_Links
on blog_Links.PostID = blog_Content.ID
LEFT OUTER JOIN blog_LinkCategories
on blog_Links.CategoryID = blog_LinkCategories.CategoryID
WHERE blog_Content.ID=@PostID AND
blog_Content.BlogID = blog_Links.BlogID AND
blog_LinkCategories.Title != ''
RETURN @CategoryList
END
```

_thanks to [Garth's 2001 article from SQLTeam.com for showing me COALESCE being used for this purpose...](http://www.sqlteam.com/item.asp?ItemID=2368)_

Expand Down
9 changes: 5 additions & 4 deletions content/Blog/converting-from-an-integer-to-an-intptr.md
Expand Up @@ -9,9 +9,10 @@ A friend of mine at work just asked me this VB question, and it is an interestin
In the end, I never really found an answer to that question, but I found out how to create a new IntPtr from an existing Integer and that seems close enough. You see, CType doesn't work because there isn't a defined conversion between the two types, and DirectCast only works with object references not value types like IntPtr. There isn't a System.Convert method for IntPtr to Int32... so what can you do? There is one option though, the constructor for IntPtr can accept an Int32 or a Int64 (Integer or Long in VB terms) and will assign the supplied value to the newly created IntPtr.

<pre><font color="Blue" family="Microsoft Sans Serif">Dim x <font color="Blue" family="Microsoft Sans Serif">As IntPtr
<font color="Blue" family="Microsoft Sans Serif">Dim y <font color="Blue" family="Microsoft Sans Serif">As <font color="Blue" family="Microsoft Sans Serif">Integer = -1
x = <font color="Blue" family="Microsoft Sans Serif">New IntPtr(y)
</pre>
```vb
Dim x As IntPtr
Dim y As Integer = -1
x = New IntPtr(y)
```

I never asked why there was a need to cast from Integer to IntPtr, but I'm assuming it is for some scenario where a handle/pointer is normally supplied or returned but -1 is used to indicate a special case...
41 changes: 37 additions & 4 deletions content/Blog/drawing-rotated-text.md
Expand Up @@ -5,13 +5,46 @@ type: posts
---
A customer emailed me today (via the VB FAQ blog) with a question; "how can I output text at different angles, to write the cardinal points around a compass for example..." so I decided to fire up a quick sample

<pre><font color="blue" family="Microsoft Sans Serif">Public <font color="blue" family="Microsoft Sans Serif">Enum Direction <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Integer N = 0 NW = 1 W = 2 SW = 3 S = 4 SE = 5 E = 6 NE = 7 <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Enum <font color="blue" family="Microsoft Sans Serif">Protected <font color="blue" family="Microsoft Sans Serif">Overrides <font color="blue" family="Microsoft Sans Serif">Sub OnPaint(<font color="blue" family="Microsoft Sans Serif">ByVal e <font color="blue" family="Microsoft Sans Serif">As System.Windows.Forms.PaintEventArgs) e.Graphics.<font color="blue" family="Microsoft Sans Serif">Clear(<font color="blue" family="Microsoft Sans Serif">Me.BackColor) <font color="blue" family="Microsoft Sans Serif">Dim bounds <font color="blue" family="Microsoft Sans Serif">As Rectangle <font color="blue" family="Microsoft Sans Serif">Dim g <font color="blue" family="Microsoft Sans Serif">As Graphics <font color="blue" family="Microsoft Sans Serif">Dim rotation <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Single = 0 g = e.Graphics bounds = <font color="blue" family="Microsoft Sans Serif">New Rectangle(50, 50, <font color="blue" family="Microsoft Sans Serif">Me.Width - 100, <font color="blue" family="Microsoft Sans Serif">Me.Height - 100) <font color="blue" family="Microsoft Sans Serif">Dim rect <font color="blue" family="Microsoft Sans Serif">As System.Drawing.RectangleF g.DrawEllipse(Pens.Black, bounds) <font color="blue" family="Microsoft Sans Serif">Dim myMatrix <font color="blue" family="Microsoft Sans Serif">As Drawing2D.Matrix <font color="blue" family="Microsoft Sans Serif">Dim sf <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">New StringFormat(StringFormatFlags.NoWrap) sf.Alignment = StringAlignment.Center myMatrix = g.Transform() rect = <font color="blue" family="Microsoft Sans Serif">New System.Drawing.RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height) <font color="blue" family="Microsoft Sans Serif">For i <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Integer = 0 <font color="blue" family="Microsoft Sans Serif">To 7 <font color="blue" family="Microsoft Sans Serif">If i &gt; 0 <font color="blue" family="Microsoft Sans Serif">Then myMatrix.RotateAt(45, <font color="blue" family="Microsoft Sans Serif">New PointF(<font color="blue" family="Microsoft Sans Serif">Me.Width / 2, <font color="blue" family="Microsoft Sans Serif">Me.Height / 2), Drawing.Drawing2D.MatrixOrder.Append) g.Transform = myMatrix <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">If <font color="blue" family="Microsoft Sans Serif">Dim directionString <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">String directionString = System.<font color="blue" family="Microsoft Sans Serif">Enum.GetName(<font color="blue" family="Microsoft Sans Serif">GetType(Direction), i) g.DrawString(directionString, <font color="blue" family="Microsoft Sans Serif">New Font(<font color="red" family="Microsoft Sans Serif">"Arial", 12, FontStyle.Bold), Brushes.Black, rect, sf) <font color="blue" family="Microsoft Sans Serif">Next <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Sub </pre>


```vb
Public Enum Direction As Integer
N = 0
NW = 1
W = 2
SW = 3
S = 4
SE = 5
E = 6
NE = 7
End Enum
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.Clear(Me.BackColor)
Dim bounds As Rectangle
Dim g As Graphics
Dim rotation As Single = 0
g = e.Graphics
bounds = New Rectangle(50, 50, Me.Width - 100, Me.Height - 100)
Dim rect As System.Drawing.RectangleF
g.DrawEllipse(Pens.Black, bounds)
Dim myMatrix As Drawing2D.Matrix
Dim sf As New StringFormat(StringFormatFlags.NoWrap)
sf.Alignment = StringAlignment.Center
myMatrix = g.Transform()
rect = New System.Drawing.RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height)
For i As Integer = 0 To 7
If i > 0 Then
myMatrix.RotateAt(45, New PointF(Me.Width / 2, Me.Height / 2), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
End If
Dim directionString As String
directionString = System.Enum.GetName(GetType(Direction), i)
g.DrawString(directionString, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, rect, sf)
Next
End Sub
```

If you want to try this code, create a new Windows Forms application in VS.NET 2003, and paste this code into your Form, after the "Windows Form Designer generated code" region.

The result will be an image like this: ![](http://msdn.microsoft.com/vbasic/art/compass.png)
The result will be an image like this: ![Output sample](http://msdn.microsoft.com/vbasic/art/compass.png)

If you are looking for more info on GDI+ drawing in VB.NET, I'd suggest [my article on the subject](http://msdn.microsoft.com/library/en-us/dndotnet/html/designsurface.asp) 🙂 and there is [a good book available from AW](http://www.amazon.com/exec/obidos/ASIN/0321160770/duncanmackenz-20?dev-t=mason-wrapper%26camp=2025%26link_code=xm2)

Expand Down
@@ -1,22 +1,33 @@
---
date: 2004-06-05T10:47:00+00:00
title: Early &#038; Adopter fill you in on "Application Level Events"
title: Early & Adopter fill you in on "Application Level Events"
type: posts
---
The [3 Leaf](http://www.3leaf.com/) guys, (well probably just one of them... but who knows which one), talk about ["Application Level Events" in Whidbey](http://ea.3leaf.com/2004/06/application_lev.html)

Here's a code snippet to illustrate what they are talking about... something that I like to think of as "Global.asa" (I haven't done a lot of web work since ASP) for Windows applications...

<pre><font color="blue" family="Microsoft Sans Serif">Namespace My Partial <font color="blue" family="Microsoft Sans Serif">Friend <font color="blue" family="Microsoft Sans Serif">Class MyApplication <font color="blue" family="Microsoft Sans Serif">Private <font color="blue" family="Microsoft Sans Serif">Sub MyApplication_Shutdown(<font color="blue" family="Microsoft Sans Serif">ByVal Sender <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Object, _ <font color="blue" family="Microsoft Sans Serif">ByVal e <font color="blue" family="Microsoft Sans Serif">As System.Windows.Forms.ShutdownEventArgs) _ <font color="blue" family="Microsoft Sans Serif">Handles <font color="blue" family="Microsoft Sans Serif">Me.Shutdown <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Sub</pre>

<pre><font color="blue" family="Microsoft Sans Serif">Private <font color="blue" family="Microsoft Sans Serif">Sub MyApplication_StartUp(<font color="blue" family="Microsoft Sans Serif">ByVal sender <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Object, _ <font color="blue" family="Microsoft Sans Serif">ByVal e <font color="blue" family="Microsoft Sans Serif">As System.Windows.Forms.StartupEventArgs) _ <font color="blue" family="Microsoft Sans Serif">Handles <font color="blue" family="Microsoft Sans Serif">Me.Startup <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Sub</pre>

<pre><font color="blue" family="Microsoft Sans Serif">Private <font color="blue" family="Microsoft Sans Serif">Sub MyApplication_StartupNextInstance(<font color="blue" family="Microsoft Sans Serif">ByVal Sender <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Object, _ <font color="blue" family="Microsoft Sans Serif">ByVal e <font color="blue" family="Microsoft Sans Serif">As System.Windows.Forms.StartupNextInstanceEventArgs) _ <font color="blue" family="Microsoft Sans Serif">Handles <font color="blue" family="Microsoft Sans Serif">Me.StartupNextInstance <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Sub</pre>

<pre><font color="blue" family="Microsoft Sans Serif">Private <font color="blue" family="Microsoft Sans Serif">Sub MyApplication_UnhandledException(<font color="blue" family="Microsoft Sans Serif">ByVal sender <font color="blue" family="Microsoft Sans Serif">As <font color="blue" family="Microsoft Sans Serif">Object, _ <font color="blue" family="Microsoft Sans Serif">ByVal e <font color="blue" family="Microsoft Sans Serif">As System.Threading.ThreadExceptionEventArgs) _ <font color="blue" family="Microsoft Sans Serif">Handles <font color="blue" family="Microsoft Sans Serif">Me.UnhandledException <font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Sub</pre>

<pre><font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Class</pre>

<pre><font color="blue" family="Microsoft Sans Serif">End <font color="blue" family="Microsoft Sans Serif">Namespace</pre>
```vb
Namespace My
Partial Friend Class MyApplication
Private Sub MyApplication_Shutdown(ByVal Sender As Object, _
ByVal e As System.Windows.Forms.ShutdownEventArgs) _
Handles Me.Shutdown
End Sub
Private Sub MyApplication_StartUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.StartupEventArgs) _
Handles Me.Startup
End Sub
Private Sub MyApplication_StartupNextInstance(ByVal Sender As Object, _
ByVal e As System.Windows.Forms.StartupNextInstanceEventArgs) _
Handles Me.StartupNextInstance
End Sub
Private Sub MyApplication_UnhandledException(ByVal sender As Object, _
ByVal e As System.Threading.ThreadExceptionEventArgs) _
Handles Me.UnhandledException
End Sub
End Class
End Namespace
```

Make sure you check out [the whole post](http://ea.3leaf.com/2004/06/application_lev.html) for a pretty screenshot 🙂

0 comments on commit a74df3b

Please sign in to comment.