Scott Hanselman

How to attach MP3 sound effects to PowerPoint animation elements

February 29, '08 Comments [6] Posted in Musings | Tools
Sponsored By

imageI'm working on a presentation for the DE (Developer Evangelists) the day before Mix. Since so many MSFT folks are getting together in one place, we usually take advantage and do some side meetings, etc.

I'm doing this cool slide (at least I think so) and I added a small animation as picture comes in from off screen.

I wanted to add an MP3 to that effect so that it'd play as the animation happened. I wandered around the UI for a white, trying to figure this out.

It's a little counter-intuitive, but each Effect Element can have its own sound attached, so you have to Right Click on the Element in the Custom Animation Pane, as seen at right.

Click Effect Options and you'll see this dialog:

image

When you select Other Sound... you'll get a File Dialog prompting you for a WAV file. Here's where I got stuck for a moment. It ONLY allows WAV files and I wanted to play an MP3. Well, I could have converted the MP3 to a WAV, but not only would it have made the file a lot bigger, but I would have had to go looking for a converter.

It turns out that the WAV format can support MP3-compressed audio as long as the WAV header (wrapper) is correct. So, rather than "uncompressing" my MP3 into a fat WAV (using RAW PCM Audio), I can just run this little command line app "MP3 Decoder" and it will create a .WAV file with the MP3 inside.

Run the little app by Niklas Beisert and you're on your way. The file will be roughly the same size (still small!). Attach the "now WAV" to your animation and you've just successfully attached an MP3 to an animation in PowerPoint.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 102 - Mike Pizzo on the ADO.NET Entity Framework

February 29, '08 Comments [13] Posted in ASP.NET | Learning .NET | LINQ | Podcast | Tools
Sponsored By

figure1 My one-hundred-and-second podcast is up. In this episode, I sit down with Michael Pizzo, the Principal Architect of the ADO.NET Entity Framework. He gets technically down and dirty pretty fast and I get answers to all the hard questions like "Are LINQ to SQL and LINQ to Entities competing?" and "Which one should I use?" A very cool guy and a fun interview that finally set my head straight about the data stack.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

If you have trouble downloading, or your download is slow, do try the torrent with µtorrent or another BitTorrent Downloader.

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Check out their UI Suite of controls for ASP.NET. It's very hardcore stuff. One of the things I appreciate about Telerik is their commitment to completeness. For example, they have a page about their Right-to-Left support while some vendors have zero support, or don't bother testing. They also are committed to XHTML compliance and publish their roadmap. It's nice when your controls vendor is very transparent.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The Weekly Source Code 17 - ASP.NET MVC Community Code Edition

February 27, '08 Comments [15] Posted in ASP.NET | ASP.NET MVC | Source Code
Sponsored By

I've been working on new Videos for ASP.NET MVC and the Mix conference, and I wanted to read some code that folks have created using the December CTP of ASP.NET MVC. There's a lot of good changes coming in the next Preview release and that feedback comes from active community members, so it's always good to read real source of real apps to see what folks are doing.

And so, Dear Reader, I present to you seventeenth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading this week.


CodeCampServer (source)

This application is a free open-source Code Camp management application, so if you're thinking of running a Code Camp, start here. As of this writing, it's build on the December drop of ASP.NET MVC and also uses StructureMap, IESI Collections, MVC Contrib, log4net, RhinoMocks, NUnit and NHibernate. Aaron Lerch and others have been working on this app for the Indy Code Camp, so if you're around Indianapolis check them out.

Better Things

One thing that's fun to see when reading code is when folks name classes something like "BetterMousetrap," where the class name advertises that it's superior to something specific. This project has "BetterMvcHandler:"

public class BetterMvcHandler : MvcHandler
{
	protected override void ProcessRequest(IHttpContext httpContext)
	{
		try
		{
			base.ProcessRequest(httpContext);
		}
		catch (Exception ex)
		{
			throw new Exception("Route used:" + RequestContext.RouteData.Route.Url, ex);
		}
	}
}

All they are doing is catching all exceptions, showing the current URL via the route, and pushing the original exception down a level. Smells a little iffy to me, but the valuable thing for the MVC Team to notice about this is that people need more insight into what is happening with Routes while debugging.

Here they use RhinoMocks so they can test their controllers without firing up ASP.NET/IIS. This will change some in the next drop, but this is totally the right idea. I've got a full 20 minute video coming showing just how to do this very thing:

namespace CodeCampServer.UnitTests
{
    public static class Extensions
    {
        public static IHttpContext DynamicIHttpContext(this MockRepository mocks, string url)
        {
            IHttpContext context = mocks.DynamicMock();
            IHttpRequest request = mocks.DynamicMock();
            IHttpResponse response = mocks.DynamicMock();

            SetupResult.For(context.Request).Return(request);
            SetupResult.For(context.Response).Return(response);
            SetupResult.For(request.AppRelativeCurrentExecutionFilePath).Return(url);
            SetupResult.For(request.PathInfo).Return(string.Empty);            

            return context;
        }
    }
}

Law of Demeter

When creating lots of Domain Objects, like in this application, on of the things that comes up a lot is the validity (or not) of the Law of Demeter. Basically this law is a design guideline that says your object should avoid reaching deeply into other objects.

For example, in this application, there's an Attendee object. It has a Contact object, which has things like FirstName, LastName, Email, etc. If you see something like this:

[Test]
public void ShouldGetProperName()
{
	Attendee attendee = new Attendee();
	attendee.Contact.FirstName = "Homey";
	attendee.Contact.LastName = "Simpsoy";
	Assert.That(attendee.GetName(), Is.EqualTo("Homey Simpsoy"));
}

You might want to ask yourself if reaching "two steps" in in order to get the FirstName and LastName is a good idea as now you're coupling the caller not only to Attendee, but also Contact, not to mention you're assuming that Contact isn't null. If you follow this rule religiously (and I'm not saying you should) the downside is that you end up with a bunch of wrapper methods like GetFirstName, etc. on your top level object. It's something to think about. Perhaps it's less valid in the context of a Domain Model where all these objects find themselves intertwined, but if you find yourself writing a.b().c().d.something, your sense of code smell really should kick in.

Helper Things

Another thing to look for when reading code that uses a framework you've worked on is methods or classes named "Helper." This is another clue that maybe your framework isn't meeting the downstream developer's needs, especially if they have a large number of helpers to get-around issues with your framework.

 public static class LinkHelpers
 {
     public static bool IsActive(this ViewPage thePage, string controller, string action)
     {
         return thePage.ViewContext.RouteData.Values["controller"].ToString() == controller &&
                thePage.ViewContext.RouteData.Values["action"].ToString() == action;            
     }
     
     public static bool IsActive(this ViewMasterPage thePage, string controller, string action)
     {
         return thePage.ViewContext.RouteData.Values["controller"].ToString() == controller &&
                thePage.ViewContext.RouteData.Values["action"].ToString() == action;            
     }
...

There are a number of extension methods in this project where the developers have spot-welded new methods onto ViewPage and ViewMasterPage as mix-ins or extension methods. Interestingly though, they never ended up using the Helpers! I usually create helpers after things really start to hurt and I've moved into the Refactoring stage. It's usually a good idea to get a holistic perspective on the project first, rather than creating a number of Helpers and associated overloads in anticipation of future pain.

Again, I'm not picking on this project, rather just using it as a jumping off point for discussion. It's certainly easy to read code and throw stones. As Linus likes to say, "talk is cheap, show me the code."


Kigg - Digg clone in ASP.NET MVC (Live Demo)

There's a good writeup on how Kazi Manzur Rashid and Sonu wrote this Digg Clone. They are doing a couple of interesting things in their application.

JSON and Ajax

They are using the new DataContractJsonSerializer that was added in .NET 3.5 and lives in System.Runtime.Serialization.Json and lets you serialize your objects to and from Javascript Object Notation (JSON). They created a json.aspx file that takes the current ViewData and serializes it to JSON:

    Response.Clear();
    Response.ContentType = "application/json";
    Response.Write(ViewData.ToJson());

Simple and it works. Whenever a controller wants to make JSON, they just ReviewView("Json", result). Personally, I would have made a JsonViewEngine and had the controller set its ViewEngine when neeeded, but suppose that would have rendered (ahem) the first parameter of RenderView moot.

They make good use of LINQ. Reading a nice clean LINQ query always makes me smile.

public TagItem[] GetTags(int top)
{
   return Tags.Select (
                  t => new TagItem {
                      ID = t.ID,
                      Name = t.Name,
                      Count = t.StoryTags.Count()
                  }
               )
               .OrderByDescending(t => t.Count)
               .ThenBy(t => t.Name)
               .Take(top)
               .ToArray();
}

Complex Views and ViewData

The main pages are fairly complex and include data from a number of different places, listing stories, tag clouds and categories. There's also multiple forms (remember the days when you could have multiple forms) on a page, like for the search box as an example. They've created a abstract BaseViewData class that others derive from, adding extra bits of data for their specific view.

For example, the Story Detail Page adds to the standard ViewData:

    public class StoryDetailData : BaseViewData
    {
        public StoryDetailItem Story
        {
            get;
            set;
        }
    }

And then the StoryController has this clever method that gets ViewData only if the type T is a BaseViewData and has a public parameterless constructor (that's the new() at the end):

private T GetViewData<T>() where T : BaseViewData, new()
{
    T viewData = new T();

    viewData.IsAuthenticated = IsUserAuthenticated;
    viewData.UserName = CurrentUserName;
    viewData.Categories = DataContext.GetCategories();
    viewData.Tags = DataContext.GetTags(_topTags);

    return viewData;
}

It populates the methods shared by the base class and returns the derived type. I wouldn't have come up with this on my own without some thought.

Each of these projects have different styles but each is a good place to start looking when writing a new ASP.NET MVC Application.


Related Posts and Links to Read

Technorati Tags: ,,

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Amazon Kindle

February 26, '08 Comments [40] Posted in Reviews
Sponsored By

DSC_0031UPDATE TWO MONTHS LATER: Now that I've had the Kindle for two months, I still think it's horribly ugly, but I use it EVERY DAY. I subscribe to the NYTimes, to Newsweek and a few blogs. I've purchased 12 books so far and converted/downloaded 20 free ones. The battery life is very good as long as you only turn on the Wireless when you need it. Additionally, I've started using the Kindle as my primary Audible audiobook device and love it. I just slapped a 2gig SD card in and I've got 50+ hours of audio. It's the only device I need for long plane rides.

A year ago I had a Sony Reader for a month and reveled in its awesome screen. It's true, in case you haven't heard, e-ink looks like paper. At least, as close to paper as anything that's not paper can look.

I finally broke down and got an Amazon Kindle for my birthday.

If you are already bored with this post and want to stop here, here's the conclusion. I love it.

Why?

The Good Stuff

This device exists for one reason and one brilliant reason only, for Amazon to more easily extract money from my wallet. It's an entire device built around the concept of "One Click" ordering. You do get a second chance if you accidentally order a book, but it's designed for the impulse buyer. If I hear about a book on NPR or The Daily Show, I can get it immediately. If I read a nice book cover at the Airport bookstore on a long layover, I can buy it.

Once you realize its purpose and accept it and are OK with it, you'll like this as well. I like the "any book in the world in one minute or less" (and Bezos is not kidding, the books show up FAST) that I'm disappointed when a book isn't available.

The screen interface is clean, if slow to redraw (because of the e-ink), with just a few obvious usability things that I'm sure they'll fix with regular updates.

DSC_0032I was also thrilled to see that it integrates with Audible, so I popped a two gig SD card in and grabbed a gig and a half of books (about 2 weeks of audio) from my Audible subscription. Why not use a MP3 player? I have had a love/hate relationship with my iPod and consequently have faded away from using it. I find myself listening to XM Radio more often, or using a Zune with the All You Can Listen To Zune Pass, so my iPod has kind of laid fallow. At this point, I just really like the idea of all my books, audio or otherwise, on this one device. It also has a surprisingly loud speaker so I can listen to books without headphones which surprised me.

DSC_0034The Kindle also has an experimental mobile web browser. I say Mobile, because you should consider the Kindle like a really slow Mobile Phone with a slow to redraw grayscale screen. My blog recognizes the Kindle as a mobile device and renders nicely, even with pictures.

This discovery was just an added benefit. I can also check email (painfully) with Gmail's mobile interface. This alone justified, to me, the Kindle's keyboard that I'd previously written off as silly. The Kindle has the potential to be quite the handheld computer if Amazon allows it. For now, I'll just bookmark my new Mobile Home Page http://cantoni.mobi and be happy.

It works great with PRC Mobile eBooks (a standard) and as such the whole Baen Free Library (and many other similar ones) are available to me.

The Kindle has its own email address so I can send myself PDFs for 10cents and they'll show up pretty nicely. No, I haven't done PDFs with big images or code, but I can tell you that technical books looked lousy and hard to read on the Sony Reader, and I have no reason to think that the Kindle would be better.

There's a collection of newspapers available, so I got a trial subscription to the NYTimes. I love it. It shows up every day and it's got pictures and everything. Reading the newspaper has naturally fit into my day much more cleanly now, and I'm not in front of a browser for 30 minutes reading. It's more linear in that respect and I prefer it.

It's also got blogs, but they cost a buck or two and I'm not in there so phooey on them. ;)

When you're in an EVDO coverage area, the wireless is surprisingly fast.

The "Meh" Stuff

The Next Page buttons run almost the length of both sides of the thing so I keep accidentally turning pages. Also, I've fallen asleep holding the buttons at least twice and found myself with a dead battery and on the last page.

It's ugly. From a design perspective, it's just not sexy. That said, the Sony Reader wasn't exactly clever either. If I were Amazon I would have gotten the iPod designers on board to help. I will say that it's design is more thoughtful than the Sony Reader's and after a few days I stopped caring. It just works.

The screen is paperback book sized, and I wish it were about 30% larger. There's just too much bezel framing it.

It's still $150 more than I'd like it to be, but I bought it anyway because I KNOW I'll use it. I use it every day to read the newspaper, which was also a surprise. (see above)

DSC_0034 DSC_0033 DSC_0032 DSC_0031

Do be warned, there isn't coast-to-coast coverage. If you live outside the US, or outside a decent-sized city, you won't have coverage. That said, I still live an hour outside of Portland and I have coverage and I likely will have coverage everywhere in the US that I'd visit on a business trip.Be sure to check the Kindle Coverage Tool.

Conclusion

I'm thrilled with the purchase, overall. The wireless ability is the key. I didn't want YET another device to dock to my machine. I am so sick of syncing things and looking for tiny USB cables. I even think I could get a device like this for an elder relative and they'd be able to use it without trouble. I suspect that the Kindle will have me reading more often (and I already read a lot). Recommended.

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

LINQ to Everything - LINQ to XSD adds more LINQiness

February 23, '08 Comments [11] Posted in LINQ | Programming | XML
Sponsored By

It's funny when you work at a company that has as many small projects as it has big ones. I hear one of two things:

"Is _______ dead? I haven't heard anything in a month from _____ team's blog! It must be dead.

or

"Can you just stop with the 99 different ways to do _______? There's more happening that I can handle."

I'll try to help with the latter in the coming months. Even though we hear about technologies like LINQ to SQL and LINQ to Entities or ASP.NET MVC and WCF and get confused about if they are complementary, there is (usually) a plan behind the whole stack, even if that plan isn't very well-communicated. I'll do a diagram or two to help soon.

But first, looking at the Is ____ dead? question. It'd be cool if someone just dropped a blog post as a "ping" every few weeks like "We're still here! Nope, not dead!" kind of like an Out of Office Response, but for blogs.

For example, LINQ to XSD was mentioned in June of 2007, looked rockin' sweet, and then went silent. However, small teams like this continue to move the ball forward, but we (the outside world) don't hear from them. I'll try to find those projects and ping for the people.

Just yesterday, LINQ to XSD surfaced (I actually had a video call with them on Weds) with a new release.

LINQ to XSD creates .NET classes with much better fidelity than what's created with (the aging) XSD.exe. Now, of course, XSD.exe makes classes for XmlSerialization, while LINQ to XSD makes classes that use an XDocument (not XmlDocument) as the backing store, so we are comparing Apples to Carburetors, but if your goal is to get Objects that come from an XML source, you should take a look at LINQ to XSD.

For example, if I take one of the goofiest schemas, OFX, a financial services schema (disclosure, I was the Vendor Committee Chair for OFX for a few years so I'm to blame a bit) and run it through LinqToXml.exe, here's some differences.

For example, in the XSD for OFX there's some types like "Amount" that have Restriction Facets. The type is a string, but it must match a certain regular expression, like:

<xsd:simpleType name="AmountType">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="32"/>
        <xsd:minLength value="1"/>
        <xsd:whiteSpace value="collapse"/>
        <xsd:pattern value="[\+\-]?[0-9]*(([0-9][,\.]?)|([,\.][0-9]))[0-9]*"/>
    </xsd:restriction>
</xsd:simpleType>

However, when that's turned into generated code via XSD.exe and XmlSerialization, we get:

private string amountField
  
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string AMOUNT {   
get {        
return this.amountField;    
}    
set {        
this.amountField = value;    
} }

Which kind of sucks, from a fidelity point of view. We've lost information, the restriction is gone and the Type is gone.

Here's the same thing generated with LINQ to XSD:

public sealed class AmountType {     
[DebuggerBrowsable(DebuggerBrowsableState.Never)]    
public static Microsoft.Xml.Schema.Linq.SimpleTypeValidator TypeDefinition =
new Microsoft.Xml.Schema.Linq.AtomicSimpleTypeValidator(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String),
new Microsoft.Xml.Schema.Linq.RestrictionFacets(((Microsoft.Xml.Schema.Linq.RestrictionFlags)(46)), null, 0, 0, null, null, 32, null, null, 1,
new string[] { "^(([\\+\\-]?[0-9]*(([0-9][,\\.]?)|([,\\.][0-9]))[0-9]*))$"}, 0, XmlSchemaWhiteSpace.Collapse));    
private AmountType() {} }

...and...then the accessor:

public string AMOUNT {     
get { XElement x = this.GetElement(XName.Get("AMOUNT", ""));        
return XTypedServices.ParseValue<string>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);     }
    set { this.SetElementWithValidation(XName.Get("AMOUNT", ""), value, "AMOUNT", global::ofx.net.types.Item2003.Item04.AmountType.TypeDefinition);     } }

Note that this is generated, so don't judge it on aesthetics, it's about the experience as a consumer of the API. This is cool because we don't lose anything, the mapping between CLR type and XSD type is clean enough, you get a real type, but you can still access it as a string. If you set a value it's validated on the fly.

Remember again, this is an interesting, if biased, comparison as LINQ to XSD uses an XDocument as the backing store and its properties access the DOM, while XSD.exe/XmlSerializer makes copies using dynamically generated temporary helpers and XmlReaders/XmlWriters to make Objects out of your Angle Brackets.

Another good example of a quiet team that still has cool stuff coming is LINQ to SQL as they update for SQL 2008.

Dear Reader, what's the best way for a team to tell you they are not dead?

Related Posts

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.