…meie igapäevast IT’d anna meile igapäev…


Adding a service reference to ASP.NET vNext/ASP.NET Core 1.0

Recently I started a new project in ASP.NET vNext aka ASP.NET 5, or as it is known since yesterday, ASP.NET Core 1.0. Since right now the framework is still in RC stage, there is next to no documentation to speak of… but that is a topic for another day.

But I had to add several WCF service references to the project to communicate with the back-end server. While we used to have a reasonably nice dialog for service references, it no longer exists in VS 2015 for ASP.NET Core 1.0. However – there is a plugin for adding “Connected services”, read about it at http://blogs.msdn.com/b/webdev/archive/2015/12/15/wcf-connected-service-visual-studio-extension-preview-for-asp-net-5-projects.aspx.

And I cannot stress this enough – while this plugin is in preview/current stage, do not use it. It is not capable of re-using code in referenced assemblies, which means it generates new classes instead of re-using old ones – and it cannot re-create generic classes. E.g. Response<User> becomes ResponseOfUserFq_SrmLzS, which is really not what is expected or wanted.

Instead, use good old svcutil from command line (you should probably create a cmd file, since you’ll probably want to update the service reference repeatedly):

svcutil.exe /l:cs /t:code /n:*,Your.Project.Desired.NameSpace /r:"fullpath-to-dto-assembly.dll" /r:"fullpath-to-model-assembly.dll" /r:"fullpath-to-vendor-assembly.dll" /o:Reference.cs http://localhost:9000/SomeServices/OurService.svc?fullwsdl

This will fetch the service info and create the service client (Reference.cs) and output.config while re-using all of the classes from assemblies specified with the /r keys. /n key allows you to specify the namespace for the generated code.

Note that the code generated with svcutil will require full .NET framework, not just .NET Core 1.0.

After I had figured out all of the above, I put my service configuration to wwwroot\web.config and expected it to work.

Nope. Enpoint configuration not found. No matter what I did, I could not get my development server (Kestrel) to read the <system.serviceModel> wwwroot\web.config. However, invalid XML in there gave an instant error… explain that?!

Googling was not all that helpful. There seems to be no way for ASP.NET Core to read service configuration from JSON files. But then I stumbled upon a lead – release announcement for ASP.NET 5 beta 7 had a single line announcing support of app.config when running on a full .NET framework.

And this is what I needed to do – instead of using good ol’ web.config (oh, how I hate thee!), you have to create an app.config in the root folder of your website (not wwwroot!), same place where project.json lives. You can just move the output.config there and rename it to app.config – and System.ServiceModel will now happily read the configuration from there.


Some fun with FizzBuzz in C#

Filed under: Isiklikud,Programmeerimine — Sander @ 13:34:03
Tags: ,

image As a very first thing, I must say that I don’t like whiteboard coding exercises during the job interviews.

These exercises have almost never any relation to real-life programming problems (“Reverse a linked list?” If your reply is anything besides “linkedList.Reverse();”, your answer is wrong.). There are only a few dozen common whiteboard coding questions – and every candidate with a common sense will review those before the interview.

Finally, success with whiteboard coding seems to have next to no connection with the actual qualities of the candidate. And yes, this includes “solving a problem under pressure”.

I much prefer to give the candidates a small task, to do at home in 2..3h. This will give me much more information – what is his coding style? Can he write high-quality and well-commented code? Did he actually manage to finish all parts of the task – and if not, then why? Does he even want the position enough to do a proper job?

That all said, FizzBuzz does have one good use – it can be used to quickly weed out the candidates who cannot program at all. If they cannot do a simple logical exercise, and write a loop with a couple of if-clauses inside it, they really shouldn’t be hired as developers.

That is why ex-coworker Erti-Chris and I were rather surprised after reading “Tales of a Non-Unicorn: A Story About The Trouble with Job Titles and Descriptions” (reddit thread). A person claiming to be “designer/developer if there ever was one” goes “OMG MATH” and cannot solve FizzBuzz (which has almost nothing to do with math)?!

Out of boredom we started to play around with FizzBuzz – albeit in C#, not JS (but all our ideas work with Javascript as well, with a little prodding) – first the “standard solution” and then limiting ourselves further and further.

The “standard solution” using modulus:

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x % 3;
  4.     var d5 = x % 5;
  6.     Print(d3 == 0, d5 == 0, x);
  7. });

Method Print is used repeatedly, it is the same everywhere:

  1. private static void Print(bool three, bool five, int i)
  2. {
  3.     if (three && !five)
  4.         Console.WriteLine("Fizz");
  5.     else if (five && !three)
  6.         Console.WriteLine("Buzz");
  7.     else if (five)
  8.         Console.WriteLine("FizzBuzz");
  9.     else
  10.         Console.WriteLine(i);
  11. }

But what if we don’t allow modulus to be used?

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x / 3f == Math.Round(x / 3f);
  4.     var d5 = x / 5f == Math.Round(x / 5f);
  6.     Print(d3, d5, x);
  7. });

But what about not using neither round nor modulus?

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x / 3 * 3 == x;
  4.     var d5 = x / 5 * 5 == x;
  6.     Print(d3, d5, x);
  7. });

(and also the same limitations as above, nutcase version. Proudly mine).

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {            
  3.     var d3 = !(x / 3f).ToString().Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
  4.     var d5 = !(x / 5f).ToString().Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
  6.     Print(d3, d5, x);
  7. });

Still too easy. What about not allowing modulus, rounding, multiplication and division?

  1. for (int i = 0, three = 0, five = 0; i < 100; i++, three++, five++)
  2. {
  3.     if (three == 3 && five == 5)
  4.     {
  5.         Console.WriteLine("FizzBuzz");
  6.         three = 0;
  7.         five = 0;
  8.     }
  9.     else if (three == 3)
  10.     {
  11.         Console.WriteLine("Fizz");
  12.         three = 0;
  13.     }
  14.     else if (five == 5)
  15.     {
  16.         Console.WriteLine("Buzz");
  17.         five = 0;
  18.     }
  19.     else
  20.         Console.WriteLine(i);
  21. }

Amusingly, the last version is fastest of them all.

And by now we were out of time and bored of this. It was fun, though – a sort of minor coding kata.

All the code above can be seen and executed in dotNetFiddle, https://dotnetfiddle.net/84PodI


How to set the language of the Google Calendar RSS/Atom feed

Filed under: Infotehnoloogia,Nipid — Sander @ 10:55:02
Tags: , , , ,

At home, Google Calendar feed was in Finnish. At work, in English. In InoReader, my current feed reader, Serbian (I think…). In my previous feed reader, Russian.

And no, I didn’t want it that way. Unfortunately, for some reason, instead of using my selected language in Calendar, Google seems to use a badly implemented combination of location sniffing and browser/client accept-language header to specify the language of the feed.

Officially there is no way to set the language of the feed (parameter reference). The “locale” in the same page does not work for feeds, nor does “lan=en” as recommended here. However, non-feed related Google Calendar forum post pointed me to the right direction.

You have to append hl=en (or other google-supported two-letter language code) to your feed URL. So that /calendar/feeds/[email]/private-[key]/basic becomes /calendar/feeds/[email]/private-[key]/basic?hl=en – or, with the other parameters, /calendar/feeds/[email/private-[key]/basic?futureevents=true&max-results=100 to /calendar/feeds/[email/private-[key]/basic?futureevents=true&max-results=100&hl=en.

Järgmine lehekülg »

The Rubric Theme. Blog at WordPress.com.


Get every new post delivered to your Inbox.

Join 83 other followers