tag:blogger.com,1999:blog-37088180474050381922024-03-13T19:29:12.115+01:00IT / Administration / Development / other stuffDaniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.comBlogger111125tag:blogger.com,1999:blog-3708818047405038192.post-61206312169435185992019-11-27T00:52:00.000+01:002019-11-27T00:52:21.035+01:00Parallax Scrolling<div dir="ltr" style="text-align: left;" trbidi="on">
This seems to be old but gold: <b>Parallax Scrolling</b>.<br />
It is an effect where you push content into different layers and scroll or move them in different speed.<br />
<br />
You can see a demo here on w3schools: <a href="https://www.w3schools.com/howto/howto_css_parallax.asp">https://www.w3schools.com/howto/howto_css_parallax.asp</a><br />
<br />
<br />
The things I found out during research (and that are really new to me) are:<br />
<br />
- different speed means also zero speed (static background images are counted as parallax)<br />
- it is not forbidden to create effects on scrolling (so eg: one image can be shown in different situations while the content in the background represents the scenes) AND this is also counted as parallax.<br />
- parallax is still cool :-)<br />
<br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-2437696819165444732019-08-26T22:51:00.001+02:002019-08-26T22:51:21.955+02:00JWT for sessions<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
got this from colleague...<br />
<br />
<a href="http://cryto.net/~joepie91/blog/2016/06/19/stop-using-jwt-for-sessions-part-2-why-your-solution-doesnt-work/">http://cryto.net/~joepie91/blog/2016/06/19/stop-using-jwt-for-sessions-part-2-why-your-solution-doesnt-work/</a><br />
<br />
the graphic is gold.<br />
<br />
kr,<br />
Daniel</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-14738872909042661832019-04-13T00:07:00.001+02:002019-04-13T00:07:42.579+02:00Over Engineering<div dir="ltr" style="text-align: left;" trbidi="on">
Over-Engineering is something most of the developers I know struggle with. Nevertheless, the term is also very subjective. What is over-engineered for developer A might be a perfect strategic step in the right direction for developer B. (in the following section the italic sentences are direct quotes from <a href="https://hackernoon.com/how-to-accept-over-engineering-for-what-it-really-is-6fca9a919263">hackernoon here</a>)<br />
<br />
<i>Over-Engineering is subjective and the damage of its subjectiveness increase as the requirements fail to present the full picture of the problem</i><br />
<br />
So to define the term:<br />
<br />
<i>Over-Engineering is when someone decides to build more than what is really necessary based on speculation</i><br />
<br />
So if we assume that speculation is the root cause then the following quote is the logical consequence:<br />
<br />
<i>To reduce the chances of considering something as Over-Engineering we need to understand the problem and to understand the problem we need to clarify the requirements as much as possible by asking "why"?</i><br />
<br />
But there is more than that... Further Reasons (as described in <a href="https://www.youtube.com/watch?v=fnHuQdX1lNs&feature=youtu.be">cloud-foundry on youtube here</a>):<br />
<br />
<ul style="text-align: left;">
<li>consider the data</li>
<ul>
<li>like:</li>
<ul>
<li>how often are things used</li>
<li>how often are things changed</li>
<li>how long does a process take</li>
<li>is the process responsive</li>
<li>...</li>
</ul>
<li>we don't have it (green field, bad data gathering)</li>
<ul>
<li>it might be too early to make a decision for further engineering (refactoring)...</li>
<li>will we have the data somewhen?</li>
<li>can we ask someone?</li>
<ul>
<li>do we really trust this guy?</li>
</ul>
</ul>
<li>do we ignore the data and might make bad decisions</li>
<li>even if something is crap: </li>
<ul>
<li>is it worth changing it?</li>
<ul>
<li>return of invest?</li>
</ul>
<li>do we have use-cases that work out better by improving the software</li>
</ul>
</ul>
<li>unnecessary complexity because of pride</li>
</ul>
<div>
Further reasons (as described in <a href="https://www.youtube.com/watch?v=GRr4xeMn1uU">build stuff-youtube here</a>):</div>
<div>
<ul style="text-align: left;">
<li>we are not listening to what we need to deliver (bicycle -> spaceship)</li>
<li>frameworks don't deliver value (even if funnier to solve any problem then one specific)</li>
<li>business guys are responsive to risk and not preventative so not implementing stuff might be ok for your product owner</li>
<li>don't focus on all the things that might go wrong, but recognize that you're still on the happy path (that nothing went wrong right now)</li>
</ul>
<div>
<br /></div>
</div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-21414098905179968822018-12-04T22:36:00.002+01:002018-12-04T22:36:36.487+01:00Call for papers - link list of link lists<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<ul style="text-align: left;">
<li><a href="https://github.com/softwaremill/it-cfp-list"><span style="color: blue;">https://github.com/softwaremill/it-cfp-list</span></a></li>
<li><a href="https://callforpapers.sandsmedia.com/"><span style="color: blue;">https://callforpapers.sandsmedia.com/</span></a></li>
<li><a href="http://www.wikicfp.com/cfp/"><span style="color: blue;">http://www.wikicfp.com/cfp/</span></a></li>
<li><a href="http://callingallpapers.com/"><span style="color: blue;">http://callingallpapers.com/</span></a></li>
<li><a href="https://www.papercall.io/"><span style="color: blue;">https://www.papercall.io/</span></a></li>
<li><a href="https://calendar.google.com/calendar/embed?src=mozilla.com_tptb36ac7eijerilfnf6c1onfo@group.calendar.google.com&ctz=America/Los_Angeles&pli=1"><span style="color: blue;">https://calendar.google.com/calendar/embed?src=mozilla.com_tptb36ac7eijerilfnf6c1onfo@group.calendar.google.com&ctz=America/Los_Angeles&pli=1</span></a></li>
<li><a href="https://10times.com/"><span style="color: blue;">https://10times.com/</span></a></li>
</ul>
<div>
<br /></div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-6520226829445366742018-08-17T18:13:00.000+02:002018-08-17T18:13:43.019+02:00cs-script or compile<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
today I evaluated how easy it is to compile code in the command line and wanted to compare it to C# interactive window.<br />
<br />
This is my generic script to compile<br />
<br />
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<span lang="EN-US">@echo off<u></u><u></u></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<span lang="EN-US">C:\Windows\Microsoft.NET\<wbr></wbr>Framework64\v4.0.30319\csc.exe /t:exe /out:output.exe *.cs >nul 2>nul<u></u><u></u></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
.\output.exe<u></u><u></u></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
del output.exe<u></u><u></u></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
pause;</div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
Consider, I need a fully blows c# file to write hello world to the console:</div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
Something like<br /></div>
<blockquote class="tr_bq" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<span class="hljs-comment" style="box-sizing: inherit; color: green; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">// A Hello World! program in C#.</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">
</span><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">using</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;"> System;
</span><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">namespace</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;"> </span><span class="hljs-title" style="box-sizing: inherit; color: #007d9a; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">HelloWorld</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">
{
</span><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">class</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;"> </span><span class="hljs-title" style="box-sizing: inherit; color: #007d9a; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">Hello</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">
{
</span><span class="hljs-function" style="box-sizing: inherit; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;"><span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd;">static</span> <span class="hljs-keyword" style="box-sizing: inherit; color: #0101fd;">void</span> <span class="hljs-title" style="box-sizing: inherit; color: #007d9a;">Main</span>(<span class="hljs-params" style="box-sizing: inherit;"></span>)
</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">{
Console.WriteLine(</span><span class="hljs-string" style="box-sizing: inherit; color: #a31515; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">"Hello World!"</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">);
</span><span class="hljs-comment" style="box-sizing: inherit; color: green; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">// Keep the console window open in debug mode.</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">
Console.WriteLine(</span><span class="hljs-string" style="box-sizing: inherit; color: #a31515; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">"Press any key to exit."</span><span style="background-color: #f9f9f9; color: black; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">);
Console.ReadKey();
}
}
}</span></blockquote>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
(see: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/hello-world-your-first-program )</div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
This is a bit much in comparison to (started in developer command prompt):</div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<blockquote class="tr_bq" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
command: csi csitest.csx<br />content: <span style="background-color: #f9f9f9; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">Console.WriteLine(</span><span class="hljs-string" style="background-color: transparent; box-sizing: inherit; color: #a31515; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">"Hello World!"</span><span style="background-color: #f9f9f9; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;">);</span></blockquote>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<span style="background-color: #f9f9f9; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 14px; white-space: pre;"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
We definitely have a winner here... </div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
<br /></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
kr,</div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: small;">
Daniel</div>
<div>
<br /></div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-15103585464149536422018-06-15T00:34:00.000+02:002018-06-15T00:34:49.553+02:00using angular-cli for vanilla javascript projects<div dir="ltr" style="text-align: left;" trbidi="on">
it is very handy to use the angular CLI using "ng serve --open" especially in combination with vs code... the usage of web-pack under the hood (and many more state of the art stuff) are very nice and implement all needed build steps with no effort at all.<br />
<br />
For <span style="background-color: white;">HTML </span>projects consider to use this template too, but reduce it to the following:<br />
<br />
* index.html: remove app-root<br />
* main.ts: remove AppModule import and usage and remove app-folder at all<br />
* use style.css as style sheet file<br />
* add a js file and add it to the scripts part in the angular.json (like src/logic.js)<br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-6031030936226404832018-05-28T20:29:00.000+02:002018-05-28T20:29:01.068+02:00c# string concatenation beyond StringBuilder<div dir="ltr" style="text-align: left;" trbidi="on">
I compared in a race with 1 million iterations the execution times of<br />
<br />
<ol style="text-align: left;">
<li>StringBuilder with an Action call to "Append" a single character (as string)</li>
<li>StringBuilder with a function call to "Append" a single character (as string)</li>
<li>direct string = string + character (as string)</li>
<li>StringBuilder with an Action called to "Append" a single character (as string) but initialized with 1M+1 size</li>
<li>StringBuilder with a direct call to "Append" a single character (as string) initialized</li>
<li>like 5 but a single character is added as a character.</li>
</ol>
<div>
<br /></div>
<div>
Here the results in ms:</div>
<div>
<br /></div>
<br />
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<div class="MsoNormal" style="font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"> V5 13</span></div>
<div class="MsoNormal" style="font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"> </span><span style="color: black; font-family: Calibri, sans-serif;"> </span><span style="color: black; font-family: Calibri, sans-serif;">V4 20<u></u><u></u></span></div>
</div>
<div>
<div style="background-color: white;">
<div style="color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<div class="MsoNormal" style="font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif; font-size: 12pt;"> V6</span><span style="color: black; font-family: Calibri, sans-serif; font-size: 12pt;"> 29</span></div>
</div>
<div style="color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
</div>
<div style="color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<div class="MsoNormal" style="font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"> V2 35</span></div>
</div>
<div style="color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
</div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"> V1 57<u></u></span></div>
<div class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif; font-size: 12pt;"> V3 </span><span style="font-family: Calibri, sans-serif;">839343</span></div>
</div>
<div style="background-color: white; font-size: 12.8px;">
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;">As we see in V4/5/6 the initialization of a string builder without the need of reallocation is the absolute performance gain by far. The indirection using an action I would consider to be a cheap operation (see 4 vs 5). </span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;">Using a StringBuilder, in this case, is a MUST as we can see it on the scoreboard. </span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;">Interesting is that adding a character instead of a string doubles the execution time.</span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;">Comparing 1 and 4 makes it obvious how expensive the allocation of further storage is. </span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="font-family: Calibri, sans-serif;">In V3 garbage collection is called constantly.</span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="color: #222222; font-family: "Times New Roman", serif; font-size: 12pt; margin: 0cm 0cm 0.0001pt;">
<span style="color: black; font-family: Calibri, sans-serif;">While these results differ heavily (especially the numbers of the execution time) from run to run even on the same machine, they differ even more on different machines. Nevertheless, the statements derived are valid.</span></div>
</div>
</div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-54634989934900488522018-05-28T19:46:00.000+02:002018-05-28T19:46:21.008+02:00windows services - installation / deinstallation toggle script<div dir="ltr" style="text-align: left;" trbidi="on">
Tried to find a script that installs a windows service if it is not installed and is capable to deinstall it if needed. Finally, I created myself the following:<br />
<br />
<blockquote class="tr_bq" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US">sc query SERVICENAME</span><span lang="EN-US">if %errorlevel% equ 0 (</span><span lang="EN-US"> echo uninstall</span><span lang="EN-US"> goto uninstall</span><span lang="EN-US">) else (</span><span lang="EN-US"> echo install</span><span lang="EN-US"> goto install</span><span lang="EN-US">)</span></blockquote>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US">Check if it is installed: if so uninstall, if not install. </span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US">in :install call:</span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal" style="background-color: white;">
</div>
<ul style="text-align: left;">
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">sc create SERVICENAME binpath=%cd%\Service.exe displayname="the service" start=demand </span></span></li>
<ul>
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">if you need to set credentials for the startup then set: obj and password</span></span></li>
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">%cd% is the current directory</span></span></li>
</ul>
<li>sc start SERVICENAME</li>
</ul>
<br />
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US"><br /></span></div>
<div class="MsoNormal" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8px;">
<span lang="EN-US">in :uninstall call:</span></div>
<div class="MsoNormal" style="background-color: white;">
</div>
<ul style="text-align: left;">
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">sc stop SERVICENAME</span></span></li>
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">sc delete SERVICENAME</span></span></li>
<ul>
<li><span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;">delete can already be called even if the service is still in "stopping" state so in a script it works the right way even with some timing issues</span></span></li>
</ul>
</ul>
<div>
<span style="color: #222222; font-family: arial, sans-serif;"><span style="font-size: 12.8px;"><br /></span></span></div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-8837754636371562192018-05-26T21:30:00.001+02:002018-05-26T21:30:11.842+02:00Printing web pages to pdf<div dir="ltr" style="text-align: left;" trbidi="on">
As an extremely lazy person I started automating a lot of tasks... so many that I started writing the results (successful execution / failed execution) into the database to query for errors. Then I started writing the logs and execution times into db. It became so huge that we wrote a dashboard application to check state.<br />
<br />
Today I want to forward this dashboard to some colleagues without granting them access to the platform... solution: mailing a pdf. I asked myself if there is a way to convert the html page into a pdf easily and found the following solution with chrome. The following snippets shows a batch script for windows.<br />
<br />
<div class="MsoNormal" style="-webkit-text-size-adjust: auto; color: #313131; font-family: "Times New Roman", serif; font-size: 16px; margin-left: 0cm; margin-right: 0cm; word-spacing: 1px;">
<span data-originalcomputedfontsize="16" data-removefontsize="true" lang="EN-US" style="font-size: 1rem;">@echo %time%<u></u><u></u></span></div>
<div class="MsoNormal" style="-webkit-text-size-adjust: auto; color: #313131; font-family: "Times New Roman", serif; font-size: 16px; margin-left: 0cm; margin-right: 0cm; word-spacing: 1px;">
<span data-originalcomputedfontsize="16" data-removefontsize="true" lang="EN-US" style="font-size: 1rem;">@"C:\Users\{user}\AppData\<wbr></wbr>Local\Google\Chrome\<wbr></wbr>Application\chrome.exe" --headless --disable-gpu --print-to-pdf=c:\{<wbr></wbr>outputFolder}\output.pdf <a data-originalcomputedfontsize="16" data-removefontsize="true" href="https://www.blogger.com/null" style="color: #4285f4; font-size: 1rem;">file:///{pathToIndex}/index.<wbr></wbr>html</a><u></u><u></u></span></div>
<div class="MsoNormal" data-originalcomputedfontsize="16" data-removefontsize="true" style="-webkit-text-size-adjust: auto; color: #313131; font-family: "Times New Roman", serif; font-size: 1rem; margin-left: 0cm; margin-right: 0cm; word-spacing: 1px;">
@echo %time%<u></u><u></u></div>
<div class="MsoNormal" data-originalcomputedfontsize="16" data-removefontsize="true" style="-webkit-text-size-adjust: auto; color: #313131; font-family: "Times New Roman", serif; font-size: 1rem; margin-left: 0cm; margin-right: 0cm; word-spacing: 1px;">
@pause</div>
<br />
<br />
Keep an eye on the fact that the screenshot is taken after onload is executed which can take several seconds.<br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-70077983549038018852018-05-05T21:05:00.003+02:002018-05-05T21:05:36.095+02:00minimal .NET core web api<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
today I tried to create a minimal .NET core web API application which returns a result as a foundation for a micro-service approach...<br />
<br />
Here the code that works (pasted into main):<br />
<br />
<br />
WebHost.CreateDefaultBuilder(args)<br />
.Configure(app =><br />
{<br />
app.Run(async context =><br />
{<br />
using (StreamWriter writer = new StreamWriter(context.Response.Body))<br />
{<br />
await writer.WriteAsync(await Task.FromResult("this works..."));<br />
}<br />
});<br />
})<br />
.Build()<br />
.Run();<br />
<br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-89333469462698591092018-05-03T23:01:00.000+02:002018-05-03T23:01:04.710+02:00sql server local time and utc time<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
there is a nice way to make a local DateTime value to a UTC DateTime value. First, I thought I can add a fixed amount of hours, but this is unfortunately not ok because change summer- to winter-time made the calculation invalid. So I found a very nice trick on StackOverflow...<br />
<br />
http://sqlfiddle.com -> SQL Server<br />
<br />
select getdate() as localtime, getutcdate() as utctime, datediff(hour, getdate(), getutcdate())<br />
<br />
We can check the local time and the UTC time and add the delta as the offset to the local time. This is unfortunately only true if the local time value is in the same timezone as you are currently, but for my case it worked...<br />
<br />
kr,<br />Daniel</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-43107734318020519002018-02-03T16:44:00.000+01:002018-02-03T16:44:11.727+01:00changing command prompt in windows 10<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
today I tried something nerdy and wanted to improve my cmd - ux in windows (using windows 10).<br />
<br />
First of all the useless stuff:<br />
<br />
color a0<br />
<br />
introducing a nice matrix look and feel.<br />
<br />
Probably you remember the quote "follow the white rabbit", so I added a bunny in the prompt:<br />
<br />
prompt $_ _$_ (\\ $_ \$B$B$_ __(_";$_ / \$_ {}___)\)_ $_$P><br />
<br />
with cls (clear screen) you see the bunny up there and it appears after any command entered... funny for about 2 minutes... then really annoying... removed it...<br />
<br />
sticking to the original output and add date and time turned out to be more useful<br />
<br />
prompt $D $T$_$P$G<br />
<br />
to much space, to few info...<br />
<br />
prompt $D $T $C%USERDOMAIN%\%USERNAME%$F$_$P$G<br />
<br />
more info!<br />
<br />
ipconfig|for /f "tokens=12 delims=: " %G in ('findstr /i ipv4') do ( echo %G ) > ip.txt<br />
set /p ip=<ip.txt<br />
prompt $D $T $C%USERDOMAIN%\%USERNAME%$F IP: %ip%$_$P$G<br />
<br />
linux / bash style:<br />
prompt %username%@%userdomain%: $P $T$$<br />
<br />
but best experience with simple stuff<br />
<br />
prompt $P $T$G<br />
<br />
kr,<br />
Daniel</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-75082966455949941012017-12-19T19:35:00.001+01:002017-12-19T19:35:34.687+01:00T4 Generation Templates VS 2017<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
It took me a lot of time to find good resources about T4 (even if there are no real alternatives built-in for visual studio). Here a small template to create multiple files easily...<br />
<br />
I used following resources exists using archive.org:<br />
<br />
<ul style="text-align: left;">
<li><a href="https://web.archive.org/web/20160501025241/http:/www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/">https://web.archive.org/web/20160501025241/http:/www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/</a></li>
<li><a href="https://web.archive.org/web/20160402073438/http://www.olegsych.com/2008/05/t4-architecture/">https://web.archive.org/web/20160402073438/http://www.olegsych.com/2008/05/t4-architecture/</a></li>
</ul>
<div>
Further resources:</div>
<ul style="text-align: left;">
<li><a href="https://resharper-plugins.jetbrains.com/packages/JLebosquain.ForTea/">https://resharper-plugins.jetbrains.com/packages/JLebosquain.ForTea/</a></li>
<li><a href="https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates">https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates</a></li>
<ul>
<li>writing info in error window: Error("error"), Warning("warning")</li>
</ul>
</ul>
<div>
<br /></div>
<br />
kr,<br />
Daniel<br />
<br />
<#@<br />
template debug="false" hostspecific="true" language="C#" #><#@<br />
<br />
assembly name="System.Core" #><#@<br />
<br />
import namespace="System.Linq" #><#@<br />
import namespace="System.Text" #><#@<br />
import namespace="System.IO" #><#@<br />
import namespace="System.Collections.Generic" #><#@<br />
<br />
output extension=".log" #><#<br />
<span style="white-space: pre;"> </span>CleanOutputFolder();<br />
<br />
<span style="white-space: pre;"> </span>string propertyName = "Prop";<br />
<br />
<span style="white-space: pre;"> </span>Enumerable.Range(1,3).ToList().ForEach(id => {<br />
<br />
<span style="white-space: pre;"> </span>StringBuilder builder = new StringBuilder();<br />
<span style="white-space: pre;"> </span>builder.AppendLine("public class Data" + id.ToString("00"));<br />
<span style="white-space: pre;"> </span>builder.AppendLine("<span style="white-space: pre;"> </span>{");<br />
<span style="white-space: pre;"> </span>Enumerable.Range(1,3).ToList().ForEach(propId => {<br />
<span style="white-space: pre;"> </span>builder.AppendLine("<span style="white-space: pre;"> </span>public int "+propertyName+propId+" { get; set; }");<br />
<span style="white-space: pre;"> </span>});<br />
<span style="white-space: pre;"> </span>builder.AppendLine("<span style="white-space: pre;"> </span>}");<br />
<br />
<span style="white-space: pre;"> </span>CreateClass("Data"+id.ToString("00")+".cs", builder.ToString());<br />
<span style="white-space: pre;"> </span>});<br />
<span style="white-space: pre;"> </span><br />
<br />
#><#+<br />
<span style="white-space: pre;"> </span>public void CleanOutputFolder()<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);<br />
<span style="white-space: pre;"> </span>string outputFolder = Path.Combine(templateDirectory, "output/");<br />
<span style="white-space: pre;"> </span>foreach(var file in Directory.GetFiles(outputFolder))<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>File.Delete(file);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>}<br />
<br />
<span style="white-space: pre;"> </span>public void SaveOutput(string outputFileName)<br />
<span style="white-space: pre;"> </span>{<br />
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);<br />
string outputFilePath = Path.Combine(templateDirectory, "output/", outputFileName);<br />
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());<br />
<br />
this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);<br />
<span style="white-space: pre;"> </span>}<br />
<br />
<span style="white-space: pre;"> </span>public void CreateClass(string fileName, string content)<br />
<span style="white-space: pre;"> </span>{<br />
#><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Threading.Tasks;<br />
<br />
namespace Test<br />
{<br />
<span style="white-space: pre;"> </span><#= content #><br />
}<span style="white-space: pre;"> </span><br />
<br />
<#+<br />
<span style="white-space: pre;"> </span>SaveOutput(fileName);<br />
<span style="white-space: pre;"> </span>}<br />
#><br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-54117460877057274512017-12-18T20:14:00.001+01:002017-12-18T20:14:51.974+01:00Dumping objects in c#<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
I had a look at different possibilities to .net objects. First I was like: "just serialize that stuff and everything will be fine", but the more I thought about it, the more I realized that I needed more...<br />
<br />
First of all: LinqPad did a great job with its functionality to dump objects, which was very inspiring to me...<br />
<br />
see:<br />
<br />
<ul>
<li><a href="https://stackoverflow.com/questions/3555317/linqpad-extension-methods">https://stackoverflow.com/questions/3555317/linqpad-extension-methods</a></li>
<li><a href="https://www.linqpad.net/CustomizingDump.aspx">https://www.linqpad.net/CustomizingDump.aspx</a></li>
</ul>
<br />
<br />
... so what might be a good solution to embed into our code...?<br />
<br />
Good fitting solution seemed to be ObjectDumper (unfortunately you can find different solutions with the same name in google):<br />
<br />
<b>ObjectDumper </b>(version: stone-age)<br />
<br />
<ul>
<li><a href="https://code.msdn.microsoft.com/vstudio/MSDN-108-C-LINQ-Samples-52207c43/sourcecode?fileId=108854&pathId=1317055433">https://code.msdn.microsoft.com/vstudio/MSDN-108-C-LINQ-Samples-52207c43/sourcecode?fileId=108854&pathId=1317055433</a></li>
<li>this version could not work with e.g. dictionaries (my first test)</li>
</ul>
<br />
<br />
<b>ObjectDumper </b>(version: old)<br />
<br />
<ul>
<li><a href="http://sourcebrowser.io/Browse/maxtoroq/DbExtensions/samples/App/Utilities/ObjectDumper.cs">http://sourcebrowser.io/Browse/maxtoroq/DbExtensions/samples/App/Utilities/ObjectDumper.cs</a></li>
<li>seem to be based on the original but slightly improved (e.g. outside interface).</li>
</ul>
<br />
<br />
<b>ObjectDumper</b> (not a single-file-solution anymore, Options to ignore fields)<br />
<br />
<ul>
<li><a href="https://objectdumper.codeplex.com/SourceControl/latest#src/ObjectDumper/Dumper.cs">https://objectdumper.codeplex.com/SourceControl/latest#src/ObjectDumper/Dumper.cs</a></li>
<li>base of: <a href="https://www.nuget.org/packages/ObjectDumper/">https://www.nuget.org/packages/ObjectDumper/</a></li>
</ul>
<br />
<br />
<b>ObjectDumper</b> (Finally the current version without a single commit in the last 2 years... same version as CodePlex?)<br />
<br />
<ul>
<li><a href="https://github.com/lassevk/ObjectDumper/tree/master/src/ObjectDumper">https://github.com/lassevk/ObjectDumper/tree/master/src/ObjectDumper</a></li>
</ul>
<br />
<br />
So I started further testing with the github version:<br />
<br />
<br />
<ul>
<li>installation: copy Dumper.cs and DumperOptions</li>
<li>DumperOptions can be removed easily... only 1 line must be patched (the rest is just handover of the options object into the recursive call)</li>
</ul>
<br />
<br />
IEnumerable<FieldInfo> fields = XY ? Enumerable.Empty<FieldInfo>() : type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);<br />
<div>
<br /></div>
<div>
you can replace XY by a constant or a static field, so even the github version can be a single file solution again.</div>
<div>
<br /></div>
<div>
<ul>
<li>alternatively nuget is available (as already mentioned)</li>
<li>its a simple recursive solution based on GetFields and GetProperties</li>
<li>can read private data using reflection but <u>can not handle static members</u></li>
<li>Every reference type is pushed into an object of class ObjectIDGenerator generating making it easy to make cross-references of objects (e.g.: backing field and property)</li>
<ul>
<li>not a feature I really need, so I tried to delete it, but found out that it is a perfect solution to remove circular stepping into the code, so it is not only for printing purpose.</li>
</ul>
</ul>
<div>
For me it works perfectly.</div>
</div>
<div>
<br /></div>
<div>
The following Test shows a first impression:</div>
<div>
<br /></div>
<div>
<blockquote class="tr_bq">
public class Data<br /> {<br /> private int secret = 15;<br /> private string secondSecret = "15";<br /> public static string staticData = "123";<br /> public int Public => secret * 2 + 3;<br /> public string Something => "something";<br /> public int StoredData { get; set; }<br /> public string StoredData2 { get; set; }<br /> public Data()<br /> {<br /> this.StoredData = 1;<br /> this.StoredData2 = "1";<br /> }<br /> public Data2 data2 = new Data2();<br /> public class Data2<br /> {<br /> public bool IsData { get; set; } = false;<br /> }<br /> }</blockquote>
</div>
<div>
<br /></div>
<div>
Dumped:</div>
<div>
<br /></div>
<div>
<blockquote class="tr_bq">
#1: data [DumpTester.Program+Data]<br />{<br /> properties {<br /> Public = 33 [System.Int32]<br /> #2: Something = "something" [System.String]<br /> StoredData = 1 [System.Int32]<br /> #3: StoredData2 = "1" [System.String]<br /> }<br /> fields {<br /> secret = 15 [System.Int32]<br /> #4: secondSecret = "15" [System.String]<br /> <StoredData>k__BackingField = 1 [System.Int32]<br /> <StoredData2>k__BackingField = "1" [System.String] (see #3)<br /> #5: data2 [DumpTester.Program+Data+Data2]<br /> {<br /> properties {<br /> IsData = False [System.Boolean]<br /> }<br /> fields {<br /> <IsData>k__BackingField = False [System.Boolean]<br /> }<br /> }<br /> }<br />}</blockquote>
</div>
<div>
you see:</div>
<div>
<ul>
<li>no static info</li>
<li>AutoProperties with Backing-Fields</li>
<li>For reference-auto-properties you see the linkage between Prop and Field (see #3)</li>
<li>ValueTypes have no reference</li>
<li>Types in the system namespace are not dumped</li>
</ul>
<div>
<br /></div>
</div>
<div>
<br /></div>
<div>
kr,</div>
<div>
Daniel</div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-84712509205265986902017-11-09T14:54:00.000+01:002017-11-09T14:54:03.428+01:00benchmarking<div dir="ltr" style="text-align: left;" trbidi="on">
Found a cool benchmarking nuget-package. It is called nbench and unfortunately I am not sure if the project is dead or not, but nevertheless the current state can add to the functional unit test the non-functional performance test which is quite cool.<br />
<br />
It can be used for .net and .net core projects with a variety of possibilities. This project fills one of the gaps of a nightly compile run and might be helpful in many cases to keep quality high.<br />
<br />
see: <a href="https://github.com/petabridge/NBench">https://github.com/petabridge/NBench</a></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-61830982859057994192017-11-09T14:02:00.000+01:002017-11-09T15:01:45.989+01:00IIS development and exceptions<div dir="ltr" style="text-align: left;" trbidi="on">
In a production environment it is often a good idea to hide some errors of e.g.: a web-page to be able to work on the root cause of the error in the background that finally the customer will not identify some strange behavior as a bug.<br />
<br />
Exactly the opposite is true for developers and testers. Find bugs! Don't cover them with any UI candy or stuff... and exactly in this trap I fell into...<br />
<br />
see customErrors on msdn: <a href="https://msdn.microsoft.com/de-at/library/h0hfz6fc(v=vs.110).aspx">https://msdn.microsoft.com/de-at/library/h0hfz6fc(v=vs.110).aspx</a><br />
<br />
and for web api 2 see: <a href="https://msdn.microsoft.com/en-us/library/system.web.http.filters.exceptionfilterattribute(v=vs.118).aspx">https://msdn.microsoft.com/en-us/library/system.web.http.filters.exceptionfilterattribute(v=vs.118).aspx</a><br />
<a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling">https://docs.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling</a><br />
<br />
see also AppDomain.UnhandledException, <span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;">Application.ThreadException / Application.SetUnhandledExceptionMode (for WinForms), DispatcherUnhandledException (for WPF), Application_Error (IIS Global asax)</span><br />
<br />
Be careful to disable stuff that makes it hard to find bugs during testing :-) </div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-83796411273688435002017-10-31T00:20:00.001+01:002017-10-31T00:20:22.123+01:00mstest with test cases<div dir="ltr" style="text-align: left;" trbidi="on">
I am still wondering why there is not better support in mstest for test-cases as it is in nunit like described in http://nunit.org/docs/2.5/testCase.html ... nevertheless I wrote a code snippet which makes life bit easier... I assemble the data to test into the test-name which is not that bad as it might sound, because in some cases e.g.: testing mathematical functions you want to see the input data which is used directly and so you would write it into the name anyway... so we can use the name of the test and reflect over it like:<br />
<br />
public static int[] GetIntArrayFromName()<br />
{<br />
StackTrace t = new StackTrace(skipFrames: 1);<br />
var frames = t.GetFrames();<br />
string name = frames.First().GetMethod().Name;<br />
return name.Split('_').Skip(1).Select(x => int.Parse(x)).ToArray();<br />
}<br />
<br />
so if you call this function inside a test-method which is called something like Test_1_2_3 you will get an array like new[]{1,2,3} which might fit quite well.<br />
<br />
[TestMethod] public void Add_1() => AddMethod(GetIntArrayFromName());<br />
[TestMethod] public void Add_1_2() => AddMethod(GetIntArrayFromName());<br />
[TestMethod] public void Add_5_4_6_3_1() => AddMethod(GetIntArrayFromName());<br />
[TestMethod] public void Add_7_5_1_3_4() => AddMethod(GetIntArrayFromName());<br />
<br />
the rest is copy / pasting which is easy...<br />
<br />
just to mention it, there do is some kind of support using the data source attribute in mstest... see: <a href="https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.datasourceattribute.aspx">https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.datasourceattribute.aspx</a> and <a href="https://stackoverflow.com/questions/21608462/how-to-run-unit-test-with-multiple-datasource">https://stackoverflow.com/questions/21608462/how-to-run-unit-test-with-multiple-datasource</a></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-16441575973078741942017-10-21T19:59:00.002+02:002017-10-21T19:59:43.814+02:00swagger integration into webapi project (Part 2 - .net core)<div dir="ltr" style="text-align: left;" trbidi="on">
While trying to setup a test web-api solution in .net core I was wondering whether the swagger integration even works for .net core with the swashbuckle nuget and yes... it does work!<br />
<br />
I used swashbuckle.aspnetcore (with .swagger / .swaggergen / .swaggerui)<br />
<br />
the only things I had to add in startup.cs were:<br />
<br />
ConfigureService:<br />
<br />
<ul style="text-align: left;">
<li>addmvc</li>
<li>addmvccore</li>
<li>addapiexplorer</li>
<li>addswaggergen</li>
<ul>
<li>swaggerdoc</li>
<li>includexmlcomments</li>
</ul>
</ul>
<div>
Configure:</div>
<div>
<ul style="text-align: left;">
<li>usemvc</li>
<li>useswagger</li>
<li>useswaggerUI</li>
<ul>
<li>SwaggerEndpoint</li>
</ul>
</ul>
<div>
done.</div>
</div>
<div>
<br /></div>
<div>
Every created controller will from now on be listed in swagger UI.</div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-17457515782403581392017-10-13T20:02:00.000+02:002017-10-13T20:02:01.216+02:00generic execution of stored procedures in c# accessing sql server<div dir="ltr" style="text-align: left;" trbidi="on">
for generic execution of stored procedures I found some helpful links to generate code:<br />
<br />
https://stackoverflow.com/questions/20115881/how-to-get-stored-procedure-parameters-details<br />
https://raresql.com/2014/01/18/sql-server-how-to-retrieve-the-metadata-of-a-stored-procedure/<br />
https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-exec-describe-first-result-set-transact-sql<br />
<br />
... but in fact I want to pass in generic data without much of validation before hand, because I want to keep it RAD (rapid application development) and test it with integration tests.<br />
<br />
Nevertheless with sqlfiddle.com we can validate that:<br />
create procedure t1(@x int) as<br />
select 1 as resultValue<br />
go<br />
<div>
<br /></div>
<div>
can be executed using (e.g.):</div>
<div>
exec dbo.t1 3;</div>
<div>
<br /></div>
<div>
parameters can be queried using</div>
<div>
<blockquote class="tr_bq">
select <br /> 'Parameter_name' = name, <br /> 'Type' = type_name(user_type_id),<br /> 'Nullable' = is_nullable,<br /> 'DirectionOut' = is_output,<br /> 'Length' = max_length, <br /> 'Prec' = case when type_name(system_type_id) = 'uniqueidentifier'<br /> then precision <br /> else OdbcPrec(system_type_id, max_length, precision) end, <br /> 'Scale' = OdbcScale(system_type_id, scale), <br /> 'Param_order' = parameter_id, <br /> 'Collation' = convert(sysname,<br /> case when system_type_id in (35, 99, 167, 175, 231, 239) <br /> then ServerProperty('collation') end) ,<br /> system_type_id, user_type_id<br /> from sys.parameters<br /> where object_id = object_id('dbo.t1')<br /> <br /> order by param_order</blockquote>
</div>
<div>
<br /></div>
<div>
(first) result record set meta data can be queried using</div>
<div>
<div>
SELECT * FROM sys.dm_exec_describe_first_result_set ('exec dbo.t1 3', NULL, 0) ; </div>
</div>
<br />
<br />
So execute a stored procedure and retrieve a datatable can be achieved using the code from:<br />
https://stackoverflow.com/questions/25121021/generic-execution-of-stored-procedure-in-csharp<br />
<br />
<pre class="default prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">public</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">DataTable</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">RunSP_ReturnDT</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">string</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> procedureName</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">List</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlParameter</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> parameters</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">string</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> connectionString</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">DataTable</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> dtData </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">DataTable</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlConnection</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> sqlConn </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlConnection</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">connectionString</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">))</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlCommand</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> sqlCommand </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlCommand</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">procedureName</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> sqlConn</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">))</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
sqlCommand</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">CommandType</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">CommandType</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">StoredProcedure</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">if</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">parameters </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">!=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">null</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
sqlCommand</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Parameters</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">AddRange</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">parameters</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">ToArray</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">());</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlDataAdapter</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> sqlDataAdapter </span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">SqlDataAdapter</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">sqlCommand</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">))</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
sqlDataAdapter</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="border: 0px; color: #2b91af; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Fill</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">dtData</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="border: 0px; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> dtData</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">}</span></code></pre>
<br />
this link shows an easy way to map datatables and datarows to objects<br />
<br />
https://www.exceptionnotfound.net/mapping-datatables-and-datarows-to-objects-in-csharp-and-net-using-reflection/<br />
<br />
(things dapper is doing for us in general).<br />
<br />
So this opens up a lot of opportunities for strongly typed argument objects (or an on-the-fly generated instance from a json-string) and output handling with a list of strongly typed instances mapped by datarows. There only needs to be a mapping between class and procedure name AND a mapping between argument fields and parameter names.<br />
<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-36674845497626152212017-10-13T18:20:00.003+02:002017-10-13T18:20:33.295+02:00swagger integration into webapi project<div dir="ltr" style="text-align: left;" trbidi="on">
In the (let's say) "early days" of .net's webapi the controllers and its operations could be listed (with the option to try the operation) using the nuget https://www.nuget.org/packages/Microsoft.AspNet.WebApi.HelpPage/ which is currently out of maintenance (I believe) because the last update was in february 2015 which is 2,5 years ago.<br />
<br />
During some research I found a perfect alternative which seems to be the more or less official successor: https://www.nuget.org/packages/Swashbuckle .<br />
<br />
There is a perfect tutorial from redgate related to swashbuckle at: https://www.red-gate.com/simple-talk/dotnet/net-development/visual-studio-2017-swagger-building-documenting-web-apis/<br />
<br />
It works in 5 minutes and allows to generate REST API Clients which means perfect fit between client and server.<br />
<br />
Things I changed (after installing the nuget):<br />
<br />
<ul style="text-align: left;">
<li>c.DocumentTitle</li>
<li>c.IgnoreObsoleteActions</li>
<li>c.IgnoreObsoleteProperties</li>
<li>c.IncludeXmlComments<br /><br />with the function from the redgate blog-entry (add xml documentation in properties)<br /><br />protected static string GetXmlCommentsPath()<br />{<br /> return System.String.Format(@"{0}\bin\webDemo.XML",<br /> System.AppDomain.CurrentDomain.BaseDirectory);<br />}</li>
</ul>
<br />
I don't needed to adapt the global.asax file from the root folder (and which does not work in a sub-folder which is very logical afterwards, but took me an 1 hour of research to find the bug).<br />
<br />
In the global.asax (application_start) I still have:<br />
<br />
<ul style="text-align: left;">
<li>simple-injector init (see: http://simpleinjector.readthedocs.io/en/latest/webapiintegration.html</li>
<li>GlobalConfiguration.Configure((config) =><br />{<br /> ((HttpConfiguration)config).MapHttpAttributeRoutes();<br />});</li>
</ul>
<br />
<br />
<br />
kr,<br />
Daniel</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-38881786411366694832017-10-11T17:40:00.003+02:002017-10-11T17:40:36.253+02:00sql server - datetime to number<div dir="ltr" style="text-align: left;" trbidi="on">
needed to transform minutes and seconds into a decimal number... it was not that easy as I thought originally... here the snippets:<br />
<br />
I needed to find out the current hours, seconds and minutes<br />
<br />
<span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">DATEPART</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">SECOND</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">,</span><span lang="EN-US" style="background-color: white; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">CURRENT_TIMESTAMP</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">)</span><br />
<span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;"><span lang="EN-US" style="color: magenta; font-size: 9.5pt;">DATEPART</span><span lang="EN-US" style="font-size: 9.5pt;">(</span><span lang="EN-US" style="color: magenta; font-size: 9.5pt;">MINUTE</span><span lang="EN-US" style="font-size: 9.5pt;">,</span><span lang="EN-US" style="color: black; font-size: 9.5pt;"> </span><span lang="EN-US" style="color: magenta; font-size: 9.5pt;">CURRENT_TIMESTAMP</span><span lang="EN-US" style="font-size: 9.5pt;">)</span></span><br />
<span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;"><span lang="EN-US" style="font-size: 9.5pt;"></span></span><br />
<span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">DATEPART</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">HOUR</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">,</span><span lang="EN-US" style="background-color: white; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">CURRENT_TIMESTAMP</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">)</span><br />
<div>
<span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;"><span lang="EN-US" style="font-size: 9.5pt;">(works for every part of the current timestamp...)</span></span><br />
<span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;"><span lang="EN-US" style="font-size: 9.5pt;"><br /></span></span>
afterwards I needed to convert it to decimal and assemble the parts into one number using convert.<br />
<br />
something like:<br />
<span style="color: blue;">select </span><span style="color: magenta;">convert</span>(<span style="color: blue;">double</span>(6, 2), @hour * 100 + @min) + <span style="color: magenta;">convert</span>(<span style="color: blue;">double</span>(6, 2), @sec);<br />
<br />
Now to cut off seconds we just need to convert the number to int again (as in the good old days of programming).<br />
<br />
<span lang="EN-US" style="background-color: white; color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span lang="EN-US" style="background-color: white; font-family: Consolas; font-size: 9.5pt;"> @hourAndMin </span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">=</span><span lang="EN-US" style="background-color: white; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-US" style="background-color: white; color: magenta; font-family: Consolas; font-size: 9.5pt;">convert</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">(</span><span lang="EN-US" style="background-color: white; color: blue; font-family: Consolas; font-size: 9.5pt;">int</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">,</span><span lang="EN-US" style="background-color: white; font-family: Consolas; font-size: 9.5pt;"> @hourAndMinAndSeconds</span><span lang="EN-US" style="background-color: white; color: grey; font-family: Consolas; font-size: 9.5pt;">)</span><br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-5004851197497405852017-07-14T21:54:00.001+02:002017-07-14T21:54:20.084+02:00SQL Server - sp_search_code<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
the following stored procedure from the stone-age of sql server 7.0 is very helpful when searching for the usage of objects inside database code (up till now).<br />
<br />
<a href="http://vyaskn.tripod.com/code/search_stored_procedure_code.txt">http://vyaskn.tripod.com/code/search_stored_procedure_code.txt</a><br />
<pre style="white-space: pre-wrap; word-wrap: break-word;">"Copyright © 1997 - 2002 Narayana Vyas Kondreddi. All rights reserved."</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">It queries the syscomments table so I would simplify the query to something like</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;"> select * from syscomments c </pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;"> where c.text like '%<TEXTTOCHECK>%' </pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">... but of course the check for encryption and object properties for filtering makes absolutely sense when you are allowed to deploy such a maintenance stored procedure. </pre>
<pre style="white-space: pre-wrap; word-wrap: break-word;">
</pre>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-91265478762066781942017-05-31T23:55:00.000+02:002017-05-31T23:55:45.806+02:00starting with polymer 2.0 in visual studio<div dir="ltr" style="text-align: left;" trbidi="on">
I was looking for an alternative for angular 2/4 since I realized that typescript development is not so funny as it looks like... even not in visual studio... as an angular 1 developer I liked the features of angular but was kind of overwhelmed from the overhead I needed to setup the same thing in angular 2/4. So after some days of research I found polymer which fits perfectly.<br />
<br />
With VS2017 we have full bower support which is great so just start with the download of the bower-package polymer (menu: project/bower-package management). The dependencies are installed automatically which makes it easy to startup my project. Additionally I added the bower_components folder into my project and started with an html page (more exactly with an asp.net page, but that does not really matter for this article).<br />
<br />
On the same level as bower_components I added a folder elements where I wanted to place my polymer-elements. My "hello world"-example in here is a polymer-element called say-hello.html which says hello to a person who's name is added as a parameter.<br />
<br />
The code of this html file is quite simple:<br />
<blockquote class="tr_bq">
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><link rel=<span style="color: #a31515;">"import"</span> href=<span style="color: #a31515;">"../bower_components/polymer/polymer-element.html"</span>>
<dom-module id=<span style="color: #a31515;">"say-hello"</span>>
<template>
<style>
:host {
color: forestgreen;
}
<<span style="border: 1px solid #FF0000;">/style></span>
<div>Hello {{guy}}!<<span style="border: 1px solid #FF0000;">/div></span>
<<span style="border: 1px solid #FF0000;">/template></span>
<script>
<span style="color: blue;">class</span> SayHello <span style="color: blue;">extends</span> Polymer.Element {
constructor() { <span style="color: blue;">super</span>(); }
<span style="color: blue;">static</span> get is() { <span style="color: blue;">return</span> <span style="color: #a31515;">'say-hello'</span>; }
<span style="color: blue;">static</span> get properties() {
<span style="color: blue;">return</span> {
guy: { type: String, value: <span style="color: #a31515;">'<default_name>'</span> }
};
}
}
customElements.define(SayHello.is, SayHello);
<<span style="border: 1px solid #FF0000;">/script></span>
<<span style="border: 1px solid #FF0000;">/dom-module></span></pre>
</td></tr>
</tbody></table>
</div>
</blockquote>
Without going into any further details say-hello.html can now print "Hello John!" in green to John if John is set as the parameter value of name in a call like <say-hello guy="John"></say-hello><br />
<br />
Very helpful resource for e.g.: the class definitions in javascript (ES6) is <a href="http://es6-features.org/#ClassDefinition">http://es6-features.org/#ClassDefinition</a> which I used a lot.<br />
<br />
kr,<br />
Daniel<br />
<br /></div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-84630218100179405852017-03-24T16:23:00.000+01:002017-03-24T16:23:00.462+01:00Fluent interface (API) in C#<div dir="ltr" style="text-align: left;" trbidi="on">
Hi,<br />
<br />
I was wondering why "fluent API" or "fluent interface" brings so many developer into trouble. I do like that kind of style, but I am not sure I would sacrifice my whole development style for this nice calling structure.<br />
<br />
As a C# developer I found a way to go for me. I wrote an extension method on object-level like this:<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4
5
6
7
8</pre>
</td><td><pre style="line-height: 125%; margin: 0;"> <span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Fluent</span>
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> T Do<T>(<span style="color: blue;">this</span> T item, Action<T> method)
{
method(item);
<span style="color: blue;">return</span> item;
}
}
</pre>
</td></tr>
</tbody></table>
</div>
<br />
now i can work fluent like this:
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13</pre>
</td><td><pre style="line-height: 125%; margin: 0;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program</span>
{
<span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: #2b91af;">string</span>[] args)
{
Console.Out
.Do(x => x.WriteLine(<span style="color: #a31515;">"test1"</span>))
.Do(x => x.WriteLine(<span style="color: #a31515;">"test2"</span>))
.Do(x => x.WriteLine(<span style="color: #a31515;">"test3"</span>))
.Do(x => x.WriteLine(<span style="color: #a31515;">"test4"</span>))
.Do(x => x.WriteLine(<span style="color: #a31515;">"test5"</span>))
.Do(x => x.WriteLine(<span style="color: #a31515;">"test6"</span>));
}
}
</pre>
</td></tr>
</tbody></table>
</div>
<br />
great.<br />
<br />
It is probably not that expressive as it is in a real fluent interface, but it works for every single object in every single case...<br />
<br />
Nevertheless see Martin Fowler's original post on FluentInterfaces: <a href="https://www.martinfowler.com/bliki/FluentInterface.html">https://www.martinfowler.com/bliki/FluentInterface.html</a><br />
<br />
kr,<br />
Daniel</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0tag:blogger.com,1999:blog-3708818047405038192.post-54268956136225566362017-03-18T08:57:00.000+01:002017-03-18T08:57:25.771+01:00Lightning fast (minimal) setup for a JSON Rest API using WebAPI<div dir="ltr" style="text-align: left;" trbidi="on">
While development time it is often necessary to mock services or create services for test. These don't need to consider security or performance issues, but have to return valid responses.<div>
<br /></div>
<div>
So... </div>
<div>
<br /></div>
<div>
<ul style="text-align: left;">
<li>Create ASP.NET-WebApplication (currently I used regular .NET framework application and not CORE)</li>
<ul>
<li>consider to use Azure or not (I believe that for test-services no Azure usage will be the default)</li>
</ul>
<li>Empty Template</li>
<li>Add NuGets</li>
<ul>
<li>Microsoft.AspNet.WebApi and its dependencies<br /></li>
<li>(Newtonsoft.Json for JSON Operations)<br /></li>
<li>(System.Data.SQLite for in Memory or file Database implementing Linq and standard interfaces usable for any DB-Communication library)</li>
<li>(Dapper for DB-Communication)</li>
</ul>
<li>Add a global.asax file</li>
<ul>
<li>Add the following code to Application_Start</li>
</ul>
</ul>
<div>
<div>
GlobalConfiguration.Configure((config) =></div>
<div>
{</div>
<div>
((HttpConfiguration)config).MapHttpAttributeRoutes();</div>
<div>
<br /></div>
<div>
config.Routes.MapHttpRoute(</div>
<div>
name: "DefaultApi",</div>
<div>
routeTemplate: "api/{controller}/{id}",</div>
<div>
defaults: new { id = RouteParameter.Optional }</div>
<div>
);</div>
<div>
});<br /></div>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>Add a new Item (WebApi-Controller) ... I called it in my example MyController<br /></li>
<li>I removed the code generated and implemented the following example for demonstration</li>
</ul>
</div>
<div>
<div>
[HttpGet]</div>
<div>
public IHttpActionResult GetData()</div>
<div>
{</div>
<div>
return Ok(new List<string> { "data1", "data2", "data3" });</div>
<div>
}<br /></div>
</div>
<div>
<ul style="text-align: left;">
<li>you can test this method (after starting in debugger) using the web browser<br />see: http://localhost:63268/api/My/<br />(Attention: the port is randomly generated by visual studio: check in your Properties, which port visual studio assigned you for the debugging sessions, or see which page is started when debugging session starts).<br /></li>
</ul>
<div>
This small tutorial showed an easy way of creating a REST Api using WebApi. Consider using http://www.restapitutorial.com/ for further investigation into REST (especially which Http-Methods should be used for which operation) because using the wrong http-method can be really confusing.</div>
</div>
<div>
<br /></div>
<div>
If you added the nugets in the parenthesis you would be able to use better data stores than "List". By using: </div>
<div>
data = new SQLiteConnection("Data Source=:memory:");</div>
<div>
data.Open();</div>
<div>
</div>
<div>
... you can create an in-memory datastore with an initialized connection object inheriting IDbConnection which is the standard interface for SqlConnection, OdbcConnection and all the others like oracle and stuff...</div>
<div>
<br /></div>
<div>
Using dapper makes a simple Get-Request to a really simple one-liner. See:</div>
<div>
<br /></div>
<div>
<div>
[HttpGet, Route("api/InMemory/Dapper")]</div>
<div>
public IHttpActionResult TestDapper()</div>
<div>
{</div>
<div>
return Ok(data.Query("select * from data"));</div>
<div>
}</div>
</div>
<div>
<br /></div>
<div>
Consider that this storage is non-persistent, but could be perfectly used for testing purposes.</div>
<div>
<br /></div>
<div>
kr, Daniel</div>
</div>
Daniel Kienböckhttp://www.blogger.com/profile/09731406281981615725noreply@blogger.com0