<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bruno Piovan</title><link>http://weblogs.asp.net/brunopiovan/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>BEncoding and Torrent files with .Net</title><link>http://weblogs.asp.net/brunopiovan/archive/2009/05/03/bencoding-and-torrent-files-with-net.aspx</link><pubDate>Sun, 03 May 2009 22:36:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7071406</guid><dc:creator>brunopiovan</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/brunopiovan/rsscomments.aspx?PostID=7071406</wfw:commentRss><comments>http://weblogs.asp.net/brunopiovan/archive/2009/05/03/bencoding-and-torrent-files-with-net.aspx#comments</comments><description>&lt;P&gt;I wrote some code to handle bencoding/decoding in C#, the code is based on the specification. I created also a helper class to open/save torrent files and also compute its info_hash.&lt;/P&gt;
&lt;P&gt;I wrote this project in C#, but the sample below is in visual basic. I don't think C# developers would have problems to understand it, but if you have any question just let me know.&lt;/P&gt;&lt;PRE style="WIDTH: auto; OVERFLOW: scroll"&gt;Sub Main()
    'opens a torrent file and display its info_hash
    Dim torrentFile As BDictionary = Torrent.ParseTorrentFile("C:\Users\Bruno\Desktop\test.torrent")
    Console.Write("Existing torrent's info_hash: ")
    Console.WriteLine(Torrent.ComputeInfoHash(torrentFile).ToString)

    'creates a new torrent file
    Dim newtorrent As New BDictionary()
    newtorrent.Add("created by", "Bruno Piovan")

    'adds some integers
    newtorrent.Add("Ticks", Environment.TickCount)
    newtorrent.Add("Negative", Decimal.MinValue)

    'creates an info dictionary and adds it
    Dim info As New BDictionary
    newtorrent.Add("info", info)

    'generates some random bytes
    Dim sha As SHA512 = SHA512.Create
    Dim bytes() As Byte = sha.ComputeHash(Encoding.UTF8.GetBytes(Environment.TickCount.ToString))

    'adds the random bytes to the info dictionary
    info.Add("bytes", bytes)

    'adds a list
    Dim list As New BList
    For Each p As Process In Process.GetProcesses
        list.Add(p.ProcessName)
    Next
    info.Add("Processes", list)

    'computes the info_hash of the new torrent
    Console.Write("New torrent's info_hash:      ")
    Console.WriteLine(Torrent.ComputeInfoHash(newtorrent).ToString)

    'saves the torrent
    Torrent.SaveTorrent(newtorrent, "C:\Users\Bruno\Desktop\new-torrent.torrent")
End Sub&lt;/PRE&gt;
&lt;P&gt;If you use this code, let me know if you find any bug or wrong implementation.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7071406" width="1" height="1"&gt;</description><enclosure url="http://weblogs.asp.net/brunopiovan/attachment/7071406.ashx" length="9680" type="application/x-zip-compressed" /><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/Torrent/default.aspx">Torrent</category></item><item><title>How to post updates to Twitter using Visual Basic.NET and C#</title><link>http://weblogs.asp.net/brunopiovan/archive/2009/04/06/how-to-post-updates-to-twitter-using-visual-basic-net.aspx</link><pubDate>Mon, 06 Apr 2009 17:32:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7030346</guid><dc:creator>brunopiovan</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/brunopiovan/rsscomments.aspx?PostID=7030346</wfw:commentRss><comments>http://weblogs.asp.net/brunopiovan/archive/2009/04/06/how-to-post-updates-to-twitter-using-visual-basic-net.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;I recently created a service to post updates to the &lt;A href="http://twitter.com/TwinsOrNot" target=_blank mce_href="http://twitter.com/TwinsOrNot"&gt;Twitter account&lt;/A&gt; of my &lt;A href="http://twinsornot.com/" target=_blank mce_href="http://twinsornot.com"&gt;website&lt;/A&gt;&amp;nbsp;(&lt;A href="http://twinsornot.com/"&gt;http://twinsornot.com/&lt;/A&gt;).&lt;/P&gt;
&lt;P mce_keep="true"&gt;I found some codes that does that, but using the &lt;A href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx"&gt;HttpWebRequest&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I decided to make it more simple by using &lt;A href="http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx"&gt;WebClient&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Here's the Visual Basic .NET code:&lt;/P&gt;&lt;PRE style="OVERFLOW: scroll"&gt;Public Sub PostTwitterUpdate(ByVal userName As String, ByVal password As String, ByVal updateMessage As String)
    Using wc As New WebClient
        wc.Credentials = New NetworkCredential(userName, password)
        ServicePointManager.Expect100Continue = False

        Dim updateMessageBytes = System.Text.Encoding.UTF8.GetBytes("status=" &amp;amp; updateMessage) 'Use UTF8 to get it properly encoded if you use characters like ç ã etc...

        wc.UploadData("http://twitter.com/statuses/update.xml", updateMessageBytes)
    End Using
End Sub&lt;/PRE&gt;
&lt;P mce_keep="true"&gt;And here is the C# version:&lt;/P&gt;&lt;PRE style="OVERFLOW: scroll"&gt;public void PostTwitterUpdate(string userName, string password, string updateMessage)
{
    using (WebClient wc = new WebClient())
    {
        wc.Credentials = new NetworkCredential(userName, password);
        ServicePointManager.Expect100Continue = false;

        byte[] updateMessageBytes = System.Text.Encoding.UTF8.GetBytes("status=" + updateMessage); //Use UTF8 to get it properly encoded if you use characters like ç ã etc...

        wc.UploadData("http://twitter.com/statuses/update.xml", updateMessageBytes);
    }
}&lt;/PRE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7030346" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/Twitter/default.aspx">Twitter</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/brunopiovan/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>
