Page Options
You are here : Home
...and the Geek shall inherit the Earth Blog... Minimize

Ok, so first OData rocks!  That and I’ve been a big fan of Entity Framework - especially EF4, marring them together is fantastic!

But I’m one that hates to hardcode anything if I can avoid doing so -- so for those that have started to implement OData feeds in their projects - the general way to set access to your EF entities is to use the string name of the entities as follows:\

   1: config.SetEntitySetAccessRule("CrystalRepositoryReports", 
   2:     EntitySetRights.AllRead | EntitySetRights.AllWrite);

Skipping to the end, what I want to end up with instead is hard-typed variation - as follows:

   1: config.SetEntitySetAccessRule(MakePlural(new CrystalRepositoryReport()), 
   2:     EntitySetRights.AllRead | EntitySetRights.AllWrite);

Now how to get there…

So as we’re using EF4 - we have the ability to instantiate a new instance of the class and get it’s name - as follows:

   1: string sName = new CrystalRepositoryReport().GetType().Name;

But -- if you know EF, that’s getting us the “Singular” version of the name - and we need the “Pluralized” version of the name, ie. “Goose” -> “Geese” (love that example <g>).

So we need to start by adding a reference to the Entity Framework PluralizationService.

image

So you need to use the following include:

   1: using System.Data.Entity.Design.PluralizationServices;

Then use the following methods:

   1: ///----------------------------------------------------------------------
   2: /// <summary>
   3: /// Makes the object name plural.
   4: /// </summary>
   5: /// <param name="obj">The object to make plural.</param>
   6: /// <returns></returns>
   7: ///----------------------------------------------------------------------
   8: private static string MakePlural(object obj)
   9: {
  10:     return MakePlural(obj.GetType().Name);
  11: }
  12:  
  13: ///----------------------------------------------------------------------
  14: /// <summary>
  15: /// Makes the string plural.
  16: /// </summary>
  17: /// <param name="sSingular">The singular string name to be made plural.</param>
  18: /// <returns></returns>
  19: ///----------------------------------------------------------------------
  20: private static string MakePlural(string sSingular)
  21: {
  22:     PluralizationService pluralizationService = 
  23:         PluralizationService.CreateService(new CultureInfo("en-US"));
  24:  
  25:     return pluralizationService.Pluralize(sSingular);
  26: }

image

Again a great crowd showed up to hear my presentation on “Windows Phone 7: Intro to Silverlight Dev” talk at the Rockford .NET User Group - pulled in both current .NET folks and iPhone guys to looking to leverage the great opportunities that Windows Phone is offering to developers.

image

Wanted to include my slides and the simple demo that we went through.

“Windows Phone 7 development took center stage at Microsoft MIX 2010 and for good reason, it's a major initiative at Microsoft incorporating some of the most exciting technologies - specifically we will take a look at building your first Silverlight application in the Windows Phone 7 Emulator and hopefully beyond. We will also briefly touch on the Windows Marketplace and the huge potential to Monetize your development efforts and get your applications out to the public. Hope to see you there!”

(Thanks to creators of the MIX slides, from which I derived much of the great information.)

Download Slides

Download Code Example

imageThe potential of developing for Windows Phone 7 is huge – and as I learn more, I want to share those resources with the rest of the growing WP7 developer community!  Keep an eye on this list as I will be adding to it.  If there a link that you would like others to see – attach it as a comment!

image Windows Phone 7: Twitter groups

 
image  Windows Phone 7: Start Here

image  Windows Phone 7: Documentation / Guidelines

image  Windows Phone 7: Books

image  Windows Phone 7: Videos / Presentations

image Windows Phone 7: Downloads

image  Windows Phone 7: Resources

image  Windows Phone 7: Window Phone Specific Blogs

image  Windows Phone 7: General Coding

image  Windows Phone 7: Silverlight

image  Windows Phone 7: XNA

image

Many thanks to the great crowd that attended my “Windows Phone 7: Intro to Silverlight Dev” talk at the Chicago Code Camp – really nice to see a standing only room full of enthusiastic future Windows Phone developers.

Chicago Code Camp 2

Wanted to include my slides and the simple demo that we went through (quickly as we ran out of time due to all the great questions <g>).

“Windows Phone 7 development took center stage at Microsoft MIX 2010 and for good reason, it's a major initiative at Microsoft incorporating some of the most exciting technologies - specifically we will take a look at building your first Silverlight application in the Windows Phone 7 Emulator and hopefully beyond. We will also briefly touch on the Windows Marketplace and the huge potential to Monetize your development efforts and get your applications out to the public. Hope to see you there!”

(Thanks to creators of the MIX slides, from which I derived much of the great information.)

Download Slides

Download Code Example

This week sees the celebration of the first National Robotics Week in the US. Since the foundation of Microsoft Robotics in 2004 by Tandy Trower and where he was Microsoft’s representative (with Stewart Tansley for Microsoft Research) in the Computing Community Consortium’s (CCC) efforts to create a “national road-map” for robotics technology, we’re excited to see the acceleration of robotics in the US and internationally. All of us at Microsoft Robotics wish great success to what we hope will become just the first of many such events in the coming years.

From the National Robotics Week “About” page:

National Robotics Week recognizes robotics technology as a pillar of 21st century American innovation, highlights its growing importance in a wide variety of application areas, and emphasizes its ability to inspire technology education. Robotics is positioned to fuel a broad array of next-generation products and applications in fields as diverse as manufacturing, health-care, national defense and security, agriculture and transportation. At the same time, robotics is proving to be uniquely adept at enabling students of all ages to learn important science, technology, engineering and math (STEM) concepts and at inspiring them to pursue careers in STEM-related fields. During National Robotics Week, a week-long series of events and activities is aimed at increasing public awareness of the growing importance of “robo-technology” and the tremendous social and cultural impact that it will have on the future of the United States.

National Robotics Week is a product of a 2009 effort by leading universities and companies to create a “national road-map” for robotics technology, which was initially unveiled at a May 2009 briefing by academic and industry leaders to the Congressional Caucus on Robotics. U.S. Representative Mike Doyle (PA-14), co-chair of the Caucus, and other members have submitted a formal resolution asking Congress to support the designation of the second full week in April as National Robotics Week.

Resources from Microsoft:

· Microsoft Robotics Developer Studio – a Windows-based environment for academic, hobbyist, and commercial developers to easily create robotics applications across a wide variety of hardware.

· Learning materials for Microsoft Robotics Developer Studio.

· Teaching materials for teaching faculty in the Microsoft Faculty Resource Center.

· Student materials for downloading Microsoft Robotics Developer Studio and other products at no cost if you are a student

· Blog entry by our colleague Stewart Tansley in Microsoft Research about National Robotics Week.

I’m on the airplane flight back to Wisconsin from the Microsoft MIX 10 conference in Las Vegas.  Working on some Windows Phone 7 demo applications and wanted blog an illustrated guide to adding the ApplicationBar to your new Windows Phone apps.

image

1) Start by downloading the new Windows Phone 7 Series demo tools at https://developer.windowsphone.com/ – as follows:

Once on that page, click on the “Download the Tools Today!” button, then click on Download the Developer Tools!

You’ll download the “vm_web.exe” which when you run it proceeds to download and install an ~238MB file.  Installation for went very smoothly, and installed everything I needed to start developing my applications.  Thumbs up to the Mobile Team – this was extremely well done – sure this wasn’t easy to get working that well.

Note, there is a link on the previous page for downloading Demo Code – grab those examples – specifically the “Application Bar Sample” which is what I dissected to write this article.

2) Open up Visual Studio, then go to File –> New –> Project – there you will see “Silverlight for Windows Phone” under the “Installed Templates”. 

In this case we’re building a “Windows Phone Application” so select that, name your project and click “OK”.

image3) In your “public MainPage()” method start by adding the following code:

   1: //----------------------------------------------------------------------
   2: // Create the application bar
   3: //----------------------------------------------------------------------
   4: ApplicationBar = new ApplicationBar();
   5: ApplicationBar.IsMenuEnabled = true;
   6: ApplicationBar.Visible = true;
   7: ApplicationBar.Opacity = 1.0;

4) VS will alert you that you are missing the “Microsoft.Phone.Shell” reference.  So right click on References and “Add a Reference” and find the “Microsoft.Phone.Shell” as illustrated – that should clear up that issue.

So in the code above, we see that we’re creating a new ApplicationBar instance, and setting a couple properties so it’s visible and so we have the “...” icon on the right (see more on that later below).

image

5) Next open the “Application Bar Sample” Demo Code and copy the images folder from that project into yours.  You should see three images in the image folder as you can see in the Solution Explorer illustration.

6) Now that we have the ApplicationBar instance and the graphics included in our project – we want to put icons on the ApplicationBar.

Add the following code – which created the ApplicationBarIconButton objects and associates the graphics.

   1: //----------------------------------------------------------------------
   2: // Create the application bar icons
   3: //----------------------------------------------------------------------
   4: ApplicationBarIconButton hide = 
   5:    new ApplicationBarIconButton(new Uri("/Images/expand.png", UriKind.Relative));
   6: ApplicationBarIconButton opacity = 
   7:    new ApplicationBarIconButton(new Uri("/Images/opacity.png", UriKind.Relative));
   8: ApplicationBarIconButton enabled = 
   9:    new ApplicationBarIconButton(new Uri("/Images/menuenabled.png", UriKind.Relative));

image 7) We follow up with adding the following code to wire up the event that do something when the buttons on the ApplicationBar are clicked. 

Note, that you don’t have these event methods defined yet – for me, I have ReSharper installed and it gives me an easy way to create stub methods by just clicking on “Create method ‘enabled_Click' ”

   1: //----------------------------------------------------------------------
   2: // Wire up the events
   3: //----------------------------------------------------------------------
   4: hide.Click += hide_Click;
   5: opacity.Click += opacity_Click;
   6: enabled.Click += enabled_Click;

Either way – here is an example of the code called when the event handler fires, just setup similar methods for the other events.

   1: private void enabled_Click(object sender, EventArgs e)
   2: {
   3:     throw new NotImplementedException();
   4: }

8) Now we just easily add the ApplicationBarIconButtons to the ApplicationBar as follows:

   1: //----------------------------------------------------------------------
   2: // Add icons to the menu bar
   3: //----------------------------------------------------------------------
   4: ApplicationBar.Buttons.Add(hide);
   5: ApplicationBar.Buttons.Add(opacity);
   6: ApplicationBar.Buttons.Add(enabled);

9) Just a little more code gives us the ability to have the great functionality of the “More Options” scrolling up section native to the ApplicationBar.  We follow the same patter as above, creating the instance this time of ApplicationBarMenuItems, wiring up their click events and adding them to the ApplicationBar.MenuItems collection, as follows:

   1: //----------------------------------------------------------------------
   2: // Creat the menu items
   3: //----------------------------------------------------------------------
   4: ApplicationBarMenuItem foregroundItem = new ApplicationBarMenuItem("use foreground color");
   5: ApplicationBarMenuItem accentItem = new ApplicationBarMenuItem("use accent color");
   6:  
   7: //----------------------------------------------------------------------
   8: // Wire up the events
   9: //----------------------------------------------------------------------
  10: foregroundItem.Click += foregroundItem_Click;
  11: accentItem.Click += accentItem_Click;
  12:  
  13: //----------------------------------------------------------------------
  14: // Add the menu items to the application bar
  15: //----------------------------------------------------------------------
  16: ApplicationBar.MenuItems.Add(foregroundItem);
  17: ApplicationBar.MenuItems.Add(accentItem);

image10) You’re almost there – run the application in the simulator and you get the illustration to the left.

Wait?  What happened to our nice icons?  Why are there “X”s?

This stumped me for a little bit – and is one reason I wanted to share my experience with everyone.

 

 

 

 

 

 

image 11) Ok – so missed one step after adding the images to the project.  Click on one of the images in the Solutions Explorer – you see that that “Build Action” is set to “Resource” – simply change all of them to “Content”.

 

 

 

 

 

 

image

image

12) Run your application again in the emulator – and awesome!  There are our icons – and – when we click on the “...” we see the ApplicationBar scroll up to reveal our ApplicationBarMenuItems.  Very very cool rewards for a minimal amount of code.

 

Summary: Wow. Even cooler than having written this article while on the airplane ( gotta love the free WiFi trial on AirTran ) – I’m loving the new Windows Phone 7 Series (WP7) development tools.

“I’m all in” ( see what terminology one picks up in Vegas ) for WP7 development and will continue to evangelize the product! 

Way to go Microsoft Mobile Team – looking forward to getting great apps out into the Marketplace. – and hopefully sooner than later replacing my iPhone with a brand new sparkly Windows Phone. :)

Good coding!

image

Currently at Microsoft MIX 2010 conference in Las Vegas (#Mix10) in the session on “Distributing and Monetizing Windows Phone Applications and Games”.

Very excited about the huge potential for leveraging my existing .NET skills and my extensive background with Mobile Development.  Highly encourage others to download the development tools – very smooth installation process – encourage others to get the tools.

Also, while sitting in the conference, I already registered for an account to distribute Window Phone 7 applications – the Marketplace is going to be huge!

To register – go to http://developer.windowsphone.com – the price is just $99.

I’m just waiting for… “Your corporate approver … will soon receive an email with instructions on how to authorize your request. Please ensure the corporate approver follows these instructions to finalize your registration.” – so if you’re my “corporate approver” reading this – drop me an email. :)

“According to a recent survey from Microsoft, remote-working programs can benefit employees and employers alike through increased productivity, reduced overhead and happier workers.  …they are actually more productive and efficient when working remotely. With less time spent commuting and fewer cubicle “drive bys” causing distractions, respondents say, more time can be spent on the task in front of them.”

Read More...

I’m a big fan of EF (Entity Framework), specifically loving EF4 in Visual Studio 2010 RC – and wanted to share some tips that I’ve learned working with EF1/EF4 along the way.

In EF, you generally either do LINQ to Entities, or LINQ to ObjectQuery – both have their advantages and disadvantages. 

Specifically advantages that I use are for LINQ to Entites is that you can use lamda expression formatting for strong typed retrieval – not so for LINQ to ObjectQuery (see below). 

But LINQ to ObjectQuery has it’s advantages as well – the one big advantage that I take advantage of in my coding patterns is the fact that I can call the .Include() method after the initial query – thus I can “Eager” load tables based on some condition.  Will show more on late .Include() calls in future blog posts.

I believe that this is non-obvious, and I’ve never seen anyone else doing this before – but works very well for the approach I take, and wanted to share in case you need to use LINQ to ObjectQuery and distain not being able to use strong typed query formatting < as I do > in LINQ to Entities.  :)

   1: //----------------------------------------------------------------------
   2: // Example LINQ to ObjectQuery - note not using strong type where clause
   3: //----------------------------------------------------------------------
   4: ObjectQuery<RepositoryFile> selectQuery1 = 
   5:     this.DataContext.RepositoryFiles.Where("item.FileName = 'Word.doc'");
   6:  
   7: //----------------------------------------------------------------------
   8: // Example of LINQ to Entities - note we DO strong type the where clause
   9: //----------------------------------------------------------------------
  10: IQueryable<RepositoryFile> selectQuery2 = 
  11:     this.DataContext.RepositoryFiles.Where(item => item.FileName == "Word.doc");
  12:  
  13: //----------------------------------------------------------------------
  14: // Example of LINQ to ObjectQuery but using LINQ to Entities strong 
  15: //  typed syntax, but then casting it back to ObjectQuery
  16: //----------------------------------------------------------------------
  17: ObjectQuery<RepositoryFile> selectQuery3 = 
  18:     (ObjectQuery<RepositoryFile>) this.DataContext.RepositoryFiles
  19:     .Where(item => item.FileName == "Word.doc");

image

355MB/s of goodness are on on their way…

So, in an effort to boost my development laptops overall speed (it’s not bad but it’s not an i7 <g>) – I decided address my drive speed bottleneck and to look at picking up an SSD (Solid State Drive).

Started doing my research, and found that most the reviews were from 2009.  So in an effort to get the latest and greatest, searched for CES 2010 and SSD and came up with awesome reviews for the Crucial RealSSD C300.

But alas, it was not out (been checking their site daily-ish) – until today!

So, now it has been ordered, should be here by the end of the week… :)  Will review it when I get it.

Print  
Lance
LinkedIn Facebook Windows LIVE Twitter
Blog Code Minimize
Development Links Minimize
Interests Minimize
Personal / Family Minimize
Search Blog Minimize
Twitters Minimize

Print  

Copyright 2008 by Lance Larsen ( A.I. Labs )
Privacy StatementTerms Of Use