lunes, octubre 26, 2009

SDDN Sydney November Meeting

 

[NOTE: From now on, we will be publishing all Sydney SDDN info on http://sydney.sddn.org.au, please subscribe to the RSS. Starting next month I’ll stop publishing announcements on my blog]

For this month, Justin King will be speaking about RIA Services and Miguel Madero will talk about different Testing Approaches for Silverlight Applications.

As usual we will meet the first Tuesday of the month at the Crown Hotel (map) in 162 Elizabeth Street at 6:00 pm to get some dinner and start the discussion followed by the talks at 6:30 pm.

Please RSVP on Facebook.

.NET RIA Services – Building Data Driven applications in Silverlight 3

Learn how Microsoft is simplifying the traditional n-tier application pattern by bringing together ASP.NET and Silverlight. See the new application framework that removes some of the complexity for connecting to your data layer and see patterns for working with data, implementing reusable and independently testable application logic, ease of client side validation and  see how this relates to other patterns such as MVVM. We are sure this will lead to lots of architecture debates and pros/cons of this framework.

Testing in Silverlight 

At first sight it looks like we don’t have a lot of options to test Silverlight Applications. Although it’s not an easy task, we do have a lot of alternatives. In this demo oriented talk, Miguel will present different approaches, techniques and types of tests from simple Unit Testing and Mocks to Visual Tests, UI Automation, REPL Testing, Performance, Memory Leaks and Recorded Web Tests.

martes, octubre 06, 2009

Geek Events in Sydney

 

Some people have asked me about making the information about events available. I maintain a separate calendar for Geek Events and I decided to make it public. You can use the following links respectively to subscribe from an RSS Reader, Add it to a Calendar App or just view the page in HTML. For more information about the links read this page.

This is the embedded version of the calendar.

Keep in mind that ATM this is just my personal list of events, it certainly doesn’t represent everything going on in Sydney. Please feel free to suggest me new events.

sábado, octubre 03, 2009

SDDN Sydney October Meeting – Tools

 

This month we’ll have three talks about tools.

As usual we will meet the first Tuesday of the month (October 6th) at the Crown Hotel (162 Elizabeth St). We’ll get there at 6:00 pm to start some open discussions and get a meal, to go on with the talks from 6:30 to 8:30 and then continue with the Networking part of the event.

Please confirm your assistance through the mail list (ozsilverlight@ozsilverlight.com) or the facebook group.

domingo, agosto 23, 2009

SDDN Sydney September Meeting - Lightning talks

 

For our September meeting we will do some lightning talks. You can't miss it. These are some of the talks we'll have.

  • Expression Design – Lee Goodaman
  • Rx Framework – Ali Shafai
  • Debugging Memory Leaks – Miguel Madero
  • Dashboards – Chris Anderson
  • Html-XAML Converter - (not confirmed)
  • New Network Stack – Paul Glavich
  • Silverlight with Azure – David Burela
  • Flex - (not confirmed)

The best is that we can still make some room for yours. Lightning talks can be the perfect opportunity for virgin speakers to have a quickie without worrying for having to prepare for an hour long performance. Experienced presenters will definitely have something to say and 10 minutes is the perfect time to deliver a Wow demo.

If you want to speak, just leave comment, reply in the mailing list or shoot me an email. If you’re not sure of what to speak about we can bounce some ideas.

  • Validations
  • Behaviours
  • Using Blend
  • Sketchflow
  • Designer/Developer Workflow
  • Games
  • MVVM
  • Animations
  • Making your app look good
  • Testability
  • Architecture
  • Design Tips
  • Integrating Silverlight with non-.NET Backends
  • Making money with Silverlight
  • Scaling RIA Applications
  • RIA Services
  • Debugging in Silverlight
  • Finding and Avoiding Memory Leaks
  • Tools for Silverlight
  • The coolest thing that you found last week
  • Creating iPhone apps using MonoTouch and Silverlight

As always, we’ll see you on the first Tuesday of the month (September 1st) at the Crown Hotel. Try to get there early and leave late. The talks start at 6:30, but we meet half hour before to get some beers and have a chat. After the presentations we usually have dinner and discuss further the topics of the day.


View Larger Map

miércoles, julio 22, 2009

Silverlight Designer and Developer Network Sydney - August Meeting

This month Jose Fajardo from Cynergy Systems will talk on “Don't lose site of what's important, Interactivity and Experience” at the Crown Hotel. Here are all the details:

Crown Hotel
162 Elizabeth St
Sydney
August 4th. 6:00 pm for drinks, 6:30 for the talk
Use the registration tool on the top of the SDDN Site.


View Larger Map
 

If you are interested in a particular topic or have any suggestions for future meetings, please let us know.

Here are the details of the talk.

Don't lose site of whats important, Interactivity and Experience
by Jose Fajardo

Patterns, Frameworks, MVVM, Prism, MEF, these are all great aides to helping us deliver a RIA solutions, BUT what they all lack is a designers perspective. Experience has shown me that the majority of a project is spent in xaml and creating interactivity through animations and styling. The view model is lean and clean BUT the view layer through evolutions of the WPF/Silverlight technology has gotten much heavier and more complex. I want to walk through with you the new features in SL and Blend from the perspective of bring order to the chaos in our view layer, and in so doing helping extend our frameworks to be relevant for designers.

lunes, junio 29, 2009

Silverlight Designer and Developer Network Sydney - July Meeting

This month Ali Shafai will talk on Silverlight, Prism and Unity and Miguel Madero will do a mini presentation on a less attractive, but important topic, Security in Silverlight at the Crown Hotel. Here are all the details:

Crown Hotel
162 Elizabeth St
Sydney
July 7th. 6:00 pm
Use the registration tool on the top of the SDDN Site.


View Larger Map
Silverlight, Prism and Unity
The holy trinity
by Ali Shafai

Ali will be building a LOB application with Silverlight 3 using prism (with MVVM) and will be showing how to use Unity to inject the dependencies into your classes. The application will have the skeleton of a minimal prism application.

I will also share some of my findings on more advanced topics such as:

  • dynamically creating views
  • region managers and how to use them
  • best practices on wiring events
  • loading essential data before application loads
  • showing a splash screen while the essential data is being loaded
  • tricks on styling your controls beyond what you thought possible
  • How to break the application into smaller assemblies

Ali Shafai started programming a few months before he could touch a computer, during this time, he was the programmer, the program and the computer. Then he got his hands to real computers and learned COBOL, PL/I, BASIC, C, Prolog, X86 Assembly, C++, Object Pascal, C# and Python in that exact order. He can still remember the first program he wrote and the joy he felt writing it. He moved to Sydney in 2001, was introduced to XP, TDD, CI and some other acronyms. In 2004 the company he was working for (EDI) won the 2004 Consensus Software Award and Microsoft Realizing Potential Award, he then joined forces with Chris Anderson and Mark Wallis and formed Peer Placements, a software talent management company. He is still enjoying programming and does freelance software development. His latest joy is Silverlight/Prism/Unity.

Security in Silverlight
by Miguel Madero

Miguel will show in several demos different Application Security concerns specific to Silverlight Applications commonly overlooked. He will teach us how to avoid being hacked and protect our data with some basic tips. These are some of the topics covered in this lightning talk:

  • Common Hacking Techniques
  • Security as an Aspect
  • End to end data protection
  • UI Level Security
  • Authentication Mechanisms
  • Authorization and User Context
  • Service Level Security

Miguel has been programming for fun for the last 15 years when he realized that it was better to play with QBasic and Pascal than Prince of Persia. He found out that he could actually get some money out of this hobby so he started a couple of web companies 5 years later and then a Development Shop before moving to Australia to work for Readify where he’s now having fun coding some of the coolest projects in Australia. He discovered Silverlight two years ago and it’s still keeping him busy and entertained.

martes, mayo 26, 2009

Silverlight Designer and Developer Network – June Meeting

 

Next Tuesday, June 2 at 6:30 at Microsoft in Sydney (1 Epping Road, North Ryde NSW) we will have the SSDN Sydney’s June Meeting. This time Tatham Oddie will be talking about the new Out of Browser features in Silverlight 3 and Sergey Klementiev will presenting “LOB applications in Silverlight Lap around middle tier”. You will also have the opportunity to win a copy full of Expression 2 Suite and the best of all network amongst your Silverlight peers. So don’t miss it.

miércoles, mayo 13, 2009

First Virtual Silverlight Designer and Developer Network Meeting

UPDATE 18/05/09: this is the link for the event, please register before the meeting and be sure you have Live Meeting installed on your computer. Some people have asked me about the place and how is this a Virtual Event. We’ll be using this tool called Live Meeting that allow us to interact with audio, video and share the desktop, polls, Q&A, etc, but rather than trying to explain what Live Meeting is, you can just try it tonight. Just register and follow the instructions.

SDDN it’s doing great after several meetings and trainings in Melbourne, Adelaide, Perth and Sydney we decided to try something a bit different that will give the opportunity to everyone to participate. Including designers and developers from Canberra and other cities, where we have not done any events yet.

When and Where?

May 18, 2009 at 9:00 pm Sydney Time. This will give enough time to everyone in the West Coast to get home, have dinner and be ready for the meeting. We’ll do it through Live Meeting. I’ll update this post with the link ASAP.

Format

Instead of the typical presentation, we decided to have an open discussion around different topics. Each topic will have a different moderator who will do a brief introduction and open the floor for discussion. The moderator won’t be answering all the questions, he’s just a facilitator for the group, but also another participant with experience in the discussed topic. We’ll have three different topics during the meeting.

Who will participate?

Everybody that has an interest in Silverlight can attend. This is a space for Designers and Developers. In the last meetings we had a bigger presence of developers, but we’re really targeting both audiences, so you can expect topics of mutual interest.

miércoles, abril 29, 2009

First Meeting of Silverlight Designer and Developer Network in Sydney

Our next meeting is on Tuesday the 5th of May in Sydney

What's on?

This meeting we will see Chris Anderson (blog), from Peer Placements will be discussing advanced styling in Silverlight for both developers and designers. Topics will cover styling strategies, tools, advanced xaml techniques, fashions, and a discussion on designing user experiences.  

Jordan Knight (Blog) from Readify will run through the exciting new features in Silverlight 3, and demonstrate how you might use them in a real working reference application. This in depth session will cover perspective 3D, pixel shaders, navigation features, out of browser and much more. Other concepts like Model-View-ViewModel, dependency injection, unit testing and designing template friendly (read designer friendly) applications will also be touched upon.

WIN!

Attendees will have the opportunity to win a copy of the full Expression 2 suite, worth $1000!

When and Where?

The date and time: Tuesday May 5 at 6:00 PM for a 6:30 PM start.

The venue is the Pyrmont Bridge Hotel, Level 2, Pyrmont, NSW. See map for details.

Attendance is FREE, but please RSVP by entering your details in the registration in the registration tool on the site (http://www.sddn.org.au) or send an email to info@sddn.org.au.

Who will this group interest?

The focus of the group is not just on developers. Traditionally developers have had great community support, whereas designers not so much… now that Silverlight 2 is out we plan to change this.

Silverlight is as interesting for developers as it is for designers. Due in part to Silverlight’s excellent separation of design and development concerns we have new problems to solve around finding the best ways to work together.

To this end the SDDN will facilitate an ongoing discussion and promote the development of ideas and best practices for anyone who works with Silverlight.

To register interest head over to http://www.sddn.org.au. Use the registration tool in the header of the site.

viernes, noviembre 28, 2008

Windows and TimeZones

People from IT and DB guys have told me they can't rely on Windows when it comes to TimeZones and when time zone adjustments are necessary. I've seen systems re-implementing this feature again just to have have more control. At first this seemed unnecessary for me, but I just noticed today, talking with my sister in law that I had the wrong time of Argentina.

image
The main clock is Sydney in the image is Sydney.

I thought the cause was that Argentina was an additional clock and not my "main clock", so I change that and noticed that according to windows Buenos Aires start's the Daylight Savings beings on December. How hard is for windows to get this right?

image

According to the first page I found in Google (http://www.timeanddate.com/worldclock/) Argentina moved to Daylight Saving and the time is 8:29 not 7:29.

image

How disappointed. Well, let's give it another try and manually update it.

image

Wait for a while

image

Doesn't work :(

 image

Let's try another server

image

Same with all their servers. Failed. Why do they need so many servers only for time? If there were a valid reason, why would the user have to select a different one? Is it like Microsoft saying, "probably we will get it wrong, so we will give you more options just in case (which by the way might also fail)" or "probably you need to create your own time server in case you want to run an anarchy and don't want to go to daylight saving periods". This Internet Server's won't fix our Daylight Saving, they care about time not time zones, so they actually have an other purpose and could bring new problems for systems where seconds or milliseconds are important.

I remember that Microsoft distributed a patch for Windows and Windows Mobile to be able to adjust properly for the Daylight Saving in Sydney. Probably I need a patch for my recently configured Time Zone that went to summer time two months ago. Windows Update? Nothing

Well this isn't not that bad, Microsoft, has this Server product that works fantastic. But they still got it wrong (also in windows seven).

image

Now a typical discussion would go like this:

Customer: We need to adjust the {Enter Feature Heare} based on the time zones of our new markets.  
NET Guy: Microsoft is super cool. We can just rely on them for this time zone thingy and we don't care about it. When we do datetime comparisons it takes into account the TimeZone and when saving it or sending it over the wire that information is also considered and we can easily adjust it to UTC, transport or Local time.
IT Guy 1: That doesn't work. (Because .NET relys on the OS info)
IT Guy 2: All we need to do is keep patching the system for all our servers and client machines on time for all our different markets
IT Guy 1: That's a pain.
IT Guy 3: We better move the time manually and disable the auto adjust for daylight saving.
IT Guy 1: That's a pain in the !@$%!@(~. 
IT Guy 4: .NET Guy, could you do it for us?
NET Guy: I can't it's too complex. If MS didn't got it right it's because it's super dupper complex and we better not code it ourselves, it's going to be more painful. It's better to install that patches, that's why MS provides it.
IT Guy 4 (taking advantage of the super hero pride of the dev): Com'on you're better than Microsoft, you can do everything (sarcastically smiling)
Customer: Uses the puppy face look
NET Guy (all full in drunk in pride and self-steem): I am going to do it.

This is a code that should work on DotNet, but it doesn't.

// Buenos Aires at 19:45 (UTC -3 +1 For Daylight Saving) == UTC 21:45
var argentinianDate = new DateTime(2008, 11, 29, 19, 45, 0, DateTimeKind.Local);
Console.WriteLine(argentinianDate.ToUniversalTime());

// UTC 21:45 == 19:45 Buenos Aires
var utcDate = new DateTime(2008,11,29,21,45,0,DateTimeKind.Utc);
Console.WriteLine(utcDate.ToLocalTime());

Console.ReadLine();


image 


So if the OS gets it wrong, you will get it wrong also in .NET.




  1. There're other options hacks.


    According to this blog post. You can use this tool called "tzedit" to create a custom time zone and decide when you want to start your Daylight Savings. That way you and your family can start saving at a different time of the year, you will be probably late for work, but saving light.


  2. A blog from Microsoft even mentions as Option 1 to move your TZ to GMT-2.


  3. There other option is to install a patch, that isn't supported on Windows Vista and Server 2008 systems and it's only targeted to enterprise suers. What? By the way, this post was published one day before the daylight saving started.

sábado, octubre 25, 2008

Reflector Add-In's Save the Day

Recently my brother had a problem with an old winforms application we developed to help him upload images and product information. The issue was really simple, once I had a chance to run and debug the application the issue was evident. The app was using FTP to upload pictures to the website and the credentials were invalid.

image

Easy I thought, go to the config file and change it, it'll probably be encrypted and might give me a hard time to hack. I opened it and didn't find anything. Let's open reflector and see what's happening I have a Stack Trace to start with, but that wasn't the best place. I remembered the name of the user, so the Reflector Add-in Code Search quickly pointed me to the right place:

image

From there a double click sent me to the method

image

Great. Someone thought it was safer to hard code it instead of using the web.config.

Then the question remains, how can we change it? The proper solution would be to open Visual Studio, connect to TFS, get the sources, edit recompile and sent back the new version. However I don't think the latest version is stable, so I would need to search for a label to get the latest deployed version. I'm running on a really slow connection now and that would probably take a while, beside it's sunday and I'm ready to go surfing (or at least try to).

Option 2. In that same screen just open Reflexil (another Reflector-Addin) locate the IL line that sets the password (this is not as hard as it sounds) and edit the string.

image

Then we simply save the assembly. This was probably the hardest part, this was the first time I used Reflexil and I was expecting the Save As option to be right next to the place where I do the edit, in the Tools menu or a toolbar, I finally found the option when clicking file in Reflector.

image

After that, just save the file e-mail it and ready to go, but then I had the brilliant idea of write this post and it took me more time than the fix.

You can find this an other reflector add-ins in http://www.codeplex.com/reflectoraddins

lunes, octubre 06, 2008

Learning with Tests (MessageBroker in NInject)

A great way to learn a few coding practices is to get an open source project (one good, don't get the first thing you see en codeplex) and trying to understand the code, how they apply patterns, use certain classes or reuse code through the project. The best way to start (with most of the good projects) is with the tests.

I have been playing lately with Ninject, a Dependency Injection Framework,  it's well designed, auto-documented and documented (probably too much documentation at the code level), the downside is that the wiki, the blog posts and tutorials barely cover the basics. However, the tests do a good job to describe the project at a higher level. As an example an example we can see one of the tests for the MessageBrokerModule.

        [Test]
public void OnePublisherOneSubscriber()
{
using (var kernel = new StandardKernel(new MessageBrokerModule()))
{
PublisherMock pub = kernel.Get<PublisherMock>();
Assert.That(pub, Is.Not.Null);

SubscriberMock sub = kernel.Get<SubscriberMock>();
Assert.That(sub, Is.Not.Null);

Assert.That(pub.HasListeners);
Assert.That(sub.LastMessage, Is.Null);

pub.SendMessage("Hello, world!");

Assert.That(sub.LastMessage, Is.EqualTo("Hello, world!"));
}
}


The code is really easy to follow, first he asserts that the kernel can create instances of the publisher and subscriber, then the publisher should have a listener, the subscriber doesn't have any message and finally he sends a message than the subscriber should receive. The other tests like OnePublisherTwoSubscribers and ManyPubsManySubscribiers are similar.

sábado, octubre 04, 2008

Task Board for Scrum for Team System

 

I have been using Scrum for Team System since beta 1 and I quickly fell in love with that template. It reflects the way we were working, however, there was a big gap in the process, specially when planning for a sprint, we usually did all the prioritizations, sizing, assigning and breakdown of Product Backlog Items using other tools like Mindmanager, Excel or sticky notes.

Recently the guys from Conchango, creators of the template, released a beta of a tool that will help use fill that gap. It's a cool WPF tool that will interact with TFS and allow us to create and edit sprint backlog items.

I don't think the tool will replace Mindmanager and the whiteboard still will be an indispensable resource, but I don't think I would like to go back to Excel to edit my items (well lets see how it goes after a couple of sprints of working with it).

When I was looking at the tool I was thinking, mmm yes, you can move a task from In Progress to Done, that's cool, but excel can do much more specially with pivot tables and reports, but then I saw the rest of the features, like changing to Planning Mode to start adding Product Backlog Items, automatically doing the binding between product backlogs and sprint backlog items, searching, filtering and reporting and I have to say, this tool is something worth to try. So in two weeks I'll let you know more about this.

I'm still not sure about the pricing scheme and I'm a bit concern. At the moment is beta, and you can simply request a license, but it doesn't seem something that will remain free. I will need to consider if this is a tool that every developer on the team will be able to use.

Crispin Parker from Conchango published some useful webcasts and a post with more info on the product.

By the way, it would be great to get a surface to use this tool.

lunes, septiembre 15, 2008

Sydney ALT.NET Group

The newest user group in Sydney will have it's first meeting on September 30 at the Thoughtworks offices. Richard Banks published the agenda and details in the group's blog, but what exactly is an ALT.NET Group? Why do we need another one if we have generic groups like Sydeny's DNUG and RDN or technology specific groups like OzTFS and OzSilverlight? 

ALT for Alternative has caused a lot of controversy that lead to misunderstanding, so let's better start for what it's NOT, it's not the anti-microsoft group, its not the open source community tired of Java wanting to use something better (altough some of them might be part of the group), its not a group that loves NHibernate and hates Entity Framework.

Simply is a group of developers that like to look for better ways to do their work, keeping a "get things done" approach and commonly identified with agile practices, continuous improvement and the pragmatic thinking, people who "use what works while keeping an eye out for a better way".

If you feel identified with these ideas, come and join us or if you're not in Sydney, find an ALT.NET User Group or create a new one.

In our first meeting we will have talks about Ruby and Mocking.

Recommending reading/listening:

martes, septiembre 09, 2008

C# and more dynamic features (C# 4.0?)

static void Main(string[] args)
{
    dynamic
    {
        object myDynamicObject = GetDynamicObject();
        myDynamicObject.SomeMethod();         // call a method   
        myDynamicObject.someString = "value"; // Set a field
        myDynamicObject[0] = 25;              // Access an indexer
    }
}

How cool is it? I don’t know, probably will be something dangerous if not used with care, C# depend a lot of compile time checking.

To see more about this see Charlie Calvert’s Blog

martes, agosto 19, 2008

Cool Site with great controls, components and skins - www.wpfstyles.com

Logo If you haven't you gotta check www.wpfstyles.com by Andrew den Hertog. The just released site oriented to the dev community, is quickly becoming a great resources for controls, components and skins sharing for WPF and Silverlight. Go give it a try and if you have something, share it and if you need something, probably you will find it here. If you don't check it back later, the site is new and people is starting to publish content, so don't freak out if you don't see 1,000 controls yet.

Personal Note/Public Apology: There has been a while without a post, because I have been traveling a lot and didn't have Internet connection in several of those places. I just moved to another country and I'm still getting installed, but you can expect frequent posts again.

martes, agosto 05, 2008

Using the ASP.NET Providers from Silverlight - Membership, Roles and Profile

Brad Abrams wrote an excellent post about how to set everything in the server and client to consume this services. He covers for areas:

1. Login\Logout
2. Save personalization settings
3. Enable custom UI based on a user's role (for example, manager or employee)
4. A custom log-in control to make the UI a bit cleaner

These Services are simple wrappers to the actual providers and only provider the most common functions (i.e. Membership has login/logout, but not CreateUser), but would be pretty straightforward to extend them. If your application is not 100% SL and you have parts already build in ASP.NET you can easily combine them, for example, use the Login controls to Authenticate users, but use the Role Services to restrict certain functions depending on who is who.

sábado, agosto 02, 2008

Value Converters - More Simple Samples

This is the third of several posts related to Value Converters. Reading the posts in order can be useful, but not necessary. The first post, Databinding 101, served as an intro to the problem and the second, DefaultValueConverter, introduced the basics about ValueConverters. Now we're ready to present several examples to give you more ideas of where ValueConverters can be used.

 

ImageSourceConverter

The Image control doesn't update its Source property automatically, so setting it to a path will work only the first time, but if the path in your datasource changes it won't be reflected, well the ImageSourceConverter will help you. This is really a bug that will be corrected in SL RTM, but meanwhile this is another place to use ValueConverters.

public class ImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string path = (string)value;
return new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}


VisibilityConverter



You might want to change the visibility of a control based on a boolean property of your objects, this is simple with the VisibiltyConverter:



public class VisibilityConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return Visibility.Visible;
return Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}


StringFormatConverter



This is one of my favorites. ASP.NET and Winforms use a StringFormat that let you display properly numeric or date objects (use these cheat sheet as reference). With this converter for example you can simply pass the ConverterParameter of C to format a numeric value as currency and will work similar to the way it does in the mentioned platforms. This is another convertar that I feel should be part of the Binding object.



public class StringFormatConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string formatString = parameter.ToString();
return String.Format("{0:" + formatString + "}", value);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new InvalidOperationException("This Convert supports only OneWay binding");
}
}


StringFixedLengthConverter



For some controls you might want to specify a fixedlength for the text. You can do it with the StringFixedLengthConverter setting its ConverterParameter. This is rarely useful...



public class StringFixedLengthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return GetFixedLengthText((string)value, int.Parse((string)parameter));
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

private string GetFixedLengthText(string originalString, int maxChars)
{
int textLength = originalString.Length;
if (textLength > maxChars)
return originalString.Substring(0, maxChars - 3) + "...";
int padding = (int)Math.Round((maxChars - textLength) / 2d);
string paddingChars = "";
for (int i = 0; i < padding; i++)
paddingChars += " ";
return paddingChars + originalString + paddingChars;
}
}


IfNullChangeColorConverter



This is not common, but we had run into cases where we need to change the color of a control in case a property is null. This could be combined with the DefaultValueConverter presented yesterday. Imagine you will display a DefaultValue of 'Not Available' if the person doesn't have a phone number, but you also want to greyout the text to emphasize the lack of data. To create this effect, specify the desired color in the ConverterParameter (if no value is specify grey will be used).



public class IfNullChangeColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return new SolidColorBrush(GetColor(parameter));
return new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
}

public Color GetColor(object parameter)
{
byte[] argbColor = new byte[4];
if (parameter != null)
{
string[] argbColorStrings = parameter.ToString().Split(',');
for (int i = 0; i < 4; i++)
{
argbColor[i] = byte.Parse(argbColorStrings[i]);
}
}
else
{
//#FFC0C0C0
argbColor[0] = 255;
argbColor[1] = 192;
argbColor[2] = 192;
argbColor[3] = 192;
}
return Color.FromArgb(argbColor[0], argbColor[1], argbColor[2], argbColor[3]);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}


Creating ValueConverters is really easy and these examples are meant to show that, rather than to try to cover every scenario. However, ValueConverters have many drawbacks. You can't combine them (e.g. use StringFormat and DefaultValue for the same property because the binding object only allows one) and won't scale easily (you will end up with lots of classes for super simple scenarios). Tomorrow I will talk about a pattern that can overcome these drawbacks.



You can download the attached code here with the last examples and the classes presented here.


I format my code using Manoli's website


Don't forget to vote for your favorite topics for this column.

viernes, agosto 01, 2008

Professional Visual Studio 2008 for Sale Now.

As I mentioned before I was invited to write the chapters of Team System in the book Professional Visual Studio 2008, well the book is finally out now and you can get it in Amazon, Barnes & Noble or your favorite bookstore. This is the Table of Contents:

Table of Contents

Part I: Integrated Development Environment

Chapter 1: A Quick Tour
Chapter 2: The Solution Explorer, Toolbox, and Properties
Chapter 3: Options and Customizations
Chapter 4: Workspace Control
Chapter 5: Find and Replace, and Help

Part II: Getting Started

Chapter 6: Solutions, Projects, and Items
Chapter 7: Source Control
Chapter 8: Forms and Controls
Chapter 9: Documentation Using Comments and Sandcastle
Chapter 10: Project and Item Templates

Part III: Languages

Chapter 11: Generics, Nullable Types, Partial Types, and Methods
Chapter 12: Anonymous Types, Extension Methods, and Lambda Expressions
Chapter 13: Language-Specific Features
Chapter 14: The My Namespace
Chapter 15: The Languages Ecosystem

Part IV: Coding

Chapter 16: IntelliSense and Bookmarks
Chapter 17: Code Snippets and Refactoring
Chapter 18: Modeling with the Class Designer
Chapter 19: Server Explorer
Chapter 20: Unit Testing

Part V: Data

Chapter 21: DataSets and Data Binding
Chapter 22: Visual Database Tools
Chapter 23: Language Integrated Queries (LINQ)
Chapter 24: LINQ to XML
Chapter 25: LINQ to SQL and Entities
Chapter 26: Synchronization Services

Part VI: Security

Chapter 27: Security in the .NET Framework
Chapter 28: Cryptography
Chapter 29: Obfuscation
Chapter 30: Client Application Services
Chapter 31: Device Security Manager

Part VII: Platforms

Chapter 32: ASP.NET Web Applications
Chapter 33: Office Applications
Chapter 34: Mobile Applications
Chapter 35: WPF Applications
Chapter 36: WCF and WF Applications
Chapter 37: Next Generation Web: Silverlight and ASP.NET MVC

Part VIII: Configuration and Internationalization

Chapter 38: Configuration Files
Chapter 39: Connection Strings
Chapter 40: Resource Files

Part IX: Debugging

Chapter 41: Using the Debugging Windows
Chapter 42: Debugging with Breakpoints
Chapter 43: Creating Debug Proxies and Visualizers
Chapter 44: Debugging Web Applications
Chapter 45: Advanced Debugging Techniques

Part X: Build and Deployment

Chapter 46: Upgrading with Visual Studio 2008
Chapter 47: Build Customization
Chapter 48: Assembly Versioning and Signing
Chapter 49: ClickOnce and MSI Deployment
Chapter 50: Web and Mobile Application Deployment

Part XI: Automation

Chapter 51: The Automation Model
Chapter 52: Add-Ins
Chapter 53: Macros

Part XII: Visual Studio Team System

Chapter 54: VSTS: Architect Edition
Chapter 55: VSTS: Developer Edition
Chapter 56: VSTS: Tester Edition
Chapter 57: VSTS: Database Edition
Chapter 58: Team Foundation Server

I also had a chance to review a couple of chapters. Writing a book was a great experience and I hope you will enjoy the results.

As Dave Gardner mentioned there are books available for instructors from the publisher and other's through the books's page. Nick Randolph mentioned later than they will have books to give away in TechEd Australia and TechEd New Zealand.

Value Converters - Default Value Converter

This is the second of several posts related to Value Converters. Reading the posts in order can be useful, but not necessary. As we saw yesterday sometimes we need to specify a DefaultValue for cases where there's no value specified by our datasource. This is a look of the application with data, then without a phone number and the third pic shows how would it look with the DefaultValueConverter.

With data:

Without data:
image
Wit DefaultValueConverter:
image
The change in XAML is really simple, this is the original line:
<TextBlock Text='{Binding Mode=OneWay, Path=PhoneNumber}'/>
 
This is the modified line:

<TextBlock Text='{Binding Mode=OneWay, Path=PhoneNumber, ConverterParameter="[Not Available]", Converter={StaticResource DefaultValueConverter}}'/>

We also need to add a Resource that holds the reference to our DefaultValueConverter

<UserControl.Resources>
<SilverlightApplication14:DefaultValueConverter x:Key="DefaultValueConverter"/>
</UserControl.Resources>

We added two attributes to the Binding object, a ConverterParameter and a resource that will hold an instance of our ValueConverter. A ValueConverter is simply a class that implements IValueConverter and consists of two methods Convert and ConvertBack. ConvertBack is used with TwoWay BindingMode, but we won't use it here. The Convert method simply checks if the value is null and if it is, it returns the parameter which will hold the object specified in the ConverterParameter.

public class DefaultValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return parameter;
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

In WPF the Binding object has a DefaultValue property, so there's no need to create a ValueConverter there.


You can download the attached code here
I format my code using Manoli's website
Don't forget to vote for your favorite topics for this column.