May 10, 2012

Windows Registry file (.reg) doesn't register key

It was a nice test for me. I needed to give a .reg file for a collegue of mine (its a long story) to recreate a setting for something we're doing. Long story short - I needed to add a path under a certain key so I did the following:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Key1\SubKey1]
"PathKey1"="C:\SomeFolder\SomeSubFolder\SomeExecutable.exe"
When I ran it on my PC to verify it's working I saw it created the keys all the way to the "SubKey1" but the string value PathKey1 wasn't added. Can you say what the problem was? I wasn't sure as well. Then I've found you have a nifty little menu option in registry that says "Export" and it will create the reg file for you. I ran it and out of curriosity I opened the file in Notepad to see what was I missing. The thing is that RegEdit want to have the "\" escaped with another "\" so the successfull reg file will be:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Key1\SubKey1]
"PathKey1"="C:\\SomeFolder\\SomeSubFolder\\SomeExecutable.exe"
The catch here is that no matter RegEdit won't be able to create the String value it will tell you that it succeeded. I will most probably never use to manually add things in Notepad, I'll use Regedit Export functionality now that I know it but be sure to always check that paths added to the registry via .reg file are double escaped. Hope this helps.

Feb 27, 2012

2 ways to make estimations in the software world.



I've watched a presentation held by Joel Semeniuck. As his LinkedIn profile states, he is currently "Executive VP at Telerik", anyway, this post is not about Joel himself but about estimating how much does it take to complete a given software project.

I was thinking about this over and over again.
Actually - each time I gave an estimation while I was at Telerik - my team lead used to double it in order to get somewhat accurate estimation.
And I was pretty ashamed in the beginning. I always push as much as possible in order go be a great software developer, I stay night, I work weekends, whatever it takes. And still I can hardly meet my deadlines.
(Note: I wasn't working night / weekends @Telerik, this is a generalization of my whole life as a software developer.)

Why would that be? I am trying so hard and still no result.
(to be honest - there are lots of cases that I was able to meet deadlines, but they were about things I already knew how to do step by step so they don't count. Or do they?).

And it's the bolded sentence above that got me thinking.
And I came up with yet another software development law. Maybe it only applies to me so it is not actually a law that will cover the whole software development industry, but let me first say it and then I'll discuss it:

"You can estimate a software project using two algorithms - the algorithm that all Windowses prior Vista used to estimate file copy time and the way all Windowses including Vista and later use to estimate the time it will take to copy a file."

First of all what's the difference?
In Windowses prior Vista the way explorer will tell you how much time will it take to copy file / files would be somewhat random, then it starts to fluctuate during the copy progress. Ever started with 2 minutes, gone to 10 minutes? Well that's what I'm talking about.
In Windowses starting from Vista - the system will be much more acurate, except for one thing - it will not tell you how long will take to calculate how long would it take to copy the files. So you first wait for Windows to do some estimations by chunking the data it has to deal with. And then it will be more accurate in saying how long will you wait.
(Note: I probably miss a lot from their algorithms but this is the end user impression it leaves).

So basically if you start estimating like older Windowses - you will be looking at one large chunk of work and you will be able to estimate that chunk roughly.
If you give your estimation the way Vista and newer Windowses work - you will have much more acurate estimation as you would have chunked all the data upfront. And there will be much less room for errors. So in the ideal case you will have to split the big chunk into really really small tasks you know you can do in an hour.
The bad thing using the second approach is that when asked "What's your estimate on this?" you will need to say "Gee, I don't know, I will first need to take my time to estimate it, I'll then be more acurate.", "How much time would you need to estimate this?", "Gee I don't know. You'll have to wait for me.".

So to summarize:
Estimating like old Windows: "It will take 2 months and it may go up to 10 months. I may be able to complete it in 2 weeks though."

Estimating like new Windows: "Come back later. Or better - I'll call you when I have an estimation. I know you have a decision to take but I can't do anything about it yet.".

I am leaving you decide which one to use :). Maybe a mix of both?

P.S. If you think about it - this applies to known projects. Add some third party black box integration and you will fluctuate the same way windows fluctuates when it downloads a file - it tries to take into account a variable that is changing randomly - the speed of your internet connection. For such projects you can go from 1 hour to 1 year or even to work 1 year and understand that the project cannot be completed (well guess what - although Windows states it will get your file in 1 hour, it doesn't tell you what will happen if you decide to disable your internet adapter).

Jan 18, 2012

Find and open a file in Visual Studio.

I remember that a collegue of mine used that a lot. I forgot it so I will just post it here so anyone (including me can benefit of it).

In order to find a file / class in Visual Studio - use the "Find In Files" toolbar combobox. You will however need to write a magic word before it starts searching, just type "> of" before the file name, like "> of User". VS will help you with some of the files that contain this name:



Hope this raises a bit more of productivity out there.
If you need more - you may want to try Telerik Just Code ;).

Nov 23, 2011

Scroll event not fired in some Telerik Windows Forms Controls (maybe WPF as well)


First of all - this is not quite an issue.
Since the Telerik controls are compound controls (for example the list view has Root Element, List Element, things like that), what scroll are you subscribing to?

Do you subscribe to the whole control?
Do you subscribe to the RootElement? To the ListView?

To remove that kind of questions, Telerik came up with the idea that it will be better to rise the appropriate control scroll, instead the entire control scroll.
Consider this:

radListControl1.Scroll

vs:

radListControl1.ListElement.VScrollBar.Scroll

If you are called like the first one, how do you know who called you?
If you are called in response to the second one, however, you will know that the ListElement (the items placeholder) has changed its vertical scroll so you can respond to this easilly (for example in a case of Virtualization it will mean it may be hungry for some more items ;).

To be honest at first I was a bit frustrated but now when I got it it makes a lot of sense.

Disclaimer: I am not part of Telerik anymore so this is just my guess, why they did it that way and my own explanation. I may be wrong :).

Sep 29, 2011

Kindle Fire is comming! Amazon is taking orders on the new Kindle In Color (Kindle Fire)

Are you ready to get one?
Lot's of rumors that this little thing will be one of the main competitors to the Apple iPad. No one knows yet. With date of release set to 15 november, the Kindle Fire is a long awaited addition to the old Kindle.

Here is the old one (I have one and I'm pretty happy with it):


and here is the new, shiny tablet that Amazon will offer at the end of this year:




Honestly, I am thinking to get one, although pretty happy with the old Kindle, I need to stay in the business :). I would be happy to be able to optimize some of my upcomming products to work well in both - Kindle Fire and the old Kindle, so having both will be of great help to me.
On the other hand if you just need to read stuff, I belive to old Kindle will be enough.


+

= Happy developer.

Sep 2, 2011

LinkedIn API - request failed with 401 - unauthorized (cause #1 of N)


If you experience that, make sure you are encoding your request properly. For example http://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,picture-url,headline,location:(name)),num-results)?keyword=" + HttpUtility.UrlPathEncode(user.FullName).

In the above example if the user full name is Pavel Donchev, if you use HttpUtility.UrlEncode(user.FullName) the result will be Pavel%Donchev.
It should be Pavel%20Donchev, which is result of calling HttpUtility.UrlPathEncode instead HttpUtility.UrlEncode.

Almost unnoticeable difference mixed with generic message that may cause lots of head aches for you.

Aug 16, 2011

SQL Server–have another instance redirecting to existing SQL Server

I was in a need to have an SQL instance renamed.

This is because I have SQL instance on my server and wanted to have it on other computers as well so I don’t need to change the Connection Strings each time I deploy.

I first tried to rename it but to no avail. Then I found this little neat trick to have another instance that can “redirect” to the original server (e.g. you have (local)\Instance and want it to redirect to (local)).

To do this follow the instructions bellow:

1. Go to Start Menu => Microsoft SQL Server 2008 => Configuration Tools => SQL Configuration Manager.

image

2. In the SQL Configuration Manager expand the SQL Native Client 10.0 configuration node

image

3. Right click Aliases node and select “New alias”

image

4. In the Alias – new popup, in the Alias Name field type the name you want to have for redirection, in the server field type the server the alias will redirect to:

image

5. Go to management studio and type the new instance name in the server name text box to test the connection:

image

It worked pretty well for me, hopefully it will work for you as well!

Aug 9, 2011

A book is born!!!

As most of you know, I was involved in writing a book about C# programming (we were 30 authors, each had to write a chapter and edit a chapter).You can click on its cover in order to be taken to download the PDF version:

Hope you will enjoy it.

Oh, almost forgot – it is in BULGARIAN Winking smile. There were some plans to have it translated but as I am not a part of telerik anymore, I don’t have any information from the kitchen how far this project went.

Please be sure to say a great thanks to telerik for sponsoring this book!

Jul 14, 2011

Application suddenly becomes slow

I experienced this while I was developing my application in Visual Studio.
It happened for no apparent reason (I didn't remember to make any signifficant changes in this application).

It was really frustrating. The thought that I may need to rething the whole application was a nightmare.

I was in panic and started to think what the problem for this sudden degradation might be.

And guess what?
It appeared to be because of a conditional breakpoint I have set in one of the complex modules.

The program flow was passing through this line of code hundreds of thousand of times so Visual Studio was kind of slow determining if the condition for the breakpoint is true or not.

So remember this for the rest of your life:
"Conditional breakpoints may slow your application considerably, before doing stupid things in case of sudden performance degradation - be sure to remove your breakpoints first (Debug Menu => Disable All Break Points), then check the performance again.".

Jul 13, 2011

SVN Server - problem connecting to the SVN server

I had a problem today connecting my laptop to the SVN Server on my PC (a.k.a the Server).

The Tortoise SVN was saying something like "OPTIONS:" and then a long message saying the remote server didn't returned the information it needed.


I tried to browse with Internet explorer and instead a folder structure of my SVN repositories, I got a white page.

After a while of wondering I identified the problem - i forgot the "s" in https.

I didn't considered this as a possible problem because I expected to be presented "Remote server not found" or something like that in this case.

Have a great coding!

Jul 12, 2011

Sitefinity E-Commerce module is out (in Beta)!

There was a lot of passion about this module.
Some of the partners may not be really happy (those that offer their own E-Commerce modules).
Others will be as they will not need to worry which 3rd party module they need to buy and integrate and what head aches will there be while integrating.

Anyway - Telerik announced the availabillity of the long awaited E-Commerce module.

It is currently in Beta.

More information can be found on this
forum.

Jul 7, 2011

Me, Telerik, Introduction To C# programming book (some personal updates)

Ok, lot's of things happened recently.

First of all - I quit Telerik and got back to Veliko Tyrnovo.
A brave decision I have chosen in order to try to deliver more than it was expected from me ;).
This one was really though to decide as I really enjoyed being part of Telerik. A LOT!

Anyway, sometimes we need to sacrifice things in order to try to get to the next level.

And the next level for me is to try to do something for Veliko Tyrnovo (it is not my birth place, but I spent signifficant part of my life here and really love this city).

I thought it may be beneficial to the city if I quit Telerik and try to establish a company here + try to engage young potential developers attention so they get direction and momentum at a very early stage of their lives (not quite sure if you know or it is the same way in your country but here, it feels like there is a lot of depression).

It feels like the young people are somehow smashed and forced to belive they are no good, hence they become sellers in stores, car wash workers, gas station workers and stuff like that, just because they weren't directed at an early stage. They are vibrating at very low frequencies. Their frequencies are enough to just get them to graduate and find any job that will give them some money. No dreams at all.

To be specific - my company and my future initiative to try to help young developers have nothing in do one with each other so far.
Currently I am not an employer, I am not even a business entity yet.
All I have is some money (as usual - not enough for everything I think I need), some ideas, some dreams and a lot of energy.
The initiative with the young people is something I will do aside from my other activities. I imagine giving them materials, helping them answering questions, founding some user groups and things like that.

To be honest, I realise I have very limited capacity, I don't expect to make a revolution and make Veliko Tyrnovo "the silicon hills :)" but still, if I can help 1 or 2 young developers a year, that will be awesome and I believe it will lead in a signifficant improvement over the long run.

I am rising some money now for my company (well, yes, if you wish, count this as a marketing material, I am not asking anyone for anything, I am working toward this but will not return anyone with a good offer ;).

With all the friends (or should I use my network to look more like pro :) I think it is possible for me to get started and do some of the things I dreamed of.

Last but not least, I was involved in writing a book (I was one of the 30 authors) at Telerik. Leading this book was part of the work of Svetlin Nakov (check his blog to see more information about the Telerik Academy he is currently leading).
They updated us that the book is in pre-release stage (actually it is available for free download but I am really eager to see my name in a printed book ;).

That's all for now.
Wish you a great and productive day!!!

Jul 1, 2011

Awesome Presentation Framework from Telerik Silverlight Divisions

For LOB applications it is important that the users have their preferences saved (and later - loaded) once they have them set.

Telerik is now addressing this issue by unveiling awesome Persistance framework for the Silverlight Controls.

More information can in the
Telerik Presentation Framework blogpost by the Silverlight Division.

Ofcourse it was possible to achieve that before, but it tooks way more plumbing than now.

Currently the PersistenceManager class will take all the plumbing itself (probably you may need to implement another provider if you want to store the UI information in place other than the IsolatedStorage but still), letting you focus on the really important, application specific problems instead on plumbing...

It is really worthy to go with Telerik :).

Jun 28, 2011

Visual Studio AddIn - never put dots in a command.

I was following an article on how to create a command and add it to the Code Window context menu, it was going really well until some point.

I ran the code and Visual Studio was crying with E_INVALID_ARGS error on the

this._applicationObject.DTE.Commands.AddNamedCommand

This one is widelly used and pretty standard method so I thought the problem is somewhere in my code.

I realized that almost all the parameters I am passing to this method are pretty common as well so the problem must be at ....

Well, the command name I used was containing dots, that's why the error.
If you receive this message, please check the command name for dots (the second parameter you are passing to this method).

Since Visual Studio and other addin types seem to be working with very similar framework (the so called "extensibillity framework"), I suspect this rule is also applicable for other types of addins such as Outlook, Excel, Word, etc.

WebForm_InitCallback is not defined error (and some resolutions)

I was happilly working while all the sudden I started to get this message.
It took some googlin' in order to understand what is going on.

It was because my development server date was wrong (few months in the past).
Synchronizing it resolved the issue.
Also I read you may experience this problem in case you are changing the current thread culture.

Hope this helps ...

Jun 21, 2011

Sitefinity 4.1 SP2 is out!

A service pack for my favourite CMS has just been released.

The list of features and bugfixes can be found at:

http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/sitefinity-4-1-sp2-is-released.aspx

Can't wait to finish my ongoing work in order to get some time and try it.

Jun 10, 2011

Convert string to a known type (using its default converter)

I was in a need to get a type, instantiate it and then fill its properties (I'm currently doing an engine that will give me an instant CRUD UI).

So what I basically needed was to be able to fill a new object instance out of a Hashtable (the key is the name of the property and the value is its string representation).

I wanted to be able to convert that string value into the type it needs to be.
Here is some code to help you get it:

foreach(string strPropertyName in htValues.Keys)
{
PropertyInfo pi = entity.GetType()
.GetProperties()
.ToList()
.FirstOrDefault(property => property.Name == strPropertyName);
}
(this is kind of pretotype so don't blame me if you don't like the code :).

In the above code I am iterating in the keys of the hashtable, so if I have an user object it will strPropertyName will hold "FirstName", then "LastName".
So far so good, I am able to fill the object and send it to the EntityFramework for DB Persistance.

The problem was when the strPropertyName was holding "BirthDate" as it is a DateTime and the EntityFramework or the Reflection (not quite sure which one) was crying it can't Convert the string to the respective type for me.

Here is how I solved the problem:
// Create a new Instance of the given type.
object entity = Activator.CreateInstance(this.EntityType);
// Iterate through all the properties.
foreach(string strPropertyName in htValues.Keys)
{
// Get the property with that name:
PropertyInfo pi = entity.GetType()
.GetProperties()
.ToList()
.FirstOrDefault(property => property.Name == strPropertyName);
// Get the default type converter for the given property type:
TypeConverter converter = TypeDescriptor.GetConverter(pi.PropertyType);
// Set the value by converting non-values to the given type
// and setting null where it is a null value.
pi.SetValue(entity, htValues[pi.Name] == null ? null : converter.ConvertFromString(htValues[pi.Name].ToString()), new object[] { });
}

Basically the thing you (and I!) need to remember is that the TypeDescriptor class has a GetConverter() method that takes a type and returns a TypeConvertor for that type.

Now in order to be able to convert from string to that type you just need to call .ConvertFromString(string value) of the TypeConverter returned by the TypeDescriptor.

Hope this helps someone out there. To me it seems it can give you a great deal of abstraction and I (for some reason) believe this is heavilly used in nowadays OR/M's.

Jun 9, 2011

Get the underlying type out of a Nullable

It appeared to be really simple actually, this post title suggest the solution:

Type nonNullableType = null;
if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
nonNullableType = new NullableConverter(property.PropertyType).UnderlyingType;
else
nonNullableType = property.PropertyType;

What we actually do is to check if the type is nullable or not, if so - we are getting its Underlying type, and if not - we are getting the type itself.

Check if a type is Nullable or not

I was in a need to determine if the type of PropertyInfo is a nullable or not.
Here is what I've found on MSDN about this:

property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)

So you basically need to determine if the type is generic (makes sense as nullable is a type that takes T (Nullable)) and then to check if the type is a Nullable then.

Now, I really wondered do I really need both checks?
As it was coded that way at MSDN I first didn't look at that, but I wanted to tackle it a bit more.

First I thought that the first one is needed to protect you from the null value returned by the GetGenericTypeDefinition() method.
But what's the problem even if it does?
Well, you get InvalidOperationException saying "This operation is only valid on generic types.".

So you definetelly need both checks ;).
It is kind of ugly for me, maybe it will be better to create an extender to the Type type. Something like "IsGeneric()", but the Is prefix always suggests property while this is a method.

Anyway, I'll go with that.
In the next post I'll show you how to get the type out of a Nullable<>.

May 27, 2011

Programming - Rule #1 follow your data from the UI to the Database and back

It can save you a lot of time :).
I had to fix a bug with a value not updating on the UI.
I attached with the debugger and followed the code to the Save() method of the manager.
Then I started looking for some problems in the database (asynchronous triggers failing etc.).

I wasn't quite sure where the problem is for a while.
Then I decided to hit F11 on the Save() method of the manager with the hope to see what query it was generating.

Guess what?
It wasn't the query but the fact that the Manager was overriding the Base Manager Save() method, as it needs to convert a DTO object to DataObject in order to save it.
Well I didn't even need to read through all the properties to know for sure that the property that wasn't updating was missing in the list of assignments in the convert method (in order to defend myself I would say that 99.9% of our managers aren't overriding save methods, it is very unlikely so I didn't considered that to be the problem).

Happy coding and remember Assumptions are your worst enemy :). They are the things that waste most of your time.