﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <title>circumdev</title>
    <description>My discussions of tools, tips, and obscure findings around software development.</description>
    <link>http://www.circumdev.net/circumdev.net-root/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.0.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://www.circumdev.net/circumdev.net-root/opml.axd</blogChannel:blogRoll>
    <dc:creator>Joshua Freeman</dc:creator>
    <dc:title>circumdev</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <item>
      <title>Do you know the Waze?</title>
      <description>&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;From handheld GPS  to full blown built-in automotive navigation systems, t&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;oday GPS is becoming a common use technology. I like many of you have probably been using GPS in one form or another for many years. I've never quite been able to shake that feeling though, the one that it could be so much more. Have you ever been in that traffic jam, stuck, moving inches at a time? Ever thought, "if only I had known, I would have went the other way" or "I wish I could tell everyone else, so they don't get stuck here too"? I know I have. Well the day has come thanks to a great mobile program called &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="float: left; margin-left: 10px; margin-right: 10px;" src="/image.axd?picture=2010%2f2%2fwaze_logo_thumb.gif" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;The idea is simple, combine GPS, your phone's internet connection, and a community of drivers. On the surface &lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt; is just like most other GPS units, a map that shows where you currently are. You can get turn by turn directions and other routing support as well. But that's where the similarity ends. With &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt; you also get real time traffic information as you drive. Not the canned, rarely updated, and expensive data you might have come to expect from commercial t&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;raffic services, or the often too late information from the local radio station. Nope, real live information provided by the community (you and other drivers using &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;). In a traffic jam, see an accident, pass a speed trap, come across an obstacle &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;in the road? Click the button and let everyone else know. &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt; also uses your location and speed to identify traffic problems, reporting it without having to do anything at all. These messages are sent out to others nearby and displayed on their (your) map so that they (you) can see them and avoid them.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;The other common problem with GPS, out of date maps. Have you ever used a GPS and came across a new road not yet on the map (maybe added in the last &lt;strong&gt;year or two&lt;/strong&gt; since your maps were updated? Guess what, the maps are also part of the community. You can mark the spot and come back to it later from your web browser to add, edit, or delete roads.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;On a fun note, &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt; also has a point system. Roads where no one has driven yet have dots on the map, when you drive over them your car turns into a 'road muncher' and eats the dots. Sorta like playing that favorite dot eating video game with your car. Recently &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt; also announced that it was offering a Valentine's Day promotion. They are adding special 'goodies' to the maps like cupid's arrows, hearts, and special treasure chests. If you drive over one of these 'goodies' you get bonus points, and with the treasure chests you have the potential to win real world prizes like movie tickets, chocolate, or other prizes. I have to admit I've driven out of my way more than once just to get new dots or grab some 'goodies'. &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt; is 100% community driven and free, so the more people that actively use it, the better it gets. So&lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt; check it out I don't think you'll be disappointed. &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt; is available for iPhone, Android, Windows Mobile, and other mobile devices. Oh and by the way, I use &lt;/span&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;a href="http://bit.ly/bkXGEC"&gt;Waze&lt;/a&gt; instead of that fancy built-in navigation system in my car because I think it is better!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;Happy driving and wazing!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;</description>
      <link>http://www.circumdev.net/circumdev.net-root/post/Do-you-know-the-Waze.aspx</link>
      <author>Admin</author>
      <comments>http://www.circumdev.net/circumdev.net-root/post/Do-you-know-the-Waze.aspx#comment</comments>
      <guid>http://www.circumdev.net/circumdev.net-root/post.aspx?id=287b6b48-69ed-456c-838c-92c0189c3fd0</guid>
      <pubDate>Wed, 10 Feb 2010 22:05:00 -0600</pubDate>
      <category>Blog</category>
      <category>Mobile</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://www.circumdev.net/circumdev.net-root/pingback.axd</pingback:server>
      <pingback:target>http://www.circumdev.net/circumdev.net-root/post.aspx?id=287b6b48-69ed-456c-838c-92c0189c3fd0</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.circumdev.net/circumdev.net-root/trackback.axd?id=287b6b48-69ed-456c-838c-92c0189c3fd0</trackback:ping>
      <wfw:comment>http://www.circumdev.net/circumdev.net-root/post/Do-you-know-the-Waze.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.circumdev.net/circumdev.net-root/syndication.axd?post=287b6b48-69ed-456c-838c-92c0189c3fd0</wfw:commentRss>
    </item>
    <item>
      <title>.NetCF HttpWebRequest and HttpWebResponse Have No Cookie Support</title>
      <description>&lt;p&gt;&lt;span style="font-family: verdana; font-size: 12pt;"&gt;
&lt;p&gt;For space saving reasons some parts of the .Net Framework are left out of the .Net Compact Framework. Unfortunately, (at least for me), one of the things not making the cut is the cookie support methods for the HttpWebRequest and HttpWebResponse classes. What this means is developers are left to handle cookies in their own code.&lt;/p&gt;
&lt;p&gt;Cookies play an important role in web applications and sometimes your application will be required to read and/or set them. One of my applications &lt;a title="Chronobis" href="http://www.chronobis.com/"&gt;Chronobis&lt;/a&gt; falls into this category. In order to authenticate to OWA servers using FORM based authentication, you must accept, store, and send cookies. The full version of the .Net Framework handles this almost seamlessly for you. However, in the Compact Framework you are on your own.&lt;/p&gt;
&lt;p&gt;I decided to write an encapsulated CookieManager class to solve this problem for &lt;a title="Chronobis" href="http://www.chronobis.com/"&gt;Chronobis&lt;/a&gt;, which I am providing here as an example of how to handle cookies in your .NET Compact Framework application.&lt;/p&gt;
&lt;p style="color: red; font-size: 8pt; font-weight: bold;"&gt;Warning: This code assumes that every cookie stored will be sent. This means that I effectively ignore the cookie attribute values (Comment, Domain, Max-Age, Path, Secure, and Version). If your situation warrants, you might need to extend this code to account for them.&lt;/p&gt;
&lt;pre style="background-color: beige; border-style: solid; border-color: black; border-width: 1px; padding: 10px 10px 10px 10px; font-family: courier new; font-size: 10pt; overflow: scroll;"&gt;
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace net.frejos.http
{
    public class CookieManager
    {
        private Dictionary cookieValues;

        public Dictionary CookieValues {
            get {
                if (this.cookieValues == null) {
                    this.cookieValues = new Dictionary();
                }

                return this.cookieValues;
            }
        }

        public void PublishCookies(HttpWebRequest webRequest)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Cookie: ");
            foreach (string key in this.CookieValues.Keys) {
                sb.Append(key);
                sb.Append("=");
                sb.Append(this.CookieValues[key]);
                sb.Append("; ");
                sb.Append("$Path=\"/\"; ");               
            }

            webRequest.Headers.Add(sb.ToString());
            sb = null;
            webRequest = null;
        }

        public void StoreCookies(HttpWebResponse webResponse)
        {
            for (int x=0; x &amp;lt; webResponse.Headers.Count; x++) {
                if (webResponse.Headers.Keys[x].ToLower().Equals("set-cookie")) {
                    this.AddRawCookie( webResponse.Headers[x] );
                }
            }

            webResponse = null;
        }

        private void AddRawCookie(string rawCookieData)
        {
            string key = null;
            string value = null;

            string[] entries = null;

            if (rawCookieData.IndexOf(",") &amp;gt; 0)
            {
                entries = rawCookieData.Split(',');
            }
            else { 
                entries = new string[] { rawCookieData };
            }

            foreach (string entry in entries) {
                string cookieData = entry.Trim();

                if (cookieData.IndexOf(';') &amp;gt; 0)
                {
                    string[] temp = cookieData.Split(';');
                    cookieData = temp[0];
                }

                int index = cookieData.IndexOf('=');
                if (index &amp;gt; 0)
                {
                    key = cookieData.Substring(0, index);
                    value = cookieData.Substring(index + 1);
                }

                if (key != null &amp;amp;&amp;amp; value != null)
                {
                    this.CookieValues[key] = value;
                }

                cookieData = null;
            }

            rawCookieData = null;
            entries = null;
            key = null;
            value = null;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            foreach (string key in this.CookieValues.Keys) {
                sb.Append("{");
                sb.Append(key);
                sb.Append(",");
                sb.Append(this.CookieValues[key]);
                sb.Append("}, ");
            }
            if (this.CookieValues.Keys.Count &amp;gt; 0)
            {
                sb.Remove(sb.Length - 2, 2);
            }
            sb.Append("]");

            return sb.ToString();
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;A typical usage of this class would look something like this:&lt;/p&gt;
&lt;pre style="background-color: beige; border-style: solid; border-color: black; border-width: 1px; padding: 10px 10px 10px 10px; font-family: courier new; font-size: 10pt; overflow: scroll;"&gt;
CookieManager cookieManager = new CookieManager();
// Set a cookie value
cookieManager.CookieValues["FavoriteCookie"] = "Chocolate Chip";

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
// Publish the cookies to the request before asking for the response
cookieManager.PublishCookies(webRequest);

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
// Store any cookies returned from the response
cookieManager.StoreCookies(webResponse);

// Get the value of a cookie
string session = cookieManager.CookieValues["SESSIONID"];

webRequest = (HttpWebRequest)WebRequest.Create(url2);
cookieManager.PublishCookies(webRequest);

webResponse = (HttpWebResponse)webRequest.GetResponse();
&lt;/pre&gt;
&lt;p&gt;Just in case you need a cookie RFC refresher, or need to add the missing functionality, you can find the &lt;a title="RFC 2109" href="http://www.faqs.org/rfcs/rfc2109.html"&gt;RFC here&lt;/a&gt;.&lt;/p&gt;
&lt;p style="font-size: 8pt;"&gt;The example source code contained within this post is provided under the terms of the &lt;a href="http://www.opensource.org/licenses/mit-license.php"&gt;MIT License&lt;/a&gt;. Copyright&amp;copy; 2008-2009 Joshua Freeman.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.circumdev.net/file.axd?file=2009%2f4%2fCookieManager.cs"&gt;CookieManager.cs (3.39 kb)&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.circumdev.net/circumdev.net-root/post/Net-CF-HttpWebRequest-and-HttpWebResponse-Have-No-Cookie-Support.aspx</link>
      <author>Admin</author>
      <comments>http://www.circumdev.net/circumdev.net-root/post/Net-CF-HttpWebRequest-and-HttpWebResponse-Have-No-Cookie-Support.aspx#comment</comments>
      <guid>http://www.circumdev.net/circumdev.net-root/post.aspx?id=0f8ac92e-7b7e-48a4-ad49-41b086d8c598</guid>
      <pubDate>Sat, 25 Apr 2009 00:58:00 -0600</pubDate>
      <category>.Net Compact Framework</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://www.circumdev.net/circumdev.net-root/pingback.axd</pingback:server>
      <pingback:target>http://www.circumdev.net/circumdev.net-root/post.aspx?id=0f8ac92e-7b7e-48a4-ad49-41b086d8c598</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.circumdev.net/circumdev.net-root/trackback.axd?id=0f8ac92e-7b7e-48a4-ad49-41b086d8c598</trackback:ping>
      <wfw:comment>http://www.circumdev.net/circumdev.net-root/post/Net-CF-HttpWebRequest-and-HttpWebResponse-Have-No-Cookie-Support.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.circumdev.net/circumdev.net-root/syndication.axd?post=0f8ac92e-7b7e-48a4-ad49-41b086d8c598</wfw:commentRss>
    </item>
  </channel>
</rss>