May 30 2010

Visual Studio Snippets

Category: Desktop and Server | MobileJoel Ivory Johnson @ 03:11

As a developer if you are not using some type of code generation tools then you are not achieving your true potential. In addition to plugins being available such as ReSharper or CodeRush Visual Studio has had the ability to automate some code generation builtin. One of the facility provided is code snippts. A snippet is a code template. You can define your own for patterns that you find yourself implementing over and over.

If you've never used snippets and want to get started then start off by downloading this file. It's a template for making your own snippets.  Then watch this video demonstrating how to use that file to create and use your own snippets.

 

Tags: ,

May 27 2010

Forward Comaptibility Update for Visual Studio 2010

Category: Desktop and ServerJoel Ivory Johnson @ 02:32

Now that Visual Studio has gone RTM you may find yourself needing to use both Visual Studio 2008 for maintaining your existing Windows Mobile projects while using Visual Studio 2010 for other things. You may have also noted that Visual Studio 2008 does work with TFS 2010. To resolve this problem there's a forward compatibility update for Visual Studio 2008. The update weighs in at 11 megabytes and will allow Visual Studio 2008 to work with TFS 2010.

You can download it from here.

Tags:

May 21 2010

What is the Cloud?

Category: Desktop and ServerJoel Ivory Johnson @ 07:13

The other day I was asked "What is cloud computing." I looked at it as being a concept that you just know like "time." How many of you can give a complete definition of time without referencing a dictionary? A short version of what I told him is that if some one uses cloud services it means they use computers that are some where else owned by some one else.

Cloud

But I heard some one give a nice analogy explaining cloud computing. So I am taking it as my own.

I live in a house. Imagine for a moment that I decided to power the house by means of my own. I'd have to have a generator of some type constructed (solar batteries, hydroelectric generator, windmill, nuclear, what ever). That generator would require some type of maintenance. If I needed more power than the generator could produced then I would either need to suffer through having sufficient power or I would need to add more generators. If I add more generators and then find that many times I don't need them then I have the extra expense of maintaining these extra generators. I don't know anything about maintaining such equipment myself. So I'd either have to be trained in doing so in addition to the other tasks I do around the house or would need to pay some one else to take care of this.

Thankfully that's not how things work at my house. My neighbors and I get our electricity from our power company. I have no idea where it is generated or how it is generated. I honestly don't care as long as it makes it's way to me. If I need to use more electricity than usual in a month it's available. If I use less than I can do so and pay less. I don't have to worry about the space constraints for a generator or hiring staff to take care of it. I just pay for the electricity I need and go on about my business.

That's pretty much how Cloud Computing works in a nutshell. Only instead of purchasing electricity you are purchasing computing and/or storage. You may not know where the computer is actually located. On some plans if more computational power is needed the number of machines allocated can automatically increase for as long as needed and then decrease when no longer needed. There's no need to worry about maintaining the machines as the company that sold them will take care of that.

Tags: ,

May 3 2010

Try Windows Azure and SQL Azure Free for One Week

Category: Desktop and ServerJoel Ivory Johnson @ 14:24

Now is a perfect opportunity to get your feet wet with Microsoft Cloud Computing. You can try SQL Server Azue and Windows Azure free for one week. You can get a Windows Azure bootcamp pass to learn Azure at your own pace between May 3 and May 10. You can find information on the bootcam pass and the learning material  here.

Tags:

May 3 2010

Silverlight Themes Available

Category: Desktop and ServerJoel Ivory Johnson @ 12:03

I've been waiting for this for a while but now the Silverlight 4 themes are now available for download. If you've not seen them before they are some pretty cool looking clean themes that you can use in your XAML applications. If you are looking for the Metro look go for the theme called Cosmopolitan.

 

You can grab them from here.

Tags:

Mar 15 2010

Free Upgrade to Expressions Blend 4

Category: Desktop and Server | MobileJoel Ivory Johnson @ 05:21
If you have Expressions Blend 3 you are in luck. Microsoft will be allowing you to upgrade to Expressions Blend 4 for free.

Tags: , ,

Mar 13 2010

What to Expect from XNA Game Studio 4.0

Category: Desktop and Server | Mobile | XNAJoel Ivory Johnson @ 04:12

XNA Game Studio will be made public within the next one to two months. Here's a few of the updates

  • You'll be able to use the Mouse APIs on Windows Phones. The Mouse API will actually use the Multitouch functionality and return the position of rhte first point.
  • There are two XNA Profiles, Reach and HighDef
    • The Reach profile prvide maximum compatibility across the three screens
    • The HighDef profile is for Xbox/PC. While it lacks WP7S Compatibility it lets you take advantage of the device's capabiities
  • The Multitouch APIs are now available to Windows targets
  • The ZuneHD won't be getting XNA 4.0
  • XNA 4.0 isn't designed to be backwards compatibile with XNA 3.1. Compatibility was sacrificed in the interest of progress.
  • Windows Phones will have the Same aspect ratio but different screen resolutions
    • To the developer both devices have the same resolution. WP7S contains hardware scaling
    • WP7S also contains hardware functionality for scree rotation
  • Custom effects are not available on Windows Phone 7 Series
  • Emulator will be available. You don't need to own a Windows 7 Phone.

 

Tags: , , ,

Mar 2 2010

New MSDN Subscription Level:Essentials

Category: Desktop and ServerJoel Ivory Johnson @ 10:38

Microsoft is making some adjustments to the Visual Studio and MSDN licensing with the release of Visual Studio 2010. For customers that purchase Visual Studio via retail the MSDN Essentials Subscription will be available. MSDN Essentials Subscribers will have access wo Windows 7 Ultimate Edition, Windows Server 2008 R2, SQL Server Datacenter R2, and 20 hours of Windows Azure usage. Presales of Visual Studio will open on 9 March 2010 at the Microsoft store and other select stores.

Found via Somasegar's Weblog

Tags:

Feb 27 2010

Sharing Source Files Among Projects

Category: Desktop and Server | MobileJoel Ivory Johnson @ 06:01

There are times when you will want to share the same source code among several projects. A common way to do so is with a shared assembly; you put common functionality in one project and then share the output among several other projects. But at times this solution isn't suitable such as when you have functionality that you plan to share across more than one .Net runtime (ex: Desktop Framework, Compact Framework, and Silverlight Runtime). For these cases you can copy your source code to the projects for all three run times. But then you end up with three branches of code and may need to make sure thay are synced up with each other.

It is possible to use the same source file in different projects by adding a link for the file from another project so that each project is using the same runtime. Since it is the same physical files changes to the file done from one project are visible to all the projects using the same linked file. Adding a linked file is easy. To link to one file's project from another right-click on the project, select Add->Existing Item and navigate to the file. Once you've found the file click on it and then click on the down triangle on the Add button and select "Add as Link."

A potential problem from using this solution is you may have items in a class that you don't want to be visible in another class. You can selectivly hide sections of code using a few preprocessor directives. As a simple example let's say I made a Windows Form application and I have all of the files from it linked to a second project. I have code in a method that is setting the text on a label. But I want the text to be set differently depending on the project in which it is run. The preprocessor directives I will use are #if, #else, and #endif.

#if App1
            txtMyMessage.Text="Hello from App1";
#else
            txtMyMessage.Text = "Hello from App2";
#endif

In the above code only the C# code in the #else, block will be compiled. The code in the #if block will be ignore. For my first project I want to code in the #if block to be used. To accomplish this I need to add a Conditional Compilation Symbol. I right-click on the project and select Properties. Under the Build tab I can add conditional compilation symbols. I've done this for the first project and have added a symbol named App1. So now the first block of code will get compiled and the second block ignored.

While this solution has it's advantages it is not the end-all solution for sharing functionality across projects. If you find yourself using excessive conditional compilation blocks in your code then you may have reached a point at which it is better off having two seperate source files.

Tags:

Feb 25 2010

Avoid the Undocumented and Unsupported functions

Category: Desktop and Server | MobileJoel Ivory Johnson @ 11:53

Between the MSDN forums and some e-mails that I've received I am seeing a common theme among some of the questions; they deal with undocumented features of Windows phones. My advice when it comes to such features is that it is better to avoid them than to try an figure out how to make something work with an undocumented feature.

One might call me lazy for this, but it is not from laziness that I give this advice. Using undocumented features comes with some risks. One risk is that a program that uses an undocumented feature may have reduced compatibility across devices and firmware versions. My first encounter with this is when I was writing an article on Windows Mobile Power Management. During the time that I was writing it an update was made available for my TyTn II from Windows Mobile 6.0 to 6.1. After the update some of the code examples I had written no longer worked because of changes in the power manager.

If you look through the MSDN documentation on Windows Phones you'll see that it is mixed with the documentation on Windows Embedded CE (which makes since given that that Windows Phone operating systems are derived from Windows Embedded CE. On some of the pages you'll see that a certain feature is supported on Windows Embedded CE but not Supported on Windows Mobile. Sometimes when you will see a feature listed as supported on Windows Embedded CE but not on Windows Phones even though you can find Windows Phones that have the feature implemented. For items like this you'll find that the functionality may be optional (and thus not on all Windows phones) and/or the implementation may have a lot of dependencies on OEM decisions (and may not work the way that you would expect). Another example is customizing a notification icon that shows up in the task bar. Doing this was agains the Made for Windows Mobile guidelines. And if you take a look at Windows Mobile 6.5.3 you'll see that this old technique may not work on newer devices

The ramification of making programs that require functionality that may or may not be present and may or may not behave a certain way when present is that your program could end up with limited compatibility and inconsistent stability across devices.

The same functions are not undocumented and unsupported to every one. OEMs (who are implementing the device, drivers, and portions of the operating system) will have documentation and support for many of the low level functions available in Windows. Manu of these functions aren't mentioned in MSDN documentation. Application developers typically need higher level access to the device and generally less of these functions will be available to them.

I'm not labelling all instances of using undocumented and unsupported features as bad. There are actually quite a few scenarios in which this provides some pretty nice solutions. When applied with discipline everything has its place. So I'm stating this more as a general rule and thing that for the general case these areas of functionality are better left untouched for general development.

Tags:

Feb 24 2010

Visual Studio 2010 Resources RC Resources

Category: Desktop and Server | MobileJoel Ivory Johnson @ 10:59

@MSDN_Forum posted some good resources on getting started with Visual Studio 2010 Release Candidate.

Tags:

Feb 8 2010

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.Parameter name: item

Category: Desktop and ServerJoel Ivory Johnson @ 16:21

I was trying to deply a WCF service to one of my web servers the other day and ran into a problem. I kept getting the following error message:p>

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.Parameter name: item

The problem didn't happen on my local machine but did on the web server making it a little difficult to figure out what was causing it. It happened on the server because my web server is in a shared hosting environment in which case the WCF service also needs to know the host header. To do this I navigated to <system.serviceModel> in the web.config and added the following:

<serviceHostingEnvironment>
<baseAddressPrefixFilters>    
    <add prefix=http://MyHostHeader />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

Tags:

Dec 27 2009

Handling Cookies with Redirects and HttpWebRequest

Category: Desktop and ServerJoel Ivory Johnson @ 15:08

The HttpWebRequest handles redirects automatically. That's usually a nice feature but it can actually get in the way when the web server is setting cookies in the same response in which it is sending a redirect. For some odd reason the HttpWebRequest object will totally discard cookies that are set with a redirect response. I ran into a problem with this when I was working in some code that interfaced to Google Voice and it was driving me crazy since I didn't know where the problem was coming from.

Once I figured out what was happening the solution to the problem was simple. The first step is to disable the class's automatic response to redirect request. When a response is returned from the class it's necessary to check the response to see if it includes a redirect and if so create a new request. Since a redirect could occur more than once it is necessary to do this in a loop. With each new WebRequest that is created it is necessary to set the CookiesContainer member.

A simplified version of my code looks like the following:

HttpWebRequest GetNewRequest(string targetUrl)
{
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUrl);
     request.CookieContainer = SessionCookieContainer;
     request.AllowAutoRedirect = false;
     return request;
}


HttpWebRequest request = GetNewRequest(targetUrl);
HttpWebResponse response= (HttpWebResponse)request.GetResponse();

while (response.StatusCode == HttpStatusCode.Found)
{
     response.Close();
     request = GetNewRequest(response.Headers["Location"]);
     response= (HttpWebResponse)request.GetResponse();
}

//--At this point the redirected response is ready to be used

Trying to perform this same thing on the .Net Compact Framework is a little more challenging since it doesn't support cookies at all. I'll discuss the solution I used in another post within the next few days.

Tags:

Nov 30 2009

Improved FindControl for Windows desktop and mobile

Category: Desktop and Server | MobileJoel Ivory Johnson @ 14:45

A few days ago I posted some code containing an implementation for a Windows Forms version of FindControl. Aviad P. pointed out a correction and a way that the routine can be simlified. While I had intended the original code to do abreadth-first search it was doing a combination of depth and breadth. The functionality could also be implemented with a single loop. The result of the messages the resulting code from our communication is below.

Control FindControl(string target) {
    return FindControl(this,target);
}
static Control FindControl(Control root, string target){
    if(root.Name == target)
        return root;
    List currentLevel = new List<Control>() { root };
    while (currentLevel.Count > 0)
    {
        Control match = currentLevel.FirstOrDefault(x => x.Name == target);
        if (match != null) return match;
        currentLevel = currentLevel.SelectMany(x => x.Controls.Cast<Control>()).ToList();
    }    return null;
}

Tags: ,

Nov 17 2009

Up to 800 Answers in the Microsoft Forums

For those that don't know I've been active in the Microsoft Forums for a little over a year.  I've been keeping track of how many answers I've provided. It took me about a year to reach 500 answers in August. It is now November and I am up to 800 questions.  Im active in more Windows Phone related forums now. That's why my rate of answering questions has gone up.

800 questions

View my profile here.

Tags: