ASP.NET Podcast

ASP.NET Podcast is geared towards the Microsoft .NET Framework and ASP.NET.
The podcast is run by Wally McClure, David Penton, and Paul Glavich.
Welcome to ASP.NET Podcast Sign in | Join | Help
in Search

ASP.NET Podcast

The ASP.NET Podcast features, technical talks, interviews, news, reviews, and Wallyisms. Wallace B. (Wally) McClure, David Penton, and Paul Glavich are your hosts. We talk about ASP.NET, AJAX, Performance, Databases, WCF, Silverlight, Cloud Computing, Windows Azure, and whatever else we decide to talk about.

  • ASP.NET Podcast Show #141 - Angel and Venture Financing for Technology Professionals with Rachael Qualls

    Subscribe to Everything.

    Subscribe to WMV.

    Subscribe to M4V.

    Subscribe to MP3.

    Download WMV.

    Download  M4V for iPod.

    Download MP3.

    Show Notes:

    Personal Note from Wally: My favorite quote from the discussion: "We're not looking for an ad-based play."
  • ASP.NET Podcast Show #140 - ASP.NET 4.0 Ajax Databinding

    Subscribe to Everything.

    Subscribe to WMV.

    Subscribe to M4V.

    Subscribe to MP3.

    Download WMV.

    Download M4V.

    Download MP3.

    Show Notes:

    PS. I started getting sick about 5-10 minutes into the show, so if I sound somewhat confusing after that, I apologize.

    Source Code:

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Content.aspx.cs" Inherits="TwitterApp.Content" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:ScriptManager ID="sm" runat="server">

    <Scripts>

    <asp:ScriptReference ScriptMode="Inherit" Name="MicrosoftAjax.js" Path="~/js/MicrosoftAjax.js" />

    <asp:ScriptReference ScriptMode="Inherit" Path="~/js/MicrosoftAjaxAdoNet.js" />

    <asp:ScriptReference ScriptMode="Inherit" Path="~/js/MicrosoftAjaxTemplates.js" />

    </Scripts>

    <Services>

    <asp:ServiceReference Path="~/TwitterService.svc" />

    </Services>

    </asp:ScriptManager>

    <asp:TextBox ID="Status" runat="server"

    TextMode="MultiLine" Rows="2" Columns="70" /><br />

    <input type="button" ID="btnSubmit"

    onclick="SubmitStatus()" value="Submit Status" />

    <hr width="98%" />

    <script language="javascript" type="text/javascript">

    var userName = "More_Wally";

     

    function SubmitStatus() {

    var Status = $get('<%=Status.ClientID %>');

    var userStatus = Status.value;

    Status.value = "";

    TwitterService.SubmitUserStatus(userName, userStatus,

    TwitterPostCallBack);

    }

    function TwitterPostCallBack(result) {

    TwitterService.GetUserTimeLine(userName,

    TwitterServiceCallBack, TwitterServiceFailure);

    }

    var dv;

    function pageLoad() {

    var tblS = $get("tblStatus");

    var uiElement = $get("twitterFriendsTimeLineListView");

    dv = new Sys.UI.DataView(uiElement);

    dv.add_itemCreated(fillExtra);

    dv.initialize();

    TwitterService.GetFriends(userName, StoreFriendsCallBack);

    TwitterService.GetUserTimeLine(userName, TwitterServiceCallBack, TwitterServiceFailure);

    }

    var dd;

    function StoreFriendsCallBack(result) {

    dd = result;

    }

    function TwitterServiceCallBack(result) {

    dv.set_data(result);

    //dv.updated();

    //tblStatus.style.visibility = "visible";

    }

    function FriendsCallBack(result, userCtx) {

    dd = result;

    DisplaySelect(dd, userCtx);

    }

    function DisplaySelect(data, userCtx) {

    var i;

    var opt;

    var sel = $get("to" + userCtx.index);

    sel.options.add(new Option("", ""));

    for (i = 0; i < data.length; i++) {

    opt = new Option(data[i].name, data[i].screen_name);

    sel.options.add(opt);

    }

    }

    var i = 0;

     

    function fillExtra(sender, Args) {

    var ctx = Args.get_templateContext();

    var dt = Args.get_dataItem();

    var strOut = "";

    var strReturn = "<br />";

    var Out = $get("Output");

    var userCtx =

    {

    index: ctx.index

    }

     

    if (i == 0) {

    strOut = "ctx<br />";

    for (m in ctx) {

    strOut += m + strReturn;

    }

    strOut += "<br/>ctx.nodes[0]<br />";

    for (m in ctx.nodes[0]) {

    strOut += m + strReturn;

    }

    strOut += "<br/>Data Item:<br />";

    for (m in dt) {

    strOut += m + strReturn;

    }

    Out.innerHTML = strOut;

    }

    i++;

    if (dd == null) {

    TwitterService.GetFriends("More_Wally", FriendsCallBack, null, userCtx);

    }

    else {

    DisplaySelect(dd, userCtx);

    }

    }

    function TwitterServiceFailure(result) {

    alert("An error occurred");

    }

    function IterateDV() {

    var count = dv.get_items().length;

    var rw = "";

    var controlId;

    var ctx = dv.get_templateContext()

    for (i = 0; i < count; i++) {

    if (i == 0) {

    //rw = dv.get_items()[i].elements[0].childNodes[2].childNodes[0].innerHTML;

    rw = $get("Number" + i).innerHTML;

    }

    else {

    rw += "," + $get("Number" + i).innerHTML;

    }

    }

    alert(rw);

    }

    function SendMessage(i) {

    var userName = "More_Wally";

    var sendTo = $get("to" + i).value;

    var userStatus = $get("message" + i).value;

    TwitterService.DMSend(userName, sendTo, userStatus,

    TwitterPostCallBack, TwitterServiceFailure);

    }

    String.prototype.parseURL = function() {

    var URL = /[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/;

    var matches = this.match(URL);

    var stringToReplace = this;

    while (matches != null ) {

    var m = matches[0];

    var url = "<a href='" + m + "'>" + m + "</a>";

    stringToReplace = stringToReplace.replace(m, url);

    matches = stringToReplace.substring(stringToReplace.indexOf(url) +

    url.length).match(URL);

    }

    return (stringToReplace);

    };

    String.prototype.parseUsername = function() {

    var userName = /[@]+[A-Za-z0-9-_]+/;

    var matches = this.match(userName);

    var stringToReplace = this;

    while ( matches != null ) {

    var m = matches[0];

    var finalMatch = m.replace("@", "");

    var url = "<a href='http://twitter.com/" + finalMatch + "' target='_new'>" + m + "</a>";

    stringToReplace = stringToReplace.replace(m, url);

    matches = stringToReplace.substring(stringToReplace.indexOf(url) + url.length).match(userName);

    };

    return (stringToReplace);

    };

    String.prototype.parseHashtag = function() {

    var hashTag = /[#]+[A-Za-z0-9-_]+/;

    var matches = this.match(hashTag);

    var stringToReplace = this;

    while (matches != null) {

    var m = matches[0];

    var finalMatch = m.replace("#", "%23");

    var url = "<a href='http://search.twitter.com/search?q=" + finalMatch +

    "' target='_new'>" + m + "</a>";

    stringToReplace = stringToReplace.replace(m, url);

    matches = stringToReplace.substring(stringToReplace.indexOf(url) +

    url.length).match(hashTag);

    };

    return (stringToReplace);

     

     

    };

    </script>

    <input type="button" id="btnIterate"

    value="Iterate" onclick="IterateDV()" />

    <table>

    <tr valign="top" align="left">

    <td>

    <table id="tblStatus" >

    <thead>

    <tr>

    <th>

    User Name

    </th>

    <th>

    Status

    </th>

    <th>

    Number

    </th>

    </tr>

    </thead>

    <tbody id="twitterFriendsTimeLineListView"

    class="sys-template" >

    <tr>

    <td valign="top" align="left">

    {{UserName}}<br />

    <img sys:src="{{ ProfileImage }}" /><br />

    <span style="font-size:smaller">

    {{ StatusDate }}

    </span>

    </td>

    <td valign="top" align="left">

    <span code:after="$element.innerHTML=Status.parseURL().parseUsername().parseHashtag()" />

    <!--{{Status.parseURL().parseUsername().parseHashtag()}}--></td>

    <td>

    <div sys:id="{{ 'Number' + $index }}">{{ $index }}</div>

    <div code:if="($index % 2) == 0">even</div>

    <div code:if="($index % 2) == 1">odd</div>

    </td>

    </tr>

    <tr>

    <td>

    <select sys:id="{{ 'to' + $index }}" ></select>

    <input type="text" sys:id="{{ 'message' + $index }}" size="50" />

    </td>

    <td>

    <input type="button" sys:id="{{ 'btn' + $index }}"

    value="Send a direct message" onclick="{{ 'SendMessage(' + $index + ')' }}" />

    </td>

    </tr>

    <tr>

    <td colspan="2">

    2 way data binding<br />

    { binding Status }<br />

    <input type="text" value="{ binding Status }" />

    </td>

    </tr>

    <tr>

    <td colspan="2">

    <div code:before="if (i != 19) {" code:after="}">break</div>

    <hr width="98%" code:if="$index != 19" />

    </td>

    </tr>

    </tbody>

    </table>

    </td>

    <td>

    <div id="Output">

    </div>

    </td>

    </tr>

    </table>

    </asp:Content>

     

    Images:

  • ASP.NET Podcast Show #139 - David Penton and Pat Helland on Cloud Computing - audio

  • ASP.NET Podcast Show #138 - Coding Microsoft Velocity with David Penton - video

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    (The cool kids subscribe, why not you?!?)

    Download WMV.

    Download M4V.

    Download MP3.

    Code Samples: http://www.aspnetpodcast.com/CS11/files/folders/podcastsupportfiles/entry1293.aspx

    Show Notes:

    ----- Code Sample Notes -----

    • Four (4) assembly references are needed for a cache project:
    • CacheBaseLibrary.dll
    • CASBase.dll
    • ClientLibrary.dll
    • FabricCommon.dll
    • Import System.Data.Caching for code using Velocity
    • You must start with a CacheFactory. No parameters in the construct means to read from a configuration file.
    • From there, cache is accessed via a CacheName. You can use Cache.DefaultCache for the default (returns null) For CTP2, you cannot easily seek out if a region is created.
    • Cache.DefaultRegion is null as well.
    • There is quite a bit of log messages that are exposed by default in Velocity. Especially for a Cache Miss.

    Format: wmv
    Duration: 23:00

  • ASP.NET Podcast Show #137 - Install and Configuration of Microsoft Velocity with David Penton - video

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    (The cool kids subscribe, why not you?!?)

    Download WMV.

    Download M4V.

    Download MP3.

    Show Notes:

    ----- Installation Notes -----

    • CTP1 must be uninstalled first!
    • .Net Framework version 3.5
    • PowerShell version 1.0
    • Cluster configuration options
    • XML based
    • SQL Server (or SQL CE) based
    • Set cache cluster/host options
    • Cluster Name
    • Cluster Size: small (1-3), medium (4-6), large (7-10)
    • Cache Host port (default 22233)
    • Cache Cluster port (if configuring) (default 22234)
    • Max Server Memory

    ----- Configuration Notes -----

    • XML Configuration file or SQL Server
    • PowerShell is the de-facto configuration tool Desktop icon is created during installation for the PowerShell entrance Keep in mind that any parameter values are case-sensitive Basic help comes from
    • Get-CacheHelp
    • Other typical options (some have obvious names)
    • Start-CacheCluster
    • Stop-CacheCluster
    • Restart-CacheCluster
    • Get-Cache (shows the current Cache Names available and the regions)
    • New-Cache (creates a new cache name)
    • Remove-Cache (removes an existing cache name)
    • Get-CacheConfig (shows statistics for the cache node specified)
  • ASP.NET Podcast Show #136 - Rachel Appel on Dynamic Data

    Subscribe to everything.

    Subscribe to MP3.

    Download.

    Show Notes:

    PS. Apologies for the delay as I have been sick and concentrating on other things.
  • ASP.NET Podcast Show #135 - Development Methodologies as Religion

    Subscribe to all

    Subscribe to MP3 only

    Download

    Show Notes:

    • Superbowl, football, Cowboys (you have got to be kidding me).
    • Refactoring, TDD, and the great religious debates of software systems.
    • Coaching systems. Great Players make Great Coaches. Systems need to be molded to players.  Don't force one size fits all.
    • Ok, I feel better now.
  • ASP.NET Podcast Show #134 - General Thoughts on Windows Azure - Audio only

    Subscribe to all

    Subscribe to MP3

    Download

    Show Notes:

  • ASP.NET Podcast Show #133 - Windows Azure Table Storage - video

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    Download WMV.

    Download M4V (iPod).

    Download MP3.

    Win a ticket to the MDC in Detroit.  Enter here. 

    Show Notes:

    • CRUD Application
    • CRUD application.
    • Message.
    • Message Data Service Context.
    • This example is taken from Hands On Labs.

    Source Code for Default.aspx.cs:

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Data.Services.Client;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Microsoft.Samples.ServiceHosting.StorageClient;
    using Microsoft.ServiceHosting.ServiceRuntime;

    namespace TableCloudService_WebRole
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string statusMessage = String.Empty;
                if (!Page.IsPostBack)
                {
                    DisplayMessages();
                }
            }

            protected void lbDisplayMessages_Click(object sender, EventArgs e)
            {
                DisplayMessages();
            }

            protected void OnDeleteMessage(object sender, CommandEventArgs e)
            {
                LinkButton lb = (LinkButton)sender;
                GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

                if (e.CommandName == "Delete")
                {
                    string PartitionKey = ((HiddenField)gvr.FindControl("hdPartitionKey")).Value;
                    string RowKey = ((HiddenField)gvr.FindControl("hdRowKey")).Value;
                    string TimeStamp = ((HiddenField)gvr.FindControl("hdTimeStamp")).Value;
                    string Body = ((TextBox)gvr.FindControl("txtBody")).Text;
                    string Name = ((TextBox)gvr.FindControl("txtName")).Text;
                    MessageDataServiceContext context = GetContext();

                    //var m = (from mess in context.Messages
                    //         where
                    //             (mess.PartitionKey == PartitionKey) &&
                    //             (mess.RowKey == RowKey)
                    //         select mess).Single();
                    var m = new Message();
                    m.PartitionKey = PartitionKey;
                    m.RowKey = RowKey;
                    m.Timestamp = Convert.ToDateTime(TimeStamp);
                    context.AttachTo("Messages", m, "*");
                   
                    context.DeleteMessage(m);
                    RoleManager.WriteToLog("Verbose", "Delete Message.");
                    DisplayMessages();
                }
            }
            protected void OnUpdateMessage(Object sender, CommandEventArgs e)
            {
                LinkButton lb = (LinkButton)sender;
                GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

                if (e.CommandName == "Update")
                {
                    string PartitionKey = ((HiddenField)gvr.FindControl("hdPartitionKey")).Value;
                    string RowKey = ((HiddenField)gvr.FindControl("hdRowKey")).Value; ;
                    string TimeStamp = ((HiddenField)gvr.FindControl("hdTimeStamp")).Value; ;
                    string Body = ((TextBox)gvr.FindControl("txtBody")).Text; ;
                    string Name = ((TextBox)gvr.FindControl("txtName")).Text; ;
                    MessageDataServiceContext context = GetContext();

                    //var m = (from mess in context.Messages
                    //         where
                    //             (mess.PartitionKey == PartitionKey) &&
                    //             (mess.RowKey == RowKey)
                    //         select mess).First();
                    var m = new Message();
                    m.PartitionKey = PartitionKey;
                    m.RowKey = RowKey;
                    m.Timestamp = Convert.ToDateTime(TimeStamp);
                    m.Body = Body;
                    m.Name = Name;
                    context.AttachTo("Messages", m, "*");
                    context.UpdateMessage(m);
                    RoleManager.WriteToLog("Information",  "Update complete.");
                    DisplayMessages();
                }
            }

            protected void Timer1_OnTick(Object sender, EventArgs e)
            {
                DisplayMessages();
            }

            private void DisplayMessages()
            {
                MessageDataServiceContext context = GetContext();
                RoleManager.WriteToLog("Verbose", "Display Messages.");
                messageList.DataSource = context.Messages.Take(10);
                messageList.DataBind();
            }

            private MessageDataServiceContext GetContext()
            {
                MessageDataServiceContext context;
                StorageAccountInfo accountInfo = StorageAccountInfo.GetAccountInfoFromConfiguration("TableStorageEndpoint");
                TableStorage.CreateTablesFromModel(typeof(MessageDataServiceContext), accountInfo);
                context = new MessageDataServiceContext(accountInfo);
                RoleManager.WriteToLog("Verbose", "Message Data Service Context created.");
                return context;
            }

            protected void SubmitButton_Click(object sender, EventArgs e)
            {
                StorageAccountInfo accountInfo = StorageAccountInfo.GetAccountInfoFromConfiguration("TableStorageEndpoint");
                MessageDataServiceContext context = new MessageDataServiceContext(accountInfo);
                context.AddMessage(this.nameBox.Text, this.messageBox.Text);
                nameBox.Text = String.Empty;
                messageBox.Text = String.Empty;
                DisplayMessages();
            }
        }
    }

    Source Code for Default.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TableCloudService_WebRole._Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Azure Table Example Page</title>
            <style type="text/css">
            body { font-family: Verdana; font-size: 9pt; }
            h1 { font-size: 12pt; color: #555555; }
            li { list-style-type: none; }
            form { background-color: #eeeeff; width: 80%; margin: 0 auto; padding: 1em; border: solid 1px #333333; }
            #entryform, #messages { margin: 1em 0 }
            #entryform li span { float: left; width: 15%; color:#333333; margin-top:0.25em; }
            #entryform input[type="text"] { border: solid 1px #999999; }
            #messages { border: solid 1px #999999; }
            #messages li { padding: 0.5em; }
            .error { color: #ff0000; }
            .even { background-color: #ccccff; }
            .odd { background-color: #ffffff; font-style: italic; }       
            .messageBox { width: 73%; }
        </style>

    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="sm" runat="server" />
        <div>
            <h1>Windows Azure Chat</h1>
            <ul id="entryform">
                <li><span>Your name</span><asp:TextBox ID="nameBox" runat="server" Text="Anonymous" /></li>
                <li><span>Message</span><asp:TextBox ID="messageBox" runat="server" CssClass="messageBox" /> <asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click" /></li>
                <li><span><asp:LinkButton ID="lbDisplayMessages" runat="server" OnClick="lbDisplayMessages_Click" Text="Update Messages" /></span></li>
            </ul>
                    <div>
                        <asp:Label ID="status" runat="server" CssClass="error" />
                    </div>
                    <asp:GridView ID="messageList" runat="server" AutoGenerateColumns="false">
                        <AlternatingRowStyle CssClass="even" />
                        <RowStyle CssClass="odd" />
                        <Columns>
                        <asp:TemplateField HeaderText="Name">
                        <ItemTemplate>
                            <asp:HiddenField ID="hdPartitionKey" runat="server" Value='<%#Eval("PartitionKey") %>' />
                            <asp:HiddenField ID="hdRowKey" runat="server" Value='<%#Eval("RowKey") %>' />
                            <asp:HiddenField ID="hdTimeStamp" runat="server" Value='<%#Eval("TimeStamp") %>' />
                            <asp:HiddenField ID="hdName" runat="server" Value='<%#Eval("Name") %>' />
                            <asp:HiddenField ID="hdBody" runat="server" Value='<%#Eval("Body") %>' />
                            <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' />
                            said:
                        </ItemTemplate>
                        </asp:TemplateField>                   
                        <asp:TemplateField HeaderText="Message">
                        <ItemTemplate>
                            <asp:TextBox ID="txtBody" runat="server" Text='<%# Eval("Body") %>' />
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Operations">
                        <ItemTemplate>
                            <asp:LinkButton ID="updateMessage"
                                CommandName="Update"
                                runat="server" Text="Update" OnCommand="OnUpdateMessage" />
                            <asp:LinkButton ID="deleteMessage"
                                OnClientClick="return confirm('Delete Message?');"
                                CommandName="Delete"
                                runat="server" Text="Delete" OnCommand="OnDeleteMessage" />               
                        </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
        </div>
        </form>
    </body>
    </html>

    Source for Message.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Microsoft.Samples.ServiceHosting.StorageClient;

    namespace TableCloudService_WebRole
    {
        public class Message : TableStorageEntity
        {
            //private string PartitionKey;
            //private string RowKey;
            public string Name { get; set; }
            public string Body { get; set; }

            public Message()
            {
                PartitionKey = "a";
                RowKey = String.Format("{0:10},{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks,
                    Guid.NewGuid().ToString());
            }
        }
    }

    Source for MessageDataServiceContext.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Microsoft.Samples.ServiceHosting.StorageClient;

    namespace TableCloudService_WebRole
    {
        public class MessageDataServiceContext : TableStorageDataServiceContext
        {
            public MessageDataServiceContext(StorageAccountInfo accountInfo) : base(accountInfo)
            {
            }

            public IQueryable<Message> Messages
            {
                get
                {
                    return this.CreateQuery<Message>("Messages");
                }
            }

            public void AddMessage(string name, string body)
            {
                Message MessageEntity = new Message { Name = name, Body = body };
                this.AddObject("Messages", MessageEntity);
                this.SaveChanges();
            }

            public void DeleteMessage(Object MessageEntity)
            {
                this.DeleteObject(MessageEntity);
                this.SaveChanges();
            }

            public void UpdateMessage(Object MessageEntity)
            {
                this.UpdateObject(MessageEntity);
                this.SaveChanges();
            }
        }
    }

    Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

  • ASP.NET Podcast Show #132 - Windows Azure Blob Storage - video

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    Download WMV.

    Download MP4 for iPod.

    Download MP3 (audio only).

    Win a ticket to the MDC in Detroit.  Enter here.

    Show Notes:

    • Azure SDK.
      •  Vista SP1.
      • Visual studio 2008/.NET 3.5 SP1.
      • Local Development.Speed.
      • VPC.
      • Improvements are coming.
      • YMMV.
    • Project type.
      • Configuration settings.
      • Web Project.
    • Storage Client.
    • Local Development Fabric.
    • Local Development Storage.
    • Hands on Labs. This example is taken, with modifications, from the hands on labs.

     

    Local Development Storage Setup:

    Development Storage Setup

    Local Development Storage:

    Storage Icon

    Source Code for Default.aspx.cs file:

    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Globalization;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Microsoft.ServiceHosting.ServiceRuntime;
    using Microsoft.Samples.ServiceHosting.StorageClient;

    namespace CloudImageService_WebRole
    {
        public partial class _Default : System.Web.UI.Page
        {
            private string unknownValue = "unknown";
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    RefreshGallery();
                }
            }

            protected void upload_Click(object sender, EventArgs e)
            {
                if (imageFile.HasFile)
                {
                    status.Text = "Inserted [" + imageFile.FileName +
                        "] - Content Type [" + imageFile.PostedFile.ContentType + "]";
                    SaveImages(Guid.NewGuid().ToString(), imageName.Text, imageDescription.Text,
                        imageTags.Text, imageFile.FileName, imageFile.PostedFile.ContentType,
                        imageFile.FileBytes);
                    imageTags.Text = String.Empty;
                    imageDescription.Text = String.Empty;
                    imageName.Text = String.Empty;
                    RefreshGallery();
                }
                else{
                    status.Text = "No image file uploaded.";
                }
            }

            private void SaveImages(string id, string name, string description, string tags, string fileName, string contentType, byte[] data)
            {
                BlobProperties properties = new BlobProperties(string.Format(CultureInfo.InvariantCulture, "image_{0}", id));
                NameValueCollection metadata = new NameValueCollection();
                BlobContainer container = GetContainer();
                metadata["Id"] = id;
                metadata["Filename"] = fileName;
                metadata["ImageName"] = String.IsNullOrEmpty(name) ? unknownValue : name;
                metadata["Description"] = String.IsNullOrEmpty(description) ? unknownValue : description;
                metadata["Tags"] = String.IsNullOrEmpty(tags) ? unknownValue : tags;
                properties.Metadata = metadata;
                properties.ContentType = contentType;
                BlobContents imageBlob = new BlobContents(data);
                container.CreateBlob(properties, imageBlob, true);
               
            }

            protected void OnBlobDataBound(object sender, ListViewItemEventArgs e)
            {
                BlobContainer container = GetContainer();
                if (e.Item.ItemType == ListViewItemType.DataItem)
                {
                    Repeater metadataRepeater = e.Item.FindControl("blobMetadata") as Repeater;
                    BlobProperties blob = ((ListViewDataItem)(e.Item)).DataItem as BlobProperties;
                    NameValueCollection metadata = container.GetBlobProperties(blob.Name).Metadata;
                    metadataRepeater.DataSource = from key in metadata.AllKeys
                                                  select new
                                                  {
                                                      Name = key,
                                                      Value = metadata[key]
                                                  };
                    metadataRepeater.DataBind();
                }
            }

            protected void OnDeleteImage(object sender, CommandEventArgs e)
            {
                BlobContainer container = GetContainer();
                if (e.CommandName == "Delete")
                {
                    string blobName = (string)e.CommandArgument;
                    if (container.DoesBlobExist(blobName))
                    {
                        container.DeleteBlob(blobName);
                    }
                    else
                    {
                        status.Text = "Item does not exist";
                    }
                    RefreshGallery();
                }
            }

            private void RefreshGallery()
            {
                BlobContainer container = GetContainer();
                images.DataSource = container.ListBlobs(String.Empty, false);
                images.DataBind();
            }

            /// <summary>
            /// This is code written against an early CTP.
            /// It is neither production ready or a best of breed.
            /// It is merely code that works today.
            /// </summary>
            /// <returns></returns>
            private BlobContainer GetContainer()
            {
                string blobContainer = RoleManager.GetConfigurationSetting("ContainerName");
                BlobStorage blobStorage = BlobStorage.Create(StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration());
                BlobContainer newContainer = blobStorage.GetBlobContainer(blobContainer);
                if (!newContainer.DoesContainerExist())
                {
                    newContainer.CreateContainer(null, ContainerAccessControl.Public);
                }
                return (newContainer);
            }
        }
    }

    Source code for Default.aspx:

     <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CloudImageService_WebRole._Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Azure Blob Storage Engine Page</title>
            <style type="text/css">
            body { font-family: Verdana; font-size: 12px; }
            h1 { font-size:x-large; font-weight:bold; }
            h2 { font-size:large; font-weight:bold; }
            img { width:200px; height:175px; margin:2em;}
            li { list-style: none; }
            ul { padding:1em; }
            
            .form { width:50em; }
            .form li span {width:30%; float:left; font-weight:bold; }
            .form li input { width:70%; float:left; }
            .form input { float:right; }
            
            .item { font-size:smaller; font-weight:bold; }
            .item ul li { padding:0.25em; background-color:#ffeecc; }
            .item ul li span { padding:0.25em; background-color:#ffffff; display:block; font-style:italic; font-weight:normal; }
        </style>

    </head>
    <body>
        <form id="form1" runat="server">
        <div>
                <h1>Image Gallery (Windows Azure Blob Storage)</h1>
            <div class="form">
                <ul>
                    <li><span>Name</span><asp:TextBox ID="imageName" runat="server"/></li>
                    <li><span>Description</span><asp:TextBox ID="imageDescription" runat="server"/></li>
                    <li><span>Tags</span><asp:TextBox ID="imageTags" runat="server"/></li>
                    <li><span>Filename</span><asp:FileUpload ID="imageFile" runat="server" /></li>
                </ul>
                <asp:Button ID="upload" runat="server" onclick="upload_Click" Text="Upload Image" />
            </div>
            <div>
            Status: <asp:Label ID="status" runat="server" />
            </div>

                <asp:ListView ID="images" runat="server" OnItemDataBound="OnBlobDataBound">
                <LayoutTemplate>
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                </LayoutTemplate>
                <EmptyDataTemplate>
                    <h2>No Data Available</h2>
                </EmptyDataTemplate>            
                <ItemTemplate>            
                    <div class="item">
                        <ul style="width:40em;float:left;clear:left" >
                        <asp:Repeater ID="blobMetadata" runat="server">
                        <ItemTemplate>
                            <li><%# Eval("Name") %><span><%# Eval("Value") %></span></li>
                        </ItemTemplate>
                        </asp:Repeater>
                        <%-- UNCOMMENT THE FOLLOWING LINES FOR DELETE FUNCTIONALITY --%>
                            <li>
                            <asp:LinkButton ID="deleteBlob"
                                    OnClientClick="return confirm('Delete image?');"
                                    CommandName="Delete"
                                    CommandArgument='<%# Eval("Name")%>'
                                    runat="server" Text="Delete" oncommand="OnDeleteImage" />                
                            </li>
                        </ul>                    
                        <img src="<%# Eval("Uri") %>" alt="<%# Eval("Name") %>" style="float:left"/>
                    </div>
                </ItemTemplate>
            </asp:ListView>
        </div>
        </form>
    </body>
    </html>

    .csdef file:

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="CloudImageService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
      <WebRole name="WebRole">
        <InputEndpoints>
          <!-- Must use port 80 for http and port 443 for https when running in the cloud -->
          <InputEndpoint name="HttpIn" protocol="http" port="80" />
        </InputEndpoints>
        <ConfigurationSettings>
          <Setting name="AccountName" />
          <Setting name="AccountSharedKey" />
          <Setting name="BlobStorageEndpoint" />
          <Setting name="QueueStorageEndpoint" />
          <Setting name="TableStorageEndpoint" />
          <Setting name="ContainerName" />
        </ConfigurationSettings>
      </WebRole>
    </ServiceDefinition>

    cscfg file:

    <?xml version="1.0"?>
    <ServiceConfiguration serviceName="CloudImageService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
      <Role name="WebRole">
        <Instances count="1"/>
        <ConfigurationSettings>
            <Setting name="AccountName" value="devstoreaccount1" />
            <Setting name="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
            <Setting name="BlobStorageEndpoint" value="http://127.0.0.1:10000/" />
            <Setting name="QueueStorageEndpoint" value="http://127.0.0.1:10001/" />
            <Setting name="TableStorageEndpoint" value="http://127.0.0.1:10002/" />
            <Setting name="ContainerName" value="storagegallery" />
        </ConfigurationSettings>
      </Role>
    </ServiceConfiguration>

  • ASP.NET Podcast Show #131 - General discussions on Cloud Computing with Wally, David, and Scott Cate - mp3 audio

    Subscribe to everything!

    Subscribe to the MP3 file(s) only.

    Download.

    Show Notes:

    • General discussions on  Cloud Computing.
    • Scott on CloudDB.  Scott gets into the specifics of CloudDB, including how to let customer's setup databases.
  • ASP.NET Podcast Show #130 - David and Wally talk about .NET 3.5 Service Pack 1

    Subscribe to Everything.

    Subscribe to MP3.

    Download.

    Show Notes:

    • Where is Dave at?
    • Let's talk new features in SP1.
  • ASP.NET Podcast Show #129 - Caching with .NET 3.5 SP1

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    Download WMV.

    Download M4V (iPod).

    Download MP3.

    Show Notes:

    • New Caching Support in .NET 3.5 SP1.

    Source Code:

        protected void Page_Load(object sender, EventArgs e)

        {

            string Output = String.Empty;

            if (!Page.IsPostBack)

            {

                lblOutput.Text = GetCacheItem();

            }

        }

     

        private string GetCacheItem()

        {

            string OutValue = String.Empty;

            if (Cache["Test"] != null)

            {

                OutValue = Convert.ToString(Cache["Test"]);

            }

            else

            {

                OutValue = DateTime.Now.ToString();

                Cache.Insert("Test", OutValue, null,

                    DateTime.Now.AddSeconds(10),

                    TimeSpan.Zero, OnUpdateCallback);

            }

            return (OutValue);

        }

        private void OnUpdateCallback(String key, CacheItemUpdateReason r,

            out Object ObjectToCreate, out CacheDependency CacheDependencies,

            out DateTime DateTimeExpire, out TimeSpan TimeSpanExpire)

        {

            ObjectToCreate = DateTime.Now;

            CacheDependencies = null;

            DateTimeExpire = DateTime.Now.AddSeconds(10);

            TimeSpanExpire = TimeSpan.Zero;

        }

     

  • ASP.NET Podcast Show #128 - AJAX with jQuery

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    Download WMV.

    Download iPod Video.

    Download MP3.

    Show Notes:

    Source Code:

    jQuery Version:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title>jQuery Example</title>

    </head>

    <body>

        <form id="form1" runat="server">

    <!--

    <script language="javascript" type="text/javascript"

        src="jquery-1.2.6-vsdoc.js"></script>

    -->

    <script language="javascript" type="text/javascript"

        src="jquery.pack.js"></script>

    <div>

    <label for="lblOutput">

        Text Out:

    </label>

    <div id="lblOutput" />

     

    <script language="javascript" type="text/javascript">

        $(document).ready(function() {

            $.ajax({

                type: "POST",

                contentType: "application/json; charset=utf-8",

                url: "GetData.asmx/ReturnData",

                data: "{i: 47}",

                dataType: "json",

                success: function(msg) { onSuccess(msg); },

                error: function() {

                    alert("An error occurred on the server.");

                }

            });

        });

     

        function onSuccess(msg) {

            var newline = "<br />";

            $('#lblOutput').html("Name: " + msg.d.Name + newline +

                    "Notes: " + msg.d.Notes + newline +

                    "Passed Value: " + msg.d.PassedValue);

        }

    </script>

     

    </div>

        </form>

    </body>

    </html>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    ASP.NET AJAX Version:

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

        <script type="text/javascript">

       

          function pageLoad() {

              GetData.ReturnData(47, onSuccess);

          }

          function onSuccess(result) {

              var newline = "<br />";

              $get('lblOutput').innerHTML = "Name: " + result.Name +

                    newline + "Notes: " + result.Notes + newline +

                    "Passed Value: " + result.PassedValue;

     

          }

       

        </script>

    </head>

    <body>

        <form id="form1" runat="server">

    <label for="lblOutput">

        Text Out:

    </label>

        <div id="lblOutput" />

     

        <div>

            <asp:ScriptManager

                ID="ScriptManager1" runat="server"

                >

                <Services>

                    <asp:ServiceReference

                        Path="~/jQuery/GetData.asmx" />

                </Services>

                </asp:ScriptManager>

        </div>

        </form>

    </body>

    </html>

  • ASP.NET Podcast Show #127 - Dynamic Data

    Subscribe to All!

    Subscribe to WMV.

    Subscribe to M4V (iPod).

    Subscribe to MP3.

    Download WMV.

    Download M4V (iPod).

    Download MP3.

    Show Notes:

    Source Code:

    Global.asax:

    model.RegisterContext(typeof(db35sp1Entities), new ContextConfiguration() { ScaffoldAllTables = true });

    Metadata class:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;

    namespace Dynamic_Data
    {
        [DisplayColumn("Name")]
        [MetadataType(typeof(tbItemMetaData))]
        public partial class tbItem
        {
            private class tbItemMetaData
            {
                [DisplayName("Item Display Name")]
                [StringLength(30)]
                [Required(ErrorMessage="Item name is required.")]
                public object Name { get; set; }

                [DisplayFormat(DataFormatString="{0:c}")]
                [Range(0, 500, ErrorMessage="Standard Cost should be between {1} and {2}.")]
                public object Price { get; set; }
            }

            // Note the naming convention of On X Changing and the nullable value.
            partial void OnPriceChanging(decimal? value)
            {
                if (value < 0)
                {
                    throw (new ValidationException("Price must be positive, afterall we aren't paying you to take it."));
                }
            }
        }

        [MetadataType(typeof(tbOrderMetaData))]
        public partial class tbOrder
        {
            private class tbOrderMetaData
            {
                [ScaffoldColumn(true)]
                [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
                public object DateUpdated { get; set; }
            }
        }  
    }
     

More Posts Next page »

This Blog

Syndication

Powered by Community Server, by Telligent Systems