<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7413274486781112158</id><updated>2012-01-27T18:17:50.617-05:00</updated><category term='WinRT'/><category term='Visual Studio'/><category term='LightSwitch'/><category term='Windows 8'/><category term='Salesforce'/><category term='XAML'/><title type='text'>Dan's .NET Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1666586937267578261</id><published>2011-11-24T10:43:00.001-05:00</published><updated>2011-11-24T10:44:30.289-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinRT'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>WinRT File Access</title><content type='html'>In my last post I showed how to use an OpenFilePicker in a WinRT application to get access to a file selected by the user. Now let’s take a look at how you access the file system directly without prompting the user. We will start with a simple application that lists the names of the files in the user’s Picture Library.&lt;br /&gt;Start by creating a C# Windows Metro Style Application. Within the Grid element add the following XAML to create textblock we can use to display the name.&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;TextBlock x:Name="TextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;In the code behind add the following code to handle the UserControl_Loaded event:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;private async void UserControl_Loaded(object sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;var folder = KnownFolders.PicturesLibrary;&lt;br /&gt;var files = await folder.GetFilesAsync();&lt;br /&gt;&lt;br /&gt;foreach (StorageFile file in files)&lt;br /&gt;{ &lt;br /&gt;    TextBlock.Text += file.FileName + ":" + file.ContentType + "\n"; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Before running the code, select Exceptions from the Debug menu and check Common Language Runtime Exceptions Thrown. Now run the application and you will notice that it throws a System.UnauthorizedAccessException. Why does this happen?&lt;br /&gt;&lt;br /&gt;As I mentioned in my last post, WinRT apps run in a pretty strict sandbox and by default have very limited access to the file system. We got around this last time because we let the user pick a file, so they would have full knowledge of what they are allowing the application to access. But in this case, since we are directly accessing the file system, we get an exception. To solve this problem, double click Package.appxmamnifest in the solution explorer the click on the Capabilities tab.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh5.ggpht.com/-7nkzzaskoJE/Ts5mCHsiYLI/AAAAAAAABlU/3KaNg_yh4z4/s1600-h/clip_image002%25255B4%25255D.jpg"&gt;&lt;img alt="clip_image002" border="0" height="374" src="http://lh6.ggpht.com/-yHKCQFNKZEs/Ts5mCbX2D8I/AAAAAAAABlY/y21LqhEWuFw/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image002" width="526" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;On this screen we can specify what we want application to be allowed to do. To give the application access to the Picture Library, put a check next to Picture Library Access. If you then re-run the application you will not get an exception and a list of the pictures will be displayed. At first this might seem a little pointless. If the programmer can just click a check box to get access it’s not particularly good security. The value is that it will make it much easier for the prospective user of the app to know what the app is allowed to do. Although we haven’t seem Microsoft’s Windows 8 app store yet, it’s entirely possible that when we look at the information about an app before we purchase it, we will able to see a list of these Capabilities so we know exactly what the app has access to. &lt;br /&gt;&lt;br /&gt;Now that we understand about Capabilities, lets look at how the code actually works. In the first line we create a new folder object from one of the KnownFolders. In this case the code selects the PictureLibrary, but we could also select folders like the MusicLibrary, VideosLibrary, or DocumentLibrary.&lt;br /&gt;&lt;br /&gt;Once we have the folder object the second line calls it’s GetFilesAsync method to return a list of StorageFile objects for the files in the folder. As always with WinRT, if a method could potentially take more the 50ms to run, it’s executed asynchronously. The next three lines iterate through the list of StorageFiles and display their names.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1666586937267578261?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1666586937267578261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1666586937267578261' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1666586937267578261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1666586937267578261'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/11/winrt-file-access.html' title='WinRT File Access'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/-yHKCQFNKZEs/Ts5mCbX2D8I/AAAAAAAABlY/y21LqhEWuFw/s72-c/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-8877173053991765273</id><published>2011-10-21T16:13:00.001-04:00</published><updated>2011-10-21T16:15:02.479-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Windows 8 Metro File Picker</title><content type='html'>This is one of a series of posts I have been doing while exploring the new WinRT environment in Windows 8. In this article I am going to talk about the file pickers functionality.&lt;br /&gt;In .NET apps when we need to prompt the user to select a file we have a common dialog that can be displayed. WinRT Metro apps provide something similar called a picker. The way the file picker works is particularly import for WinRT applications. These applications run in a sandbox and by default they have limited access the user’s files. If the app needs to have arbitrary access to user files it must declare this in the Capabilities section of its manifest. This, in theory, would allow the user to know exactly what the app is allowed to do before they download it. &lt;br /&gt;This is where the file picker comes into play. The file picker returns a StorageFile object which can be used to directly access only the file that the user picked. Since the user is in complete control of the selection there is no need to declare this capability in the manifest. &lt;br /&gt;To demonstrate a file picker let’s create a small application that will allow the user to pick an image file and then display that file in an image control. &lt;br /&gt;First create a new C# Windows Metro Style Application. In the XAML view of MainPage.xaml, add the following code inside the Grid element:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;Button x:Name="UIOpenFile" Content="Open File" HorizontalAlignment="Left" Margin="17,18,0,0" VerticalAlignment="Top" Click="UIOpenFile_Click"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;Image x:Name="UIImage" HorizontalAlignment="Left" Margin="27,74,0,0" VerticalAlignment="Top" /&amp;gt;&lt;/pre&gt;&lt;br /&gt;In the code behind for MainPage add the following namespaces:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;using Windows.Storage.Pickers;&lt;br /&gt;using Windows.UI.Xaml.Media.Imaging;&lt;/pre&gt;&lt;br /&gt;Then add the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;async private void UIOpenFile_Click(object sender, RoutedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    var picker = new FileOpenPicker();&lt;br /&gt; &lt;br /&gt;    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;&lt;br /&gt;    picker.ViewMode = PickerViewMode.Thumbnail;&lt;br /&gt;    picker.FileTypeFilter.Add(".jpg");&lt;br /&gt;    picker.FileTypeFilter.Add(".jpeg");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    var file = await picker.PickSingleFileAsync();&lt;br /&gt;    if (file == null) return;&lt;br /&gt;&lt;br /&gt;    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);&lt;br /&gt;    BitmapImage image = new BitmapImage();&lt;br /&gt;    image.SetSource(stream);&lt;br /&gt;    UIImage.Source = image;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;When you run the application and click the button you will get a file picker screen open to your picture library. If you pick an image file it will be displayed in the image control. Let look at how this code works. &lt;br /&gt;&lt;br /&gt;First note that the event handler is marked as async. Any potentially long running functions in WinRT will run asynchronously so this keyword is needed for this to work. &lt;br /&gt;&lt;br /&gt;The first thing we do in the function is create a FileOpenPicker object and set its properties. &lt;br /&gt;&lt;br /&gt;The SuggestedStartLocation property specifies one of a series of standard locations that the picker should start in. In this case we are starting in the PictureLibrary, but the user is free to browse to other locations. &lt;br /&gt;&lt;br /&gt;The next property, ViewMode, determines how the picker will display the files. There are currently two options:&lt;br /&gt;&lt;br /&gt;PickerViewMode.Thumbnail&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh4.ggpht.com/-LDjUW770LME/TqHSXSlx8tI/AAAAAAAABj8/rOmsD37dIro/s1600-h/clip_image002%25255B4%25255D.jpg"&gt;&lt;img alt="clip_image002" border="0" height="389" src="http://lh6.ggpht.com/-Txw_N8Yhy0Y/TqHSXueWgNI/AAAAAAAABkE/68c7tfQLDh4/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image002" width="217" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;PickerViewMode.List &lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/-BwNex7zEzZ8/TqHSX3qdQ_I/AAAAAAAABkM/5WFaYm0kynA/s1600-h/clip_image004%25255B4%25255D.jpg"&gt;&lt;img alt="clip_image004" border="0" height="423" src="http://lh3.ggpht.com/-Gys-uFPh6NA/TqHSYHa9B2I/AAAAAAAABkU/7hJtRWux2u4/clip_image004_thumb%25255B1%25255D.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image004" width="222" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The last property we need to setup is the FileTypeFilter. This is a generic list of strings, each being one of the file type extensions that you want to the picker to look for. In this case we are just adding two, .jpeg, and .jpg. Note that if you don’t add any file types you will get an exception when you display the picker, and you can’t use wildcards. I am assuming that Microsoft will eventually need to add a way to pick any file type. &lt;br /&gt;&lt;br /&gt;Once the properties are set on the picker we call it’s PickSingleFileAsync() method to display the picker and allow the user to select a single file. The await keyword will cause the function to pause until the picker is closed, but not block the UI thread. The function will return either a StorageFile object or a null if the user canceled the picker. &lt;br /&gt;&lt;br /&gt;As I mentioned at the beginning of the article, we don’t get just a filename back from the picker, but a StorageFile object. In the last four lines of the code we use the object to create a read only stream, create a BitmapImage object from the stream, and then finally set that image as the source of the image control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-8877173053991765273?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/8877173053991765273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=8877173053991765273' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8877173053991765273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8877173053991765273'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/10/windows-8-metro-file-picker.html' title='Windows 8 Metro File Picker'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/-Txw_N8Yhy0Y/TqHSXueWgNI/AAAAAAAABkE/68c7tfQLDh4/s72-c/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2181479065109929326</id><published>2011-09-28T20:39:00.001-04:00</published><updated>2011-09-28T20:43:09.116-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Windows 8 Secondary Tiles</title><content type='html'>In the past couple posts I have showed various ways of manipulating the start menu tile for an application. Besides manipulating the main tile your app can also create secondary tiles when the user wants to see more information then can easily be displayed on a single tile. You can see an example of this in the Weather app. Open the app and add a second city, right click to bring up the app bar and click Pin City. Once you do this a second tile will appear on the start screen with the information for that city. Let’s look at how you create a secondary tile. &lt;br /&gt;Before you can create a secondary tile you need, at a minimum, a 150x150 pixel image for the tile. Create the image and save it as a .PNG file in your applications Images directory then add it to the application in solution explorer. Set the Build Action property on the image to Content, and the Copy to Output Directory property to “Copy if Newer” or “Copy Always”. Once you have the image you can use the following code to display it:&lt;br /&gt;&lt;i&gt;Note: You will want to include the Windows.UI.StartScreen namespace in your file. &lt;/i&gt;    &lt;br /&gt;&lt;pre class="brush: csharp;"&gt;async public void ShowSecondayTile() &lt;br /&gt;{&lt;br /&gt;  Uri logo = new Uri("ms-resource:images/SecondayLogo.png");&lt;br /&gt;  SecondaryTile secondaryTile = new SecondaryTile("MySecondaryTile1",&lt;br /&gt;    "Secondary Tile",&lt;br /&gt;    "Hello World Secondary",&lt;br /&gt;    "Tile 1 activated",&lt;br /&gt;    TileDisplayAttributes.ShowName,&lt;br /&gt;    logo);&lt;br /&gt;  bool isPinned = await secondaryTile.RequestCreateAsync();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;First we need to create a Uri object to point to the tile image we added to the images folder. Next we create the secondary tile object. The parameters passed to the constructor mostly correspond to the properties you set in the manifest for the default startup tile. &lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;- tileId: Since you can create more the one secondary tile the tileId uniquely identifies the tile to your application. If you add more then one tile with the tileId the later one will replace the earlier. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;- shortName: A name that is displayed on the tile if you set the ShowName attribute. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;- displayName: The name displayed when you hover over the tile.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;- arguments: A string that you want passed back to your application when the tile is clicked. We will talk more about this later. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;- displayAttributes: Any attributes you need to set on the tile, for example ShowName.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;- logoRefernce: Uri of the image to use for the square tile. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Besides the properties you set in the constructor there are also properties on the object for setting things like the WideLogo, SmallLogo, ForegroundText, etc.&lt;br /&gt;&lt;br /&gt;Once you have the SecondaryTile object setup the last line requests the creation of the tile. When that line is executed the user will see a popup that looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/-T6LZbUKObsY/ToO-NQH9hFI/AAAAAAAABjE/VKF31JMsdQE/s1600-h/clip_image001%25255B3%25255D.jpg"&gt;&lt;img alt="clip_image001" border="0" height="244" src="http://lh5.ggpht.com/-i_ltVcdB2Ig/ToO-Ng8rn-I/AAAAAAAABjI/ayGPHsixcz0/clip_image001_thumb.jpg?imgmax=800" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image001" width="183" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This shows an image of the tile, gives the user a chance to change the shortName and has a button to accept the request. If the user accepts, the function will return a true. If they click off the popup the request will be denied and the function will return a false. &lt;br /&gt;&lt;br /&gt;One interesting thing to note in this line is the “await” keyword. Await, along with async in the function declaration are new keywords in C# that are used to handle asynchronous functions and you will see these used a lot in Windows 8 Metro applications. The details of how these work are beyond the scope of this article, but in short, execution will not continue to the next line until RequestCreateAsync is complete, but unlike in synchronous programming it won’t block the UI thread either. Essentially the ShowSecondayTile function is suspended until the async function completes. &lt;br /&gt;&lt;br /&gt;Once the secondary tile is displayed the user can remove it from the start menu by right clicking it and selecting Remove from the app bar. We can also have our application request the removal of a secondary tile with this code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;async private void RemoveSecondaryTile() &lt;br /&gt;{&lt;br /&gt;    var secondaryTile = new SecondaryTile(“MySecondaryTile1”);&lt;br /&gt;    bool isDeleted = await secondaryTile.RequestDeleteAsync();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;The first line creates a SecondaryTile object based on the tileId we set when we created the tile, and the second line requests the removal. The removal works just like the creation where the user will be prompted if they want to remove it and the functional will return true of false based on what the user chooses to do. &lt;br /&gt;&lt;br /&gt;When the user clicks on a secondary tile, Windows will launch your application just as if they had clicked on the main tile. To determine which secondary tile launched the app you can use the Arguments property on SecondaryTile object. In your application’s App.xaml.cs file you will see the following default code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;protected override void OnLaunched(LaunchActivatedEventArgs args) &lt;br /&gt;{&lt;br /&gt;    Window.Current.Content = new MainPage();&lt;br /&gt;    Window.Current.Activate();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;The LaunchActivatedEventArgs object contains a string property called Arguments that will contain the contents of the Arguments property we set on the secondary tile. One way to handle this would be to modify the MainPage contructor to accept a LaunchActivatedEventArgs object as a parameter and then modify the OnLaunched event to pass args to MainPage. In the MainPage constructor you can then get the Arguments property and handle it as needed. &lt;br /&gt;&lt;br /&gt;While digging a little deeper into secondary tiles I noticed that both the TileUpdateManager and BadgeUpdateManager have methods to create updaters for secondary tile. For badges you call use a line like this to get a secondary tile updater:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(“MySecondaryTile1”)&lt;/pre&gt;&lt;br /&gt;where the parameter passed is the tileId of the secondary tile. This updater would then allow us to show badges on the tile. We should be able to do something similar for notifications but I always got an exception when I called CreateTileUpdaterForSecondayTile(“MySecondaryTile1”) . Not sure if I am doing something wrong or if this is a bug.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2181479065109929326?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2181479065109929326/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2181479065109929326' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2181479065109929326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2181479065109929326'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/windows-8-secondary-tiles.html' title='Windows 8 Secondary Tiles'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/-i_ltVcdB2Ig/ToO-Ng8rn-I/AAAAAAAABjI/ayGPHsixcz0/s72-c/clip_image001_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-5924968236239952811</id><published>2011-09-26T19:14:00.001-04:00</published><updated>2011-10-21T16:15:15.649-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Windows 8 Metro Tile Badges</title><content type='html'>In my last post I showed how to make notifications appear on an application’s start menu tile. In this post I will show another way to show information on the tile, badges. Badges are small icons that show up in the lower right corner of a tile on top of either the default startup tile, or on top of a notification. The process for displaying a badge is pretty much the same as displaying a notification, it just uses difference classes.&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var xmlDocument = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);&lt;br /&gt;xmlData.Text = xmlDocument.GetXml();&lt;br /&gt;var textNode = xmlDocument.SelectSingleNode("/badge");&lt;br /&gt;textNode.Attributes[0].NodeValue = UIBadgeValue.Text;&lt;br /&gt;var badge = new BadgeNotification(xmlDocument);&lt;br /&gt;BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The first line gets the XML template for the badge. There are two template types for badges, Number and Glyph. Number display a one or two digit number. For example you could use this to display the number of unread e-mails in a e-mail application. The number badge looks like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/-CqjZSzlsf0M/ToEHQlKKdAI/AAAAAAAABi0/nyxK9VJ9bac/s1600-h/NumberBadge2.jpg"&gt;&lt;img alt="NumberBadge" border="0" height="124" src="http://lh4.ggpht.com/-9NSwEye_TZk/ToEHQ-rTxII/AAAAAAAABi4/4XenFitl-BY/NumberBadge_thumb.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="NumberBadge" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The second type is Glyph which displays one of a series of predefined icons. A error glyph badge looks like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh4.ggpht.com/-oqC92eudtlg/ToEHQ4TvCZI/AAAAAAAABi8/9ljvIUe1JS4/s1600-h/GlyphBadge2.jpg"&gt;&lt;img alt="GlyphBadge" border="0" height="126" src="http://lh6.ggpht.com/-aK7U-IfwOz0/ToEHSIZ4eWI/AAAAAAAABjA/Ph6axT7uw1s/GlyphBadge_thumb.jpg?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="GlyphBadge" width="244" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The schema for both types of badges is the same:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;badge value=””/&amp;gt; &lt;span style="font-family: Georgia;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The next two lines set the value attribute in the schema. For the number badge this will be one or two digits. For the glyph badge it will be one of the following values:&lt;/span&gt; none,activity,alert,available,away,busy,newMessage,paused,playing,unavailable,error &lt;span style="font-family: Georgia;"&gt;The last two lines create a badge object and display it on the tile.&lt;/span&gt; &lt;span style="font-family: Georgia;"&gt;Removing a badge works just like removing a notification:&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();&lt;/pre&gt;&lt;br /&gt;Just like notifications, badges have a ExpirationTime property that should control when the badge expires, but I have not had any luck getting that property to work. &lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-5924968236239952811?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/5924968236239952811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=5924968236239952811' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5924968236239952811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5924968236239952811'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/windows-8-metro-tile-badges.html' title='Windows 8 Metro Tile Badges'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/-9NSwEye_TZk/ToEHQ-rTxII/AAAAAAAABi4/4XenFitl-BY/s72-c/NumberBadge_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-4403135312748506760</id><published>2011-09-22T18:08:00.001-04:00</published><updated>2011-10-21T16:15:22.884-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Metro App Tile Notification</title><content type='html'>&lt;br /&gt;In my last post I showed you how to configure the start menu tile for a Windows 8 Metro app. The tiles can be used for more the just displaying a static startup icon, they can also display content that is relevant to your app so that the user can get information from the app without even leaving the start menu. &lt;br /&gt;There are a couple ways to do this. The first one I will show is notifications. A notification displays some content on the tile instead of its default text and icon. A good example of this is the Stocks app that comes with Windows 8. When you start the app the current stock information will be setup as notifications so when you go back to the start menu you will see the tile rotate through the values for each stock market. Let's take a look at how you do a notification in a C# Metro app. &lt;br /&gt;&lt;i&gt;Note: The current version of Windows 8 is pre-beta and still a little buggy. I have found this especially true with the notifications, sometime they just don't work for no apparent reason.&lt;/i&gt; &lt;br /&gt;&lt;i&gt;&lt;/i&gt;&lt;br /&gt;The appearance of a notification is controlled by an XML template, so the first step in sending a notification is to get a template to work with like this: &lt;br /&gt;&lt;i&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Note: You will want to include the Windows.UI.Notifications namespace.&lt;/i&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var xmlTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText01);&lt;/pre&gt;&lt;br /&gt;This command will return an XmlDocument object containing the TileWideText01 template that you can fill out with the data you want to display. You can see a full list of all the templates &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.notifications.tiletemplatetype%28v=VS.85%29.aspx"&gt;here&lt;/a&gt;. Unfortunately that page doesn't show the actual XML in the template which you need to know before you can modify it. You may want to put a TextArea on your application form and set it's Text property to xmlTemplate.GetXml() to see the XML. The XML for the TileWideText01 template looks like this: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;tile&amp;gt;&lt;br /&gt;  &amp;lt;visual lang="en-US"&amp;gt;&lt;br /&gt;    &amp;lt;binding template="TileWideText01"&amp;gt;&lt;br /&gt;      &amp;lt;text id="1"&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;      &amp;lt;text id="2"&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;      &amp;lt;text id="3"&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;      &amp;lt;text id="4"&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;      &amp;lt;text id="5"&amp;gt;&amp;lt;/text&amp;gt;&lt;br /&gt;    &amp;lt;/binding&amp;gt;&lt;br /&gt;  &amp;lt;/visual&amp;gt;&lt;br /&gt;&amp;lt;/tile&amp;gt; &lt;br /&gt;&lt;br /&gt;and the resulting &lt;/pre&gt;&lt;br /&gt;tile will look something like this: &lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh4.ggpht.com/-tZ-MqlBZpb4/Tnux9ubuypI/AAAAAAAABis/W9G0YB7gsj4/s1600-h/clip_image002%25255B3%25255D.jpg"&gt;&lt;img alt="clip_image002" border="0" height="119" src="http://lh3.ggpht.com/-7RizilJ4JxE/Tnux9yNcMUI/AAAAAAAABiw/Kg7fvIP6718/clip_image002_thumb.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image002" width="244" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;To get our text into the notification we need to modify the XML. Here I use XPath to select the first text node and set its value: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var textNode = xmlTemplate.SelectSingleNode("/title/visual/binding/text[@id='1']"); &lt;br /&gt;var newText = xmlTemplate.CreateTextNode(text); &lt;br /&gt;textNode.AppendChild(newText); &lt;/pre&gt;&lt;br /&gt;Next we need to create a tileNotification object from the xml: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var tileNotification = new TileNotification(xmlTemplate); &lt;/pre&gt;&lt;br /&gt;Finally we need to update the notification on the tile: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); &lt;br /&gt;tileUpdater.Update(tileNotification); &lt;/pre&gt;&lt;br /&gt;If you put this code in the form constructor of a C# Metro app, run the app, and then switch to the Start screen you will momentarily see the default startup tile, then the notification will slide into view. The notification will continue to be displayed even if the application is terminated, the computer restarted, or even if the app is un-installed and re-installed (I think this is un-intended and may change in later versions.) &lt;br /&gt;&lt;br /&gt;There are two ways for you to remove the notification. The first way is to replace it with a different notification. The second way it to clear it with the following command: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;TileUpdateManager.CreateTileUpdaterForApplication().Clear(); &lt;/pre&gt;&lt;br /&gt;This will remove the notification and restore the tile to the initial startup appearance. &lt;br /&gt;&lt;br /&gt;Normally you can only have one notification active at a time, but there is also a way to show multiple notifications. First execute this command: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;TileUpdateManager.CreateTileUpdaterForApplication()&lt;br /&gt;&lt;br /&gt;.EnableNotificationQueue(true); &lt;/pre&gt;&lt;br /&gt;Then add up to five notifications and the tile will rotate between them. If you add more than five the most recent five added will be shown. &lt;br /&gt;&lt;br /&gt;One other thing you can do with notifications is set an expiration date and time. You do that like this: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;tileNotification.ExpirationTime = new DateTimeOffset(DateTime.Now.AddMinutes(5)); &lt;/pre&gt;&lt;br /&gt;This command will make a notification expire 5 minutes after it has been added to the tile. After the notification expires the initial startup tile will be displayed just like when you use the Clear command.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-4403135312748506760?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/4403135312748506760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=4403135312748506760' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4403135312748506760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4403135312748506760'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/metro-app-tile-notification.html' title='Metro App Tile Notification'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/-7RizilJ4JxE/Tnux9yNcMUI/AAAAAAAABiw/Kg7fvIP6718/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-3344534542575683431</id><published>2011-09-18T08:02:00.001-04:00</published><updated>2011-10-21T16:15:30.737-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Metro App Tile Basics</title><content type='html'>&lt;p&gt;In my last post I showed the basics of how to create a simple Metro app. By default the tile displayed on the start screen for the app is not very useful, so I'll show you how to change it. &lt;/p&gt;  &lt;p&gt;First open the app you created last time, or create a new blank Metro app. When the project is open double click on Package.appxmanifest in the Solution Explorer, this will bring up an editor screen for the manifest. On the Application UI tab scroll down a little bit to the Tile section:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-MeeOBUlR7Ks/TnXd6-l2xvI/AAAAAAAABgw/TdAkgbN7qLk/s1600-h/clip_image002%25255B4%25255D.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/-i4ha81Il704/TnXd7QEWAtI/AAAAAAAABg0/PC-eJY4rjsY/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800" width="432" height="255" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The first two properties define the image that will be used for the small and large tiles on the start screen. These images can either be .png or .jpg. The small logo must be 150x150 pixels, and the large must be 310x150 pixels. If you don't specify a large logo, then you will not be given the option to switch to a larger tile on the start screen.&lt;/p&gt;  &lt;p&gt;The next property, Small Logo, is used to specify the logo that will appear for the application on the search results screen. This must be a 30x30 pixel .png or .jpg. &lt;/p&gt;  &lt;p&gt;The Show Name property determines if the name of the application should be displayed on the tile. If you do not specify a Short Name the Display Name will be used. You can also control the color of the name text by using the Foreground Text drop down. Here is an example of a large logo with a solid blue background and the name shown:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-PvB_Le2EwKo/TnXd7tzVFeI/AAAAAAAABg4/zaUCR3V_YCc/s1600-h/clip_image003%25255B3%25255D.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh6.ggpht.com/-uwZNCui-0Yo/TnXd7yB1MjI/AAAAAAAABg8/ygDiuGE1WeM/clip_image003_thumb.jpg?imgmax=800" width="244" height="127" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Background Color property is used to control the background color of the tile and the splash screen. You will only see the background color on a tile when you leave parts of the image transparent.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-3344534542575683431?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/3344534542575683431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=3344534542575683431' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3344534542575683431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3344534542575683431'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/metro-app-tile-basics.html' title='Metro App Tile Basics'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/-i4ha81Il704/TnXd7QEWAtI/AAAAAAAABg0/PC-eJY4rjsY/s72-c/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1645923999126786717</id><published>2011-09-16T18:59:00.001-04:00</published><updated>2011-10-21T16:15:37.651-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Windows 8 Metro Apps</title><content type='html'>One of the major new features in Windows 8 is the concept of Metro style apps. The term “Metro” is used to describe a new design style for application user interfaces and an apps overall user experience. The Metro style interface can currently be seen in the Microsoft Zune media player and the Windows Phone 7 operating system. For more information on Metro check out Microsoft’s &lt;a href="http://www.microsoft.com/design/toolbox/tutorials/windows-phone-7/metro/"&gt;Metro Design Language&lt;/a&gt; page.&lt;br /&gt;Metro apps in Wind0ws 8 run under a totally new operating environment called Windows Runtime or WinRT. I am not going to get into the details of WinRT here since quite honestly I have still not entirely gotten my head wrapped around it. Fortunately WinRT supports various languages and technologies that you are probably already familiar with so it’s not to hard to&amp;nbsp; get up to speed writing Metro apps. &lt;br /&gt;If you have installed the Windows 8 Developer Preview with developer tools you can use this walkthrough to make your first Metro app. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;Startup Visual Studio 11 Express &lt;/li&gt;&lt;li&gt;Click New Project. &lt;/li&gt;&lt;/ol&gt;&lt;a href="http://lh5.ggpht.com/-FpeKgf7T74w/TnPUrwlOasI/AAAAAAAABgg/ROUFFaLtm1w/s1600-h/clip_image002%25255B4%25255D.jpg"&gt;&lt;img alt="clip_image002" border="0" height="334" src="http://lh4.ggpht.com/-Ulvp6piNs5c/TnPUsGHg6RI/AAAAAAAABgk/WNlD33PP7DE/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image002" width="550" /&gt;&lt;/a&gt;&lt;br /&gt;You will see templates for a Windows Metro style apps for each of the supported languages. Note that this preview version of Visual Studio is only setup to do Metro apps. Javascript apps use HTML and CSS for their user interface, but unlike browser based apps they can have full access to the WinRT runtime. VB.NET, C#, and Visual C++ all use XAML for their UI’s which should be familiar to anyone who has done WPF or Silverlight apps.&lt;br /&gt;&lt;ol start="3"&gt;&lt;li&gt;Select the Windows Metro style template under Visual C#, and then click Application in the center panel. This will create a basic blank Metro app. &lt;/li&gt;&lt;li&gt;For the Name of the application enter HelloWorld then click OK. &lt;/li&gt;&lt;/ol&gt;If we ran the app now we would just get a blank screen so let’s add a little bit of content.&lt;br /&gt;&lt;ol start="5"&gt;&lt;li&gt;In the XAML view, between the Grid tags, add the following code: &lt;/li&gt;&lt;/ol&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;TextBlock Text="Hello World" HorizontalAlignment="Center" Margin="20" TextWrapping="Wrap" VerticalAlignment="Top" FontFamily="Georgia" FontSize="16"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;ol start="6"&gt;&lt;li&gt;Save you program then click Run. &lt;/li&gt;&lt;/ol&gt;Once the program compiles and runs you will get a black screen with a clock icon as the app loads then a black screen with the words “Hello World” in the top center. The first thing you will notice is that the app takes up the entire screen, this is a major design elements of Metro apps. If you have a large enough screen Windows 8 will provide the ability to do two apps side by side, but the standard is going to be one app displaying at a time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another thing you will notice is that there is no obvious way to close the app. The app lifecycle is much different in Metro. When you switch from one app to another the current app goes into a suspended state but remains in memory, then if you switch back to it, it will become active again. If memory starts running low the OS will automatically start terminating suspended apps. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Press the Windows key to bring up the Metro Start screen, scroll all the way to the right and you will see this icon:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/-YFB223i6qAI/TnPUtIvmgRI/AAAAAAAABgo/cIB9xaPH8TU/s1600-h/clip_image001%25255B3%25255D.jpg"&gt;&lt;img alt="clip_image001" border="0" height="128" src="http://lh3.ggpht.com/-oUG1oxqYtZ4/TnPUtVxmNaI/AAAAAAAABgs/v2CyzIrlL34/clip_image001_thumb.jpg?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image001" width="132" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is the default icon that represents you new app. If you hover your mouse over it the Hello World name will pop up. To get back to Visual Studio just click the Desktop tile on the Metro start screen. Since your app is still suspended in the background remember to click stop to terminate it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1645923999126786717?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1645923999126786717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1645923999126786717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1645923999126786717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1645923999126786717'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/windows-8-metro-apps.html' title='Windows 8 Metro Apps'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/-Ulvp6piNs5c/TnPUsGHg6RI/AAAAAAAABgk/WNlD33PP7DE/s72-c/clip_image002_thumb%25255B1%25255D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-6054447221173619556</id><published>2011-09-15T18:59:00.001-04:00</published><updated>2011-09-15T18:59:09.869-04:00</updated><title type='text'>New Development Tools</title><content type='html'>&lt;p&gt;In conjunction with Microsoft’s Build conference this week they have released preview versions of quite a few development tools. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;Windows 8&lt;/a&gt; – As I mentioned yesterday the developer previews of Windows 8 have been released. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.asp.net/mvc/mvc4"&gt;ASP.NET MVC 4 Developer Preview&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/hh127353"&gt;Visual Studio 11 Developer Preview&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/hh127353"&gt;.NET Framework 4.5 Developer Preview&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.asp.net/vnext"&gt;ASP.NET&amp;#160; 4.5 Developer Preview&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://wcf.codeplex.com/"&gt;WCF Web API Preview 5&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://watwindows8.codeplex.com/"&gt;Windows Azure Toolkit for Windows 8&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So many new technologies to learn, so little time!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-6054447221173619556?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/6054447221173619556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=6054447221173619556' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6054447221173619556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6054447221173619556'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/new-development-tools.html' title='New Development Tools'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2291402589994031083</id><published>2011-09-14T19:25:00.001-04:00</published><updated>2011-09-15T19:00:05.541-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 8'/><title type='text'>Windows 8</title><content type='html'>&lt;p&gt;Yesterday at Microsoft’s &lt;a href="http://www.buildwindows.com/"&gt;Build Conference&lt;/a&gt; they provided a lot of new information for developers about Windows 8. I highly recommend checking out the day one &lt;a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/KEY-0001"&gt;keynote&lt;/a&gt; speech, it’s long but worthwhile. &lt;/p&gt;  &lt;p&gt;If you want to try out Windows 8 you can download a developer (pre-beta) preview &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;here&lt;/a&gt;. There are 64 and 32 bit versions of just the OS, as well as a 64-bit version that also contains early versions of Visual Studio 11 and Expression Blend 5 that will allow you to immediately get started with Windows 8 development. &lt;/p&gt;  &lt;p&gt;To try it out I decided to load the 64-bit version with the tools in a virtual machine. I first tried if with VMware Workstation, but it seemed to have a problem with the Win 8 installer and it failed before the install even got started. Virtual PC doesn’t support 64-bit, guests but I presume the 32-bit version of Windows 8 will work with it. I finally got it installed using &lt;a href="http://www.virtualbox.org/"&gt;Oracle Virtual Box&lt;/a&gt;, just remember that you need to have a processor that supports hardware virtualization to do this. The install went very smoothly with the exception of one crash while entering my Windows Live password. After a re-start the install process finished without any more problems. &lt;/p&gt;  &lt;p&gt;The new Metro user interface can be a little tricky at first, especially if you don't have a computer with touch capability, so here are a few tips to help you out.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Be sure you have you screen resolution set to at least 1024x768 or the Metro style apps will not start up. &lt;/li&gt;    &lt;li&gt;You can click on the Desktop tile to get to a Windows 7 style desktop. Once you have done that you can switch back and forth between the desktop and the Metro start screen using the Windows key. &lt;/li&gt;    &lt;li&gt;There is no Windows 7 style start menu; it's just the Metro start screen. There doesn't seem to be a way to turn the old start menu back on and no indication if Microsoft will add this feature or not. &lt;/li&gt;    &lt;li&gt;If you don't have touch, then you will need to fall back to keystrokes for a lot of things. Here are a couple useful ones: &lt;/li&gt; &lt;/ol&gt;  &lt;blockquote&gt;   &lt;p&gt;Windows Key+F: Opens the search files panel&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Windows Key+Q: Opens the search apps panel&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Windows Key+C: Opens the charms panel&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Windows Key+I: Opens settings charm&lt;/p&gt; &lt;/blockquote&gt;  &lt;ol start="start"&gt;   &lt;li&gt;To shut down Windows (you would think this would be obvious), press Windows Key+I, click the Power icon, then click Shut down or Restart from the popup menu. &lt;/li&gt; &lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2291402589994031083?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2291402589994031083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2291402589994031083' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2291402589994031083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2291402589994031083'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/windows-8.html' title='Windows 8'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-6538279870508679069</id><published>2011-09-04T13:09:00.001-04:00</published><updated>2011-09-04T13:14:53.643-04:00</updated><title type='text'>GridView Header Issue</title><content type='html'>&amp;nbsp; &lt;br /&gt;If you have worked with the ASP.NET GridView you may notice an odd problem relating to the header text alignment. If you set the grid’s HeaderStyle.HorizontalAlign property to Left the headers will appear left aligned in Chrome, Firefox and older versions of IE (as well as IE compatibility mode), but in later version of IE the header text will stay centered instead of left aligned. Here is the HTML that comes from the GridView:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;table cellspacing="0" rules="all" border="1" id="GridView1" style="width:50%;border-collapse:collapse;"&amp;gt;     &lt;br /&gt;    &amp;lt;tr align="left"&amp;gt;                &lt;br /&gt;        &amp;lt;th scope="col"&amp;gt;Field1&amp;lt;/th&amp;gt;&lt;br /&gt;        &amp;lt;th scope="col"&amp;gt;Field2&amp;lt;/th&amp;gt;&lt;br /&gt;        &amp;lt;th scope="col"&amp;gt;Field3&amp;lt;/th&amp;gt;        &lt;br /&gt;    &amp;lt;/tr&amp;gt;         &lt;br /&gt;    &amp;lt;tr&amp;gt;               &lt;br /&gt;        &amp;lt;td&amp;gt;Data1&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;Data2&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;Data3&amp;lt;/td&amp;gt;        &lt;br /&gt;    &amp;lt;/tr&amp;gt; &lt;br /&gt;&amp;lt;/table&amp;gt;&lt;/pre&gt;&lt;br /&gt;The reason for this alignment problem is the align attribute on the &amp;lt;tr&amp;gt; element. In the later version of IE this alignment is not inherited by the &amp;lt;th&amp;gt; elements like it is in other browsers. I have been doing some reading on this issue and there seems to be some debate as to whether this is what the HTML specification intended or not. I will leave that debate to others and just show how to resolve the problem. &lt;br /&gt;If you are not auto generating the columns you can fix this by setting the HeaderStyle.HorizontalAlign property to the appropriate value for each of your columns. So in this example I would set them to Left. The GridView will now output the following HTML:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;table cellspacing="0" rules="all" border="1" id="GridView1" style="width:50%;border-collapse:collapse;"&amp;gt;&lt;br /&gt;    &amp;lt;tr align="left"&amp;gt;                &lt;br /&gt;        &amp;lt;th align="left" scope="col"&amp;gt;Field1&amp;lt;/th&amp;gt;&lt;br /&gt;        &amp;lt;th align="left" scope="col"&amp;gt;Field2&amp;lt;/th&amp;gt;&lt;br /&gt;        &amp;lt;th align="left" scope="col"&amp;gt;Field3&amp;lt;/th&amp;gt;         &lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;Data1&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;Data2&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;Data3&amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You will see that each &amp;lt;th&amp;gt; element now has an align attribute which will work the same in any browser. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You also can achieve the same thing using CSS which has the advantage of working whether you are auto generating the columns or not. To do this first add this style to either the header of your page, or to a CSS file: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;style type="text/css"&amp;gt; &lt;br /&gt;    .gvclass table th {text-align:left;} &lt;br /&gt;&amp;lt;/style&amp;gt; &lt;/pre&gt;&lt;br /&gt;Then wrap your GridView in a div tag that uses the .gvclass: &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;div class="gvclass"&amp;gt; &lt;br /&gt;    &amp;lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="50%"&amp;gt; &lt;br /&gt;    &amp;lt;/asp:GridView&amp;gt; &lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-6538279870508679069?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/6538279870508679069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=6538279870508679069' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6538279870508679069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6538279870508679069'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/09/gridview-header-issue.html' title='GridView Header Issue'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2876553740892774526</id><published>2011-02-27T16:27:00.000-05:00</published><updated>2011-10-21T16:16:01.500-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Query Deserialization</title><content type='html'>&lt;br /&gt;In my last article about the Salesforce REST API I showed how to query for records. The JSON encoded result of the query looks something like this:&lt;br /&gt;&lt;pre class="brush: js;"&gt;{&lt;br /&gt;"totalSize" : 2,&lt;br /&gt;"done" : true,&lt;br /&gt;"records" : [ {&lt;br /&gt;"attributes" : {&lt;br /&gt;"type" : "Account",&lt;br /&gt;"url" : "/services/data/v20.0/sobjects/Account/0017000000Q9SFkAAN"&lt;br /&gt;},&lt;br /&gt;"Id" : "0017000000Q9SFkAAN",&lt;br /&gt;"AccountNumber" : "12345",&lt;br /&gt;"Name" : "Big Account"&lt;br /&gt;}, {&lt;br /&gt;"attributes" : {&lt;br /&gt;"type" : "Account",&lt;br /&gt;"url" : "/services/data/v20.0/sobjects/Account/0017000000O1LiGAAV"&lt;br /&gt;},&lt;br /&gt;"Id" : "0017000000O1LiGAAV",&lt;br /&gt;"AccountNumber" : "6789",&lt;br /&gt;"Name" : "Small Account"&lt;br /&gt;}]&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The next question is how to de-serialize this back into an object. Like I have shown before we can use the JavaScriptSerializer class in the .NET Framework to do this, but what would the object model have to look like? One way we could do it is like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public class sfdcAttributes&lt;br /&gt;{&lt;br /&gt;    public string Type { get; set; }&lt;br /&gt;    public string Url { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class sfdcAccount&lt;br /&gt;{&lt;br /&gt;    public string Id { get; set; }&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string AccountNumber { get; set; }&lt;br /&gt;&lt;br /&gt;    public sfdcAttributes Attributes { get; set; }    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class sfdcAccountCollection&lt;br /&gt;{&lt;br /&gt;    public bool Done { get; set; }&lt;br /&gt;    public int TotalSize { get; set; }&lt;br /&gt;    public string nextRecordsUrl { get; set; }&lt;br /&gt;    public List&amp;lt;sfdcAccount&amp;gt; Records { get; set; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will work but it has two problems. First we would have to create a collection class for each SFDC object we want to work with and most of the code for that class would be duplicated from one object to the next. The second problem is that because we put the Attributes property in the sfdcAccount class we can’t use it do do inserts or updates since Attributes isn’t a property on the Account object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To solve the first problem we can use generics:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public class sfdcCollection&amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt;    public bool Done { get; set; }&lt;br /&gt;    public int TotalSize { get; set; }&lt;br /&gt;    public string nextRecordsUrl { get; set; }&lt;br /&gt;    public List&amp;lt;T&amp;gt; Records { get; set; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;This is a generic SFDC collection class that we can use with any type of object. To solve the second problem we need to pull out the Attributes property. Here is a way to handle that:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public class sfdcAccountForCollection : sfdcAccount&lt;br /&gt;{&lt;br /&gt;    public sfdcAttributes Attributes { get; set; }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;Here we create a class just for use with the collections that are returned by the query function. We inherit from the base sfdcAccount class so it keeps this additional class very simple.  To use these classes to de-serialize the JSON response, we just do this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;sfdcCollection&amp;lt;sfdcAccountForCollection&amp;gt; accts = ser.Deserialize&amp;lt;sfdcCollection&amp;lt;sfdcAccountForCollection&amp;gt;&amp;gt;(json);&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2876553740892774526?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2876553740892774526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2876553740892774526' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2876553740892774526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2876553740892774526'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/02/salesforce-rest-api-query_27.html' title='Salesforce REST API Query Deserialization'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-4789798040245813325</id><published>2011-02-24T17:13:00.001-05:00</published><updated>2011-02-24T17:13:50.103-05:00</updated><title type='text'>log4net Presentation</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;For anyone who attended my presentation on log4net at the &lt;a href="http://www.phillynj.net/"&gt;PhillyNJ.NET&lt;/a&gt; meeting 2/21/2011, here are the related file. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://cid-cdfc440c69bcc96f.office.live.com/view.aspx/.Public/BlogFiles/Log4NetPresentation.ppt"&gt;Power Point Presentation&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://cid-cdfc440c69bcc96f.office.live.com/self.aspx/.Public/BlogFiles/Log4NetDemo.zip"&gt;log4net Demo Source Code&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you are in South Jersey of the Philadelphia area be sure to check out the next meting on March 29th where David Isbitski from Microsoft will do a presentation on Real World Windows Phone 7 Development. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-4789798040245813325?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/4789798040245813325/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=4789798040245813325' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4789798040245813325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4789798040245813325'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/02/log4net-presentation.html' title='log4net Presentation'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2096000171586386837</id><published>2011-02-09T19:55:00.003-05:00</published><updated>2011-02-09T19:58:00.826-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Query</title><content type='html'>A couple weeks ago we looked at how to read a record from SFDC using the REST API. The read function has limited usefulness since it requires us to know the internal ID of a record to be able to read it, and in most cases you won’t know this ID. A more useful way of reading records is to use the Query function. &lt;br /&gt;Query allows you to execute Salesforce Object Query Language (SOQL) queries to retrieve a set of records.&amp;nbsp; SOQL is similar to an SQL SELECT statement. I am not going to go into the details of SOQL, but you can learn more about it &lt;a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql.htm"&gt;here&lt;/a&gt;.&lt;br /&gt;The code for doing a Query is pretty much the same as the code I presented in the &lt;a href="http://danlb.blogspot.com/2011/01/salesforce-rest-api-read-record.html"&gt;Salesforce REST API Read Record article&lt;/a&gt;, the only difference being the URI. The URI will look something like this:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;var uri = instanceURL + “&lt;/code&gt;/services/data/v20.0/query?q=SELECT id,accountNumber,name from account&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;You will see that we have added a query string called q that contains the SOQL query. Note that in SOQL you must specify all the fields you want returned. There is no equivalent of ‘SELECT *’ in SOQL. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The response from the query will look something like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: js;"&gt;{&lt;br /&gt;"totalSize" : 2,&lt;br /&gt;"done" : true,&lt;br /&gt;"records" : [ {&lt;br /&gt;"attributes" : {&lt;br /&gt;"type" : "Account",&lt;br /&gt;"url" : "/services/data/v20.0/sobjects/Account/0017000000Q9SFkAAN"&lt;br /&gt;},&lt;br /&gt;"Id" : "0017000000Q9SFkAAN",&lt;br /&gt;"AccountNumber" : null,&lt;br /&gt;"Name" : "Big Account"&lt;br /&gt;}, {&lt;br /&gt;"attributes" : {&lt;br /&gt;"type" : "Account",&lt;br /&gt;"url" : "/services/data/v20.0/sobjects/Account/0017000000O1LiGAAV"&lt;br /&gt;},&lt;br /&gt;"Id" : "0017000000O1LiGAAV",&lt;br /&gt;"AccountNumber" : "CC978213",&lt;br /&gt;"Name" : "GenePoint"&lt;br /&gt;}]&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The first things in the response are two fields called totalSize and done. These are important  because there is a limit to the number of record a query can return. My experimentation showed the  limit to be 2000 records in this case, but that limit my be different in other situations. The totalSize property tells you how many records met the criteria of the query, even if that total is greater then the record limit. If the total is greater then the done property will be false and there will be an additional property called nextRecordsUrl that looks like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New;"&gt;"nextRecordsUrl" : "/services/data/v20.0/query/01g7000000FBzMHAA1-2000"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;To get the next batch of records you would do another HTTP GET using this URL, and then repeat the process until the done property comes back true. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The actual results of the query will be contained in the records array. Each record will contain a series of attributes, one of which is the URL you can use to read the entire record. Following the attributes will be the fields that you requested in the query.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2096000171586386837?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2096000171586386837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2096000171586386837' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2096000171586386837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2096000171586386837'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/02/salesforce-rest-api-query.html' title='Salesforce REST API Query'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-5133074050161028676</id><published>2011-01-29T08:42:00.004-05:00</published><updated>2011-01-29T08:44:12.263-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Update and Delete Record</title><content type='html'>So far we have looked at how to create and read records from Salesforce using the REST API, so the final two basic operations we need are Update and Delete.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Update&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;The code for doing an update is almost identical to the code for doing an insert with just two small differences.&lt;br /&gt;First we need to specify the ID of the record we want to update in the URI just like we did for a read:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;var uri = instanceURL + &lt;/code&gt;&lt;code&gt;"/services/data/v20.0/sobjects/Account/0017000000hX4Iz"&lt;/code&gt;&lt;code&gt;;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="font-family: Georgia;"&gt;Second we will use PATCH for the HTTP method instead of POST. Not that PATCH isn’t a standard HTTP method, but fortunately the .NET WebRequest class allows for arbitrary methods. &lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="font-family: Georgia;"&gt;Just like with an insert you put the JSON or XML encoded object into the body of the request. You can put all the fields in the body or just the ones you want to update.&amp;nbsp; If you decide to use XML for the body don’t forget to change the ContentType from JSON to XML:&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;pre&gt;req.ContentType = "application/xml";&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;The only other difference with an update is the response. Unlike the other function we have looked at so far, the content of the response will be empty if the update succeeds. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style="font-family: Georgia; font-size: small;"&gt;&lt;b&gt; Delete&lt;/b&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Delete is probably the simplest operation. We use the same URI as an update, one that contains the id of the record we want to delete, and set the HTTP method to DELETE. Nothing needs to be put in the body of the request for a delete. Just like an update, if the delete is successful the response will be empty.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-5133074050161028676?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/5133074050161028676/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=5133074050161028676' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5133074050161028676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5133074050161028676'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/01/salesforce-rest-api-update-and-delete.html' title='Salesforce REST API Update and Delete Record'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1345202123360715771</id><published>2011-01-16T10:44:00.002-05:00</published><updated>2011-01-16T10:45:22.580-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Read Record</title><content type='html'>In my last post I showed how to create a new record in Salesforce using the REST API, now lets look at reading a record. &lt;br /&gt;To access a record you need to add the record’s id to the end of the object URI that I showed in the last post. For example to access a specific account record you would use:&lt;br /&gt;&lt;a href="http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe" title="http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe"&gt;http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe&lt;/a&gt;&lt;br /&gt;The id’s aren’t shown directly when you edit a record in SFDC, but you can find the record id in the URL when you are editing a record. You can also get an id from the response when you create a record as we saw last time.&lt;br /&gt;The code to perform the read will look something like this:&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public string ReadData()&lt;br /&gt;{&lt;br /&gt;var uri = instanceURL + "/services/data/v20.0/sobjects/Account/0017000000hX4Iz";&lt;br /&gt;&lt;br /&gt;var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);&lt;br /&gt;req.Headers.Add("Authorization: OAuth " + accessToken);&lt;br /&gt;req.Headers.Add("X-PrettyPrint:1");&lt;br /&gt;req.ContentType = "application/json";&lt;br /&gt;req.Method = "GET";&lt;br /&gt;&lt;br /&gt;WebResponse resp;&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;resp = req.GetResponse();&lt;br /&gt;}&lt;br /&gt;catch (WebException ex)&lt;br /&gt;{&lt;br /&gt;resp = ex.Response;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var sr = new System.IO.StreamReader(resp.GetResponseStream());&lt;br /&gt;return sr.ReadToEnd().Trim();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;This is pretty much the same code we used for the insert but it uses an HTTP GET instead of POST,&amp;nbsp; and there is no body needed for the request. You will also notice a new header, X-PrettyPrint:1. This will make SFDC return the response in a more readable format with appropriate line breaks and indentation. This header can be used in any of the REST API commands.&lt;br /&gt;&lt;br /&gt;The response will contain the JSON formatted Account object. Remember, as always, you can add .xml to the end the URI to have the response returned in XML instead of JSON.&lt;br /&gt;&lt;br /&gt;By default this command will return all the fields in the record. You can specify only the fields you want to return like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe?fields=AccountNumber,Name" title="http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe"&gt;http://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe?fields=AccountNumber,Name&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We have added a query string called fields to the URI which lists the fields you want to return.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1345202123360715771?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1345202123360715771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1345202123360715771' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1345202123360715771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1345202123360715771'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/01/salesforce-rest-api-read-record.html' title='Salesforce REST API Read Record'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-8301257616223337767</id><published>2011-01-08T14:48:00.002-05:00</published><updated>2011-01-08T14:52:56.259-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Record Creation</title><content type='html'>In my last few articles I showed the basics of how to connect to Salesforce using the REST API and how to use some basic functions. Now lets look at how to actually manipulate the data stored in SFDC. We will start by looking at how to insert a new record.&lt;br /&gt;When you are working with tables (called objects in the SFDC nomenclature), the URI will look something like this:&lt;br /&gt;http://na1.salesforce.com/services/data/v20.0/sobjects/Account/&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://na1.salesforce.com/"&gt;http://na1.salesforce.com&lt;/a&gt;&amp;nbsp; is the instance URL that you get during the login process. &lt;/li&gt;&lt;li&gt;/services/data/v20.0/ indicates the version of SFDC you will be using. &lt;/li&gt;&lt;li&gt;sobjects/ is the resource we will be accessing, in this case the SFDC objects (tables). &lt;/li&gt;&lt;li&gt;Account/ is the name of the object we will be creating the new record in. &lt;/li&gt;&lt;/ul&gt;To insert a new record we will do an HTTP POST to this URI. In the headers we will pass the authorization token, and in the body we will pass the JSON encoded data we want to insert. For example here is a simple piece of JSON that will insert a new Account with the name TestAccount and number 1234567.&lt;br /&gt;&lt;pre class="brush: js;"&gt;{    &lt;br /&gt;"Name" : "TestAccount",&lt;br /&gt;"AccountNumber" : "1234567"&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;Now lets look at the C# code to perform this insert. First, to simplify the creation of our JSON lets create an Account class that we can serialize. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public class sfdcAccount&lt;br /&gt;{&lt;br /&gt;public string Name { get; set; }&lt;br /&gt;public string AccountNumber { get; set; }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Next we will setup our URI and the account object&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var uri = instanceURL + "/services/data/v20.0/sobjects/Account/";&lt;br /&gt;&lt;br /&gt;var acct = new sfdcAccount();&lt;br /&gt;acct.Name = "NewAccount";&lt;br /&gt;acct.AccountNumber = "123456";&lt;/pre&gt;&lt;br /&gt;and then serialize the account object into JSON.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var ser = new JavaScriptSerializer();&lt;br /&gt;var body = ser.Serialize(acct);&lt;/pre&gt;&lt;br /&gt;We can now create our HTTP request.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);&lt;br /&gt;req.Headers.Add("Authorization: OAuth " + accessToken);&lt;br /&gt;req.ContentType = "application/json";&lt;br /&gt;req.Method = "POST";&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Here we create an HttpWebRequest object pointing to the URI we specified earlier. We then set a header that contains the access token we got during the login process, set the content type to JSON and finally specify that this is an HTTP POST request.&lt;br /&gt;&lt;br /&gt;Next we need to add the body of the request. This code will convert our JSON to a byte array an attach it to the request.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;byte[] data = System.Text.Encoding.ASCII.GetBytes(body);&lt;br /&gt;req.ContentLength = body.Length;&lt;br /&gt;var os = req.GetRequestStream();&lt;br /&gt;os.Write(data, 0, data.Length);&lt;br /&gt;os.Close();&lt;/pre&gt;&lt;br /&gt;Finally we execute the request and retrieve the result that SFDC sends back.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;WebResponse resp;&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;resp = req.GetResponse();&lt;br /&gt;}&lt;br /&gt;catch (WebException ex)&lt;br /&gt;{&lt;br /&gt;resp = ex.Response;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (resp == null) return null;&lt;br /&gt;System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());&lt;br /&gt;return sr.ReadToEnd().Trim();&lt;/pre&gt;&lt;br /&gt;The try/catch around the request is important. When there is an error executing the command SFDC will return a HTTP response code of 400 which will throw an exception. To resolve this problem we catch the exception and retrieve the response object from the exception.&lt;br /&gt;&lt;br /&gt;Assuming there are no errors, SFDC will return a JSON response that looks like this &lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: js;"&gt;{&lt;br /&gt;"id":"0017000000hX4BIAA0",&lt;br /&gt;"errors":[],&lt;br /&gt;"success":true&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family: Georgia;"&gt;First we get back the internal id of the record that was created. We can use this later to read, update, or delete this record. We also get back a true/false field indicating the success or failure of the insert and an errors field. I have not yet found a case where these are used since an error will return a different response. For example if we make the AccountNumber greater the 40 characters &lt;/span&gt;&lt;span style="font-family: Georgia;"&gt; we will get the following response:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: js;"&gt;{&lt;br /&gt;"fields":["AccountNumber"],&lt;br /&gt;"message":"Account Number: data value too large: 1234567890123456789012345678901234567890123456789012345678901 (max length=40)",&lt;br /&gt;"errorCode":"STRING_TOO_LONG"&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-8301257616223337767?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/8301257616223337767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=8301257616223337767' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8301257616223337767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8301257616223337767'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2011/01/salesforce-rest-api-record-creation.html' title='Salesforce REST API Record Creation'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7253500111871858951</id><published>2010-11-05T08:58:00.002-04:00</published><updated>2011-01-06T17:36:23.420-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce REST API Access Token</title><content type='html'>In my first article on the SFDC REST API I showed how you authenticate to Salesforce using OAuth. The main output of this process is the access token which must be provided when you make any other calls to the REST API. One of the first things I wondered about the access token is, how long does it last? It turns out that the access token is tied to the normal session timeout in SFDC and is configurable for each instance. To view or change the setting log into your account, click Setup, then under Administration Setup select Security Controls then Session Settings. &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/TNP_WshT2cI/AAAAAAAABTs/IwsI5TKjpNU/s1600-h/image%5B3%5D.png"&gt;&lt;img alt="image" border="0" height="224" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TNP_W6dFHwI/AAAAAAAABTw/iYj5v9GC_W0/image_thumb%5B1%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="562" /&gt;&lt;/a&gt; &lt;br /&gt;You can see that in this case the timeout is set to two hours. This means that if you go for more the two hours without calling the REST API the access token will expire. You can change this setting from between 15 minutes and 8 hours. &lt;br /&gt;The next question is, when the access token expires does the user have to go through the login process again? Fortunately the answer is no, this is where the refresh token comes into play. When we did the initial authentication process to get the access token we also received a refresh token. The refresh token can be used to get a new access token without the user having to enter their username and password again. &lt;br /&gt;The code to get a new access token is pretty much the same as the code we initially used to get access token.&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;{ &lt;br /&gt;&lt;br /&gt;string URI = "https://login.salesforce.com/services/oauth2/token";&lt;br /&gt;StringBuilder body = new StringBuilder();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;body.Append("refresh_token=" + refreshToken + "&amp;amp;");&lt;br /&gt;body.Append("grant_type=refresh_token&amp;amp;");&lt;br /&gt;body.Append("client_id=" + clientID + "&amp;amp;");&lt;br /&gt;body.Append("client_secret=" + clientSecret + "&amp;amp;");&lt;br /&gt;body.Append("redirect_uri = " + redirectURL); &lt;br /&gt;&lt;br /&gt;string result = HttpPost(URI, body.ToString()); &lt;br /&gt;&lt;br /&gt;JavaScriptSerializer ser = new JavaScriptSerializer();&lt;br /&gt;token = ser.Deserialize&amp;lt;TokenResponse&amp;gt;(result); &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You will notice two differences. First instead of passing the code we got when the user logged in, we pass the refresh token, and second we set the grant type to refreshToken instead of authorization_code. The function will return the same response as the initial call did with one exception. According to the OAuth specs the service is not required to return a new refresh token when a new access token is generated. This appears to be the case with SFDC since this call does not return a new refresh token. This means that you need to hold onto the original refresh token to use each time you request a new access token.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7253500111871858951?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7253500111871858951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7253500111871858951' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7253500111871858951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7253500111871858951'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/11/salesforce-rest-api-access-token.html' title='Salesforce REST API Access Token'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LNYcmNhpvTA/TNP_W6dFHwI/AAAAAAAABTw/iYj5v9GC_W0/s72-c/image_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7849818414554356198</id><published>2010-11-01T19:21:00.002-04:00</published><updated>2010-11-01T19:23:32.183-04:00</updated><title type='text'>Salesforce REST API Part 2</title><content type='html'>In my last post I introduced the new Salesforce REST API. Now I will dig into some of the details of how to use the interface.&lt;br /&gt;&lt;h4&gt;URIs&lt;/h4&gt;Like any REST API you access resources in Salesforce using various URIs like this:&lt;br /&gt;&lt;a href="http://na1.salesforce.com/services/data/v20.0/sobjects/Account/"&gt;http://na1.salesforce.com/services/data/v20.0/sobjects/Account/&lt;/a&gt;&lt;br /&gt;The first part of the URI "http://na1.salesforce.com/" identifies your Salesforce instance. This is needed because different accounts will be hosted on different servers. As I showed in the last article you retrieve the instance URL during the authentication process.&lt;br /&gt;The next piece "/services/data" identifies the service and is the same for all REST API calls. The following piece "v20.0/" is the version number which specifies the version of the API you want to use. You can retrieve a list of the available versions by calling the List Versions command which I will show in a minute. The Version command will return a URL that contains both the service and version parts of the URI.&lt;br /&gt;Next 'sobjects' is the resource you will be calling. You can get a list of the available resources using the List Resources command.&lt;br /&gt;Finally anything after the resource is specific to the resource and command you are calling.&lt;br /&gt;&lt;h4&gt;Return Type&lt;/h4&gt;By default the REST API returns its results in JSON format. You can also request that the results be returned in XML. To do this just append .xml to the end of the URI you are calling. The documentation also indicates that you can do this using the HTTP ACCEPT header, but I have not been able to get that to work. I my examples I will be showing the results in XML.&lt;br /&gt;&lt;h4&gt;List Versions Command&lt;/h4&gt;The list versions command looks like this:&lt;br /&gt;&lt;a href="https://na5.salesforce.com/services/data/.xml"&gt;https://na5.salesforce.com/services/data/.xml&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Note that in all my examples I will be using the instance URL of my account, be sure to substitute your own. &lt;/b&gt;&lt;br /&gt;Here is what is returned:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;Versions&amp;gt;&lt;br /&gt;&amp;lt;Version&amp;gt;&lt;br /&gt;&amp;lt;label&amp;gt;Winter &amp;amp;apos;11&amp;lt;/label&amp;gt;&lt;br /&gt;&amp;lt;url&amp;gt;/services/data/v20.0&amp;lt;/url&amp;gt;&lt;br /&gt;&amp;lt;version&amp;gt;20.0&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;lt;/Version&amp;gt;&lt;br /&gt;&amp;lt;/Versions&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case there is only one version available, version 2.0. Also returned is the label for the version "Winter '11" and the URL to access the API for this version. One thing to note about this command is that you do not need to authenticate before calling it. It works whether you pass the access token or not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;List Resources Command&lt;/h4&gt;The next command you will want to know about lists the resources available for a specific version. The command looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://na1.salesforce.com/services/data/v20.0/.xml"&gt;http://na1.salesforce.com/services/data/v20.0/.xml&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Remember if you want to return the results in JSON format just leave off the .xml or specify .json instead of .xml.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The result looks like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;urls&amp;gt;&lt;br /&gt;&amp;lt;sobjects&amp;gt;/services/data/v20.0/sobjects&amp;lt;/sobjects&amp;gt;&lt;br /&gt;&amp;lt;search&amp;gt;/services/data/v20.0/search&amp;lt;/search&amp;gt;&lt;br /&gt;&amp;lt;query&amp;gt;/services/data/v20.0/query&amp;lt;/query&amp;gt;&lt;br /&gt;&amp;lt;recent&amp;gt;/services/data/v20.0/recent&amp;lt;/recent&amp;gt;&lt;br /&gt;&amp;lt;/urls&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This shows the resources that are accessible through the API. The current resources are:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;sobjects&lt;/b&gt; – Allows you to access information about the objects in the database and to insert, read, updated and delete objects.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;query&lt;/b&gt; – Allows you to run SOQL queries.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;search&lt;/b&gt; – Allows you to run a SOSL search. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;recent&lt;/b&gt; – This seems to return a list of recent objects, but I haven't found any official documentation on it.&lt;br /&gt;&lt;br /&gt;That's all for now. In future postings I will get into some more details on how each of these resources is used.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7849818414554356198?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7849818414554356198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7849818414554356198' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7849818414554356198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7849818414554356198'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/11/salesforce-rest-api-part-2.html' title='Salesforce REST API Part 2'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-8736336470627801183</id><published>2010-10-30T10:47:00.006-04:00</published><updated>2011-03-20T10:04:48.108-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Salesforce'/><title type='text'>Salesforce.com REST API</title><content type='html'>&lt;p&gt;&lt;br /&gt;A while back I had the opportunity to develop a .NET desktop application that interfaced to Salesforce.com using the SOAP API, so I was very interested when I heard about SFDC's new REST based API. The beta of this interface has just been made available to developers and will eventually go into production in a future release. SFDC has made a simple Java sample available but no .NET samples yet, so I thought I would write an article explaining how to access the API from .NET. This example will be done in C# using Visual Studio 2010 and the .NET Framework 4.0 although there is no reason this couldn't be done with earlier versions of the framework.&lt;/p&gt;&lt;p&gt;To try out the API you will need a Salesforce.com developer account. You can sign up for a free account at &lt;a href="http://developer.force.com/"&gt;http://developer.force.com/&lt;/a&gt;. I am not sure if the REST API is automatically enabled for all developer accounts, but if not you can sign up for it &lt;a href="https://www.developerforce.com/events/rest_developer_preview/registration.php"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;Authentication &lt;/h4&gt;&lt;p&gt;Before you can use the REST API you need to authenticate to Salesforce.com. There are two ways to do this, using a Session ID from the old SOAP API, or using OAuth which is what I will be doing in this sample. OAuth allows an application to access a web based resource without the user having to provide their login details to the calling application. The exact details of how OAuth works are beyond the scope of this article but you can learn more at &lt;a href="http://oauth.net/documentation/getting-started/"&gt;ouath.net&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The first step in authentication is to enable the REST interface. To do this log into your SFDC account and select Setup. Under App Setup, select Develop then Remote Access, this will display a list of Remote Access Applications. The list will be empty at this point, so click on New to add a new remote access application.&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/TMwv-Gro5ZI/AAAAAAAABS8/eq_oWoEeRfo/s1600-h/clip_image002%5B4%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TMwv-S752zI/AAAAAAAABTA/NiRsvYFLxyw/clip_image002_thumb%5B1%5D.jpg?imgmax=800" border="0" height="192" width="559" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;There are two required fields, the Application name which can be anything of you choosing, and the Callback URL which needs a little explanation. OAuth is primarily designed to be used between two web sites. The web site requesting access will redirect to the SFDC login screen, and when the user has logged in the SFDC web site will re-direct back to the Callback URL you specify. If you are developing a web application this needs to be the URL of a secure (HTTPS) page. In this demo, since we are developing a desktop app, we don’t want to actually redirect so we put in an identifier of our choice that we will catch in our application.&lt;/p&gt;&lt;p&gt;Once you have filled out the form, click Save, then click on the application name on the list. The details you entered will be re-displayed along with the Consumer Key and Consumer Secret which we will need during the authentication process. I created some object level variables to hold this information:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;private string clientID = “YOUR CONSUMER KEY";&lt;br /&gt;private string clientSecret = “YOUR CONSUMER SECRET";&lt;br /&gt;private string redirectURL = "resttest:callback";&lt;/pre&gt;&lt;br /&gt;Since the key and secret are specific to my SFDC account I have omitted them in the demo. You will need to put in the ones from your account.&lt;br /&gt;&lt;br /&gt;The next thing we need to do is have our application call the SFDC login page. If this was a web app we could simply re-direct to is, but since this is a desktop app we can use the WinForms WebBrowser control. I added a WebBrowser control to my form and then put the following code in the Form_Load event:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;var authURI = new StringBuilder();&lt;br /&gt;authURI.Append("https://login.salesforce.com/services/oauth2/authorize?");&lt;br /&gt;authURI.Append("response_type=code");&lt;br /&gt;authURI.Append("&amp;amp;client_id=" + clientID);&lt;br /&gt;authURI.Append("&amp;amp;redirect_uri=" + redirectURL);&lt;br /&gt;webBrowser1.Navigate(authURI.ToString());&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;First we build a URL that points to the SFDC login page and includes the Consumer Key (called client_id) and the re-direct URL as query strings. Next we call Navigate on the web browser control to point to this location. &lt;/p&gt;Once the user has entered their credentials using the web browser control it will be re-directed to resttest:callback. We can catch this in the webBrowser_DocumentCompleted event handler:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;if (e.Url.AbsoluteUri.StartsWith("resttest:callback"))&lt;br /&gt;{&lt;br /&gt;webBrowser1.Navigate("about:blank");&lt;br /&gt;code = e.Url.Query;&lt;br /&gt;code = code.Substring(6);&lt;br /&gt;&lt;br /&gt;GetToken();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;When the redirect is found the first thing I did was redirect the web browser control to a blank page. This is not necessary but it looks nice. The URL that is returned will look like this:&lt;br /&gt;&lt;br /&gt;callback?code=aPrx9vip.t4qSZdAs_DHNIR9mEcerAoVsq.hX9qVAtUNfAibMV8ClSmYxbsxiWb81O8BzgRwLA%3D%3D&lt;br /&gt;&lt;br /&gt;We need to get the code query string since this is needed for the next part of the authentication process. The code is only valid for a short time so we need to use it to get an access token which is what we will actually use to do the REST calls. Here is the code to get the token:&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;private void GetToken() {&lt;br /&gt;string URI = "https://login.salesforce.com/services/oauth2/token";&lt;br /&gt;StringBuilder body = new StringBuilder();&lt;br /&gt;body.Append("code=" + code + "&amp;amp;");&lt;br /&gt;body.Append("grant_type=authorization_code&amp;amp;");&lt;br /&gt;body.Append("client_id=" + clientID + "&amp;amp;");&lt;br /&gt;body.Append("client_secret=" + clientSecret + "&amp;amp;");&lt;br /&gt;body.Append("redirect_uri = " + redirectURL);&lt;br /&gt;&lt;br /&gt;string result = HttpPost(URI, body.ToString());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;This time instead of passing the parameters as query string we will pass them in the body of the post. You can see that we add parameters for the code returned in the last step, the clinet_id (Consumer Key), client_secret (Consumer Secret) and redirect_uri, then call an HttpPost. The HttpPost is simply a wrapper function around a System.Net.WebRequest object. You can see the full code in the download.&lt;br /&gt;&lt;br /&gt;The result returned from the post will be the &lt;a href="http://www.json.org/"&gt;JSON&lt;/a&gt; encoded authentication data:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;{&lt;br /&gt;\"id\":\"https://login.salesforce.com/id/0axD7230dz0xrrP/x0e7f0D0A039F1y\",&lt;br /&gt;\"issued_at\":\"1288375889300\",&lt;br /&gt;\"refresh_token\":\"5APp8axZfY11MvXxUzgcRXyJ6zGtoLbD66hgHfx97d9Vklp7uFRmB6minfJwRJr_Ea4Zh563C0s_eg==\",&lt;br /&gt;\"instance_url\":\"https://na5.salesforce.com\",&lt;br /&gt;\"signature\":\"W11FfBhvQ1kwXvNsNTas+Gn3812XRmPL2utxxKbEqss=\",&lt;br /&gt;\"access_token\":\"K0DT029060yJrrP!AR4AQJMczwx9435JeGyhsY40M.OM1BJo5c72z9Hb.F6T5lvqX992pt0KPabj8Snx7L1CqaKxUi7wixxcnfIa9UDY1KiXl0fb1\"&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;If you are using .NET Framework 3.5 or 4, the easiest way to parse this is to use a JavaScriptSerializer call from the System.Web.Script.Serialization namespace. First I created a class to put the data into.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public class TokenResponse&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public string id { get; set; }&lt;br /&gt;public string issued_at { get; set; }&lt;br /&gt;public string refresh_token { get; set; }&lt;br /&gt;public string instance_url { get; set; }&lt;br /&gt;public string signature { get; set; }&lt;br /&gt;public string access_token { get; set; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Then we can use the following code to parse the response. This will convert the JSON into an instance of the TokenResponse class.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;JavaScriptSerializer ser = new JavaScriptSerializer();&lt;br /&gt;token = ser.Deserialize&amp;lt;TokenResponse&amp;gt;(result);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now the authentication process is complete, so we can actually use this token to call a REST function. We start with a wrapper function that does an HTTP GET.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;public string HttpGet(string URI, string Parameters)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.Net.WebRequest req = System.Net.WebRequest.Create(URI);&lt;br /&gt;req.Method = "GET";&lt;br /&gt;req.Headers.Add("Authorization: OAuth " + token.access_token );&lt;br /&gt;System.Net.WebResponse resp = req.GetResponse();&lt;br /&gt;&lt;br /&gt;if (resp == null) return null;&lt;br /&gt;System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());&lt;br /&gt;return sr.ReadToEnd().Trim();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;You will notice that I am adding the access_token we got in the last step as the Authorization header. To actually call this routine we do the following:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;string s = HttpGet(token.instance_url + @"/services/data/v20.0/", "");&lt;/p&gt;&lt;br /&gt;We are doing the get using the instance URL returned in the last step, and calling the REST function “/services/data/v20.0/”. This will return a list of the available REST resource and will look something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;{&lt;br /&gt;"sobjects":"/services/data/v20.0/sobjects",&lt;br /&gt;"search":"/services/data/v20.0/search",&lt;br /&gt;"query":"/services/data/v20.0/query",&lt;br /&gt;"recent":"/services/data/v20.0/recent"&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;So there are the basics of how to get started with the SFDC REST API. You can download the full code in a Visual Studio 2010 here:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="https://sites.google.com/site/danlboris/SalesforceRESTDemo.zip"&gt;Visual Studio 2010 Salesforce REST API Demo&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;You can find more information on the Developerforce web site:&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_REST_API"&gt;Getting Started with the Force.com REST API (Java)&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href="http://developer.force.com/REST"&gt;REST API Resource Page&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://wiki.developerforce.com/images/c/c9/Api_rest.pdf"&gt;REST API Documentation&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-8736336470627801183?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/8736336470627801183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=8736336470627801183' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8736336470627801183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8736336470627801183'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/10/salesforcecom-rest-api.html' title='Salesforce.com REST API'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_LNYcmNhpvTA/TMwv-S752zI/AAAAAAAABTA/NiRsvYFLxyw/s72-c/clip_image002_thumb%5B1%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2666040521345453641</id><published>2010-09-06T08:54:00.001-04:00</published><updated>2010-09-06T08:54:44.421-04:00</updated><title type='text'>LightSwitch Concurrency</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I was curious how LightSwitch dealt with database concurrency, so I setup a little test to find out. I started with the sample application I have been working on in my previous posts. First I published the application then ran the setup and finally started two instances of the application. Next I added a new record, and then opened it for editing in both instances. In one instance I made a change to the Address field and saved the record. In the second instance I made a change to Start Date field and clicked save. When I did this LightSwitch detected the concurrency violation and displayed the following screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/TITkkgU3ZsI/AAAAAAAABSQ/U-eAZJykXsI/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_LNYcmNhpvTA/TITkkzdt_II/AAAAAAAABSU/ee5iii7qKpw/clip_image002_thumb.jpg?imgmax=800" width="244" height="191" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here for each conflicting field you receive a drop down menu where you can select between the value on the server and the one from your instance.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2666040521345453641?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2666040521345453641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2666040521345453641' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2666040521345453641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2666040521345453641'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/09/lightswitch-concurrency.html' title='LightSwitch Concurrency'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_LNYcmNhpvTA/TITkkzdt_II/AAAAAAAABSU/ee5iii7qKpw/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1849936164766060403</id><published>2010-09-04T08:11:00.002-04:00</published><updated>2010-09-04T08:27:16.158-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LightSwitch'/><title type='text'>LightSwitch Query and Details Screens</title><content type='html'>&lt;p&gt;  &lt;br /&gt;In my first posting on LightSwitch I showed how to setup a screen to create a new record. This isn't very useful without a way to view and edit records. In this posting I will show how to setup a search and details screen.&lt;/p&gt;  &lt;p&gt;I am going to start with the same Employee table I created in the first post:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/TII3U4WIy1I/AAAAAAAABRg/Syr9D5DcyM0/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh6.ggpht.com/_LNYcmNhpvTA/TII3VOnL0nI/AAAAAAAABRk/wnPeR4-8pw8/clip_image002_thumb.jpg?imgmax=800" border="0" height="118" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next I created a new Search screen for Employees. When you run the app you will get the new search screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/TII3Vkipo0I/AAAAAAAABRo/yT3HqaqpnwY/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image004" alt="clip_image004" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TII3WHoJJlI/AAAAAAAABRs/xW8wey1x8wo/clip_image004_thumb.jpg?imgmax=800" border="0" height="111" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;On this screen you can browse records, search from them, export them to Excel and click the Employee name to edit the record. This brings up a couple questions. First, where does the edit screen come from? It's not the same as the Create screen we started with. Turns out LightSwitch dynamically creates the edit screen when you view the record. You can easily override this by creating a new Details Screen like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TII3XDcUN1I/AAAAAAAABRw/AD0_bnHXJjo/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image006" alt="clip_image006" src="http://lh6.ggpht.com/_LNYcmNhpvTA/TII3YNH_dcI/AAAAAAAABR0/FnCN6FxSiAQ/clip_image006_thumb.jpg?imgmax=800" border="0" height="176" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you keep the Use as Default Details Screen option checked it will become the details/edit screen that opens when you click on a record.&lt;/p&gt;  &lt;p&gt;The next question is how do you change the field that you click to view a record? This is not entirely intuitive; you need to make the change in the table view. Select the table, and then at the bottom of the properties window set the Summary Property to the one that you want to be clickable. You can also change the Display Name which will become the name at the top of the column. In this example I am using the Id as the Summary Property:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LNYcmNhpvTA/TII3ZE35BMI/AAAAAAAABR4/Y8hv13gvFOI/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image008" alt="clip_image008" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TII3ZX_HZSI/AAAAAAAABR8/n9-uOtN_WrI/clip_image008_thumb.jpg?imgmax=800" border="0" height="244" width="199" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To finish this you need to go back to the editor for the SearchEmployee screen and add the FirstName into the field list:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LNYcmNhpvTA/TII3Z1HWZtI/AAAAAAAABSA/1EupZGIwgd4/s1600-h/clip_image010%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image010" alt="clip_image010" src="http://lh5.ggpht.com/_LNYcmNhpvTA/TII3brfM6fI/AAAAAAAABSE/AGf2Llwjais/clip_image010_thumb.jpg?imgmax=800" border="0" height="244" width="177" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now when you run the application the Id will be clickable to take you to the detail/edit screen.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/TII3dbriJ5I/AAAAAAAABSI/JK5K5bs_JnY/s1600-h/clip_image012%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image012" alt="clip_image012" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TII3eUykFYI/AAAAAAAABSM/QHZ-s07jc_A/clip_image012_thumb.jpg?imgmax=800" border="0" height="80" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1849936164766060403?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1849936164766060403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1849936164766060403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1849936164766060403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1849936164766060403'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/09/lightswitch-query-and-details-screens.html' title='LightSwitch Query and Details Screens'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_LNYcmNhpvTA/TII3VOnL0nI/AAAAAAAABRk/wnPeR4-8pw8/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-934746809166543750</id><published>2010-08-22T14:49:00.003-04:00</published><updated>2010-09-04T08:27:30.976-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LightSwitch'/><title type='text'>LightSwitch Custom Controls Sizing</title><content type='html'>&lt;p&gt;When I was working on my last post I couldn't figure out how to get my custom control to auto size when the screen was resized. After looking at this a little closer I found the trick to doing this. First in the custom control's XAML change the column sizes so they are relative.&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;br /&gt;  &amp;lt;ColumnDefinition Width="1*" /&amp;gt;&lt;br /&gt;  &amp;lt;ColumnDefinition Width="1*" /&amp;gt;&lt;br /&gt;  &amp;lt;ColumnDefinition Width="1*" /&amp;gt;&lt;br /&gt;&amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;After you have re-built the control return to the designer for the CreateNewEmployee screen. Click on the Name control and then scroll to the bottom of the properties list and set the Content Size to Stretch. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/THFxHi9FwDI/AAAAAAAABRE/iZSTBVtXRn0/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh5.ggpht.com/_LNYcmNhpvTA/THFxH5iYx7I/AAAAAAAABRI/WcdiZcXR1hA/clip_image002_thumb.jpg?imgmax=800" border="0" height="219" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now the textboxes in the custom control will stretch when the page is re-sized.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-934746809166543750?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/934746809166543750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=934746809166543750' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/934746809166543750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/934746809166543750'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/08/lightswitch-custom-controls-sizing.html' title='LightSwitch Custom Controls Sizing'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_LNYcmNhpvTA/THFxH5iYx7I/AAAAAAAABRI/WcdiZcXR1hA/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-8961549215871653981</id><published>2010-08-20T20:37:00.005-04:00</published><updated>2010-09-04T08:29:35.105-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LightSwitch'/><title type='text'>Basic LightSwitch Custom Controls</title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Out of the box LightSwitch comes with a limited set of visual controls, but since the UI is rendered in Silverlight you can include other Silverlight controls including your own custom controls. Here I will provide a simple example of how to make your own custom control, its easier then you might think. To do this you will need to install LightSwitch on top of a full version of Visual Studio 2010. I am going to start with a simple table, then add a Create New Employee screen to the application. I am going to create a custom control that formats the First, Last and Middle name text boxes in a different way.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/TG8fmXoUFbI/AAAAAAAABQU/U-MZ7A0gRR4/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TG8fmsOyYrI/AAAAAAAABQY/zEq7Ulg_rVE/clip_image002_thumb.jpg?imgmax=800" border="0" height="178" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In your LightSwitch solution add a new Silverlight 4 Class Library project. I am going to call it EmployeeDbControls.   &lt;br /&gt;&lt;br /&gt;&lt;/li&gt;    &lt;li&gt;To the new project add a Silverlight User Control item. I am going to call it NameControl.   &lt;br /&gt;&lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Here is the XAML I am going to add to that control:   &lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;Grid x:Name="LayoutRoot" DataContext="{Binding Screen.EmployeeProperty}"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;Grid.RowDefinitions&amp;gt;&lt;br /&gt; &amp;lt;RowDefinition /&amp;gt;&lt;br /&gt; &amp;lt;RowDefinition /&amp;gt;&lt;br /&gt;&amp;lt;/Grid.RowDefinitions&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;br /&gt; &amp;lt;ColumnDefinition Width="150" /&amp;gt;&lt;br /&gt; &amp;lt;ColumnDefinition Width="150" /&amp;gt;&lt;br /&gt; &amp;lt;ColumnDefinition Width="150" /&amp;gt;&lt;br /&gt;&amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;TextBlock Grid.Column="0" Grid.Row="0"&amp;gt;First&amp;lt;/TextBlock&amp;gt;&lt;br /&gt;&amp;lt;TextBlock Grid.Column="1" Grid.Row="0"&amp;gt;Middle&amp;lt;/TextBlock&amp;gt;&lt;br /&gt;&amp;lt;TextBlock Grid.Column="2" Grid.Row="0"&amp;gt;Last&amp;lt;/TextBlock&amp;gt;&lt;br /&gt;&amp;lt;TextBox Margin="5" Grid.Column="0" Grid.Row="1" Text="{Binding FirstName,Mode=TwoWay}"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;br /&gt;&amp;lt;TextBox Margin="5" Grid.Column="1" Grid.Row="1" Text="{Binding MiddleName,Mode=TwoWay}"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;br /&gt;&amp;lt;TextBox Margin="5" Grid.Column="2" Grid.Row="1" Text="{Binding LastName,Mode=TwoWay}"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/Grid&amp;gt;&lt;br /&gt;&lt;/pre&gt;    &lt;p&gt;This will create three textboxes laid out in a grid. The important thing to note here is the data binding properties. First we need to set a DataContext so I am did this on the grid so that all the controls in the grid can use it. In the DataContext binding the EmployeeProperty comes from the editor for the Create New screen, you can see it just above the field names:&lt;/p&gt;    &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8fm810AII/AAAAAAAABQc/3ELzQM4AvxQ/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="clip_image004" alt="clip_image004" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TG8fn3ih54I/AAAAAAAABQg/5AWCEoF_NRc/clip_image004_thumb.jpg?imgmax=800" border="0" height="83" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt; &lt;p&gt;The second part of the binding is in the textboxes. Here we simply bind to the field names in the record. Note that the mode must be set TwoWay so we can edit and display.&lt;/p&gt;  &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Once the control is complete, build the project.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Return to the designer screen for the Create New screen and remove the FirstName, MiddleName and LastName fields.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;  &lt;li&gt;Click on the line that says "(TOP ROW) Vertical Stack", then click the Add Layout Item menu and select Custom Control. You will see this screen:&lt;br /&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8foUIutAI/AAAAAAAABQk/QoCVtJ7ueM0/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="clip_image006" alt="clip_image006" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8foqax_9I/AAAAAAAABQo/luZnpJ4us6w/clip_image006_thumb.jpg?imgmax=800" border="0" height="244" width="210" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;  &lt;li&gt;Click Add Reference… and select the EmployeeDbControls project.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Drill down on the EmployeeDbControls reference and select NameControl. Click OK to close the References screen.&lt;br /&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8fpxMogdI/AAAAAAAABQs/BOsNYaKozNg/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="clip_image008" alt="clip_image008" src="http://lh5.ggpht.com/_LNYcmNhpvTA/TG8fq9iaDEI/AAAAAAAABQw/aDshGoHGYQ0/clip_image008_thumb.jpg?imgmax=800" border="0" height="87" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;  &lt;li&gt;Click and drag the NameControl up above the Address field.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;  &lt;li&gt;Make sure the NameControl is selected, then in the property window change the Display Name from ScreenContent to Name.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;  &lt;li&gt;Run the application. When you open the CreateNewEmployee screen you will see the new control. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8fsExnF9I/AAAAAAAABQ0/R1sp5QkR638/s1600-h/clip_image010%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="clip_image010" alt="clip_image010" src="http://lh6.ggpht.com/_LNYcmNhpvTA/TG8fs6CnnUI/AAAAAAAABQ4/fUoPqmBd1a4/clip_image010_thumb.jpg?imgmax=800" border="0" height="191" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If I wanted to I could create a Details Screen for the Employee table and add the new name control to that screen so we have the same control when we are editing a record.&lt;/p&gt;&lt;p&gt;This is a very basic example but will get you started with designing custom controls for LightSwitch.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-8961549215871653981?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/8961549215871653981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=8961549215871653981' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8961549215871653981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8961549215871653981'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/08/basic-lightswitch-custom-controls.html' title='Basic LightSwitch Custom Controls'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LNYcmNhpvTA/TG8fmsOyYrI/AAAAAAAABQY/zEq7Ulg_rVE/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2114265079198696229</id><published>2010-08-20T20:28:00.002-04:00</published><updated>2010-09-04T08:29:46.393-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LightSwitch'/><title type='text'>LightSwitch Table Relationships</title><content type='html'>&lt;p&gt;  &lt;br /&gt;In my last post I introduced Microsoft's new RAD tool called Visual Studio LightSwitch. In the example in that post I showed how to create an application with a single table, now I’ll explain how to do table relationships. &lt;/p&gt;  &lt;p&gt;Last time I created an employee table. Now I want a table that lists the work history for each employee. First add a new table called WorkHistory. You will notice that I did not put a foreign key on the WorkHistory table to relate it to the Employee table; LightSwitch will take care of this for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/TG8djC8xF-I/AAAAAAAABP0/ZufDLHC5dNE/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8dj5k4NkI/AAAAAAAABP4/uZZKuL3Ucv4/clip_image002_thumb.jpg?imgmax=800" border="0" height="80" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A note on table naming. LightSwitch tries to be very helpful in naming your tables. The name you type at the top of the table editor is actually the entity name, it represents a single thing. The name that shows up in the Solution Explorer is the table name which LightSwitch will try to pluralize for you. So the WorkHistory entity creates a table called WorkHistories. For this reason do not pluralize the entity name. If you were to enter WorkHistories as the entity name you would end up with a table called WorkHistoriesSet. &lt;/p&gt;  &lt;p&gt;Once you have created the table you need to setup the relationship by clicking the Relationship… button which brings up the relationship designer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8dkiMx_yI/AAAAAAAABP8/Q-UvA60Jnfs/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image004" alt="clip_image004" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8dl50AnII/AAAAAAAABQA/Km87HPB6WnY/clip_image004_thumb.jpg?imgmax=800" border="0" height="244" width="234" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The options are set at the top of the screen and relationship will be displayed both graphically and in plain English. The Navigation Property is the name of the property that will be created on each table to manage the relationship. &lt;/p&gt;  &lt;p&gt;The change will not automatically show up in the Add New screen I created last time, so the easy fix is to delete that screen and add a new one. When you select Employee for the Screen Data you will now get the option of including the Employee WorkHistories on the screen.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/TG8dmP3mXwI/AAAAAAAABQE/pHNR9dW97hg/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image006" alt="clip_image006" src="http://lh5.ggpht.com/_LNYcmNhpvTA/TG8dnb7wziI/AAAAAAAABQI/pkP_oTAvYEs/clip_image006_thumb.jpg?imgmax=800" border="0" height="175" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you run the application you will now have an Add New screen where the employee's details and work history can be edited.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8dngYp_4I/AAAAAAAABQM/UiXNonmXaJw/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image008" alt="clip_image008" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TG8doXayn2I/AAAAAAAABQQ/TY0N-F6pBFg/clip_image008_thumb.jpg?imgmax=800" border="0" height="169" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2114265079198696229?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2114265079198696229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2114265079198696229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2114265079198696229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2114265079198696229'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/08/lightswitch-table-relationships.html' title='LightSwitch Table Relationships'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_LNYcmNhpvTA/TG8dj5k4NkI/AAAAAAAABP4/uZZKuL3Ucv4/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7637513359340192255</id><published>2010-08-20T18:11:00.002-04:00</published><updated>2010-09-04T08:29:58.161-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LightSwitch'/><title type='text'>Microsoft Visual Studio LightSwitch Beta 1</title><content type='html'>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;LightSwitch is a new tool from Microsoft for doing rapid application development of data driven applications. It's sort of like Microsoft Access but with a much more robust underlying architecture. The design tool is actually a version of Visual Studio 2010 that has been simplified to allow even someone without programming skills to build a database and the front end application to manipulate it without having to write any code. On the back end LightSwitch can use SQL Server (including SQL Express), SQL Azure or SharePoint for data storage, and uses Silverlight 4 either in our out of browser for the user interface. &lt;/p&gt;  &lt;p&gt;LightSwitch Beta 1 is currently available to MSDN subscribers, and will be available to the general public on August 23&lt;sup&gt;rd&lt;/sup&gt;, 2010.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installation&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;LightSwitch is currently being provided as a DVD ISO image. Installation is very simple. Currently the only option during install is where you want to install the program. The installer will install any pre-requisites that you need along with an instance of SQL Server 2008 Express edition. If you already have Visual Studio 2010, LightSwitch will be integrated into the existing install. I have installed this on a Windows XP system that already had VS 2010, and a Server 2003 machine that did not and both install worked without any problems. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Building an Application&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It is extremely easy to get an application up and running. I created a little employee tracking application with the ability to search records, add new records and edit existing ones in literally less the 5 minutes. &lt;/p&gt;  &lt;p&gt;When you startup Visual Studio there will be two new project types one for Visual Basic and one for C#.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LNYcmNhpvTA/TG79bvt738I/AAAAAAAABPM/1VdTR46rfbs/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh6.ggpht.com/_LNYcmNhpvTA/TG79cHrz4nI/AAAAAAAABPQ/paX8ea6F9Uk/clip_image002_thumb.jpg?imgmax=800" border="0" height="170" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next you will be prompted to Create new table or Attach to external database. When you select Create new table you get a classic table editor screen. Here you can enter your field names; select their data type and indicate if they are required fields. You can also change some of the other field settings using the property window. This process has been made very user friendly. If there is something it doesn’t like about a field name as you are typing it you will immediately get a tooltip explaining the error. The data types have been simplified from what you would see in SQL Server, for example no VarChar, NVarChar, or Text, just a String data type. There are also special data types for things like e-mail addresses and phone numbers.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_LNYcmNhpvTA/TG79cYAICnI/AAAAAAAABPU/8mJU9b0ns2s/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image004" alt="clip_image004" src="http://lh6.ggpht.com/_LNYcmNhpvTA/TG79djQhuQI/AAAAAAAABPY/T__S4JqCiX8/clip_image004_thumb.jpg?imgmax=800" border="0" height="195" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once your table is complete click the Screen… and you will be able to add the visual parts of your application. I added two screens, a New Data Screen to add records and a Search Data Screen to search for records. You simple select the screen type, and then select the table it will work with from the Screen Data drop down. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG79emmSuBI/AAAAAAAABPc/u5iKOIRdCKU/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image006" alt="clip_image006" src="http://lh5.ggpht.com/_LNYcmNhpvTA/TG79gbWlP1I/AAAAAAAABPg/YWKq6wXZJww/clip_image006_thumb.jpg?imgmax=800" border="0" height="175" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;At this point you have a fully working application that you can execute.&lt;/p&gt;  &lt;p&gt;Here’s a screen shot of the add screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/TG79iJb6ULI/AAAAAAAABPk/5hTpnDtQrX4/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image008" alt="clip_image008" src="http://lh4.ggpht.com/_LNYcmNhpvTA/TG79in6TypI/AAAAAAAABPo/fr_7vuRs9Eg/clip_image008_thumb.jpg?imgmax=800" border="0" height="192" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And here is the search screen&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_LNYcmNhpvTA/TG79kNzUwwI/AAAAAAAABPs/zWF1J8uvlm8/s1600-h/clip_image010%5B3%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image010" alt="clip_image010" src="http://lh3.ggpht.com/_LNYcmNhpvTA/TG79p-0dzQI/AAAAAAAABPw/aZ3K3e9C3V4/clip_image010_thumb.jpg?imgmax=800" border="0" height="193" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Initial Reaction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I am not a big fan of tools like this that dumb down the development process. They tend to get you 80% of the way to what you want to build, but leave no way of getting the remaining 20% that would truly make the application useful. The tools is good for entering data, but the only current option for output is Excel export. It could really use a simple point and click report designer. For me the jury is still out on this tool. What is currently there is very nicely done, but it is still very limited. If Microsoft continues to improve the functionality this could be a great alternative to developing applications in Access. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;More information&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Here are some links to get more information on LightSwitch:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/default.aspx"&gt;Office MSDN LightSwitch Site&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/jasonz/archive/2010/08/03/introducing-microsoft-visual-studio-lightswitch.aspx"&gt;Jason Zanders Weblog: Introducing Microsoft Visual Studio Light Switch&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/jasonz/archive/2010/08/11/lightswitch-architectural-overviews.aspx"&gt;Jason Zanders Weblog: LightSwith Architectural Overview&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7637513359340192255?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7637513359340192255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7637513359340192255' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7637513359340192255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7637513359340192255'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/08/microsoft-visual-studio-lightswitch.html' title='Microsoft Visual Studio LightSwitch Beta 1'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_LNYcmNhpvTA/TG79cHrz4nI/AAAAAAAABPQ/paX8ea6F9Uk/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-6569323794495222386</id><published>2010-05-30T15:47:00.003-04:00</published><updated>2010-09-04T08:30:10.178-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><title type='text'>XAML Presentation Questions</title><content type='html'>&lt;p&gt;During my presentation at &lt;a href="http://www.phillynj.net/"&gt;PhillyNJ.NET&lt;/a&gt; there were a couple questions I could not immediately answer.&lt;/p&gt;  &lt;h4&gt; x:Name&lt;/h4&gt;  &lt;p&gt;When you create a blank Silverlight project in Visual Studio you start with the following code:&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;UserControl x:Class="SilverlightApplication1.MainPage"&lt;br /&gt;  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;br /&gt;  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&lt;br /&gt;  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&lt;br /&gt;  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;br /&gt;  mc:Ignorable="d"&lt;br /&gt;  d:DesignHeight="300" d:DesignWidth="400"&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;Grid x:Name="LayoutRoot" Background="White"&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;/UserControl&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Someone questioned why the Name property on the Grid is in the ‘x’ namespace when other properties aren’t.  The ‘x’ namespace is the base XAML namespace. The XAML standard specifies a name property that applies to all elements which is references by x:Name. Classes that are serialized into XAML can also have their own Name property,  for example the Grid element has a Name property. In WPF and Silverlight the Name property on the objects is mapped directly to the x:Name XAML property, so you could use either x:Name or Name and everything would work fine. The use of x:Name just seems to be done by convention.&lt;/p&gt;&lt;h4&gt;Label vs Textblock&lt;/h4&gt;&lt;p&gt;One of the more common controls in Winforms is the label control. There is no label control in the base Silverlight installation, but there is one if the Silverlight Toolkit. This brings up the question, what is the difference between a label and the standard TextBlock control? It turns out TextBlock isn’t technically a control. It derives from FrameworkElement, whereas Label derives from ContentControl which gives label extra functionality that TextBlock doesn’t have. For example a Label can use a control template, and can contain content other then plain text.&lt;/p&gt;&lt;h4&gt;Non-Rectangular Windows&lt;/h4&gt;&lt;p&gt;In Winforms it was a little tricky to do non-rectangular windows, but it’s actually pretty easy in WPF. There is a good example here, &lt;a title="http://devintelligence.com/2007/10/shaped-windows-in-wpf/" href="http://devintelligence.com/2007/10/shaped-windows-in-wpf/"&gt;http://devintelligence.com/2007/10/shaped-windows-in-wpf/&lt;/a&gt;. I have not seen any indication that you can do non-rectangular windows in Silverlight. This actually wouldn’t be to useful since you would still be constrained to the rectangular browser window.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-6569323794495222386?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/6569323794495222386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=6569323794495222386' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6569323794495222386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6569323794495222386'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/05/xaml-presentation-questions.html' title='XAML Presentation Questions'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-9042823628885801883</id><published>2010-05-30T14:02:00.002-04:00</published><updated>2010-09-04T08:30:21.543-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XAML'/><title type='text'>XAML UI for WPF and Silverlight Presentation</title><content type='html'>&lt;p&gt;Thanks to everyone who attended my presentation at the May meeting of &lt;a href="http://www.phillynj.net/"&gt;PhillyNJ.NET&lt;/a&gt;. Here are the Visual Studio 2010 projects for that I used in the demo:&lt;/p&gt;  &lt;p&gt;XAML Basics Demo &lt;/p&gt;  &lt;p&gt; &lt;iframe style="padding: 0px; background-color: rgb(252, 252, 252); width: 98px; height: 115px;" title="Preview" marginheight="0" src="http://cid-d668a901bbd1db7e.skydrive.live.com/embedicon.aspx/.Public/blog/XAML%20Demo%20End.zip" marginwidth="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;XAML Data binding Demo&lt;/p&gt;  &lt;p&gt;&lt;iframe style="padding: 0px; background-color: rgb(252, 252, 252); width: 98px; height: 115px;" title="Preview" marginheight="0" src="http://cid-d668a901bbd1db7e.skydrive.live.com/embedicon.aspx/.Public/blog/DataBindingDemoEnd.zip" marginwidth="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-9042823628885801883?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/9042823628885801883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=9042823628885801883' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/9042823628885801883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/9042823628885801883'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2010/05/xaml-ui-for-wpf-and-silverlight.html' title='XAML UI for WPF and Silverlight Presentation'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7106787788191659409</id><published>2009-10-21T07:44:00.002-04:00</published><updated>2010-09-04T08:30:35.291-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Visual Studio 2010 Beta 2</title><content type='html'>&lt;p&gt;If you have yet heard, Microsoft has release beta 2 of Visual Studio 2010. It’s currently available to MSDN Subscribers and will be available to the general public sometime today.  The final release of VS2010 is currently scheduled for March 22nd, 2010. You can get more information and look out for the public download at MSDN:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Microsoft has also released a &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=752CB725-969B-4732-A383-ED5740F02E93&amp;amp;displaylang=en"&gt;Visual Studio 2010 training kit&lt;/a&gt; which contains presentations, hands-on labs and demos to get you up to speed with this new release. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7106787788191659409?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7106787788191659409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7106787788191659409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7106787788191659409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7106787788191659409'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/10/visual-studio-2010-beta-2.html' title='Visual Studio 2010 Beta 2'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7185119451644123007</id><published>2009-07-12T11:22:00.002-04:00</published><updated>2010-09-04T08:30:55.713-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>VS 2010 Generate From Usage</title><content type='html'>&lt;p&gt;Microsoft has been adding more and more features to Visual Studio to encourage Test Driven Development. One of the new features in VS2010 for TDD is “Generate From Usage.” &lt;/p&gt;  &lt;p&gt;One of the tenants of true test driven development is that you should write your unit tests before you write your code. One little tricky part of this in Visual Studio is that you loose the help of IntelliSense and sometimes it will even get in your way. To get around this problem, developers will often stub out their classes and methods first, and then write their tests. Generate From Usage in VS2010 provides another way to do this. &lt;/p&gt;  &lt;p&gt;To try this out we will create a very simple math class called MyMath that has one method call Add(n1,n2) that will add two numbers together and return the result. First create a solution with a new C# Test Project and C# Class Library Project. In the TestMethod1 method of the UnitTest1 class type the following code (type it instead of cutting and pasting to see the full effect of this feature):&lt;/p&gt;  &lt;p&gt;MyMath math = new MyMath();&lt;/p&gt;  &lt;p&gt;Assert.AreEqual(3,math.Add(1, 2));&lt;/p&gt;  &lt;p&gt;First thing you will notice is that when you type “new” and press the space bar, IntelliSense will popup and you will see the MyMath class on the list even though we haven’t defined it yet. The editor figures out that you are intending to create a class called MyMath so it puts in on the list.&lt;/p&gt;  &lt;p&gt;As expected you will get red squiggles under MyMath since it doesn’t exist yet. At this point you would normally go and manually stub out this class, but Generate From Usage makes this easier. If you right click on MyMath and select Generate/Class, Visual Studio will automatically create a new stub for the MyMath class. By default it will put the new class in the test project which is probably not where you want it. To get around this instead of clicking Generate/Class, use Generate/Other…, this will pop-up this dialog box:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/Sln_pxYsbYI/AAAAAAAAAu0/F5-mh6F2ll0/s1600-h/clip_image001%5B5%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image001" alt="clip_image001" src="http://lh4.ggpht.com/_LNYcmNhpvTA/Sln_qHoW2sI/AAAAAAAAAu4/VkqqZMqDnj8/clip_image001_thumb%5B2%5D.jpg?imgmax=800" border="0" height="419" width="474" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This give you more control over the generation of the code. In the location section you can change the project so that the new file goes to the Class Library project. Now if you build the solution the squiggles under MyMath will go away and the Add function will be flagged instead. &lt;/p&gt;  &lt;p&gt;Now you can right-click on Add and select Generate/Method Sub and this will generate a method stub in the MyMath class. In this case there is no Other option since there really aren’t any other options for creating the Method since to be usable it must be in the MyMath class, must be public and must be called Add. &lt;/p&gt;  &lt;p&gt;There is one tricky thing with this feature that I will demonstrate with another example. Let’s say we want to create a new class called Host. In TestMethod1 type Host and press the space bar. When you do this IntelliSense will try to be helpful. Since there isn’t a class called Host in the default namespaces it will put in something that is there; HostTypeAttribute. This is not what we wanted. To get around this there is a new feature in IntelliSense called Consume-First Mode. When the IntelliSense box pops up press Ctrl+Alt+Space to toggle to consume-first mode. In this mode instead of forcing you into a class that already exists it will just accept what you typed when you press the space bar. Once this mode is turned on it will stay in this mode until you press Ctrl+Alt+Space again while an IntelliSense window is open. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7185119451644123007?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7185119451644123007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7185119451644123007' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7185119451644123007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7185119451644123007'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/07/vs-2010-generate-from-usage.html' title='VS 2010 Generate From Usage'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LNYcmNhpvTA/Sln_qHoW2sI/AAAAAAAAAu4/VkqqZMqDnj8/s72-c/clip_image001_thumb%5B2%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-4592539590925886956</id><published>2009-06-28T09:58:00.002-04:00</published><updated>2010-09-04T08:31:13.727-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>IntelliSense Transparency</title><content type='html'>&lt;p&gt;While I was playing with Visual Studio 2010 I ran across a cool little feature that I assumed was new to the VS2010 editor but turns out to also be available in VS2008. When an IntelliSense window opens there are times when you need to quickly see something that is underneath it. To do this all you have to do is press and hold the CTRL key. This will cause the window to become transparent until you release the key again:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_LNYcmNhpvTA/Skd3Gxn7C4I/AAAAAAAAAsM/9sgNV8iNejY/s1600-h/clip_image002%5B4%5D.jpg"&gt;&lt;img style="border: 0px none; display: inline;" title="clip_image002" alt="clip_image002" src="http://lh4.ggpht.com/_LNYcmNhpvTA/Skd3HLDQJaI/AAAAAAAAAsQ/iD6yWHXiCY0/clip_image002_thumb%5B1%5D.jpg?imgmax=800" border="0" height="352" width="440" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-4592539590925886956?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/4592539590925886956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=4592539590925886956' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4592539590925886956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4592539590925886956'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/06/intellisense-transparency.html' title='IntelliSense Transparency'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_LNYcmNhpvTA/Skd3HLDQJaI/AAAAAAAAAsQ/iD6yWHXiCY0/s72-c/clip_image002_thumb%5B1%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-28580126881914495</id><published>2009-06-01T17:29:00.002-04:00</published><updated>2010-09-04T08:32:01.160-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Visual Studio 2010 Editor</title><content type='html'>&lt;p&gt;One of the biggest changes in Visual Studio 2010 is the text editor. When you first fire it up you will definitely notice a lot of small visual changes to it but the biggest changes are under the hood. The editor has been re-written in C# using WPF for the presentation layer, and Microsoft’s new &lt;a href="http://www.codeplex.com/MEF"&gt;Managed Extensibility Framework (MEF)&lt;/a&gt; to make the editor much more extensible. &lt;/p&gt;  &lt;p&gt;Here are a couple of the nice new features found in the editor. Visual Studio has always had the little plus and minus boxes on the left side of the editor which allows you to expand and collapse blocks of code. In VS 2010 there is an addition to this. If you hover over one of the minus boxes VS will highlight all the code in that block. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/SiRIS3B501I/AAAAAAAAAgM/7aG6dQUqol0/s1600-h/VS2010Editor13.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="VS2010Editor1" alt="VS2010Editor1" src="http://lh5.ggpht.com/_LNYcmNhpvTA/SiRITP-IN6I/AAAAAAAAAgQ/uao6XLfHMr8/VS2010Editor1_thumb1.jpg?imgmax=800" border="0" height="251" width="514" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Another similar feature works with identifiers like variable names. If you hover your mouse over a variable in a class or function VS will automatically highlight all the other instances of that identifier. This is a handy way to quickly see where you variable is used.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_LNYcmNhpvTA/SiRITenDIwI/AAAAAAAAAgU/F21F58uIb_g/s1600-h/VS2010Editor24.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="VS2010Editor2" alt="VS2010Editor2" src="http://lh6.ggpht.com/_LNYcmNhpvTA/SiRITa-Qo8I/AAAAAAAAAgY/a1eE1bDBXvo/VS2010Editor2_thumb2.jpg?imgmax=800" border="0" height="270" width="521" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Finally, VS 2010 has a build in code zooming feature. If you hold the CTRL key and roll the mouse wheel you can increase and decrease the font size in the code window. This is not a feature you are likely to use in your day to day work, but it is very handy when you are doing technical presentations and the audience is having a hard time seeing the code. &lt;/p&gt;  &lt;p&gt;None of the features is earth shattering, but I think the real promise of the new editor will come from it’s extensibility model. Once third party developers start taking advantage of this I think we will see a lot of very cool add-ons to the editor.&lt;/p&gt;  &lt;p&gt;If you want to learn more about the editor check out the &lt;a href="http://www.hanselminutes.com/default.aspx?showID=165"&gt;Hanselminutes podcast #147&lt;/a&gt; where Scott interviews Noah Richards who is one of the developers of the new editor.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-28580126881914495?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/28580126881914495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=28580126881914495' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/28580126881914495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/28580126881914495'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/06/visual-studio-2010-editor.html' title='Visual Studio 2010 Editor'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_LNYcmNhpvTA/SiRITP-IN6I/AAAAAAAAAgQ/uao6XLfHMr8/s72-c/VS2010Editor1_thumb1.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-8707755202864231505</id><published>2009-05-23T08:55:00.002-04:00</published><updated>2010-09-04T08:32:18.541-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Visual Studio 2010 Beta</title><content type='html'>&lt;p&gt;Microsoft has just released the beta of Visual Studio 2010 to the general public. You can download and get more information here, &lt;a title="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx&lt;/a&gt;. Note that the first install link on this page is for the web installer, but you can click on “See More Download Options” to download the ISO version.&lt;/p&gt;  &lt;p&gt;I’ve installed it without any problems on both Windows 7 RC1 and Windows XP. If you install on Windows 7 there is a compatibility problem with the version of SQL Server that installs with Visual Studio, but Microsoft provides a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/6a569376-4207-4184-a8a7-73d5168c787e"&gt;workaround.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So far I have been pretty happy with the beta. The changes from 2008 are not dramatic but there are definitely some nice new features. The biggest changes you will notice are in the code editor which has been completely re-written. There have also been a few small language changes to C# and VB.NET but no where near as many as were introduced in 2008. &lt;/p&gt;  &lt;p&gt;2010 provides support out of the box for things like Silverlight, and the F# language. These are available in 2008 but have to be installed separately. You may notice that ASP.NET MVC Framework is NOT included in this beta. According to &lt;a href="http://haacked.com/archive/2009/05/18/aspnetmvc-vs2010-beta1.aspx"&gt;Phil Haacked&lt;/a&gt; the release of MVC was to late to be included in Beta 1 but will be included in the next beta.&lt;/p&gt;  &lt;p&gt;As I work with 2010 some more I will be posting about some of the new features.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-8707755202864231505?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/8707755202864231505/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=8707755202864231505' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8707755202864231505'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/8707755202864231505'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/05/visual-studio-2010-beta.html' title='Visual Studio 2010 Beta'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1359433970631452677</id><published>2009-05-22T16:56:00.001-04:00</published><updated>2009-05-22T16:56:04.705-04:00</updated><title type='text'>PhillyNJ.NET</title><content type='html'>&lt;p&gt;For those of you in the South Jersey area, I will be doing a presentation at the PhillyNJ.NET meeting on Thursday, May 28th at 6:00PM. The presentation will be an introduction to the Microsoft ASP.NET MVC Framework. PhillyNJ.NET is a sub-chapter of the &lt;a href="http://www.phillydotnet.org/"&gt;Philly.NET&lt;/a&gt; user group and usually meets at Greenwich Township Public Library in Gibbstown, NJ. You can get more information on the &lt;a href="http://www.phillynj.net/"&gt;PhillyNJ.NET&lt;/a&gt; web site.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1359433970631452677?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1359433970631452677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1359433970631452677' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1359433970631452677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1359433970631452677'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/05/phillynjnet.html' title='PhillyNJ.NET'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-6412858779077789018</id><published>2009-04-11T10:54:00.001-04:00</published><updated>2009-04-11T10:54:24.122-04:00</updated><title type='text'>ASP.NET MVC Framework</title><content type='html'>&lt;p&gt;Microsoft has finally made available the 1.0 release of the ASP.NET MVC Framework. The framework provides a new way of developing ASP.NET web applications that is based around the classic Model View Controller design pattern. In an MVC app instead of each page being a separate file there are three components that work together to deliver a web page to the user:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Model&lt;/b&gt; – The model is the class or classes that represent the data that will be displayed on the page. This may be a group of in memory objects, a class that accesses an XML file, a database access layer, etc. The framework doesn’t put any restrictions on what the model can be.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;View&lt;/b&gt; – This is the file that generates the output that is sent to the browser. Views are HTML files that can also contain scripts to embed dynamic data in the output. These are very similar to .ASPX files used in ASP.NET web forms. The view only works with data that is passed to it by the controller. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Controller&lt;/b&gt; – The controller class is responsible for handling input from the user, updating the model, extracting data from the model needed to build a view and finally deciding what view should be displayed. The controller doesn’t have any direct control over how that data will be presented, that will be handled by the view.&lt;/p&gt;  &lt;p&gt;It’s important to note that the MVC Framework is not layered on top of the existing Web Forms model, but instead is a totally different way of developing ASP.NET apps. You do lose a lot of things that you may have gotten used to in web forms. In MVC there is no viewstate, no event handlers, and you can only make limited use of server controls. Giving up these things has its upside; it makes the page processing cycle much simpler and thus much faster. It also makes it much easier to get full control of the HTML output. &lt;/p&gt;  &lt;p&gt;The biggest advantage to using MVC is the separation of concerns that is promotes. By having a clear separation between display, data and control it makes it easier to maintain large applications and also makes I much easier to perform automated unit testing. &lt;/p&gt;  &lt;p&gt;I have been doing some work with the MVC Framework and although there is a learning curve it wasn’t too hard to get up to speed with it. I don’t think MVC will totally replace Web Forms, but I think it is very well suited to certain types of applications. As you start developing new ASP.NET apps you will want to look at the pros and cons of MVC and Web Forms and decide which would be more appropriate for a given application. &lt;/p&gt;  &lt;p&gt;If you want to give it a try you can download the MVC Framework from &lt;a href="http://www.asp.net/mvc/"&gt;http://www.asp.net/mvc/&lt;/a&gt;. You will need to be running Visual Studio 2008 or Visual Web Developer 2008 SP1 to use it. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-6412858779077789018?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/6412858779077789018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=6412858779077789018' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6412858779077789018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6412858779077789018'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/04/aspnet-mvc-framework.html' title='ASP.NET MVC Framework'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-6470813690770296178</id><published>2009-04-03T19:34:00.001-04:00</published><updated>2009-04-03T19:34:17.487-04:00</updated><title type='text'>Verbatim Literal Strings</title><content type='html'>&lt;p&gt;I am filing this one under “you learn something new every day”. This is a little feature of the C# language that I only recently learned about. &lt;/p&gt;  &lt;p&gt;As you probably know when you put literal strings in a C# program certain character sequences are interpreted as escape characters.&amp;#160; For example if you do this:&lt;/p&gt;  &lt;p&gt;&lt;textarea style="width: 393px; height: 38px" class="c#" rows="rows" cols="cols" name="code"&gt;string s = &amp;quot;line1\nline2&amp;quot;;&amp;lt;br /&amp;gt;Console.WriteLine(s);&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;it will output &lt;/p&gt;  &lt;p&gt;line1   &lt;br /&gt;line2 &lt;/p&gt;  &lt;p&gt;because \n is interpreted as a newline. What if we actually wanted the characters \n to be displayed? You could do this:&lt;/p&gt;  &lt;p&gt;&lt;textarea style="width: 398px; height: 38px" class="c#" rows="rows" cols="cols" name="code"&gt;string s = &amp;quot;line1\\nline2&amp;quot;;&amp;lt;br /&amp;gt;Console.WriteLine(s);&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;This works fine for simple short strings, but starts to get a little ugly in more complex strings especially when you are dealing with regular expressions or URLs.&amp;#160; Here is an alternative syntax that does the same thing:&lt;/p&gt;  &lt;p&gt;&lt;textarea style="width: 397px; height: 38px" class="c#" rows="rows" cols="cols" name="code"&gt;string s = @&amp;quot;line1\nline2&amp;quot;;&amp;lt;br /&amp;gt;Console.WriteLine(s);&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;The &lt;a href="mailto:&amp;lsquo;@&amp;rsquo;"&gt;‘@’&lt;/a&gt; character tells the compiler to take the string verbatim and not to interpret any escape sequences. This syntax also allows you to do things like this:&lt;/p&gt;  &lt;p&gt;&lt;textarea style="width: 396px; height: 86px" class="c#" rows="rows" cols="cols" name="code"&gt;string s = @&amp;quot;line1&amp;lt;br /&amp;gt;line2&amp;lt;br /&amp;gt;line3&amp;quot;;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Console.WriteLine(s);&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;If you didn’t use a verbatim string definition here this would cause a syntax error. In this case since it will actually each piece of text on a different line. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-6470813690770296178?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/6470813690770296178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=6470813690770296178' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6470813690770296178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/6470813690770296178'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/04/verbatim-literal-strings.html' title='Verbatim Literal Strings'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-144611817337795220</id><published>2009-03-18T20:02:00.001-04:00</published><updated>2009-03-18T20:03:24.374-04:00</updated><title type='text'>Patterns &amp; Practices Application Architecture Guide 2.0</title><content type='html'>&lt;p&gt;Microsoft has just released the most recent update to their Application Architecture Guide. I got a copy of the first edition of this book quite a few years ago and it has remained close at hand on my bookshelf since then. This version is a much needed update to the guide.&lt;/p&gt;  &lt;p&gt;The purpose of this book is to provide&amp;#160; guidance on how to do good application design. Although it’s primary focus is on designing Microsoft .NET apps, it contains a lot of material that is applicable to any development platform. &lt;/p&gt;  &lt;p&gt;The book is divided up into four parts. The first part is called Fundamentals. It starts with a discussion of the basic concepts of application architecture, provides a high level overview of the .NET platform, and finally provides a fairly large collection of design guidelines. &lt;/p&gt;  &lt;p&gt;The second part, called Design, walks your through the process of how to design an application. It goes through the things you will have to decide on during the design process and provides guidance on how to make these decisions. &lt;/p&gt;  &lt;p&gt;Part three, Layers, discusses the traditional layers that are found in an application. It provides information on how to design presentation, business logic, data access and services layers and&amp;#160; discusses how to map various Microsoft technologies to these layers.&lt;/p&gt;  &lt;p&gt;Finally part four, Archetypes, goes over each major type of application you may have to design and talks about the design considerations as they relate to each type of app. In this part you will find information on designing web apps, rich Internet apps, mobile apps, etc. &lt;/p&gt;  &lt;p&gt;The appendix of the book contains some very useful technology “cheat sheets” for Data, Integration, Presentation, and Workflow. In each section you will find information on the related .NET technologies along with guidance to help in deciding which technologies are best suited to your specific design scenario.&lt;/p&gt;  &lt;p&gt;You can download the guide for free from, &lt;a title="http://www.codeplex.com/AppArchGuide" href="http://www.codeplex.com/AppArchGuide"&gt;http://www.codeplex.com/AppArchGuide&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can also hear a talk with Rob Boucher, one of the authors of the guide on the Dot Net Rocks podcast 426, &lt;a title="http://www.dotnetrocks.com/default.aspx?showNum=426" href="http://www.dotnetrocks.com/default.aspx?showNum=426"&gt;http://www.dotnetrocks.com/default.aspx?showNum=426&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-144611817337795220?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/144611817337795220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=144611817337795220' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/144611817337795220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/144611817337795220'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/03/patterns-practices-application.html' title='Patterns &amp;amp; Practices Application Architecture Guide 2.0'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1998662062529212444</id><published>2009-03-15T10:36:00.001-04:00</published><updated>2009-03-15T10:36:28.750-04:00</updated><title type='text'>Changes coming to SDS</title><content type='html'>&lt;p&gt;There was an &lt;a href="http://blogs.msdn.com/ssds/archive/2009/03/10/9469228.aspx"&gt;announcement&lt;/a&gt; this week from the SDS development team in Microsoft that there will be a change in direction for SDS. Instead of the schema-less database I have been talking about over last few weeks it will be moving towards full blown SQL Server hosted in the cloud. The big advantage is that it will make it much easier to migrate existing database apps to the Azure platform. &lt;/p&gt;  &lt;p&gt;This decision also makes sense when you consider that a lot of the features of the existing SDS are already available as part of other Microsoft data access technologies. For example Azure already has a schema less database technology in the form of &lt;a href="http://msdn.microsoft.com/en-us/library/dd179423.aspx"&gt;Azure Table Storage.&lt;/a&gt; You can also get the REST based database interface by using &lt;a href="http://msdn.microsoft.com/en-us/library/cc956153.aspx"&gt;ADO.NET Data Services&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you are getting confused by all the different data access technologies Microsoft is providing, you are not alone. I really should do a post that describes the different technologies that are out there. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1998662062529212444?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1998662062529212444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1998662062529212444' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1998662062529212444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1998662062529212444'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/03/changes-coming-to-sds.html' title='Changes coming to SDS'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-165947046115775410</id><published>2009-02-28T10:34:00.001-05:00</published><updated>2009-02-28T10:34:35.277-05:00</updated><title type='text'>Querying SDS - Sorting</title><content type='html'>&lt;p&gt;   &lt;br /&gt;This is the fifth part of a series of posts about SQL Data Services (SDS). Last time I showed the basics of how to query SDS, now I will show some more query options. Let’s start with the basic query from last time that returns all the entities in a container&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;By default the entities will be sorted by the Id property. We can sort by other properties like this&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities orderby e[&amp;quot;DateDue&amp;quot;] select e&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Note that just like in the Where clause flexible properties in the orderby clause use the syntax like e[“DateDue”] but metadata properties use the e.Verison syntax. By default the sort is done in ascending order. You can sort descending like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities orderby e[&amp;quot;DateDue&amp;quot;] descending select e&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;You can also sort by multiple properties &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities orderby e[&amp;quot;Completed&amp;quot;],e[&amp;quot;DateDue&amp;quot;] select e&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;As I have mentioned before SDS entities are schema-less so there could be entities in a container that don’t have one of the properties you are sorting on. In these cases the entities will still appear in the output. I have not seen any official documentation that explains how these are handled but it appear they are treated as having a null value and are sorted to the top of the list. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-165947046115775410?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/165947046115775410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=165947046115775410' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/165947046115775410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/165947046115775410'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/02/querying-sds-sorting.html' title='Querying SDS - Sorting'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-610165023745356939</id><published>2009-02-08T11:40:00.001-05:00</published><updated>2009-02-08T11:41:09.545-05:00</updated><title type='text'>Querying SDS</title><content type='html'>&lt;p&gt;In my last post I showed how to put data into an SDS database, now we will look at how to get it out. As I mentioned at the end of the last post every entity in SDS has a unique address that can be used to retrieve it directly. For example if I put in this address, https://testsds.data.database.windows.net/v1/Tasks/T1000, and click Get it will retrieve the entity we created last time:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 396px; height: 150px" name="code" rows="rows" cols="cols"&gt;&amp;lt;Entity xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot; xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;T1000&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Version&amp;gt;50976472&amp;lt;/s:Version&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Message xsi:type=&amp;quot;x:string&amp;quot;&amp;gt;Finish blog entry on SDS&amp;lt;/Message&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateAdded xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-01T00:00:00&amp;lt;/DateAdded&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateDue xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-07T00:00:00&amp;lt;/DateDue&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Completed xsi:type=&amp;quot;x:boolean&amp;quot;&amp;gt;false&amp;lt;/Completed&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/Entity&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;This is good for retrieving a single entity, but if we want to find a group of entities based on some parameters we need to use queries. First let’s create two more entities so we have something to query. Change the address so it points back at the Tasks container, for example https://testsds.data.database.windows.net/v1/Tasks/. Enter each of these entities and click Post.&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 397px; height: 262px" name="code" rows="rows" cols="cols"&gt;&amp;lt;Entity xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot; xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;T1001&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Message xsi:type=&amp;quot;x:string&amp;quot;&amp;gt;Take out the trash&amp;lt;/Message&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateAdded xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-02T00:00:00&amp;lt;/DateAdded&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateDue xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-08T00:00:00&amp;lt;/DateDue&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Completed xsi:type=&amp;quot;x:boolean&amp;quot;&amp;gt;true&amp;lt;/Completed&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/Entity&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;Entity xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot; xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;T1002&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Message xsi:type=&amp;quot;x:string&amp;quot;&amp;gt;Buy Valentines day gift&amp;lt;/Message&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateAdded xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-03T00:00:00&amp;lt;/DateAdded&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateDue xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2009-02-13T00:00:00&amp;lt;/DateDue&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Completed xsi:type=&amp;quot;x:boolean&amp;quot;&amp;gt;false&amp;lt;/Completed&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/Entity&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;After creating the entities change the address back to the container once again. &lt;/p&gt;  &lt;p&gt;Let’s start with the simplest query, enter this in the query box and click Query:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This will return an EntitySet with all three entities in our Tasks container. This query has no conditions so it will return all the entities in a container. &lt;/p&gt;  &lt;p&gt;Earlier I showed you how to retrieve a single entity by doing a Get on its address, but you can also retrieve and entity using a query like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities where e.Id==&amp;quot;T1001&amp;quot; select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Here we have added one condition, e.Id==”T1001” which simply means to retrieve all entities where the Id property is T1001. Since each Id is unique this will return a single entity. &lt;/p&gt;  &lt;p&gt;What if we wanted to query for all tasks that have not been completed:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities where e[&amp;quot;Completed&amp;quot;]==false select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You will notice a difference in the syntax for this condition. Instead of e.Completed, we used e[“Completed”] instead. The e.Id syntax we used last time is only used for metadata properties. When you query flexible properties you have to use the e[“Completed”] syntax. &lt;/p&gt;  &lt;p&gt;What if we made a mistake in the query and did this instead:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities where e[&amp;quot;Complete&amp;quot;]==false select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In a traditional database this would throw and exception since the field Complete doesn’t exist in the database, but since SDS is schema less this will not throw an error, it just won’t return any entities. &lt;/p&gt;  &lt;p&gt;We are not limited to just specifying one condition, here we query for all incomplete tasks that are due after 2/12/2009:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;from e in entities where e[&amp;quot;Completed&amp;quot;]==false &amp;amp;&amp;amp; e[&amp;quot;DateDue&amp;quot;] &amp;gt;DateTime(&amp;quot;2009-02-12&amp;quot;) select e&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We use the logical operator “&amp;amp;&amp;amp;” to specify one condition and another. Also notice that when we compare to the literal date value we must use the DateTime(“”) function, if you just compared to “2009-02-12” it would not work. &lt;/p&gt;  &lt;p&gt;That’s the basics of querying SDS. I will talk about some other query topics in my next post.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-610165023745356939?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/610165023745356939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=610165023745356939' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/610165023745356939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/610165023745356939'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/02/querying-sds.html' title='Querying SDS'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-3912170415306447117</id><published>2009-02-03T17:31:00.001-05:00</published><updated>2009-02-03T17:31:42.152-05:00</updated><title type='text'>Working with SDS</title><content type='html'>&lt;p&gt;In my last two posts I showed you how to get setup to use SQL Data Services, and I described the SDS data model. Now it’s time to start actually working with SDS by using the SSDS Explorer tool.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;SDS can be accessed in two ways, using a &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/a&gt; based protocol, or using &lt;a href="http://en.wikipedia.org/wiki/SOAP_(protocol)"&gt;SOAP&lt;/a&gt;. The SDS Explorer tool uses the REST method. At the top of the screen you will see the address (URI) that the requests will be sent to, and the buttons at the bottom represent the various actions that can be executed. &lt;/p&gt;  &lt;p&gt;The first step will be to create an authority to work in. If you click the authority button a template for a new authority will be inserted into the text editor. It will look like this:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 401px; height: 70px" name="code" rows="rows" cols="cols"&gt;&amp;lt;s:Authority xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/s:Authority&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;To create the authority you will first need to put an ID for the authority in the &amp;lt;s:ID&amp;gt; tag. A couple notes on creating the ID. First it must be globally unique over the entire SDS system, meaning that no two people can create the same authority ID. You may want to prefix your authority ID with the application name you created when you signed up for SDS. The ID also must only contain lower case letters, numbers and dashes. Finally, once you create an authority you currently cannot delete it, I assume this will change before the final release of SDS. Once you have entered an ID click the Post button. If everything is working ok you should get a green check mark next to the action buttons and you should receive no errors.&lt;/p&gt;  &lt;p&gt;Once you have created the authority the address will automatically change to contain your authority ID. For example if you authority is called ‘testsds’ you will see this:&lt;/p&gt;  &lt;p&gt;https://testsds.data.database.windows.net/v1/&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you now click Get you will see some information about the authority. Towards the top you will see the ID you just created in the &amp;lt;s:ID&amp;gt; tag. Below this you will see various statistics about the authority which we won’t get into here. &lt;/p&gt;  &lt;p&gt;Now that we have setup an authority, we can create a container inside of it. Click on the Container button to get a template for adding a container. Just like with Authority you need to give the Container an ID. Container IDs can contain both upper and lower case and they ARE case sensitive so ‘Tasks’ would be a different container from ‘tasks’. Enter the ID within the &amp;lt;s:Id&amp;gt; tags and press the Post button to create the container. Here is the code for creating a container called ‘Tasks’:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 398px; height: 70px" name="code" rows="rows" cols="cols"&gt;&amp;lt;s:Container xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;Tasks&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/s:Container&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;Once again the Address will change to include the container ID, it will look something like this:&lt;/p&gt;  &lt;p&gt;https://testsds.data.database.windows.net/v1/Tasks&lt;/p&gt;  &lt;p&gt;Let’s take the “Tasks” off the end of the address so we can go back to the authority level and then click Query, this will query for the contents of the authority. The result will look something like this:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 398px; height: 118px" name="code" rows="rows" cols="cols"&gt;&amp;lt;s:EntitySet xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot; xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Container&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;Tasks&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Version&amp;gt;50890052&amp;lt;/s:Version&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/s:Container&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/s:EntitySet&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;Here you can see all the containers inside the authority. In this case there is only the Tasks container we just created. Change the address back to https://testsds.data.database.windows.net/v1/Tasks so we are working with the Tasks container once again. &lt;/p&gt;  &lt;p&gt;We have created an authority and container, now we can add an entity to the container. Let’s create a simple entity to hold a task like you would have in a to-do list application Here is the code for creating the entity&lt;/p&gt;  &lt;p&gt;&lt;textarea class="xml" style="width: 393px; height: 134px" name="code" rows="rows"&gt;&amp;lt;Entity xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:x=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; xmlns:s=&amp;quot;http://schemas.microsoft.com/sitka/2008/03/&amp;quot;&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;s:Id&amp;gt;T1000&amp;lt;/s:Id&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Message xsi:type=&amp;quot;x:string&amp;quot;&amp;gt;Finish blog entry on SDS&amp;lt;/Message&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateAdded xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2/1/2009&amp;lt;/DateAdded&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;DateDue xsi:type=&amp;quot;x:dateTime&amp;quot;&amp;gt;2/7/2009&amp;lt;/DateDue&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;Completed xsi:type=&amp;quot;x:boolean&amp;quot;&amp;gt;false&amp;lt;/Completed&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/Entity&amp;gt;&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;The first thing we had to fill out in the entity template is the ID, remember that the ID must be unique within the container. We then have four flexible properties, one string property called Message, two datetime properties called DateAdded and DateDue and finally a Boolean property called Completed. You can see that in each property we specify the name of the property using the tag name, and also the data type in the xsi:type attribute. Within the tags we put the actual data. Once you have entered this click Post to add it to the database. &lt;/p&gt;  &lt;p&gt;As always, the address will change again to include in the ID of the entity. You will notice that everything in the database, authorities, containers and entities have their own unique addresses. So if we use this address, https://testsds.data.database.windows.net/v1/Tasks/T1000, and then click Get, we will retrieve entity T1000 from the container Tasks in authority testsds.&lt;/p&gt;  &lt;p&gt;That covers the basics of how to get data into SDS, next time I will talk about how to query the data.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-3912170415306447117?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/3912170415306447117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=3912170415306447117' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3912170415306447117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3912170415306447117'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/02/working-with-sds.html' title='Working with SDS'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-2336973773866136125</id><published>2009-01-24T08:53:00.001-05:00</published><updated>2009-01-24T08:53:00.411-05:00</updated><title type='text'>SDS Data Model</title><content type='html'>&lt;p&gt;SQL Data Services is often referred to as “SQL Server in the cloud”. Despite this designation it actually operates quite a bit differently then a traditional relational database. In this post I will describe the SDS data model. There are three parts to the data model, Authorities, Containers and Entities.&lt;/p&gt;  &lt;p&gt;Authorities are the highest level of organization in SDS. An authority corresponds to a specific SQL Server instance in one of Microsoft’s data centers. The authority name will be the first part of the DNS address used to access SDS. &lt;/p&gt;  &lt;p&gt;The next lower level of the hierarchy is a container. Depending on how it’s used a container is akin to either an entire database, or a single table in a database. We will talk more about that when we get to Entities. You can have multiple containers in a single authority, and containers can contain zero or more entities, but cannot contain other containers. At present queries are restricted to a single container, you cannot query across multiple containers.&lt;/p&gt;  &lt;p&gt;The lowest level in the hierarchy is the entity where your actual data is stored. Entities are akin to records in a traditional database, but unlike traditional databases SDS doesn’t use schemas. Each entity you create in a container can potentially have a different set of fields (called properties in SDS). If you choose to have every entity in a container have the same properties, then the container behaves like a table, but if you mix different entities in a container then it’s behaving more like a complete database. This is one of the areas where SDS diverges quite a bit from the operation of a traditional relational database. &lt;/p&gt;  &lt;p&gt;There are two types of entities in SDS, non-blob which you will use most often, and blob entities used to store binary objects. We will just talk about non-blob entities here. Each entity contains a series of properties of which there are two types, metadata properties and flexible properties.&lt;/p&gt;  &lt;p&gt;There are three predefined metadata properties. The first is ID which must contain a unique value for each entity in a container. This is a string value that can have up to 64 characters. The second property is a numeric value called Version. Version is automatically assigned by the server when the entity is created and a new version number is assigned each time the entity is updated. Version can be used to handle optimistic concurrency. The final metadata property is a Kind. Kind is an optional string value that can be used to identify the type of each entity. For example if you were doing an order entry system you could have kinds like “Invoice”, “Sales Order”, etc. &lt;/p&gt;  &lt;p&gt;Finally an entity can have zero or more flexible properties. These properties contain the actual data that you want to store in the entity. Each property will have one of the following data types, string, binary, boolean, decimal or dateTime.&lt;/p&gt;  &lt;p&gt;In my next post we will start working with the SSDS Explorer tool.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-2336973773866136125?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/2336973773866136125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=2336973773866136125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2336973773866136125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/2336973773866136125'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/sds-data-model.html' title='SDS Data Model'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-4408278314460219221</id><published>2009-01-19T19:55:00.001-05:00</published><updated>2009-01-19T19:55:30.938-05:00</updated><title type='text'>SQL Data Services Getting Started</title><content type='html'>&lt;p&gt;In my last post I talked about Windows Azure. One of the components of Azure is SQL Data Services (SDS), formally known as SQL Server Data Services (SSDS), which is Microsoft’s “database in the cloud”. If you want to start learning about Azure, SDS is a good place to start since you can use it without having to setup a full Azure development environment. In this posting I will discuss how to get setup to work with SDS.&lt;/p&gt;  &lt;p&gt;The first step is to sign up for Azure Service Platform invitation codes, you can do that on this page &lt;a href="http://www.microsoft.com/azure/register.mspx"&gt;http://www.microsoft.com/azure/register.mspx&lt;/a&gt;. Microsoft is trying to regulate how many developers get on the service so you may not be able to access all the parts of Azure immediately. Once you have applied you will receive a series of e-mails with the codes. The e-mails come in pairs, the first one gives you the code and the second lets you know that is has been activated. There are three different codes and you probably won’t get them all at the same time. The one needed to access SDS is the “Microsoft .NET Services and Microsoft SQL Services” code. I received my code for this service within 24 hours of signing up, but it may take longer. At the time of this writing I haven’t received codes for any of the other services.&lt;/p&gt;  &lt;p&gt;Once you receive the code you will then have to sign up for the actual service. In the activation confirmation e-mail there will be a link to the page where you can enter the invitation code. At this point you will be asked to create a new solution. You just have to provide a name for the solution which will also become the username for logging into the service. You can only have one solution per invitation code. Once you have created the solution you will be provided a password for that solution. &lt;/p&gt;  &lt;p&gt;The final step in setting up for SDS is to download and install the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=0B1FA5C6-EC9D-440B-939E-481DD05F2627&amp;amp;displaylang=en"&gt;SDS SDK&lt;/a&gt;. Unlike the Azure SDK which requires Vista or Server 2008, the SDS SDK works under XP and even Windows 2000. &lt;/p&gt;  &lt;p&gt;Once you have the SDK installed you can test things out. In the SDK folder on the Start Menu you will find a tool called SSDS explorer. When you start the tool you should see “https://data.database.windows.net/v1/” in the address bar and “from e in entities select e” in the query box. Click the Query button and a box will pop up allowing you to enter your username and password. The username is the name of the solution you created and the password is the one you received when you created the solution. The query should run without returning any errors. &lt;/p&gt;  &lt;p&gt;Now we are finally ready to start working with SDS. I will start getting into the details of how SDS works in my next posting.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-4408278314460219221?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/4408278314460219221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=4408278314460219221' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4408278314460219221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4408278314460219221'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/sql-data-services-getting-started.html' title='SQL Data Services Getting Started'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-509756576353799461</id><published>2009-01-18T09:46:00.001-05:00</published><updated>2009-01-18T09:46:42.665-05:00</updated><title type='text'>Windows Azure</title><content type='html'>&lt;p&gt;I have recently started working with the Microsoft Windows Azure service. Announced at last years PDC, Azure is Microsoft’s “cloud computing” platform akin to Amazon’s Elastic Computer Cloud. Windows Azure will run in Microsoft data centers and provide a hosting platform to run applications either completely in the cloud, or run services that can interface with on-premise applications. &lt;/p&gt;  &lt;p&gt;The big advantage this will provide over traditional web hosting is the ability to scale on demand. At a moments notice you will easily be able to scale a service from running on one server to running on 10, at a price of course, and then scale back to one when you no longer need the extra capacity. This will be very useful for businesses that have cyclic capacity needs, like a flower shop that needs considerably more capacity around Valentines Day then at other times of the year. It’s also great for independent developers allowing them to quickly and cheaply set up a new application and then easily scale it as new customers come along and demand increases. &lt;/p&gt;  &lt;p&gt;For .NET developers Azure supports the familiar .NET languages like C# and VB.NET (although Microsoft has indicated that support for languages like PHP may come in the future) and provides tools that integrate into Visual Studio. All of this makes for an easier learning curve for existing .NET developers.&lt;/p&gt;  &lt;p&gt;I will be posting more information on Azure as I started getting familiar with the platform.&lt;/p&gt;  &lt;p&gt;You can get more information on azure on Microsoft’s &lt;a href="http://www.microsoft.com/azure/default.mspx"&gt;Azure Service Platform page.&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-509756576353799461?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/509756576353799461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=509756576353799461' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/509756576353799461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/509756576353799461'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/windows-azure.html' title='Windows Azure'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-90437047144354358</id><published>2009-01-17T09:25:00.001-05:00</published><updated>2009-01-17T09:25:49.563-05:00</updated><title type='text'>C# Type Inference</title><content type='html'>&lt;p&gt;C# 3.0 introduced a new language concept called Type Inference. Here is an example:&lt;/p&gt;  &lt;p&gt;var n = 3;&lt;/p&gt;  &lt;p&gt;Instead of specifying a type in this variable declaration the keyword var is used. When this line is compiled the compiler will determine the appropriate data type for the variable based on the initial value assigned to it. In this case ‘n’ will be an Int32. I think ‘var’ was an unfortunate choice for this keyword since it brings to mind Variants from VB6. Variants changed type based on what was assigned to them, but this is not the case with var. Variables declared with var are strongly typed but the compiler determines the type, not the programmer. The following code will not compile:&lt;/p&gt;  &lt;p&gt;var n = 3;&lt;/p&gt;  &lt;p&gt;n = “test”;&lt;/p&gt;  &lt;p&gt;This will produce the error “Cannot implicitly convert type 'string' to 'int'”.&lt;/p&gt;  &lt;p&gt;You can also use var to declare arrays like this:&lt;/p&gt;  &lt;p&gt;var nums = new[] {0, 1, 2};&lt;/p&gt;  &lt;p&gt;This will result in an array of Int32. Note that when arrays are declared every element has to be of the same type. For example this line will produce a compiler error:&lt;/p&gt;  &lt;p&gt;var nums = new[] { 0, &amp;quot;test&amp;quot;, 2 };&lt;/p&gt;  &lt;p&gt;There are a couple limitations to using var. &lt;/p&gt;  &lt;p&gt;- var can only be used for local variables and cannot be used at the class level.&lt;/p&gt;  &lt;p&gt;- The variable has to be initialized in the same line as it is declared. You cannot do:&lt;/p&gt;  &lt;p&gt;var n;&lt;/p&gt;  &lt;p&gt;n = 1;&lt;/p&gt;  &lt;p&gt;-You cannot define multiple variables at one time using var. This is not legal:&lt;/p&gt;  &lt;p&gt;var n = 3, x = 2;&lt;/p&gt;  &lt;p&gt;When you look at this feature and some of the other new features introduced in C# 3.0 they may appear of limited use and pretty random. Although these features do have their uses the main purpose is to support a major new feature in 3.0, Language Integrated Query (LINQ). I will talk about this in a later blog post.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-90437047144354358?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/90437047144354358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=90437047144354358' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/90437047144354358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/90437047144354358'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/c-type-inference.html' title='C# Type Inference'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-1393893602559610968</id><published>2009-01-16T12:28:00.000-05:00</published><updated>2009-01-16T12:29:33.633-05:00</updated><title type='text'>Programming Visual Basic applications?</title><content type='html'>Typemock have released a new version of their &lt;a href="http://www.typemock.com/?utm_source=hp&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvb"&gt;unit testing&lt;/a&gt; tool, Typemock Isolator 5.2.This version includes a new friendly &lt;a href="http://www.typemock.com/vbpage.php?utm_source=vbp&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvb"&gt;VB.NET &lt;/a&gt;API which makes Isolator the best Isolation tool for &lt;a href="http://www.typemock.com/vbpage.php?utm_source=vbp&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvb"&gt;unit testing A Visual Basic (VB) .NET application&lt;/a&gt;.&lt;br /&gt;Isolator now allows unit testing in VB or C# for many ‘hard to test’ technologies such as &lt;a href="http://typemock.com/sharepointpage.php?utm_source=spp&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvb"&gt;SharePoint&lt;/a&gt;, ASP.NET MVC, partial support for Silverlight, WPF, LINQ, WF, Entity Framework, &lt;a href="http://www.typemock.com/wcfpage.php?utm_source=wcfp&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvb"&gt;WCF unit testing&lt;/a&gt; and more.&lt;br /&gt;&lt;br /&gt;Note that the first 25 bloggers who blog this text in their blog and tell us about it, will get a Free Full Isolator license (C#, VB, and Sharepoint included - worth $139 !!!). If you post this in a VB.NET dedicated blog, you'll get a license automatically (even if more than 25 submit) during the first week of this announcement.&lt;br /&gt;&lt;br /&gt;Go ahead, click the following link for &lt;a href="http://blog.typemock.com/2009/01/get-free-isolator-licnese-for-helping.html?utm_source=vb_blog&amp;amp;utm_medium=typeblog&amp;amp;utm_campaign=isolatorvbblog"&gt;more information &lt;/a&gt;on how to get your free license.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-1393893602559610968?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/1393893602559610968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=1393893602559610968' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1393893602559610968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/1393893602559610968'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/programming-visual-basic-applications.html' title='Programming Visual Basic applications?'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-5765596811417791241</id><published>2009-01-11T10:00:00.001-05:00</published><updated>2009-01-11T10:00:44.375-05:00</updated><title type='text'>Scott Guthrie’s Blog</title><content type='html'>&lt;p&gt;If you are looking for good tutorial on the latest .NET technologies, as well as&amp;#160; alot of other cutting edge .NET info,&amp;#160; I would highly recommend checking out &lt;a href="http://weblogs.asp.net/scottgu/default.aspx"&gt;Scott Guthrie’s Blog&lt;/a&gt;. Scott is a Corporate Vice President in Microsoft’s Developer Division so always has excellent insight into Microsoft’s latest technologies. Here are direct links to some of his tutorials.&lt;/p&gt;  &lt;h4&gt;Silverlight End to End Tutorial&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx"&gt;Part 1: Creating &amp;quot;Hello World&amp;quot; with Silverlight 2 and VS 2008&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx"&gt;Part 2: Using Layout Management&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx"&gt;Part 3: Using Networking to Retrieve Data and Populate a DataGrid&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx"&gt;Part 4: Using Style Elements to Better Encapsulate Look and Feel&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx"&gt;Part 5: Using the ListBox and DataBinding to Display List Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-6-using-user-controls-to-implement-master-detail-scenarios.aspx"&gt;Part 6: Using User Controls to Implement Master/Details Scenarios&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx"&gt;Part 7: Using Templates to Customize Control Look and Feel&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-8-creating-a-digg-desktop-application-using-wpf.aspx"&gt;Part 8: Creating a Digg Desktop Version of our Application using WPF&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;LINQ to SQL&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx"&gt;Part 1: Introduction to LINQ to SQL&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx"&gt;Part 2: Defining our Data Model Classes&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx"&gt;Part 3: Querying our Database&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx"&gt;Part 4: Updating our Database&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx"&gt;Part 5: Binding UI using the ASP:LinqDataSource Control&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx"&gt;Part 6: Retrieving Data Using Stored Procedures&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/08/23/linq-to-sql-part-7-updating-our-database-using-stored-procedures.aspx"&gt;Part 7: Updating our Database using Stored Procedures&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;ASP.NET MVC Framework&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx"&gt;Part 1: Introduction&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx"&gt;Part 2: URL Routing&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx"&gt;Part 3: Passing ViewData from Controllers to Views&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx"&gt;Part 4:&amp;#160; Handling Form Edit and Post Scenarios&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-5765596811417791241?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/5765596811417791241/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=5765596811417791241' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5765596811417791241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/5765596811417791241'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/scott-guthries-blog.html' title='Scott Guthrie’s Blog'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-4990241311695572782</id><published>2009-01-06T21:01:00.001-05:00</published><updated>2009-01-06T21:02:34.412-05:00</updated><title type='text'>SetValue/GetValue</title><content type='html'>&lt;p&gt;Occasionally you will run into a situation where you want to reference the property of an object by its name instead of directly accessing the property. Using the SetValue and GetValue functions you can actually access a property where the property name is stored in a string. Let’s start with a simple object to demonstrate this&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 397px; height: 182px" name="code" rows="rows" cols="cols"&gt;public class Test&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt; private string name;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; public string Name&amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; get { return name; }&amp;lt;br /&amp;gt; set { name = value; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;Next you will need to import the Reflection namespace:&lt;/p&gt;  &lt;p&gt;using System.Reflection;&lt;/p&gt;  &lt;p&gt;Finally here is the code that will write and then read back the Name property:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 376px; height: 86px" name="code" rows="rows" cols="cols"&gt;Test testObj = new Test();&amp;lt;br /&amp;gt;PropertyInfo pi = testObj.GetType().GetProperty(&amp;quot;Name&amp;quot;);&amp;lt;br /&amp;gt;pi.SetValue(testObj, &amp;quot;Dan&amp;quot;, null);&amp;lt;br /&amp;gt;Console.WriteLine(pi.GetValue(testObj, null));&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;We start out by creating an instance of the Test object and then use the GetProperty function to get the PropertyInfo for the property “Name”. Property info allows you to access various information about a property and also provides access to the GetValue and SetValue functions. If the property can’t be found, GetProperty will return a null, so if there is any chance that the property name you are trying to access may not exist you would want to check if pi is null and handle that error appropriately. &lt;/p&gt;  &lt;p&gt;Now that we have the PropertyInfo for the Name property we can write to it with SetValue. SetValue takes three parameters. The first is the object whose property we want to set, in this case the test object. The second parameter is the value we want to set the property to. The third is use for indexed properties which we will talk about next, for this example we will set that null. &lt;/p&gt;  &lt;p&gt;Reading the value back is just as easy, we just call the GetValue function. Like SetValue, GetValue takes the object to get the property from as the first parameter, and the index as the second, again null in this example.&lt;/p&gt;  &lt;p&gt;As I mentioned you can also use SetValue/GetValue to access an indexed property. Here is another sample object to work with:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 405px; height: 182px" name="code" rows="rows" cols="cols"&gt;public class Test&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt; private int[] num = new int[5];&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; public int this[int index] &amp;lt;br /&amp;gt; {&amp;lt;br /&amp;gt; get { return num[index]; }&amp;lt;br /&amp;gt; set { num[index] = value; }&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;The code to read and write this property would look like this:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 405px; height: 70px" name="code" rows="rows" cols="cols"&gt;pi = testObj.GetType().GetProperty(&amp;quot;Item&amp;quot;);&amp;lt;br /&amp;gt;pi.SetValue(testObj, 1, new object[] { (int)1 });&amp;lt;br /&amp;gt;Console.WriteLine (pi.GetValue(testObj, new object[] { (int)1 }));&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;There are a couple differences to note here. First, in C# the default property of an object is the only one that can be indexed, that’s why the test object declares the property name as ‘this’. By default the name of the default property is ‘Item’ so that is what we pass to the GetProperty function. If you want you can change the name of this property by putting the following attribute before the property declaration in the object:&lt;/p&gt;  &lt;p&gt;[IndexerNameAttribute(&amp;quot;IndexedInstanceProperty&amp;quot;)]&lt;/p&gt;  &lt;p&gt;This will change the name of the property from Item to IndexedInstanceProperty. Note that you will have to import the System.Runtime.CompilerServices namespace to us this attribute. &lt;/p&gt;  &lt;p&gt;The second difference is the index property that is passed to the SetValue and GetValue functions. This parameter is an array of objects. In this example we are using a static index of 1 but it takes a little extra code to turn this single value into an array. &lt;/p&gt;  &lt;p&gt;You are probably not going to use SetValue and GetValue a lot but there are definitely situations where it really comes in handy. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-4990241311695572782?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/4990241311695572782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=4990241311695572782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4990241311695572782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/4990241311695572782'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/setvaluegetvalue.html' title='SetValue/GetValue'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-7323204158933069398</id><published>2009-01-02T10:13:00.001-05:00</published><updated>2009-01-02T10:20:28.979-05:00</updated><title type='text'>Unused Local Variable</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;I recently ran into an interesting quirk (not sure if I even want to call it that) in Visual Studio. Here is a piece of code that demonstrates the quirk:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="vb" style="width: 396px; height: 150px" name="code" rows="rows" cols="cols"&gt;Sub Main()&amp;lt;br /&amp;gt; Dim a As Integer&amp;lt;br /&amp;gt; a = 1&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Exit Sub&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Dim b As Integer&amp;lt;br /&amp;gt; b = 1&amp;lt;br /&amp;gt;End Sub&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;If you paste this into Visual Studio you will notice that you get a squiggly under the ‘b’ variable with an warning that says Unused Local Variable. I first encountered this in a much large function I was developing and it drove me crazy for a while until I realized that it was the Exit Sub earlier in the code that was causing it. Obviously you would never do this in production code but I had inserted the Exit Sub for debugging purposes. &lt;/p&gt;  &lt;p&gt;This quirk was interesting to me because VS was obviously smart enough to know the b=1 would never be executed but didn’t take into account the fact that it would never even be declared. You can get some more insight into this by looking at the IL disassembly for the code:&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;.method public static void  Main() cil managed&lt;br /&gt;{&lt;br /&gt;  .entrypoint&lt;br /&gt;  .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) &lt;br /&gt;  // Code size       3 (0x3)&lt;br /&gt;  .maxstack  1&lt;br /&gt;  .locals init ([0] int32 a,&lt;br /&gt;           [1] int32 b)&lt;br /&gt;  IL_0000:  ldc.i4.1&lt;br /&gt;  IL_0001:  stloc.0&lt;br /&gt;  IL_0002:  ret&lt;br /&gt;} // end of method Module1::Main&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can see in the IL that both local variables a and b are declared before that start of the start of the code. You will also notice that nothing after the Exit Sub gets compiled, the assignment of b does not show up in the IL. So the behavior we see in VS is consistent with what we see in the IL, b is defined but never used.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-7323204158933069398?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/7323204158933069398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=7323204158933069398' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7323204158933069398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/7323204158933069398'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2009/01/unused-local-variable.html' title='Unused Local Variable'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-3003947279521552988</id><published>2008-12-14T10:25:00.001-05:00</published><updated>2008-12-14T10:25:11.862-05:00</updated><title type='text'>Programming Blog Take 2</title><content type='html'>&lt;p&gt;This is going to be my second attempt at this blog. When I first started doing this blog I struggled with how to easily post well formatted code snippets. I tried for a while to find a good solution to this problem but eventually gave up. Recently I decided to revive the blog idea when I stumbled across this posting on Scott Hanselman’s Blog:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.hanselman.com/blog/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx"&gt;http://www.hanselman.com/blog/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;He talks about a couple of tools that make the process of posting code much easier. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.google.com/p/syntaxhighlighter/"&gt;Syntax Highlighter&lt;/a&gt; is a JavaScript based syntax highlighting tool. You simply put your code in a &amp;lt;pre&amp;gt; or &amp;lt;textarea&amp;gt; tag with the appropriate attributes and when the page is displayed the JavaScript will take care of the formatting. It particularly nice for use on Blogger since it runs entirely on the client. &lt;/p&gt;  &lt;p&gt;The second tool if &lt;a href="http://get.live.com/writer/overview"&gt;Windows Live Writer&lt;/a&gt;. I had heard of the tool but never used it. It’s a great tool for posting blog entries since it integrates directly with major blogging services including Blogger making it much easier to write and publish blog entries.&lt;/p&gt;  &lt;p&gt;The third tool combines the first two. Its call &lt;a href="http://www.codeplex.com/precode"&gt;PreCode&lt;/a&gt; and it’s a Syntax Highlighter plug-in for Live Writer.&lt;/p&gt;  &lt;p&gt;Using these tools has made it much easier to do these blog entries. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-3003947279521552988?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/3003947279521552988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=3003947279521552988' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3003947279521552988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/3003947279521552988'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2008/12/programming-blog-take-2.html' title='Programming Blog Take 2'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-16352016005600644</id><published>2008-12-06T13:03:00.001-05:00</published><updated>2008-12-06T13:06:03.672-05:00</updated><title type='text'>Generic C#</title><content type='html'>&lt;p&gt;In my last post I introduced Generics and showed some examples in VB.NET. Generics can also be used in C#. The TypedList class from m previous post would look like this in C#:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 391px; height: 214px" name="code" rows="rows" cols="cols"&gt;class TypedList&amp;lt;itemType&amp;gt;&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt; ArrayList list = new ArrayList();&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; public void Add(itemType item) {&amp;lt;br /&amp;gt; list.Add(item);&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; public itemType Item(int index) {&amp;lt;br /&amp;gt; return (itemType)list[index];&amp;lt;br /&amp;gt; }&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;You would declare a TypeList that accepted dates list this:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="c#" style="width: 389px; height: 22px" name="code" rows="rows" cols="cols"&gt;TypedList&amp;lt;System.DateTime&amp;gt; list = new TypedList&amp;lt;System.DateTime&amp;gt;();&lt;/textarea&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-16352016005600644?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/16352016005600644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=16352016005600644' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/16352016005600644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/16352016005600644'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2008/12/generic-c.html' title='Generic C#'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7413274486781112158.post-9071130946014448291</id><published>2008-12-03T20:44:00.003-05:00</published><updated>2008-12-03T21:17:46.266-05:00</updated><title type='text'>Generics</title><content type='html'>&lt;p&gt;The first topic I would like to talk about is .NET Generics. This language feature was introduced in .NET 2.0, and I think it’s one of the more useful new language features introduced in 2.0. It’s available in both VB.NET and C#, but I’ll be provided the examples here in VB.NET. &lt;/p&gt;  &lt;p&gt;What are Generics? Basically generics are a way to make classes that can work with multiple data types, but that can be declared to use a specific type at run time. I will use a classic example to illustrate this. &lt;/p&gt;  &lt;p&gt;One of the more useful classes in the .NET Framework is the Arraylist class. This class works pretty much like a standard array, but it allows you to dynamically add new items without having to manually re-size it. One potential downside to the Arraylist is the it’s weakly typed, meaning you can insert any type into it, and each element in an Arraylist can contain a different type. Sometimes this might be useful, but most of the time you want every item in the array to be the same type. &lt;/p&gt;  &lt;p&gt;One way to fix this is to build a strongly type wrapper class around the Arraylist. Here is the example code for a strongly type Date Arraylist:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="vb" style="width: 394px; height: 198px" name="code"&gt;Public Class DateList&amp;lt;br /&amp;gt; Private list As New ArrayList&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Sub Add(ByVal item As Date)&amp;lt;br /&amp;gt; list.Add(item)&amp;lt;br /&amp;gt; End Sub&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Function Item(ByVal index As Integer) As Date&amp;lt;br /&amp;gt; Return list(index)&amp;lt;br /&amp;gt; End Function&amp;lt;br /&amp;gt;End Class&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;This works just fine, but it would start getting a little redundant if you had to do a lot of these for different types.&lt;/p&gt;  &lt;p&gt;Generics provide an easy solution to this problem. Here is the code for the Generic version:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="vb" style="width: 401px; height: 204px" name="code"&gt;Public Class TypedList(Of itemType)&amp;lt;br /&amp;gt; Private list As New ArrayList&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Sub Add(ByVal item As itemType)&amp;lt;br /&amp;gt; list.Add(item)&amp;lt;br /&amp;gt; End Sub&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Function Item(ByVal index As Integer) As itemType&amp;lt;br /&amp;gt; Return list(index)&amp;lt;br /&amp;gt; End Function&amp;lt;br /&amp;gt;End Class&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;You will notice the biggest difference is the class declaration. The phrase “Of itemType” is saying that this class is going to be using a type that is specified at the time of declaration and we will call this type itemType. You can think of itemType as a placeholder for the actual type the class will use. We use itemType in the class anyplace we would have used Date in the previous example. So you will see in the declaration of the Add Sub that we are declaring the parameter item as type itemType. &lt;/p&gt;  &lt;p&gt;To use this class we would create an instance of it like this:&lt;/p&gt;  &lt;p&gt;Dim list As New TypedList(Of Date)&lt;/p&gt;  &lt;p&gt;When our TypeList object is created everyplace where we had itemType will essentially be replaced with Date. We now have a strongly typed Arraylist of dates. If we try to insert something other then a date an exception will be thrown at runtime. &lt;/p&gt;  &lt;p&gt;You are not restricted to using one type in a Generic class. Here is an example of how you could do a strongly type Hashtable&lt;/p&gt;  &lt;p&gt;&lt;textarea class="vb" style="width: 402px; height: 198px" name="code"&gt;Public Class TypedHastable(Of keyType, itemType)&amp;lt;br /&amp;gt; Private list As New Hashtable&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Sub Add(ByVal key As keyType, ByVal item As itemType)&amp;lt;br /&amp;gt; list.Add(key, item)&amp;lt;br /&amp;gt; End Sub&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt; Public Function Item(ByVal key As keyType) As itemType&amp;lt;br /&amp;gt; Return list(key)&amp;lt;br /&amp;gt; End Function&amp;lt;br /&amp;gt;End Class&amp;lt;br /&amp;gt;&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;You can see in the declaration of the class that we provide two types, one for the key and one for the item. To create an instance of this class so that the key would be an integer and the item to be a string you would do this:&lt;/p&gt;  &lt;p&gt;Dim table As New TypedHastable(Of Integer, String)&lt;/p&gt;  &lt;p&gt;The examples I have shown here are a good illustration of how generics work, but really aren’t necessary since the .NET Framework actually has generic versions of the major collection types build in. I’ll talk about these in my next post along with the C# generic syntax.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7413274486781112158-9071130946014448291?l=danlb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danlb.blogspot.com/feeds/9071130946014448291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7413274486781112158&amp;postID=9071130946014448291' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/9071130946014448291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7413274486781112158/posts/default/9071130946014448291'/><link rel='alternate' type='text/html' href='http://danlb.blogspot.com/2008/12/generics.html' title='Generics'/><author><name>Dan Boris</name><uri>http://www.blogger.com/profile/07071989815220997114</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
