Nermin's .Net

My Thoughts on .Net and Software Development - correct spelling is optional

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2011

Using Lambda Expressions in Csla.Net property registration

With Csla.Net 3.5 came a concept of "managed properties", properties that automatically online search engine optimization seo services provider seo in india handle business and authorization rules, without additional code reguired to wire up all those notifications.  In 3.6 managed properties were extended to allow serializing Csla.Net objects accross different runtimes (.Net to Silverlght).

The thing I do not like about property registration was, while it resembled dependency properties from WP/Silverlight, it required string constants or property names.  And string constants as we know are BAAD! 

So, in 3.6.2 we are adding another way to register properties - using Linq Expression API!  Lets take a look at the example:

    private static PropertyInfo DescriptionProperty =
    RegisterProperty(p=>p.Description);
    public string Description
    {
    get { return GetProperty(DescriptionProperty); }
    set { SetProperty(DescriptionProperty, value); }
    }
    

Besides being shorter, this syntax supports full Intellisense, as the only expressions allowed are Property expressions of properties belonging to the object. This is compile time safe.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by ndibek on Wednesday, March 04, 2009 1:23 PM
Permalink | Comments (2) | Post RSSRSS comment feed

Adding Custom Themes Support to your WPF Application

The greatest thing about Windows Presentation Foundation is that when compared to Windows Forms, it finally gives us the freedom of easily designing rich UI, that differs from same old Winforms we have been seeing from Win 95 with affordable seo new york slight re-styling. We finally have a true vector based UI, that allows us to manipulate each screen element in thousands of different ways through visual effects, animations, scaling, custom layouts etc.

But with this Great Power comes even larger responsibility. Yes we can do all these things, but we also need to assure that our UI looks consistent: If we find this really cool looking buttons library, we need to attorney search startup lawyer new york christian lawyers assure that the Tree Control that we render next to it is styled appropriately to match it, as well as list box, check boxes scroll bars...

We do not want our new UIs to be a mix of every color in the rainbow that look like water color painting of a kindergartner. We need a professional 21st century UIs. Unfortunately most of us developers are superbly creative when it comes to roof repairs leeds rv leak repair rv rubber roofing complex algorithms, while our artistic skills lack far behind. Third party controls that support custom Themes might have been a solution to this problem in Windows Forms world, but do we really have to go there in WPF? Another great thing with WPF it adds native support for custom themes. Basically you define your basic layout, drop your controls on the screen, and then similar to CSS in the web world, you define custom styles for your control in the Resources section of your XAML code. If only we had a nice library of WPF styles that we could use...

 



Well that is where "WPF Themes" Library - Open Source Project hosted on CodePlex comes in.  First it is a library of a dozen custom UI Themes for most of the standard WPF controls, allowing us to customize the look and feel of our WPF UI without touching our screens XAML.  What more the library actually comes with a Theme Manager, accentseo that allows us to dynamically load and bind our custom Themes at runtime.

How can we use these Themes?  Obviously first download WPF Themes Library project from http://www.codeplex.com/wpfthemes and include it in your WPF Solution. Then it is a matter of you deciding how do you want to select and load custom Theme at runtime.  For the purpose of this example lets presume that we want to allow our Application user to select any of these Themes at runtime in a form of the Drop Down box that we place at, lets say, top right corner of the application main screen.

So lets define this DropDown:

Ok, so if we look at the XAML above you will notice that there is a stack panel that encapulates the label and a DropDown. But wait, there is no event handler for the SelectionChanged event! How do we tell this WPF Theme library to load a theme we select from the DropDown? Well, if we take a look at the source code of the ThemeManager class that is in charge of loading Themes for us, you will notice that it defines/registers a Dependency Property called "Theme". What does that mean? It means that we can just add this propery to our root window, and bind it to the drop down selection, and that is it. Each time we change a selection in our Drop down list of available themes, ThemeManager loads that Thema and applieas it to our WPF application. The two lines of XAML that allow us to define our dependency property are listed below:



    ...

Now the last question is: How do we populate the "Available Themes" Drop Down list? We simply bind it to ThemeManager.GetThemes(), like below:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    themes.ItemsSource = ThemeManager.GetThemes();
}

And simply put - that is it, by placing the code above together with WPF.Themes project in your solution you get great set of WPF themes, that you can simply use in your app, but also customize and extend.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: C# | WPF
Posted by ndibek on Monday, November 17, 2008 3:41 AM
Permalink | Comments (1) | Post RSSRSS comment feed

Sarah gets pranked

Yet another gem from Sarah Palin. I got this one from Aaron. Enjoy!
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by ndibek on Sunday, November 02, 2008 12:18 AM
Permalink | Comments (0) | Post RSSRSS comment feed

TeamCity - an excellent .Net Continuous Build Environment

Having worked with CruiseControl.Net for years, and understanding the slow adoption of that valuable tool due to simply too high learning path for soemone who needs to quickly setup an automated build system, TeamCity promised to be an interesting alternative.

Naturally there is a TFS also, but the problem with the TFS is that it is huge, provides much more than Continous Integration - there is the Source Control and Work Item tracking.  And if you already have an existing source control like SVN, and an existing item tracking(BugTracker.Net), migration of all that to TFS just to gain the automated build capabilities is simply too much work.  Not to mention the added cost of several thousands of dollars.

So I downloaded and installed a free "Professional Edition" of TeamCity.  With this free edition one gets a CI server with support for up to 20 developers and 20 build configurations, with a limit of 3 build agents  - allowing us to have builds queued up on 3 separate computers. 

 What trully amazed me was that I had this server installed, configured and then my first build configuration setup against the version control and running in a matter of 10 minutes or so.  Everything was easy and intutitive.  I highly recommend it for folks that are new to the Continuous Integration and need to setup solution quickly and without a hassle.

 It appears that all of the major Source Control systems are supported, with the exception of Source Gear Vault.  Supported .NET platform build runners are:

  • MSBuild
  • NAnt
  • Microsoft Visual Studio Solutions
    • 2003
    • 2005
    • 2008
  • Duplicates Finder for Visual Studio 2003, 2005 and 2008 projects (C# up to version 2.0 and Visual Basic .NET up to version 8.0)

Plus you can select the Command Line runner and use any script to build your projects. 

 

 All in all this appears to be an excellent product.  Check it out for yourself at:

http://www.jetbrains.com/teamcity/ 

 

Team City - Project Build History
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,
Categories: CI | Tools
Posted by ndibek on Tuesday, October 21, 2008 8:30 AM
Permalink | Comments (0) | Post RSSRSS comment feed

CSLA.NET VB and C# Visual Studio Class Templates

As a part of upcoming CSLA.NET 3.6 beta 2 release we have added one more feature - Csla.Net Class Templates for VB.NET and C# integrated in Visual Studio 2008.  So for example, when you select "Add New Item" in Visual Studio you get following options: 

Each of the class templates from the dialog above generates a Csla object with the template selected.  So for example, for selected CommandObject template in the dialog above with the selected name CommandObject2 you get the code generated below:

using System;
using System.Collections.Generic;
using System.Text;
using Csla;
namespace ClassLibrary1
{
[Serializable]
public class CommandObject2 : CommandBase
{
#region Authorization Methods
public static bool CanExecuteCommand()
{
// TODO: customize to check user role
//return Csla.ApplicationContext.User.IsInRole("Role");
return true;
}
#endregion
#region Factory Methods
public static bool Execute()
{
if (!CanExecuteCommand())
throw new System.Security.SecurityException("Not authorized to execute command");
CommandObject1 cmd = new CommandObject1();
cmd.BeforeServer();
cmd = DataPortal.Execute(cmd);
cmd.AfterServer();
return cmd.Result;
}
private CommandObject1()
{ 
/* require use of factory methods */ 
}
#endregion
#region Client-side Code
// TODO: add your own fields and properties
bool _result;
public bool Result
{
get { return _result; }
}
private void BeforeServer()
{
// TODO: implement code to run on client
// before server is called
}
private void AfterServer()
{
// TODO: implement code to run on client
// after server is called
}
#endregion
#region Server-side Code
protected override void DataPortal_Execute()
{
// TODO: implement code to run on server
// and set result value(s)_result = true;
}
#endregion
}
}
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 3.3 by 6 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: C# | Csla.Net | Tools
Posted by ndibek on Friday, October 17, 2008 9:02 AM
Permalink | Comments (2) | Post RSSRSS comment feed