Sunday, November 6, 2011

Getting Pictures from my Windows 7 is so hard?

I just spent the morning taking cool pictures of my daughter and son, got home and want to look at them on the computer.  OMG, can it be more impossible and more confusing using Zune?  Am I asking for too much?  I want to copy the pictures from my phone to my computer.  Instead I am dealing with questions about sync relationship, copy to my collection, etc, etc., Really, I think I get enough relationships from my wife, how about just letting me copy the files?

 

I know, I know, Microsoft feels that individually selecting the pictures and emailing them to email address is suitable for a really strange user scenario..

Thursday, November 3, 2011

ASP.NET DateTime Time Zone Management

Handling dates in ASP.NET is challenging for me.  The context of DateTime is always local time and there are no smooth transitions from SQL DateTime to a .NET DateTimeOffset.  I need to timestamp an event in the local time where it occurred and then display it to the user based on their time zone.

 

Here’s what I came up with, please tell me if there is a better way.

 

1.     I collect the event (via XML message) by sending the date in DateTime.ToString(“o”) so the timezone is saved.

 

messNow.AddXML("timestamp", DateTime.Now.ToString("o"))

 

2.     I parse the inbound XML using DateTimeOffset.TryParse so I keep the time zone and avoid DateTime’s local time assumption and then store the DateTime value to preserver local time of the event and the UTC version.

 

string TimeStamp = xmlNow.Get("timestamp");

if (!string.IsNullOrEmpty(TimeStamp))

{

   DateTimeOffset dStamp;

   if (DateTimeOffset.TryParse(TimeStamp, out dStamp))

   {

      queueNow.timestamp = dStamp.DateTime;

      queueNow.utc_timestamp = dStamp.UtcDateTime;

 

3.     I sort the event using the utc_timestamp DB column and then reconstruct the DateTimeOffset by using the TimeSpan difference.

 

            DateTimeOffset oNow = new DateTimeOffset(dLocal, dLocal - dUTC);

 

4.     You can show the DateTime local to the user by using the users local TimeSpan instead of the event’s local time.

 

 

Side Note: I’ve never liked just setting my server to UTC because it only solves a few problems, you really have to bake time zone handling into your application.

Saturday, October 29, 2011

Windows 7 Phone

Honestly, is Microsoft just playing a massive joke on everyone? 

I’ve been using a Windows 7 phone for about a month now and I cannot figure out how Microsoft thinks this platform is a good idea.  Granted, the user interface is fun and cool and consolidating contacts from all sources seems workable and cool.  I am always nervous imagining how Microsoft will translate out to Facebook and LinkedIn but the inbound consolidation is very nice. 

Here are the show stoppers for the Windows Phone: 

Tombstoning:  This is a firing offense. Well, I don’t want someone to lose their job over my phone but I would station whoever came up with tombstoning at the Antarctica station.  If you don’t know, tombstoning is when the phone unloads an app to move on to the next.  The phone will load it back up when you go back to it.  What does this means to you?  Say you’re watching Netflix and you switch your phone from one hand to another and you accidentally press the very sensitive search button.  Search loads up and Netflix is tombstoned.  Why is this a problem?  Well, it takes Netflix about 2-3 minutes to reload and reconnect to whatever you were watching.  Netflix, iHeartradio, and on, and on, it’s the same for all apps.  Imagine you want to reply to an SMS; same problem.  It really is the most horrible idea ever. 

Tethering: Excuse me?  I have to attach my phone to a computer to load the media? Really?  Is this 2008?  Are we trying to move forward? Copy Apple? Finally do something interesting with Zune?  What?  Ridiculous.  I’d love for someone in Microsoft to call me and explain how I should be listening to the Dan Patrick Show around the time its really aired.   Maybe Microsoft feels on demand media is a fad and will be going away soon? 

Closed OS:  You literally cannot do anything interesting with the platform.  There are no provisions for installing business applications that are useful, e.g. compliance monitoring.  I promise them, I will never edit an Office document on my phone, please move on.  For a company chasing Apple so hard they seemed to forgot how much grief Apple is getting for having such a closed system. 

There are various small annoyances but really nothing more than any platform so I don’t think it’s fair to nitpick every hiccup.  In general, I love the phone and Samsung has a beautiful form factor but I simply cannot waste another 15 minutes trying to get the latest Jim Rome show on my phone before its completely outdated and I’m pretty sure I will spontaneously explode the next time I’m watching Doc Who on Netflix and just need to reply to my daughter’s text message

Thursday, March 24, 2011

Getting the host of the current site on ASP.NET

Normally this isn't a problem because you are working with a request which contains the host name of the current server.  I had a unique problem where I was starting some threads from the Global.asax application objects and some of those threads would generate emails that contain click-back links to the site. 

#1. I added a public variable to my Global object 


public class Global : System.Web.HttpApplication
{
   private string _ServerRoot = string.Empty;
   public string ServerRoot
   {
      get { return _ServerRoot; } 
   }

#2. I added code to the Application_start the filled in _ServerRoot

void Application_Start(object sender, EventArgs e)
{
   // create the server root
   Uri uriMap = new Uri(Context.Request.Url.AbsoluteUri);
   StringBuilder bldNow = new StringBuilder();
   bldNow.Append(uriMap.Scheme);
   bldNow.Append("://");
   bldNow.Append(uriMap.Host);
   if (uriMap.Port != 80)
   {
      bldNow.Append(":");
      bldNow.Append(uriMap.Port);
   }
   _ServerRoot = bldNow.ToString();

#3. I passed the object to my threaded object.  I chose this way so I didn't have to worry about context when I need to get the address.

void Application_Start(object sender, EventArgs e)
{
   ... other init code

   // start threads
   Friend.Current.Init(this);



#4. I save the class in my threaded object

      
public void Init(Global global)
{
   try
   {
      CurrentApplication = global;
      Init(SystemName, null);



Anytime I need to get access to the server address I just reference CurrentApplication.ServerRoot from inside my thread.

I'm looking for something cleaner, let me know if you've come up with something.