Silverlight

Dangers of Mobile E-mail

A few weeks ago, my company purchased a Blackberry for me to use.  This is the first time that I’ve owned a mobile device that has had a constant connection to the internet.  However, I’ve been surprised at how having a connected device can actually cause me to get less work done if I’m not careful.  here are a few reasons why:

1. Distractions, distractions, distractions

There are about a billion ways that a connected phone can distract you, but the biggest one is hearing it ring or feeling it vibrate every time you receive an e-mail.  There’s simply a natural impulse to see what’s going on and whether or not you need to respond.  It’s easy to get distracted, no matter how important may be the task at hand, just because the phone rings or a little ‘toast’ notification pops up in the bottom right-hand corner of your screen.  Sometimes we even welcome an interruption if we’re not heavily invested into our work.

Unless you’re in sales, where the quickness of your response might actually affect your chances of closing a sale, you’re mostly likely of the type of person that could do without being distracted every 5 minutes.  Almost always, an e-mail can wait, and hopefully those who work with you regularly will learn that they need to call you if there’s anything they need urgently.

I’ve turned off all e-mail alerts on my desktop machine and almost always keep them off on my Blackberry.  I find I got a lot more done this way.

2. Checking E-mail Frequently Can Make You Forget To Process E-mail

I have really enjoyed being able to access e-mail on the go, at home, or even when I’m at the other side of the office.  Even though I have notifications turned off, I still check it from time to time (at a moment of my choosing) to see if I need to respond to anything.  However, I notice that when I glance through my inbox for “actionable e-mails,” I tend to think that a batch of e-mail has already been processed.  This is a problem.

If I think subconsciously that an e-mail has already been processed simply because it’s marked unread, I may forget to do something important at my desktop computer that I couldn’t do on my mobile phone.  For example, I may get a request from a coworker to e-mail them a report that I had been working on.  Having viewed the e-mail on my phone already, I may skip over the item on my desktop if I’m not purposefully taking the time to process my inbox.

Processing your inbox (taken in part from David Allen’s Getting Things Done) involves going through your e-mail and filing away items that are reference only and taking action or postponing those that require more work.  Even though I’m alerted of e-mail on the phone, I find that I still have to go back to my inbox on the computer and process e-mail.  I’m always surprised at how often I come across something that I had forgotten about simply because I had read it already on my blackberry.

3. Are You Connected To The Internet or Chained To It?

A great speaker and writer, Matthew Kelly, says that technology is supposed to be our slave, but all too often we become its slave.  Naturally, this isn’t limited to just mobile devices (how easy is it to waste time on Twitter, Facebook, and reading blogs?), but mobile devices can have a tendency to really rope us in and keep us from focusing on other important areas of our lives.

I try to put the phone in a different room before going to bed and keep from checking e-mail for at least an hour when I first get up in the morning.  I really like to spend time in quiet reading and collecting my thoughts.  The days that I do this, I notice I am much more focused throughout the day.

Pass the IP Address of a User to Silverlight as a Parameter

In my beginning attempts to learn Silverlight, one of the first ideas for a project was to make a Silverlight video player that could change the source of the video file based on the location of the user.  The goal was to reduce network congestion between the branch offices back to the main office by having the Silverlight client download the media file from their local branch.  I wanted to give all users at the company the same URL to watch the video but the source of the video would actually change depending on the IP address of the user.  This is the problem I had:

How do I make Silverlight aware of the IP address of the user and then make that data available during the lifecycle of the Silverlight application?

It turns out that there are quite a few ways to accomplish this task, both in how to make the Silverlight client aware of the user’s IP address as well as how to make the variable accessible during the life of the application.

Before I go into the solution that I used, here are several resources I used to find my answer:

Getting the IP Address

I was a bit surprised to learn that there was no default method in Silverlight to get the IP Address of the current user.  Then I remembered that Silverlight is client technology and accordingly it would need to get the user’s IP address from outside of itself.  The easiest way (that I found) is to let the server that is hosting the application provide the IP address to the Silverlight client at startup.

If you looked at the answers in my first Stack Overflow question from above, you can see that some of the answers involve using JavaScript to directly modify a control within the Silverlight application.  While this is certainly possible, it seems a little complicated and I don’t want to have to create a control in Silverlight just to hold the IP address.  I found that using simple ASP.NET within the “initParams” parameters of the Silverlight object tag was the easiest method.  The code will look something like this:

Click to Enlarge

The “initParams” parameter can be used within the object tag of regular HTML or ASP.NET.  However, since I need the server to communicate the IP address to Silverlight in some way, I’m using ASP.NET (which is on the server) to pass the parameter into “initParams”.

<param name="initParams"
value="txtUserIP=<%=Request.UserHostAddress %>,cc=true,m=/relative"/>

If you were to click “View Source” after the page had loaded, you would see the actual IP address instead of the ASP tags.

Doing Something With InitParams Data

After we pass the IP Address into InitParams, we have to do something with the data on the Silverlight side.  My third question on Stack Overflow sought to find the answer to this question, but I found the best answer to be in Tim Heuer’s video on Silverlight.net.

The only place that InitParams are made available during the application lifecycle is at the application startup.  Specifically, you need to look in the code-behind of your App.xaml file (in my case, it was App.xaml.cs since I was using C#).  The Application_Startup method will look like this:

Click to Enlarge 

The InitParams are part of the StartupEventArgs e collection.  If we want to do something with the parameters in the main page, it will be important to insert our code before this.RootVisual = new MainPage();.

Storing the InitParams in a Resource Dictionary

While I certainly could create a public variable in my App.xaml.cs class, I liked Tim’s idea of using a resource dictionary.  He shows three different methods in his video demonstration, but the one I liked best was to simply pass the InitParams into the Application Resource Dictionary.  This way, the IP address will be available during the life of the application.

Click to Enlarge

A simple foreach loop will help us to add all of the InitParams to the Application’s Resource Dictionary.  You can then get the parameter value from the resource dictionary using App.Current.Resources[“txtUserIP”].ToString();.

Last Things

If you’re interested in how to hook up the source of a video to a media player in Silverlight, I recommend checking out the source code for the Silverlight 2 Video Player on Codeplex.  If you look in App.xaml.cs in the source code, you can see how they format a URI to be set as the source for the Media control.  You’ll need to use URI(txtURL, UriKind.RelativeOrAbsolute) if the link is external to your site and URI(txtURL, UriKind.Relative) if the link is in the same site.  The Media control’s source must be a URI, not just a string.

Also, the source of your media control cannot be a UNC path (e.g. //InternalServer/video.wmv) because Silverlight is sandboxed so that it does not recognize local resources.  If your Silverlight App is hosted in http, then the video must be an http source, and if it’s hosted in https, then the video must be an https source.  I had hoped to be able to simply pull video from a network share at each branch office, but because of this restriction, I would actually have to set up IIS (or some other web server) to host the videos at each site.

In regards to the IP address of the user, the IP address returned to Silverlight will only extend as far as the site on which it is hosted.  For example, if you run the Silverlight App from within your ASP.NET test hosting server on your local PC, you’ll probably get 127.0.0.1 (I think).  If it’s hosted on an IIS server behind your company’s firewall, you’ll get your internal IP address.  If the Silverlight App is hosted on a public website, you’ll get the user’s public IP address.

Lastly, make sure you video is encoded properly or else it won’t play in Silverlight.  I recommend using MS Expression Encoder to handle this task.

 

Learning Software Development and Plato’s Cave

When I went to the Atlanta Silverlight Meetup Group this past Thursday, I met several people whose college degree (or lack thereof) was completely unrelated to software development.  As someone who is trying to become a “professional” software developer and is beginning the tedious process of learning several new technologies, this discovery was very heartening and caused me to reflect on my own background in philosophy and a connection I made to learning new development technologies.

Learning software development technologies can be difficult.  It’s as much about culture, language, and the greater community ecosystem as it is about making a bunch of lines of text do cool stuff.  Sometimes it can be really difficult to understand the importance of technology without having an appreciation for where it fits in to the big picture.  The following is a thought experiment to try to help you understand what I mean.

I took a minute to think of all of the different technologies related to software development that I’ve come across in the past month.  Take a look at the following list at see if you recognize the technology and concepts on this list (in no particular order):

  • ASP
  • ASP.NET
  • .NET
  • ASP.NET MVC
  • MVVM
  • Ruby
  • Ruby on Rails
  • Mono
  • MonoTouch
  • Moonlight
  • Silverlight
  • JavaScript
  • HTML
  • DHTML
  • Java
  • JQuery
  • XAML
  • XML
  • XAP
  • MEF
  • OSLO
  • AJAX
  • DSL
  • C#
  • VB.NET
  • RIA Services
  • Entity Framework
  • WCF
  • CLR
  • OOP
  • Spark
  • Prism

When looking at that list, how much did you recognize? How many of the pieces can you fit together?  If you are an experienced developer, you were probably able to recognize the terms and automatically recognize how they exist in relation to one another.  For example, you might automatically recognize that “a XAP file is really just a zip file for Silverlight applications” or “JQuery is a library for JavaScript, which is not really related to Java.”  Sure, it’s a diverse list of technology, but you probably have at least a general idea of how the pieces fit together.

Now try to imagine (or remember) what it is like not to recognize these technologies and how they fit together.  Try, for a moment, to abandon your understanding of what you already know and put yourself in the shoes of someone for whom the term .NET is just another group of letters in a malaise of technological alphabet soup.  Think about what it might feel like to write your next Silverlight application without having a clue of why you would even want to use MVVM.

In this experiment, you may have found it quite difficult to forget things you have found important and to abandon your understanding of key technologies related to your field.  Besides, you might ask, what’s the point of trying to forget things you’ve already learned?

That’s a great question, and to get at the answer, bear with me as we take a very brief look at ancient Greek philosophy.  In Plato’s analogy of the cave (from the Republic), the majority of humanity is described as being in a dark, barely lit cave, trying to understand the world by the dim shadows cast on the walls of the cave.  It’s hard to understand the world when all you have to go on is the shadows on the wall.

Some people, however, find their way out of the cave and “see the light.”  No longer seeing just the shadows, with the light outside of the cave, they get to see the world as it “really is” and now have a better understanding of the world.  This is great! Now what?

Let’s stop here for a second and make a connection to the world of software development.  The people inside the cave represent people like me.  Some of us are content with where we are and what we know, and some of us are trying to “see the light” so we can understand software better.  Either way, we’re the ones who don’t know why we should go through the trouble of using class modules and objects in our VBA Excel applications.  We don’t know why MVVM will save us time in Silverlight development, and the phrase “separating business logic from the UI” either means nothing or doesn’t seem applicable.

On the other hand, the people outside the cave know exactly what “ORM” means, have their personal favorite, and know how to use it correctly.  Not only do they know why to use MVVM, but they contribute open source code to an MVVM framework.  Whether in their specialized discipline or in a wide range of products, these developers “get it.”

Some devs “see the light” while others are still in the cave adding button controls to their boss’s excel report (guilty). Is that all there is to it?  This is where we return to our thought experiment of trying to forget what we know about software development.

This is where the value of the analogy of the cave really shines.  The philosopher (or developer, I suppose) who is outside of the cave could simply bask in the glory of their own understanding, but to be a true philosopher (errr…developer…), he must go back into the cave and try to convince the great unwashed that they should want to get out of the cave.  He must try to get others to “see the light.”

The philosopher-developer must not only tell me where to download the latest bits for their technology of choice, they must tell me why I should want these bits in the first place.  The philosopher-developer cannot only give a cool talk at MIX that demonstrates their favorite new tool, they ought to bring me to an understanding of why I should need that tool in the first place.

The hardest part about helping others to understand why to use such-and-such technology is trying to put yourself in their place, forgetting your assumptions and trying to remember what it feels like not to know.  It’s easy to geek out and get excited with our peers, but it’s exceptionally difficult to remember what is was like to not even know why we would want to be geeking out in the first place.  A person who has donated his or herself to bringing others into the light by meeting them at their level is truly embracing the essence of what it means to be a teacher.

Here’s an example of what I mean.  I’ve read a few posts trying to explain MVVM.  Almost always, these posts will describe the different pieces of MVVM and how they work together.  That’s great, but what I need to see, as someone who is “inside the cave”, is why MVVM is even important.  Try to forget about the greatness of MVVM for a second and walk me through an example of how I might build a simple application without it.  Get on my level and try to imagine what I would do as I try to solve the problems of building the app.  After you show me how to build an app “the traditional way,” show me how MVVM will actually help me when my boss wants to add a new text block to that data form we just built.  Show me how I would have spent 2 hours making the change my way, and then show me how I would have spent 5 minutes making the change your way.

I might be kicking and screaming as I spend 8 hours trying to implement your new framework for the first time, but I’ll be grateful for your work after it’s saved my butt for the 50th time because management doesn’t know what they want in the UX of their product.  More importantly, I’ll have actually tried your technology because you took the time to show me why it was important.  In sum, you can yell and scream all you want about how great “the light” is outside of the cave, but until you come into the cave, get on my level, and then drag me out, I’ll never understand why I should want to join you.

Lastly, I’ll grant that every last blog post and conference talk does not need to be directed at the unenlightened few.  Sometimes you just need to preach to the choir or demo some tools to your community.  I understand that.  However, there are still far too many “Introduction-to-Some-Technology” blog posts that show tools and bits without showing why they are even necessary.  As frequently as new technology is introduced, you can’t always assume that everyone listening to your talk or reading your blog post about the next-big-thing is up to speed on why it is even important.

The best way to learn is by being taught by someone who wants to get on your level and guide you to a better understanding of the topic at hand.  Any volunteers?

Notes from the Silverlight Atlanta Firestarter

UPDATE: A full list of resources from the Silverlight Atlanta Firestarter is up: http://www.silverlightatlanta.net/?p=156

Here are a few quick notes that I took during the Silverlight Atlanta Firstarter.   I didn’t even attempt to take comprehensive notes, but I did jot down a few things that I found interesting.  These are more for my reference than anything else.  You won’t find a lot of content for each talk, but you’ll find a few things that I found important and worth jotting down.

At the very least, I put links to everyone’s blog or home page if I could find it.  That way you can easily look up the person if you’re interested.

Overall Impressions

Overall, the event was great.  I’m very thankful to all of the volunteers and sponsors who helped put it together.  I’m really excited about continuing my “getting started” efforts in Silverlight and am looking forward to future meetups and events.

Though they introduced a very large amount of information, it was generally presented very well and served as an excellent broad introduction to Silverlight.

Introductions

  • Corey Schuman emceed the event and introduced the speakers.  Great job!
  • Glenn Gordon was present as the “Developer Evangelist” from Microsoft.  He brings free Microsoft events, resources, and information to developers in the Southeast.  Cool.

Keynote: Tim Heuer

Tim Heuer is a program manager for Silverlight at Microsoft.

  • Tim doesn’t have a CS degree – I found this encouraging because I do not have a CS degree, but I want to get involved in web development
  • Apparently, Silverlight is really big with Yahoo! Japan.
  • Tim mentioned Kevin Dente on TwitterCan’t remember why.
    • Update: Tim has been a guest on Kevin Dente’s podcast, “Herding Code,” which Tim recommended listening to.  Thanks Alan for the reminder!
  • Search: Super Employee Alfred – A really cool example of SEO and Deep Link functionality within SL.

Silverlight Soup to Nuts: Shawn Wildermuth

I really wanted to pronounce his last name “Vildermuth.” Shawn Wildermuth did the talk on “Silverlight Soup to Nuts.” (For the record, his rotating profile picture on his blog is freaky as hell).

  • Silverlight-tour.com – A national tour for agilitrain giving workshops and classes about all the new stuff in Silverlight 3.
  • With XAML, you can name only the elements you want to appear in IntelliSense.  This reduces the clutter (such as label3,label20421,etc.) of having everything named.
  • Rock Scroll – Visual Studio Plugin – this is a cool plugin that Shawn had installed on his computer that puts a top-down look at all your code directly into the vertical scroll bar.  Plugin is written (or published) by Scott Hanselman of Microsoft.
  • Ctrl K + Ctrl D – used to format code in Visual Studio (if you needed a hint that I’m brand new to developing apps in VS, here it is)
  • SLExtensions – Because no one should have to write their own converters.  Silverlight Contrib and Silverlight Extensions recently merged.
  • this.OnPropertyChanged(“Name”); – can’t remember why I wrote this down

Anatomy of a Silverlight App: Tim Heuer

Tim’s back.

  • Silverlight Tools
    • Minimum
      • Silverlight Developer Runtime
      • SDK
    • Recommended
      • Visual Studio 2008 SP1 (you can even use the free Visual Web Developer)
      • Visual Studio Tools for Silverlight
      • Expression Blend 3
      • Expression Encoder 3
      • See http://silverlight.net/GetStarted
  • Somebody asked how you can get MS software other than retail – When applicable: Microsoft Action Pack, StudentSpark? (A program that gives students free access to developer software), BizSpark (a program that gives start-up free developer software)
  • DaFont.com – a place to get free fonts
  • Fonts must be embedded as a resource – please respect the usage rights of the font developers
  • Loaded += new … – Some events belong in the Loaded section, for after the UI has loaded.
  • .xap file is really just a zip file and contains:
    • appmanifest.xml
    • assemplies
      • your app
      • dependencies
    • content
  • Install Experience – See whitepaper for best practices.  See post on Tim’s blog.

Data Services: Rik Robinson and Steve Porter

Rik Robinson presented on Data Binding

  • {Binding …} – This is used in XAML to bind data to a XAML element.

Steve Porter also presented.

Note: At some point Chad Brooks was introduced.  He’s an Architect Evangelist from Microsoft.  He can be reached at Chad < dawt > Brooks < at > Microsoft < dawt > com.

Lighting up the UI: Mason Brown and Roger Peters

I can’t remember exactly who presented what from my notes, but Mason Brown did more of the graphics side and Roger Peters did more of the development side.

  • “Design Width” in Blend is only for design time and doesn’t interfere with the actual end presentation.
  • You can double click on a control from the left panel in Blend to easily add it to your UI with minimal code clutter.

It was hard to take notes on a lot of this stuff because it was so visually intensive in Blend.  I really liked the explanation of behaviors, though.

Update: A demo of the UI they wrote here.

Outside the Plugin: Jason Rainwater

Jason Rainwater presented on using SL 3 to interact with the browser and vice versa.  Very cool stuff.

He mentioned checking out SL 3 resources on MSDN.  I had trouble finding a link to that other than what directs to Silverlight.net.

Note: During one of the breaks, I was talking to someone whomentioned SubSonic as a possible way to interface MySQL with Silverlight and/or WCF.  I’m going to have to check that out.

Media: Corey Schuman

Corey Schuman presented on media in Silverlight.  This was a great introduction to media in Silverlight.  It’s incredible how easy it is to create a media player in Silverlight.

Sketch Flow – Rob Zelt

Rob Zelt spoke about SkitchFlow.  It was really neat to see an in-depth look at this new tool that comes with Blend 3 and SL3.  Great job.

Deployment Strategies – Sergey Barskiy

Sergey Barskiy talked about setting up a successful Silverlight deployment.  He also has a really cool accent.

  • WCF diagnostics
  • system.diagnostics.xmlWriterTraceListener

He didn’t get a chance to go over localization and reporting (I really wanted to see reporting), but he put a follow-up post on his blog for those interested in those technologies.

Community and Ecosystem – James Ashley

James Ashley presented on the Silverlight ecosystem and all of the wonderful communities and resources available to help a programmer succeed in Silverlight.

I would type out my notes from his talk, but he managed to quickly post the content onto his blog.

Sidenote: His use of the word “phenomenology” in his blog subtitle is the only direct opportunity I’ve had to apply my degree in philosophy since starting learning Silverlight.  Well done.

Last Things

Death. Judgment. Heaven. Hell.  … err … I need to finish this post…

Shawn mentioned DevCow.com as a way to connect with other developers in the Atlanta area.

Thanks again to everyone for all their hard work!  I have so many wonderful ideas.