Monday, March 21, 2011

Execute .SQL Script

If you want to execute a sql script without SQL Management Studio, you can use SQLCMD.exe.

"C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -i MySQLScript.sql

This allowed me to write a deploy.bat file which creates and fills all my required databases.

Monday, March 14, 2011

Find out Macbook Screen Model

If you have to find out your Macbook (Pro) Screen Model Number (because it is broken and you have to buy a new one on ebay), just enter
ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*
in Terminal.

It will give you something like this:
LTN154BT
Color LCD

Monday, July 5, 2010

#003 Invoking from UI Thread

Sometimes you just have to invoke a single line of code in the UI thread. The (very) old school way to to this is the following:

public delegate void VoidDelegate();
protected void WriteToConsole()
{
   Console.WriteLine("Invoked from UI Dispatcher");
}
...
View.Dispatcher.Invoke(new VoidDelegate(WriteToConsole));

To save time (and money), you can do this by using the System.Action delegate, which is a simple void delegate. By using anonymous methods, you additionally reduce the coding overhead by eliminating the need to create a separate method.

View.Dispatcher.Invoke(new 
Action(delegate{ 
Console.WriteLine("Invoked from UI 
Dispatcher"); })); 

Alternatively you can use lamda expressions for the delegate, which also reduces the coding by some chars...

View.Dispatcher.Invoke(new Action(() => 
  Console.WriteLine("Invoked from UI Dispatcher")));

Tuesday, June 29, 2010

#002 Render ReportViewer as PDF

If you want to programatically save a Microsoft.Reporting.WinForms.ReportViewer as a PDF to the filesystem or a database, the Render(...) Method will help you out by returning a byte array of the rendered file content.

Here is the code snippet:


   1:  byte[] fileData = null;
   2:  Warning[] warnings;
   3:  string[] streamids;
   4:  string mimeType;
   5:  string encoding;
   6:  string extension;
   7:   
   8:  fileData = reportViewer.LocalReport.Render(
   9:   "PDF", null, out mimeType, out encoding,
  10:    out extension,
  11:   out streamids, out warnings);

Monday, May 24, 2010

#001 create your own blog

As a software developer I'm often forced to do some ingenious hacks to get things working. So this blog should be a nice little work of reference which helps me not to forget how I solved those problems. Maybe I will also post some trivial code snippets which helps simplifying a developers life. Providing these informations to other developers and support them would be a cool side effect...