Rat's Blog
Code, Stuff and Pics
Sunday, October 23, 2016
How to make Node.js Unit tests discoverable in Visual Studio
There were no "build" errors, nothing, Visual Studio just wasn't discovering them anymore.
So and it has turned out that after the Drag&Drop operation one of the file properties was not preserved: TestFramework. In my case I just had to set it to ExportRunner.
Changing that did the trick :)
Friday, May 13, 2016
Web API Attribute Routing - not as attribute-driven as one would expect
This seems to be a carryover from convention-based routing, and it is rather unexpected that it is still there.
But if you are like me, and WebAPI came into your world just now, you would not really have that habit of naming all controllers like that, especially in the test project.
Summary: Always follow this pattern for WebAPI controller names: {Name}Controller.
And inherit from ApiController, but that's obvious.
Monday, October 12, 2015
Loose hood lock on my old QX4
As almost everybody else in US I own a car. It's an old SUV - QX4. Being on visa does not let you to earn more to keep more, so I have to spend less to keep more :) And so I fix my own car.
Anyway, this particular model is known to have one common problem - loose front hood lock. In many forums you can find the problem described as "hood rattle". I've seen a lot of forum posts about this problem, but I never actually thought that I have this problem as well.
About a week ago I noticed that my hood...shakes. Nothing crazy, but it really did not feel like it was dead on where it was supposed to be. It was definitely a bit loose. And I bet that it was like that for all the previous year!
So after a very easy fix (undo 3 bolts, push the lock down as much as possible, level the lock, tighten the bolts) I took a car for a test drive and I was shocked. All the explainable rattle, muffled clanking on speed bumps and bunch of other symptoms are gone ! I was always blaming the suspension, mounts and any piece that has rubber in it, and all this time the problem was in a front hood lock.... Crazy!
Friday, October 9, 2015
Why does my PC refuse to fall asleep?
The display would turn off, but it just never wanted to go into the Standby mode.
Long investigation revealed two issues:
- The common one - media streaming + the homegroup issue (this one is easy to google).
- My soundcard driver was keeping the PC awake using SetThreadExecutionState API.
UPDATE: It has turned out that after the restart the sound card driver is still preventing my PC from sleeping. There are two applications that can be blamed for that: Steam and UPlay. Both have some well-known bugs that do not release the sound card resources, and that prevents the PC from entering the Sleep mode. So either have to close the apps, or press the sleep button manually. Eventually I will look into some brute force way of overriding this behavior - I would rather have my PC go to sleep when unattended than not go to sleep unless I remember to press the button...
Monday, July 13, 2015
Signing ClickOnce WPF application
If you want your users to download and run your application without going through multiple scary red dialog windows with warnings, you need to sing it.
A lot of information on this topic is scattered all over the web. Microsoft has a good set of articles about it. There are bunch of answered questions on Stack Overflow. But sometimes you just want the short version. So here it is.
- To sing any code you need to buy a code signing certificate.
- Update project settings to sign and timestamp the ClickOnce manifest.
- Add a BeforePublish target into your project to sign the executable before it becomes part of the ClickOnce package.
<Exec Command=""C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /n "My Name" /t http://timestamp.comodoca.com/authenticode $(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)" />
</Target>
Where to get a code signing certificate
Short version of the story: I got this one. It was frustrating and cheap. Had to notarize a personal statement, provide a photocopy of driver license, credit card and a utility bill. Also had to publish all my personal contact info on manta.com.
Now, the long version.
First of all, not all certificates are equal - it has to be a code signing certificate (or at least it has to include that capability).
But the majority of code signing certificates are the same. I found an interesting article on this topic.
I compared VeriSign, Thawte, Comodo, K-Software and StartSSL.
First two are crazy expensive and can/should only be used by enterprises that have extra money, so I decided to ignore them from the very beginning. Prices are above 300$
Comodo and K-Software are both selling same certificates (issues by Comodo), but K-Software offers them at lower price. This is the option that I ended up going with.
The last one is StartSSL. The price is very low (59$ for 2 years for the individual certificate). But they do not support time stamping, which means that once your certificate expires your code is no longer signed. (So all of sudden your users start getting errors and warnings and would be forced to contact support or just download the latest version).
About the actual process. K-Software side of the deal is very straightforward and it is very nice dealing with their support. Really nice and helpful.
But once you start to deal with the Comodo side of the deal, it feels like some parallel universe where nothing makes sense. From my conversations it looks like all of their staff is in India and their call center is in India. Those guys are trying their best to work with you, but they still fail.
To get a certificate you have to be authenticated as future owner of the certificate. This means that you will be asked to provide a government-issued photo ID (Driver License), a document that ties you to your home address (for example, a utility bill), and a document that ties you to a financial institution. (Credit card or bank statement). They ask you to fill in an notarize a personal statement about you being you and living where you said you are. This was easy, as any UPS store has a notary in it and it costs around 10$ to notarize that one statement.
The email from Comodo says that you must mail the papers overnight to them - that's extra 50-60$ right there. But a quick call to their support has revealed that it is not necessary - just scan the papers and submit online.
The most frustrating part about that process is that they must find your phone number online in one of the public databases, like www.whitepages.com or www.manta.com. If you own a company, then it's not a big deal - the phone number and the address of your company are both public. But when you are an individual software engineer you do not want your contact information in the public directories.
Unfortunately there was no way to work around this requirement - I had to publish my info on manta.com, they took a phone number from there, a machine called me on that number and gave me some verification code.
After that you get your certificate. It will be installed straight into the certificate store on your machine, so don't be surprised when the final page just says "Success" and nothing else happens. Just export the certificate from the certificates store and you'll have your file.
Tuesday, November 4, 2014
Missing Code Map in VS2013
Right after installing the VS2013 I opened my solution, and started exploring new features. At some point I realized that none of the buttons that were referring to the Code Map feature did anything. No errors, no messages, no other actions in response to my clicks on those menu items.
I googled a bit, but I could not find any useful information. So I started thinking, and in a minute I realized that I have not been asked for the license key yet and that might be somehow related, as this feature is only available in Ultimate edition and so developers probably have tons of checks all over the place to ensure that user has the right to use that feature.
So I went into Help->About->Product License Information and registered a product.
Ta-daam, the Code Map works now just fine. This made my day a bit better.
Thursday, September 16, 2010
Popcorn Hour and Windows 7
Sunday, September 12, 2010
Ignore previous post about WPF
Monday, March 9, 2009
No more WPF for me
Thursday, November 6, 2008
WPF Windows in WinForms project
Wednesday, July 23, 2008
WPF experience - different stages
It seems to me that the experience could be split into several different stages when you work with WPF.
1. You are amazed: You type xml tags and something shows up! Cool! And those animations - ultra cool!!!
2. Trying to develop...a lot...gain experience....and still happy :)
3. You begin to understand how things work, you learn what the ItemsControl is from inside, you understand how to implement the application in a "correct" way and know how are you expected to use the framework in a right way. Now you are a bit disappointed because of the limitations - the WPF does not handle everything...
4. You implement something that is....incompatible with WPF. WPF is not as great as before, or you even start hating it.
5. You understand all benefits and limitations of WPF and start using its best parts and omit bad parts. You finally recall what the development is about (some think that it is about the usage of a technology and not about making the product). Life becomes better :)
6. You are really happy with what you are doing; you make the product and do not worry about the technology limitations.
7. You are ready to move to the next technology to be able to mix them in future.
Seems that I am currently on stage 6 and WPF is really great when you need GUI :)
Monday, July 21, 2008
GET, POST and fetching HTTP with HttpWebRequest
Once upon a time there was a HttpWebRequest. He tried to GET some HTML from YouTube to feed his web browser. HttpWebRequest had default settings and only the URL was unique, so YouTube said - Go request yourself, Bad Request 400!
I have done some basic investigation and found out that usually it is important to provide the Referrer field. So when I added that field (request.Referrer = url;) - the request worked fine for the moment...
But later I decided that I would like to POST some data to the site...I set the request method to POST (request.Method = "POST";), set content type to "multipart/form-data", specified multipart boundary and updated ContentLength (request.ContentLength = xxx;). I opened the request stream (request.GetRequestStream();) and started writing POST form data to it (and calling stream.Flush() from time to time).
After I sent the request I needed the response, so I called request.GetResponse() and read out all data from the stream it returned. (BTW - do not forget to close streams :) )
I noticed that the data is not correct, or at least some part of it is missing (the one at the beginning), so I proceeded with the investigation.
I found out that the header Expect is set to 100-continue, and the web site was against that approach. So I needed to turn it off - I used such setting : request.ServicePoint.Expect100Continue = false;
Usually I also set the UserAgent field and Accept field.
Thursday, June 5, 2008
Two names of a single element
<Window>
<MyControl Name="Control1"/>
</Window>
And inside the control (I mean the XAML file that defines the control) you make a Binding to the control itself, so you need to specify the ElementName. Like that:
<MyControl Name="Root">
<TextBlock Text="{Binding Path=Property1, ElementName=Root}"/>
</MyControl>
So, as you can see, MyControl element has two different names at the same time: Control1 and Root. But how is it possible? The answer will be like following: Different name scopes (I mean NameScope class that implements INameScope interface).
So how did we get two different name scopes for a single element? The secret is that when the UserControl is defined in XAML, and it's XAML definition is loaded, new name scope is created for the control automatically, and all names, that are set inside the control's XAML file or inside its visual tree, goes to its own name scope. And the name, defined in a window definition (like Control1 ), is registered in a windows name scope.
So that is all the magic you need :)
Monday, May 26, 2008
How do I provide custom collection view for collection in WPF?
I made some digging, and found out that there are folks that are interested what is this interface doing (along with some other interesting interfaces...)
MSDN says nothing about this interface, but it turned out that it could be quite useful in fact.
Here is how it is declared:
///
public interface ICollectionViewFactory
{
///
///
ICollectionView CreateView();
}
It turned out that when you try to create a default collection view for the collection(or when you provide your collection as an items source for the ItemsControl), databinding engine checks whether your collection implements ICollectionViewFactory interface, and if it does - your CreateView() method is called, so in case you want to implement some specific logic, like optimized grouping, or specific filtering - you just implement your own collection view and return it in CreateView() method.
Tuesday, May 20, 2008
My level in XAML :)
The proposed leveling is as following:
Level 100 – truly understand all of the above.
Level 200 – confidently read XAML (e.g. as spat out by VS2008 or Blend).
Level 300 – be able to type XAML yourself with an aim to create a structure of a bland GUI (setting basic properties and hooking events etc).
Level 400 – create styles, templates, animations and set gradient colours by hand.
I think, that everyone, who created at least one custom control for WPF (well, I mean something that could be sold), have already achieved the XAML competency level 400 :) At least most of my coworkers did and so did I. I even think that there should be one more level - 500, like God-Like...I do not think that I have achieved such level but it seems that I am somewhere between 400 and 500.
Level 500 means that you definitely know how to implement something in code that could be used correctly in XAML :) Also such level includes knowing how every tag and attribute in XAML works (like the problem with focus scopes, when you should know from the beginning that moving element to the new focus scope will change the behavior of standard WPF controls).
But any way - now we have some kind of competency levels for XAML writers :) Great!
Sunday, May 18, 2008
Post2Blog - Windows client for Blogger, or blogging outside the IE
Recently I have decided that I do not like to make posts in my blog using it’s web-interface, so I have decided to find some windows client for Blogger engine. I have done some search and found a post about the Post2Blog software, so now I am writing this post using that program, and also I am thinking on how can I make money on something like that BTW - funny notice - at the time when a guy wrote his post about this staff, it costed about $40, and now it is free. If I were him, I would be a bit upset now
Post2Blog is really cool application - it supports a variety of blogging engines (Blogger and WorldPress for example), it supports automatic images upload (I do not think that I will use that feature, but still - it is there for free ), and finally - it is FREE.
There is one thing that seems to be missing - Blog2Post is all about posting to the blog and not managing the blog, so the access to the recent posts is a bit confusive...but still - great staff, wonder could it be abandoned and became free...
Friday, April 25, 2008
Great resource for SEO-beginners
I found that blog while I was searching for the ways to trackback my own posts from other blog-engines so that I could see the list of the links to my posts...
Thursday, April 24, 2008
XAML+LoadComponent VS pure code - where are my name scopes???
So, what is the difference between loading XAML and creating element from code? I made a short research using the greatest tool in a .NET world, Reflector, and it turned out that in case when XamlReader (or, to be more specific, BamlRecordReader) meets some element, that does not support INameScope interface, it creates the namescope itself, and attaches it to the element (NameScope.SetNameScope(dependencyObject, new NameScope());).
Finally, to resolve the issue with an exception, we have manually created the NameScope and attached it to the viewport.
Also, XamlReader calls BeginInit and EndInit methods whenewer the loaded element supports ISupportInitialize interface. So you should remember to use that too when you create visual element in code.