Monthly Archives: August 2013

Hooray! See Upcoming Appointments in Outlook 2013

I am but one of thousands of Outlook users who were flabbergasted that Microsoft removed future appointments from the ToDo Bar in Outlook 2013. You can only see what’s happening on the day that is selected.

image

Not only does the calendar not BOLD the dates with appointments, it doesn’t show me what’s coming up in the next week or so besides the single 9pm appt I have tonight. I have an important appointment tomorrow afternoon but I won’t know until I open up outlook tomorrow. If I had to be somewhere at 8am tomorrow morning, I could completely miss it because I may not see the reminder until tomorrow morning.

This was a show stopper. I have really bad short term memory. I had grown very dependent on the constant reminders every time I looked at my email about what work, vet, hair, user group, dentist etc etc appts I had to be aware of in the next week or so. And the Outlook 2013 solution is either to open up the Calendar or start clicking around on the ToDo calendar. This takes explicit thought  and multi tasking. Not for me. Not at all.

Many simply refused to upgrade from Outlook 2010.

There were no add-ins that solved the problem.

Until now.

A friend who refused to update to 2013 for this reason pointed out this Coding4Fun blog post : Bringing some Outlook 2010 features into 2013 with this add-in… to me this morning. It leads to the VSTO download on codeplex. I realize that I downloaded an earlier version of this in April but never succeeded in installing it and must have just given up and forgotten about it. With today’s reminder, I tried again with the latest version. I had the same install problems today but finally solved them!

Installation Problem …. Solved

I use Chrome by default. I downloaded. Unblocked. Unzipped. but when I attempted to install, got the dreaded “Deployment and application do not have matching security zones” error message. This typically happens when you try to install right from the web without explicitly downloading, unblocking and unzipping. I tried repeatedly. Restarted my computer. Googled again and again. Finally I opened up IE, downloaded, unblocked, unzipped and installed. It worked.

See Future Appointments

I’ve closed the other ToDo bar since I only use the calendar. Otherwise I’d have to devote more of my outlook window since I can’t seem to stack the panes for the ToDo bar and the Appointment window.

I’ve set this to show me the next 7 days and to show me my local calendar, my Windows Live calendar and the internet calendar. You can see that I’ve gotten in the habit of copying my LIVE calendar to my local calendar and vice-versa. I’m not ready to go 100% dependent on the web-based calendar. So now I’m seeing the duplication but better safe than sorry. 🙂 (I’ll get into modern times soon). The tool did not black out those appts tomorrow. I did. They are private. 🙂

image

It has a feature to alert you when new mail comes in via the windows notification bar. I get a lot of mail so that is definitely a feature I disabled quickly.

Drag and Drop Emails to Create Appointments

Another Outlook 2010 feature that was inconceivably axed from 2013 was the ability to drag and drop emails onto the calendar to create appointments. It is another feature I used all the time and saw almost as many complaints on the web about its disappearance as the future appointments.

That’s back thanks to this add-in.

Go Get It!!

Here is the codeplex download page: https://outlook2013addin.codeplex.com/.

The codeplex project is created by a mystery author: https://www.codeplex.com/site/users/view/gamosoft

I am not a fan of developers who have public projects hiding behind an alias. I just want to pat their back and thank them publically and set them on a little pedestal. Maybe gamosoft is hiding because he or she is a Dalek or Cyberman or something? (yes, I’m watching too much doctor who lately)

Accidental Learning

In my Pluralsight course, Automated Testing for Fraidy Cats Like Me (an introduction to Unit Testing and TDD), I presented a use case that required retrieving  the date of a person’s most recent tweet.

The process of accomplishing that and then completely reworking it again this morning, made me think some more about how we accumulate knowledge even when we don’t have the need or time to take on learning about a big topic.

I’ve learned a lot of things by accident and because I’m curious and something of a pit bull, these become detours to otherwise productive days.

If you follow me on twitter, you see the random, seemingly unrelated things that I’m constantly wrestling with. Here’s an example.

Many Moons Ago, I Had a Silly Idea

I started with a stub method that just returned a date but I wanted to make it a little more real. I ended up spending hours and hours on this, trying to figure out the non-authentication API call to get the data.

Finally I was able to come up with a way to do that:

https://api.twitter.com/1/statuses/user_timeline/julielerman.json?count=1

Note that this was using version 1 of the twitter API and did not require authentication so it was easy enough to use this in my sample.

Then I needed to call it. I wasn’t used to making web calls from outside of some type of web application. So it took me a while to realize that I needed to use System.Net.WebClient.WebClient to execute the call. And exactly what call I wanted to execute took some time to discover as well. Naturally. It turned out that I wanted to use the DownloadString method.

 

 var uri = new Uri("https://api.twitter.com/1/statuses/user_timeline/" + twitterAlias + ".json?count=1");
 var client = new WebClient();
 var result = client.DownloadString(uri);

So I finally have the tweet. It’s was as string …not pretty. And I had to parse it to get at the DateCreated. I did some more searching and came upon a library I’d heard of (always with accolades!) countless times but had never had the chance to use: JSON.NET.

A little more exploration helped me learn I could use the API’s JObject class to parse the string into a recognized object

const string constTwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy";

and then extract the property I wanted:

o["created_at"]

But that didn’t work because it turned out that twitter has it’s very own special way of representing a date. Uggh! Back to GoogleBing for quite some time and I finally came up with the format and then how the heck to transform that format into one that could be read by .NET.

const string constTwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy";
var createdAt = DateTime.ParseExact((string)o["created_at"], 
        constTwitterDateTemplate, new System.Globalization.CultureInfo("en-US"));

Finally! I had a System.DateTime I could use!

In the end, I had a handful of lines of code to do what I wanted

public DateTime LatestTweetDateAsUtc(string twitterAlias)
{
  var uri = new Uri("https://api.twitter.com/1/statuses/user_timeline/" + twitterAlias + ".json?count=1");
  var client = new WebClient();
  var result = client.DownloadString(uri);
  var jsonString = result.Replace("[", "").Replace("]", "");
  var o = JObject.Parse(jsonString);
  const string constTwitterDateTemplate = "ddd MMM dd HH:mm:ss +ffff yyyy";
  var createdAt = DateTime.ParseExact((string)o["created_at"], 
    constTwitterDateTemplate, new System.Globalization.CultureInfo("en-US"));
  return createdAt;
}

But it had taken me hours and hours and hours to get to this.

The upside is that I learned about JSON.NET and got a basic understanding of its use.

The date transformation is one of those esoteric things I will forget I’ve done and have to search on the web next time I find I need to use it…this could be years from now. And WebClient…that could come in handy but I don’t foresee a lot of use for the work I do.

Other than the long-overdue exposure to JSON.NET, it was a wasted afternoon.

6 Months Later, I Came Across a Better Way

What I hadn’t discovered was TweetSharp. Because the v1 Twitter API is now depracated, I have to use v1.1. But v1.1 requires EVERY CALL to be authenticated.

So I had to sign up for an application key (https://dev.twitter.com/apps).

Then I looked for some help with how to authenticate my app. The code was a nightmare. More learning curves.

Then I found TweetSharp.

Within 1/2 hr I had authentication set up and figured out how to get a users’s latest tweet. And the best part was TweetSharps Tweet class does the work of transforming the date to a DateTime for you. (Using JSON.NET and possibly code similar to mine. I get I can figure that out by looking at the code on github. 🙂 )

      var service = new TwitterService(_my_ConsumerKey_providedbytwitter, my_ConsumerSecret_providedbytwitter);       service.AuthenticateWith(my_Token_providedbytwitter,my_TokenSecret_providedbytwitter);       var user = service.GetUserProfileFor(
new GetUserProfileForOptions {ScreenName = "julielerman"});       var tweet = service.ListTweetsOnUserTimeline(
new ListTweetsOnUserTimelineOptions{ UserId = user.Id, Count = 1 }).FirstOrDefault();       DateTime thedate = tweet.CreatedDate;

So….for many, nothing new here.

A Lesson Bigger Than Just The Code

What’s more interesting to me than the actual solution is the process I went through. Getting that twitter date was just a made up scenario that I decided to pursue for my example. It stopped me in my tracks and I became consumed in solving it, not once but twice. First when I was building the course and second when I wanted to share *that* code and discovered the API no longer worked. It’s fun to learn new little things that don’t require you to read a whole book. So I now know enough to be dangerous about JSON.NET and about TweetSharp. However I’m well aware of my limitations.

It also interested me to consider how this process, repeated over the years, has resulted in my having a quiver filled with a slew of little bits of very useful, somewhat scattered, information. This is very different than learning a big topic, like testing or Entity Framework. However they are a starting point at which I can leverage the tool and make it work for me.

Which somehow ties back to my keynote at CodeStock this summer where I spoke about approaching big learning curves one small bit at a time. For example how I’m currently using and benefitting from pieces of Domain Driven Design even though I’m a long way from understanding or being expert at the *whole* thing. However my pursuit of DDD is hardly accidental! I’m working diligently to understand it and use it (and share what I’ve learned).

I’m not sure if I’ve wrapped up with anything useful here but I got what I was thinking about out of my head so I can get back to wrestling with my next topic!

Entity Framework, Private Constructors and Private Setters

As I learn more and more from Domain Driven Design, my classes for DDD projects (those that are complex enough to need more than simple CRUD), are shifting from what are referred to as “anemic domain models” and more like “rich domain models”.

The term “anemic domain model” (which I still have an aversion to…the term, that is) refers to a class that doesn’t really do much at all. It has a bunch of properties and maybe some methods. To use them you instantiate or retrieve the object and then populate the properties at will. When working in DDD, the focus is on behaviors, not properties. So you would have methods to control what happens to  your objects and in doing so, constrain the properties so that they are not exposed to be set or modified “willy nilly”.

Here is an extremely simple pair of classes that are designed using some of the techniques I’m learning from DDD:

  public class AThingAsEntity
  {
    private AThingAsEntity(){}  //the private constructor

    public AThingAsEntity(string description, int anInt, string aString)
    {
      Description = description;
      SomeOtherThing = new SomeOtherThing(anInt, aString);
    }

    public int Id { get; private set; }
    public string Description { get; private set; }
    public SomeOtherThing SomeOtherThing { get; set; }

    public void TheOtherThingMustChange(int anInt, string aString)
    {
      SomeOtherThing = new SomeOtherThing(anInt, aString);
    }
  }
  public class SomeOtherThing:ValueObject<SomeOtherThing>
  {
    private int anInt;
    private string aString;

    private SomeOtherThing(){} //the private constructor 
   //this value object’s constructor is internal to prevent random instantiation
internal SomeOtherThing(int anInt, string aString) { AValue = anInt; AnotherValue = aString; } public int AValue { get; private set; } public string AnotherValue { get; private set; } }
 

I’m constraining the class so that anyone who instantiates it is required to pass in some values. And those values all have private setters. There’ s no way to write code like:

var thing=new AThingAsEntity();
thing.Description="oh i'll just put whatever I want in here. heh heh heh. Domain rules be damned";

 

That’s the way I want to write this class to represent my domain.

In the past week or so, I’ve been asked three separate times (by three different developers) if it’s possible to use this pattern of private setters with EF. The answer is “yes”. Here, let the Doctor confirm that:

And in case you’re curious, I’m doing this with EF5.

Entity Framework requires a parameterless constructor in order to materialize objects returned from queries (or loading). I  have made this concession in my class but notice that it is a private constructor. So I’m still protecting my class. Nobody can access it. But EF is still able to populate this class when I execute queries. And no, I’m not doing some magic to tell EF to use my public constructor. It really uses the private constructor.

I’ll use an integration test to demonstrate.

Note that my test is using an initializer called SeedMyThings to always drop and recreate the database and shove in this seed data:

      new AThingAsEntity("This is MY thing", 42, "That is the meaning of life")

My test sets that initializer so I can perform the test I’m interested which requires some seed data.

[TestClass]
  public class Tests
  {
    public Tests()
    {
      Database.SetInitializer(new SeedMyThings());
    }
    [TestMethod]
    public void EfCanPopulateObjectWithPrivateCtorAndSetters()
    {
      using (var context=new ThingieContext() )
      {
        var thing = context.Things.FirstOrDefault();
        Assert.IsInstanceOfType(thing,typeof(AThingAsEntity));
        Assert.AreNotEqual(0, thing.Id);
        Assert.IsFalse(string.IsNullOrEmpty(thing.Description));
        Assert.IsFalse(string.IsNullOrEmpty(thing.SomeOtherThing.AnotherValue));
      }
    }
  }

I know…all those Asserts…bad tester.  So shoot me. 😉

Anyhooooo…. the test passes. Even with my private ctor and private setters, EF is able to materialize the object and even it’s SomeOtherThing property which is a value object. (which also has a private ctor and private setters). Internally EF is reading the metadata of the model and using reflection to set the values of the properties.

I also want to point out that I had been using a protected constructor. In the past, I am sure I tried private and it didn’t work. (Maybe an earlier version of EF?) But Steve Smith asked me “if setters work as private, why not constructor?” So I tried it and voila, it worked too.

And now, for my first EVER public Git repository. You can find my little sample solution at https://github.com/julielerman/EF_and_Private_CTORs_n_Setters. 🙂

After 3 Years, Devs are Still Finding Programming Entity Framework 2ed Useful


 

I spent a year writing the 1st edition of my book Programming Entity Framework and then another year revising it for EF4 which resulted in the 2nd edition. After that Microsoft released DbContext (which sits on top of the ObjectContext for simpler coding) and Code First that sat on top of EF4. EF5 was mostly a consolidation that also took advantage of 3 new features in .NET 4.5 (enums, spatial data and query caching). VS2012 brought some nice designer improvements and a default DbContext/POCO code generator. EF6 mostly adds some advanced features to what’s already there.

But what hasn’t changed much are things like LINQ to Entities, security, ESQL, how transactions work (small change coming in EF6), databinding, code generation,and most importantly the Entity Framework internals. It is understanding the internals that give you real power over Entity Framework – not relying on the #efhelp hashtag, stackoverflow or the kindness of strangers.

It was really nice to see this brand new 5-star review of my 2nd edition book (screenshot below).

Not only does this book cover explain Entity Framework from a programming point of view, but it pulls back the covers to explain the many options available. The many comprehensive real life examples that Julie Lerman provide make this a programming Bible for Entity Framework. Whether you are using views, stored procedures, user defined functions, the T4 generator, Entities or POCO’s, Julie Lerman can help you come up with the solution that works for you.”

I still believe that a combination of the shorter focused books Programming Entity Framework DbContext and Programming Entity Framework Code First with the 2nd edition book for deeper understanding of specific topics – almost as a reference now – packs a “one-two” punch for entity framework.

And as you may know, I’m making my bigger investment in Pluralsight videos now. I have 10 videos alone on Entity Framework already along with one which is a Beginner’s training on Unit Testing & Test Driven Development.

I wrote a blog post recently on the recommended order for watching those Pluralsight videos along with suggestions to help you decide which is correct for you.

I still keep thinking about updating one or more of the Programming Entity Framework titles, but while each of the few dozen strongly worded pleas I have received to do so are tempting, a few dozen still does not justify the effort.

image

Why I am Unlikely to Attend the Fall 2013 MVP Summit

I’ve been asked so many time if I’m going to the fall MVP Summit and then when I respond “no” or “probably not”, explaining why.

Here’s why.

I had already committed to two back-to-back conferences in late October/early November.

First I have to fly west across the country to Las Vegas for DevIntersection. Then I go home, pat the dog, and hop on a plane to fly to Sweden for OreDev.

So even though there would be a week in between, I just don’t want to then fly back across to the west coast for the summit. I’m not as eager to do all of this travelling anymore.

It’s sad missing all of the great opportunities and I’m guessing this will be a critical time for EF6/VS2013, though that should all be public information anyway. So as much awesomeness as the MVP Summit is, I think I’ll most likely not be attending.

If you need to see me, come visit in Vermont. If you prefer Las Vegas then DevIntersection & AngleBrackets will be awesome. And use LERMAN for a $50 discount code for those. Oredev is an amazing conference. Sweden in November is questionable :), but the conference is worth it.

Or if my voice is enough, there’s always my Pluralsight videos! 🙂

fallsummit