Service Design and Smart Client Software FactoryThere are many OO principles as SRP or SOC out there. The service architecture of SCSF offers some issues. Programmers tend to see a service as a god object that does everything for a specific domain. This is an issue. Mixing different concerncs makes your design hardly to maintain.
One way is to seperate your concerns in different services. Add those Services by DI ( Property or Constructor injection). This is fine because we know: Composition is better than Inheritance.
[ServiceDependency]
public IDependingService MyService { get; set; }
So design your service as a composition of many smaller helper services. You can use TDD or just a test per service to optimize your development process. Each part is testable. Ever tried to write unit tests for god classes? Thats kind of not possible. And if you do, every change in the god object makes your unit tests out of date and hard to update.
Another advantage of seperating your service in many child services is the power of the object loader. You can declare your services by AddOnDemand. So your service will be loaded only if needed or used. Using more fragments makes this more efficient.
[Service(typeof(IMainService), AddOnDemand = true)]
public class MainService : IMainDetailService
{
[InjectionConstructor]
public DocumentDetailService([ServiceDependency] IDependingServiceA serviceA,
[ServiceDependency] IDependingServiceB serviceB)
{
_serviceA = serviceA;
_serviceB = serviceB;
}
}
So design your services as compositions. Separate concerns in service views and also in a meta view. For logic that don't need any views, use foundation modules to separate your logic physically. Use composition to separate your implementation logic.


 |
Created August 24, 2010, 9:44 am Decorator Pattern in C#Here comes a recommendation for an implementation of the decorator pattern in c#. This example is based on the java samples in the great book Head First Design Patterns.
///
/// an abstract base class for all main objects that
/// want to be decorated
///
public abstract class Drink
{
protected string _description = "Unknown Drink";
public abstract double Price();
public virtual string GetDescription()
{
return _description;
}
///
/// Prints this instance.
///
public void Print()
{
Console.Out.WriteLine(GetDescription() + " $" + Price());
}
}
///
/// One main object that can be decorated
///
public class Espresso : Drink
{
public Espresso()
{
_description = "Espresso";
}
public override double Price()
{
return 2.20;
}
}
///
/// Decorator inherits from main object
///
public abstract class IngredientDecorator : Drink
{
protected IngredientDecorator(Drink drink)
{
_drink = drink;
}
protected readonly Drink _drink;
public override string GetDescription()
{
return _drink.GetDescription() + ", " + _description;
}
}
///
/// Decorator for chocolate
///
public class Chocolate : IngredientDecorator
{
public Chocolate(Drink drink)
: base(drink)
{
_description = "Chocolate";
}
public override double Price()
{
return 0.29 + _drink.Price();
}
}
///
/// Decorator for scotch
///
public class Scotch : IngredientDecorator
{
public Scotch(Drink drink)
: base(drink)
{
_description = "Scotch";
}
public override double Price()
{
return 0.99 + _drink.Price();
}
}
The usage of the decorators follows this...
class Program
{
static void Main(string[] args)
{
Drink drink = new Espresso();
//decorate my espresso with double chocolate and scotch
drink = new Chocolate(new Chocolate(new Scotch(drink)));
drink.Print();
//Espresso, Chocolate, Chocolate, Scotch $3,77
}
}


 |
Created August 22, 2010, 5:29 pm Posting Sources with syntax highlightingYou can use this SyntaxHighlighter to enable coolest highlighting in your post.
Just download the zip and upload the needed files to a web folder. Then all you need to do, is to include this code in your dashboard - layout - html at the bottom end...
<link href="http://.../styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="http://.../styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://.../scripts/shCore.js"/>
<script type="text/javascript" src="http://.../scripts/shBrushCSharp.js"/>
<script type="text/javascript" src="http://.../scripts/shBrushVb.js"/>
<script type="text/javascript" src="http://.../scripts/shBrushXml.js"/>
<script type="text/javascript" src="http://.../scripts/shBrushSql.js"/>
<script type="text/javascript">
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>
All copy and pasted code that you embed in pre tags like described here will be shown like the sources above... Make sure you enable the blogger mode!


 |
Created August 22, 2010, 3:22 pm Must read books for beta geeks
There are many great books about code quality, patterns and design out there. Here is my favorite list of books. Eat them not read them.
Bibles about gettin' a better programmer...
A really cool book with many hints about increasing your productivity. Also introduces many tools that you should use in your daily work.
Very interesting guest texts with interresting stories. Tells you how to become a better programmer and how you make your own way. Includes many good hints for your career as well.
Bibles about writing better code
My standard book for clean code. That means how code should look like. Including comments, naming conventions. Rule the pathfinder rule!
Best practices with some nice use cases of software life cycle optimizations.
THE book about refactoring.
Bibles about making better designs
Head First Design Patterns
Because the GoF book can be getting boring, this book is perfect for learning design patterns. It offers the patterns in a very interesting way with many images and funny stories. Very nice to read.
Very intersting book about DDD. From ubiquitous language to complete DDD architectures.
Discusses enterprise patterns in a very detailed view.


 |
Created August 22, 2010, 11:17 am unexpected error occurred in the .NET framework data providerTo be solved by /ResetSkipPkgs command line parameter of Visual Studio
devenv.exe. Call this once if you have trouble with other add ins. It
solves the most issues.


 |
Created June 25, 2010, 1:41 pm Convert WTV files to play them in Playstation 3Windows Media Center allows you to record TV shows to your hard drive. As a proud user of a playstation 3 I checked that ps3 cant read WTV movies. You need to convert them to dvr-ms. In Vista and Windows 7 this can be done by a right click on the file. But I want this to be done automatically after a recording has been finished.
- Follow these steps to get lucky:
- Create a second folder like TV-Converted.
Go to your "Recorded TV" folder and create a file named "convert.cmd".
c:
cd \
cd windows
cd ehome
WTVConverter "E:\Recorded TV\*.wtv" "E:\TV-Converted"
del "E:\Recorded TV\*.wtv
This will convert all wtf files and save them into the new folder. Just replace the path with your path names.
Now set up a cron job or task that automatically runs that script after a recording has finished its work.
- Open your Taskplaner
- Add a new Task ( call it like WTV Converter)
- Choose "protocol a specific event"
- From the dropdown box choose "Media Player" protocol
- Choose "Recording" as source
- Set tje Event-ID to 1 (means recording has finished)
- As Action choose "Start Program"
- Select your Script like ""E:\Recorded TV\convert.cmd"
- Done!
Save it and test it. You can edit your task and add other triggers. For example EventID 3 that shows that you manually stopped a recording.
You can now add the new folder to your shared media and stream the converted files to your ps3 or where ever you want.


 |
Created January 13, 2010, 12:07 pm Short introduction to WPFThe windows presentation foundation is the biggest change in windows UI programming since Windows 3.1 was replaced by Windows 95. Since ages all UI outputs where made by GDI+ and WIN32 operations. The future is DirectX. So it was a smart step to embedd DirectX in a better way. So the WPF uses the DirectX framework and all its power to render high qualitiy graphics using hardware acceleration. To support older systems and to keep WPF extendable it implements rendering tiers. The lowest tier wont use any hardware acceleration. The highest one can use the power of current DirectX Versions.
So what is WPF? Its an abstraction level of DirectX. Not for game developers but for software developers.
Advantages
- Resolution independence
- Rich Text support
- Animations
- Hardware Acceleration
- Command Pattern (History Functionality)
- Declarative
- Resolution independence due DPI translation (autoscaling)
The only real disadvantage it that WPF only works in windows based environments. DirectX is a core windows technology. A subset of WPF is Silverlight that isnt depending on client technology by using plugins.
XAML
The Extensible Application Markup language "zammel" is a declarative language to insantiate .NET objects. You can compare it with the asp.NET controls that are declared in a ASPX files. XAML makes it more easier to sperate code from design. WPF can also be used 100% without using any XAML by writing all code manually.
- Supports Nesting Elements
- Each element has a ContentProperty Attribute that returns its content
- Markup Extension {x:static ... } allows to set properties dynamically.
- Attatched Properties allow to access properties of parent instances
- XAML is compiled to BAML (binary application markup lang) by xamlc.exe
This example code shows a window with a colored fullsize button.
<window class="Dixus.WPF.Training.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
x="http://schemas.microsoft.com/winfx/2006/xaml"
height="300" width="300">
<grid>
<button name="button1">Button
<button.background>
<lineargradientbrush>
<gradientstop offset="0" color="gray">
<gradientstop offset="1" color="yellow">
</lineargradientbrush>
</button.background>
</button>
</grid>
A basic WPF application
To understand how WPF works its a good idea to build an app from the scratch. Create an empty project and add a c# class like this. You will fiqure out which references you need. If you have no WPF window template use the UserControl and change the derived classes to window.
using System.Windows;
namespace Dixus.WPF.Training
{
class CoreWPFApp
{
[STAThread()] static void Main()
{
Application app = new Application();
MainWindow wnd = new MainWindow();
app.MainWindow = wnd;
wnd.Show();
app.Run();
}
}
}
This is just an example - not the way you would work. Visual Studio will create a app.xaml. As it works with all xaml files it will generate a partial class that derives from application. The main window wont be shown by the Show-Method then. A startup URI is set in the InitializeComponent Method (that is called in every XAML constructor).
Structure and layout
WPF provides a complete new model for positioning content. At first there is exactely one instance of a window. Every object in that model has a content property. This property can hold exactely one control. This content can be a StackPanel or a single element. The StackPanel itself can hold more than one content and so on... This is great because you have powerfull possiblities but its easy to handle.


 |
Created November 5, 2009, 10:16 am Visual StudioUnit Testing is something most developers hate. Its just boring. Nice to see that microsoft research is working on an VS IDE integrated solution for full covered unit tests.


 |
Created October 11, 2009, 7:07 pm Discovering powershellWow. I havent really something done with powershell. To take advantage of the new power i started to read about it and to try some stuff. Its really amazing!
As .net engineer i am happy that you can access all the power you can take in your IDE. So for example you can create .NET objects in a bash.
$myobject = new System.Anydotnetclasses....
Easy also the use of static classes like System.Math. Just set it to a variable and use the methods with scope operator...
$math = [System.Math]
$math::Sqrt(16)
4
So you can imagine what you are able to do to automate some tasks without the need of any compiler. You build a small script. You can connect to databases, create xml files, whatever .net allows you to do. Sure you can use WebClient class to read RSS feeds or you use the mailer to send mails.
Powershell is object based. So ill try to internalize the new unfamiliar syntax. For example to use new-item with -type directory instead of mkdir. But there is a powerfull help system. You must know that most things start with get-....
get-help new-* -detailed
This gives you a list with help entries matching commands that start with "new-". If you want more details use this:
get-help new-item
Be aware that you not only can use .net classes. You have access to WMI objects and even to COM objects. So you can easiliy connect to applications by using their COM objects. For example this shows how to create an internet explorer instance, navigating and showing the browser window...
PS C:\Users\hokr\Documents\E-Books\Powershell> $ie = new-object -comobject InternetExplorer.application
PS C:\Users\hokr\Documents\E-Books\Powershell> $ie.Navigate("http://www.dixus.de")
PS C:\Users\hokr\Documents\E-Books\Powershell> $ie.Visible = $True
I ll stop here because it doesnt make sense to write another tuturial. There are a lot good tutorials out there. Just google or bling for it :)


 |
Created July 17, 2009, 3:15 pm LINQ to SQL Debug VisualizerCreated June 8, 2009, 4:45 pm ASP.Net PathsCreated May 9, 2009, 12:22 pm Add IIS custom headers programmaticallyI was looking for a solution to add custom headers for IIS virtual folders or subfolders. There is a way using cscript.exe and adsutil.vbs in the AdminScript directory of InetPub. But here is a much more elegant way to do it. Add a reference to System.DirectoryServices to your project and you can modify headers in your deployment project or whereever like this. Protected Sub AddCustomHeaders(ByVal virtualDirName As String) Dim strPath As String = "IIS://localhost/W3SVC/1/Root/" & virtualDirName Dim de As DirectoryEntry = New DirectoryEntry(strPath) Dim myEntries As DirectoryEntries = de.Children ' Find Images Folder For Each entry As DirectoryEntry In myEntries If entry.Name = "Images" Then 'Add a custom header (here Ie6 Cache Bugfix) entry.Properties("HttpCustomHeaders").Add("Cache-Control:post-check=900,pre-check=3600") entry.CommitChanges() Exit For End If Next
End Sub
This header solves the issue that IE6 doent cache images. Its a bad idea to put the Cache-Control entry to the Virtual Directory folder. Because everything will be cached. If you do it in code, only aspx pages are affected - but not the images.
So just add the Cache Control to your images subfolder and the flicker problems are gone.
If you want to do it in a bash you can choose this way.
Change directory to C:\inetpub\AdminScripts
cscript.exe adsutil.vbs set w3svc/1/ROOT/YOURVIRTUALDIR/Images/HttpCustomHeaders "X-Powred-By: ASP.NET" "Cache-Control: post-check=900,pre-check=3600"


 |
Created April 27, 2009, 6:00 pm Dan Miser - Ignoring specified elements during XMLSerializationCreated March 3, 2009, 1:42 pm XENOCODE Virtual ApplicationsTesting web sites in every browser can be a pain. You cant run different versions of IE. But here is the solution. You can download browsers like IE6,7,8, Mozilla Firefox, Chrome, Safari that runs in a virtualized box. Thats incredible. You dont need to start a Virtual Machine to test your websites for IE6 compatiblity - the vm is included in that file. You just download the exe file from http://www.xenocode.com and you can use it! For free.


 |
Created February 25, 2009, 9:55 am How to get gmail contacts into your mobile phone1. Export google contacts as VCF 2. Convert VCF to Western Europe Codepage 28591 ( e.g. VS2008 -> Advanced Save Options )
3. Import VCF in Vista Contacts
4. Import Vista Contacts into Outlook and Sync Outlook with your mobile.
Or use a third party tool like Mobile Master.
Thats simply blah.


 |
Created February 11, 2009, 3:12 pm Rebuild Vista Performance IndexFor some reasons you cant refresh the performance index in control panel. There is am empty site. But if you set PerfCplEnabled to 1 (DWORD) then you see much more.
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Control Panel\Performance Control Panel


 |
Created February 7, 2009, 9:20 pm Most important gmail hotkeysI cant live without google mail any longer. Google Labs added some
really cool features like calendar, google docs and task integrations.
There are some cool hotkeys that make you work faster with gmail - if
you know and learn them.
z = undo k / j = pre / next in message list p /n = pre / next in message view u = go to inbox / = go to search box c = compose in message view x = select message s = star (cyclic) e = archive r = reply # = abort / delete l = label v = move shilt i/u = mark read / unread * + a = select all * + n = deselect all


 |
Created February 7, 2009, 12:49 pm Usage extended properties in SQL Server Management StudioIf you open the database properties you see extended properties for the database. Here you are able to set some user defined parameteres and values. Following code allows you to read out those values by T-SQL very easy.
declare @username SQL_VARIANT
SELECT @username = [value] from sys.extended_properties WHERE class_desc = "DATABASE" AND [Name] = "UserName"
select @username


 |
Created January 27, 2009, 1:55 pm DocProject "Send Feedback"I use the great DocProject to create code help files. You set it up in 5 minutes.
The only one thing that is annoying are the "Send Feedback" and the three default languages. But there are configfiles in /Presentation/Style/Configuration and Content that you can edit to get rid of this.
To get rid of the different declaration syntax just uncomment the ones you dont need.
CPlusPlusDeclarationSyntaxGenerator
ScriptSharpDeclarationSyntaxGenerator
To remove the "send feedback" stuff from your footer edit your sandcastle.help1x.config and look for feedback and uncomment that part.
file="..\..\Help\Presentation\Style\content\feedback_content.xml
Then open shared_content and uncomment that whole part that includes feedback related stuff. For me it was the easiest to uncomment the complete footer. Just look there and you will see what you can do.


 |
Created December 16, 2008, 2:05 pm Repair corrupt infragistics image pathsI was going crazy because my in my designer and ASP.NET Development Server no infragistics controls that use images could find them. Looks like a corrupt installation... But how to solve it. With nice help from infragistics forum i could solve it this way...
I am currently using 2008 Vol2 CLR 35... If you are using another version you probably have to change some directory names..
He tries to load the images from this path:
/aspnet_client/system_web/2_0_50727/ig_common
No where is it located? You find it here:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles
Just make sure the ig_common directory is in this path including the images folder from your infragistics installation.


 |
Created December 9, 2008, 4:28 pm Prerelease Visual Studio 2010
Download 7 GByte and you can check out the new VS 2010 CTP in a Virtual PC.
You find the download links here.
Its a Windows 2008 Server on a 25 GByte Virtual Disk. The new Visual Studio version will be including more possibilities for SOA driven development. The feature i am looking forward to is the support of UML as part of OSLO.
More information around new stuff in channel 9.


 |
Created December 3, 2008, 12:48 pm Marking code makes you more efficient
It is a really helpfull tool. Many developers dont use it but its really nice to have. Makes life easier.
The Tasks and Bookmarks in Visual Studio allows to create grouped and named bookmarks ( STRG + (K + K) ). You can edit those Bookmarks in the Bookmark window and navigate though them by STRG + ( K + N) or P for next and previous marks.
Same works fine for your task list. Just press STRG + ( K + H) and you have created a new task that is linked to your current code possision.


 |
Created December 3, 2008, 10:24 am Temporary Projects in Visual StudioIf you often create new solutions or projects just to test a piece of code or something else, you will have a lot of trash in your folders. There is a simple way to stop this.
Just disable the checkbox "Save new projecs when created" in Options - Projects and Solutions in Visual Studio IDE.


 |
Created December 3, 2008, 10:07 am Special stack chartThere are many chart types but sometimes it happens that you cant find the one you need. So you need to specialize one chart to get the one you need. This special chart shows one column as summary. All other columns are parts of the summary column shown as a stack chart. Also there are shown annotations that shows the sum of each column at the top of the stack charts.

There is no way to move the columns the way you need and also no solution to add summary annotation for stack charts. So the easy solution is to add a dummy rows to your data.
Public Overrides Function CreateResultTable() As DataTable
Dim dt As New DataTable()
dt.Columns.Add("Month", GetType(String))
dt.Columns.Add("Dummy", GetType(Int32))
dt.Columns.Add("Value1", GetType(Int32))
dt.Columns.Add("Value2", GetType(Int32))
dt.Columns.Add("Value3", GetType(Int32))
dt.Columns.Add("Anotation", GetType(Int32))
Return dt
End Function
Now we can use those dummy rows for our purposes. The Dummy Column will be our placeholder for the Y-Margin of the StackColumns and the annotation box. But how can we hide this columns in our chart? This is pretty easy. Just overwrite ChartDrawItem and hide the column by its number.
Protected Sub myChart_ChartDrawItem(ByVal sender As Object, ByVal e As ChartDrawItemEventArgs)
Handles myChart.ChartDrawItem
If e.Primitive.Column = 0 Then 'dummy row
e.Primitive.Visible = False
ElseIf e.Primitive.Column = 4 Then 'annotations row
e.Primitive.Visible = False
End If
End Sub
Now we disable those dummies. The effect is that we can place the annotations above each stack where we need it. This example shows how you add an annotation to each column and how you can disable the border and set the font.
For i As Integer = 0 To ReportsDt.Rows.Count - 1
Dim CallOut As CalloutAnnotation = New CalloutAnnotation()
CallOut.Text = CalcSum(i)
CallOut.Location.Column = 4
CallOut.Location.Row = i
CallOut.OffsetMode = UltraChart.Shared.Styles.LocationOffsetMode.Automatic
CallOut.FillColor = Nothing
CallOut.Border.Thickness = 0
CallOut.Border.Color = Drawing.Color.Transparent
CallOut.TextStyle.Font = New Font("Arial", 9,FontStyle.Bold, GraphicsUnit.Pixel, 0)
myChart.Annotations.Add(CallOut)
Next


 |
Created October 24, 2008, 11:15 am Pimp your Visual StudioCreated June 2, 2008, 4:08 pm |