Posts tagged C#
Improving Coding4Fun’s AboutPrompt
Feb 4th
While creating the Windows Phone7 version of my Master Thesis project, I needed to show some custom dialogs. Since Coding4Fun has some very nice dialogs, I explored the way that they might be customized to fit my needs. I needed a quick solution to a pressing problem.
I got in touch with this controls through WinPhoneGeek’s article Coding4Fun Toolkit for WP7 Overview and Getting Started, where he presented from the eagle’s eye the controls in the package. I was interested more in AboutPrompt control, but unfortunately he didn’t had it presented in the detail. More >
Windows Phone 7 Coding Camp
May 12th
Just joined Microsoft Students Partners for few days, and me and my colleagues in Team West were invited to a Code Camp for learn developing for Windows 7 Phone with XNA. The camp was established in the castle, in Freusburg. We traveled from Köln after my RIA Business Applications presentation in the Springboard conference.
This special event joined together five very known and respected Microsoft Evangelists: Frank Fischer, Oliver Scheer, Frank Prengel, Tom Wendel and Jan Schenk. They are experts and known figures in programming world, with expertise in Windows Phone 7, Silverlight and XNA.
In the landscape of the castle, with Towers and defensive walls, we’ve been Knights .. of Code, of course (in German is Code Ritter). The organization was purely German: perfect! We had a lot of fun, lots of presentations and access to the knowledge gathered along the years of all five Evangelists.
In the first evening (who was right our Team West own event), we had the Microsoft Phone introduction by Frank Prengel (also known as Dr. Mobile) , XNA presentation by Tom Wendel (The Ant Man) and Silverlight presentation by Oliver Scheer, known as “Mr. deep zoom”. After all presentation, a collective brainstorming revealed around 30(!) ideas for implementing next day, who were judged from usability, possibility of creation and interesting points of view by our 5 Evangelists. Finally, we created teams based on the projects appealing to us. We followed our instincts and smell the code inside each application promise.
Alensa Online
Feb 11th

Position: Team Leader and Lead Developer in Alensa Online – Software Development department
I was part of Alensa team between January 2007 and August 2008. Only the opportunity to study Media Informatics Master, held by RWTH Aachen University, could gave me enough reasons to leave Alensa Online that I enjoyed so much for almost two years.
I was in charge with our brand new solution for an online Healthcare project – Alensa Online. The Alensa Online Shopping site (www.alensa.ro) consists of an internet healthcare platform in Europe that would simplify research and self education related to health issues, and provides the customers with an interface allowing them to easily get their health questions answered by professionals. It was first developed by a third party company, then I took over the responsibility of developing and maintaining the solution.
My responsibilities were quite complex because I was the first hired person, very similar with Softwise company. This reminded me about the joy and responsibility that comes with this. Another nice surprise was to find in person of Mr. Alex Savic, the CEO of the company, a friend with whom I shared both technical discussions and personal development ones, he was one the most supportive about my decision to study in RWTH Aachen.
Shortly, at Alensa Online I were in charge with:
- Architecting and developing the web based solution using Microsoft ASP.NET / C# and SQL 2005 Server technologies;
- Performing server administration, configuration and maintenance for the Windows 2003 server, for IIS 6 and for SQL 2005 database server;
- Executing architectural modifications in order to make the website user friendly;
- Identifying, designing and developing solutions;
- Periodically testing the site functionalities and thus creating a real test environment, test cases and bug fixes;
- Performing code review, corrections and code optimization;
- Analyzing hardware/software requirements and proposing hardware/software improvements and suggestions (for example, choosing an appropriate hosting partner);
- Implementing real time traffic analysis tool to help the management department;
- Conducting internal training for his colleagues. More >
Adding events to LINQtoCSV library
Feb 6th
The User Experience that a library provides must be at least equal with is quality and speed. And frankly, CSVtoLINQ rocks on latest two, as I presented in previous articles Import CSV file and query it with LINQ and continuing in LINQ wonder world, but lacks a little on the User Experience(in our case Developer Experience) by not having some events of starting, progress and ending of the parsing.
Especially important, while parsing huge files, is a confirmation for the user that something happens and (ideally) the point in which the processing is. That is why, thanks to Matt Perdeck for sharing the entire source of the library, I was able to improve it by adding events.
So, let’s see some code!
Modifications into LINQtoCSV library – CSVContext.cs
Important: All modifications will be made in the CsvContext class from LINQtoCSV namespace – the CSVContext.cs file.
First we’ll add the ReadStarted event to the library – it will fire when the reading of the CSV file has started.
// defining the delegate
public delegate void ReadStartedHandler(object sender, EventArgs e);
// here we define the event
public event ReadStartedHandler ReadStarted;
// the call of the event processing
protected virtual void OnReadStarted() {
if (ReadStarted != null) {
// we use empty eventargs because nothing is needed on readstarted event, just the confirmation of parsing started
ReadStarted(this, EventArgs.Empty);
}
}
LINQ wonder world
Feb 5th
I am sure that, if you are a developer, at some point in your career heard about and asked yourself: what is LINQ? If not, there’s no problem, you’ll find out now : LINQ comes from language-integrated query and it is a collection of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It helps developers by extending both C# and Visual Basic, adding native querying capabilities to these languages. It also comes with class libraries to get the full advantage out of these capabilities.
As we discussed in my previous article, Import CSV file and query it with LINQ, we are able to load and parse the file into a IQuerable collection, thus giving us the oportunity to do more and more SQL- like operations on it.
The C# 3.0 specification defines a so-called Query Expression Pattern along with translation rules from a LINQ expression to an expression in a subset of C# 3.0 without LINQ expressions. The translation thus defined is actually un-typed, which, in addition to lambda expressions being interpretable as either delegates or expression trees, allows for a great degree of flexibility for libraries wishing to expose parts of their interface as LINQ expression clauses. For example, LINQ to objects works on IEnumerable<T>s and with delegates, whereas LINQ to SQL makes use of the expression trees.
Import CSV file and query it with LINQ
Feb 4th
Assume that you have an plain text, old Comma Separated Values file filled with your precious export from a legacy system. How can you process it easily now? The first answer that comes to mind is to parse it and load it into a datatable and later process it by using DataTable.Select() method. But this approach has some limitations – like splitting data into several tables and then join them.
One would imagine that parsing CSV files is a straightforward and boring task, given that it is quite a while since CSV is around. Some of them are correct – in the sense that many implementations merely use some splitting method like String.Split(). Some don’t even offer the specification of the values splitting character – so your file wouldn’t be parsed correctly if instead of , you have ; as separator – yet another thing to modify if you’re lucky enough to have the sources. Others will not handle properly field values with commas because the simple split method of the String class. But there are better implementations that take care about escaped quotes, trimming spaces before and after fields and other small and useful details, but very few that I found did it all as I liked it – and at least as importantly, in a fast and efficient manner.
How to make a Print Screen on Microsoft Source using WPF
Nov 1st
After we took a look inside of Microsoft Surface, let’s see how to take a later look on the surface, by creating printscreens of the application.
In some WPF applications you’ll need to take a quick screenshot of the user’s screen, allowing him (or them, in case of Multi User Surface) for later reviewing. Now, on Surface there can be only one full screen and active application. So it use the entire screen of the device.
Here are the steps in order to accomplish that:
First, we need to add to Visual Studio project the references to the libraries that we’ll use:
using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms;
Then, we will add create the method that will do the actual saving to a specific file, with the format PNG:
public void MakeScreenshot(String fileName)
{
Bitmap bmpScreenshot;
Graphics gfxScreenshot;
//first, we create&set a bitmap object to the size of the screen
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
//Using the bitmap, we create a graphics object
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
//Copy the rectangle (the screen in our case) - from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
// Do the saving, outputing a file by supplying the name and format it as PNG
bmpScreenshot.Save(fileName, ImageFormat.Png);
}
That’s all, folks – Use and enjoy!
C# .Net using Post with HTTPWebRequest
Aug 8th
Just a reminder for posterity : posting with .Net its so easy! Check out the Cocoa touch framework to realize the difference!
public string Post(string url, string data) {
string strReturn = null;
try
{
//Encoding the post vars
byte[] buffer = Encoding.ASCII.GetBytes(data);
//Initialisation with provided url
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
//Set method to post, otherwise postvars will not be used
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
//Closing is always important
PostData.Close();
//Get the response handle, we have no true response yet
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//information about the response
HTTPStatusCode status = WebResp.StatusCode;
string server = WebResp.Server;
//read the response
Stream WebResponse = WebResp.GetResponseStream();
StreamReader _response = new StreamReader(WebResponse);
strReturn = _response.ReadToEnd();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return strReturn.Trim();
}
Enjoy!
MIX09 Scott Hanselman’s FILE|New Project …
Mar 22nd
Scott Hanselman had a presentation at Mix 09 conference – File | New Company: Creating NerdDinner.com with Microsoft ASP.NET MVC. This was in its unique style – fun, rich in content, tricks, advices but most of all was fun.
This year he managed to create a new type of presentation – without the actual presentation! No more constrained to some slides, just him, Visual Studio and the audience. Yes, the audience – who seemed to absorb any words spoken there, helping Scott with few advices in some key points.
Create GUID in Visual Studio 2005
Dec 21st
From time to time you need to create a GUID (Global Unique IDentifier) in order to mark your dlls. Looking in my Visual Studio 2005 I saw that this command wasn’t available in any tools menu, nor in the Customize toolbars one as a shortcut to a command.
After a quick digging on MSDN site I found this. It is written in Microsoft style – a lot of information, but no solution. It just mentioned something like ”hey, we have something that you want, but guess what – we don’t have it any more”:
-
On the Tools menu, click Create GUID. The Create GUID tool appears with a GUID in the Result box.
So I started creating my own Create GUID command.
Happily, the Microsoft team provided the tool in the <visual studio install>\Common7\Tools\ directory. Usually, the <visual studio install> dir is C:\Program Files\Microsoft Visual Studio 8.
Actually, there are 2 tools for creation of GUIDs:
- GUI interface: <visual studio install>\Common7\Tools\guidgen.exe
- Console line tool: <visual studio install>\Common7\Tools\uuidgen.exe
At first look, uuidgen seemed the winner. Running uuidgen in command line revealed the needed parameters:
I proceeded to setup the Create GUID command. From Visual Studio 2005 menu > Tools > External tools you can add and setup a new command to an external tool. The setup window is straight forward for experts, but new guys can be impressed by it.
Clicking on Add button will create a new element in the list, called [New tool 1]. This name will be overridden by whatever you write in the Title text box. Next, the command text box will be filled with exact path to the tool. Clicking the ellipsis button, you’ll be sent straight to Tools dir, where you can easily find the tool required. As arguments I put the ‘c’ value which means that the output will be upper case UUID (as you can see in the previous image).
And when clicking OK, the corresponding name, as in my case Create GUID appears in the Tools menu, just above the External Tools menu.
But surprise, when I clicked the menu button, the command prompt flashed and nothing happened.
After a brief investigation, I figured out that the tool worked, but it’s output was retained in the command prompt window. This closes immediately after the tool runes successfully, outputting the GUID.
What to do ? I switched to the next tool, Guidgen. This was simply accomplished by changing the command to the corresponding tool name and removing the argument.
So after clicking on Visual Studio 2005 menu > Tools > Create GUID I got this window, in which I checked, as you can see, Registry format and then click on Copy button. Then clicking on Exit you dismiss the tool. By pasting the Clipboard content into a class, you will get this :
{949213E9-0658-4546-B3D1-F41C0475E805}
Good luck with the implementation!