tag:blogger.com,1999:blog-30909917031907499692024-03-05T11:02:22.711-08:00BorisModon programming, testing and everything in betweenAnonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.comBlogger60125tag:blogger.com,1999:blog-3090991703190749969.post-52385861996100108282017-02-05T09:38:00.000-08:002017-02-05T09:38:05.265-08:00How to choose an open source project to contribute to?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
There are plenty of open source projects, and you probably use some. Open source projects can be a good source of learning and can help improve your developing skills. You'll have a chance to read carefully written code, used by many people. You'll have a chance to receive feedback from the project owner. Finally, you can contribute to a project you love. It might be scary in the beginning, and for many developers, the big question would be:<br />
<br />
<b>How to choose an open source project?</b><br />
<br />
If there is an open source project you use and would like to contribute to it by resolving an issue that annoys you or adding a feature that would be beneficial for you, then go ahead. For those who don't know where to start, http://up-for-grabs.net/#/ is a good place. The website lists open source projects that mark their issues as easy to start with. It also allows filtering open source projects by programming language or technology.<br />
<br />
Once you narrowed your search to a list of several open source projects, the dilemma is how to choose. In this post, I'll try to give tips that might help you in choosing an open source project.<br />
<br />
<br />
<b>Interesting domain</b><br />
Before you dive deep into source code, think whether the domain of an open source project attracts you. If you're mainly a back-end person, I doubt a 3D graphics project will cause you the same passion as some other server-side component. So, do what you love.<br />
<br />
<b>Clear and permissive license</b><br />
The open source world looks very open, but there are strict rules, regarding software licensing. I am sure you don't want to deal with legal issues when you contribute a few lines of code. So, make sure the project has a clear and permissive license that appears on its website. If you are not sure what software licenses mean, here is a good and short guideline: https://choosealicense.com/<br />
<br />
<b>Unit tests</b><br />
Unit tests indicate the project was probably well-designed, open for modification, and allow you to make sure your additional code does not break existing functionality. <br />
<br />
<b>Documentation</b><br />
While documentation is usually a weak side of most open source projects, some basic documentation is required. Make sure it describes how to build the project, how to run tests, how to use it, what are contribution guidelines.<br />
<br />
<b>Continuous integration</b><br />
Although the open source scene resembles the jungle or worldwide west, the opposite is true. Open source project usually involves the cooperation of developers from different locations and time zones. Without proper methodology, which includes continuous integration on a publicly available server, would not be possible. A few CI systems provide free service for open source projects, such as AppVeyor, Travis, CircleCI, and TeamCity.<br />
<br />
<b>Responsive </b><br />
No matter what you will contribute to an open source project, I assume you prefer a timely fashioned response. Any feedback is better than no feedback. Submitting a Pull Request ignored by a project owner might be frustrating. You can view the list of open Pull Requests and get an impression of the responsiveness of the project owner.<br />
<br />
<b>Nice </b><br />
Project owners might be very sensitive about their code. It can be understood; it's their baby, and they invested many hours to do it. However, polite communication that respects contributors is one of the key conditions to get new contributors to join the project. You may look at conversations on issues, discussions on closed Pull Requests to understand how nice the owner is.<br />
<br />
<br />
I hope this blog post will help you to choose an open source project, and it will help you to improve your programming skills.<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com1tag:blogger.com,1999:blog-3090991703190749969.post-15132274298223581472016-08-29T07:39:00.000-07:002016-08-29T07:39:12.592-07:00Choosing an IoC Container talk at Israeli .NET Developers User Group<div dir="ltr" style="text-align: left;" trbidi="on">
Last week I had the honor to hold a talk at the Israeli .NET Developers User Group. The subject was "Choosing an IoC Container", but the main goal was not to choose the best container ever, rather to present different features of IoC Containers and provide the tools to compare between them. Based on the feedback I received from the survey, it achieved the goal.<br />
<br />
I would like to share the slides and the code samples presented during the talk.<br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="485" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/key/ib2Pu8B6XDPI72" style="border-width: 1px; border: 1px solid #ccc; margin-bottom: 5px; max-width: 100%;" width="595"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="https://www.slideshare.net/BorisModylevsky/choosing-an-ioc-container" target="_blank" title="Choosing an IoC container">Choosing an IoC container</a> </strong> from <strong><a href="https://www.slideshare.net/BorisModylevsky" target="_blank">Boris Modylevsky</a></strong> <br />
<br />
Source code presented during the talk is available on github:<br />
<br />
<a href="https://github.com/borismod/IoCContainers">https://github.com/borismod/IoCContainers</a><br />
<br />
<a href="https://github.com/borismod/ReSharperTnT">https://github.com/borismod/ReSharperTnT</a><br />
<br />
Enjoy!</div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-30118303233547392252016-04-29T04:11:00.002-07:002016-04-29T04:11:49.427-07:00How to verify that a class is serializable?<div dir="ltr" style="text-align: left;" trbidi="on">
Recently I've came into investigating a failing End-to-End test that was failing inside the WCF service with an exception. The exception was related to WCF serialization of the return type of the service. As usually I decided to tackle this issue in the TDD way:<br />
<br />
<ol style="text-align: left;">
<li>Write a fialing test that reproduces the issue</li>
<li>Write the minimum amount of code to make the test pass</li>
<li>Refactor if needed</li>
</ol>
<br />
I already had a failing End to End test that was failing, but it was a heavy and complex test. All I wanted to a small, fast, isolated and reproducible test that would test only the serialization of that class. We're using <a href="http://www.fluentassertions.com/">FluentAssertions </a>library for readable and intuitive assertions in our unit tests I checked whether it contains a way to verify whether a class would be successfully serialized in WCF. Unfortunately, it had two similar methods:<br /><br />
<script src="https://gist.github.com/borismod/fa3c07b4494c84f170d800077fd7cf6a.js"></script>
I need to explain what these methods exactly do for those who are not familiar with them:<br />
<br />
<ol style="text-align: left;">
<li>Serialize the instance using the selected serialization method: binary or XML</li>
<li>Deserialize the result of the above serialization</li>
<li>Compare the values of the resulted instance with the original one</li>
</ol>
<div>
It was exactly what I needed, but these methods use different serialization methods than WCF. WCF uses DataContract serialization. I decided to contribute to FluentAssertions library and to add the required method. <a href="http://www.continuousimprover.com/">Dennis Doomen</a> generously accepted my pull request and the new method is available in the official nuget package starting from version <a href="https://www.nuget.org/packages/FluentAssertions/4.5.0">4.5.0</a>. Here how it looks like with the new method:<br /><br />
<script src="https://gist.github.com/borismod/f65d9079efacbf8c12babb7c8bc9b2a5.js"></script>
<br />
Last but not least: if you encounter into WCF serialization issues, take a look at my post from 2010 with some <a href="http://www.borismod.net/2010/02/wcf-serialization-tips.html">WCF Serialization Tips</a>.
</div>
<br />
<br /></div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-40479574233796215912015-12-03T02:39:00.001-08:002015-12-03T02:39:48.153-08:00How to access TeamCity REST API from C#?<div dir="ltr" style="text-align: left;" trbidi="on">
If you work with JetBrains TeamCity as your Continuous Integration server, you probably know that it has rich REST API that allows querying builds, their configuration, builds queue and also perform CRUD operation on them. It might be extremely useful for building custom monitor, triggering builds, cleaning builds queue and many other activities.<br />
<br />
In this post I would like to present FluentTc: an easy to use library for all the above operations. When I started working on this library, I had in mind, that it should has fluent, easy to discover API. That's what I like in libraries I consume, so I developed a library that looks like I like it and I hope that you r will find it also usable and easy to use.<br />
<br />
In order to get started to use it, you need to install the recent package from Manage Nuget packages -> Search FluentTc<br />
<br />
or typing the below in your Package Manager Console of<br />
<br />
<b>install-package FluentTc </b><br />
<br />
So now, having the reference, let's get to the code.<br />
<br />
In order to get all the build of specific Build Configuration, you can simply use:<br />
<br />
<br />
<script src="https://gist.github.com/borismod/7ed2f2a5019197e5d71e.js"></script>
If you are familiar with TeamCity REST API you might know that when retrieving list of entities, it returns only some basic properties of those entities, Id, Name and some Href. It also provides an option to retrieve additional properties. And this is how it can be done using FluentTc:<br />
<br />
<script src="https://gist.github.com/borismod/13adf930a52b76982cb3.js"></script>
<br />
<br />
The above methods return default amount of builds as retrieved from TeamCity REST API. If there is large amount of builds, you'd probably prefer retrieving them with paging, i.e. a few builds each time. This is how it can be achieved with FluentTc:<br />
<br />
<script src="https://gist.github.com/borismod/f414656726a0a691fb9a.js"></script>
<br />
<br />
Of course you can apply different query filters when retrieving your builds. For example, in order to retrieve not personal, pinned, successful builds, that ran during the recent day under specific build configuration, use this:<br />
<br />
<script src="https://gist.github.com/borismod/6d0f500d60116bb90bd8.js"></script>
<br />
<b>Credits:</b>
<br>
FluentTc was inspired by Paul Stack's TeamCitySharp library.
<br>
<br>
For questions/suggestions feel free to comment below.
</div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-19464302078626295352015-11-15T02:59:00.000-08:002015-11-15T02:59:17.895-08:00How to add some fun to software development?<div dir="ltr" style="text-align: left;" trbidi="on">
A few days ago I gave a talk titled "<b>10 ways to add fun to development process</b>" at the ALM User Group in Microsoft Raanana. I would like to thank Elad Avneri, the group organizer, for inviting me to the group. During the talk I mentioned some tools and extensions and in this post I will summarize them.<br />
<br />
For those of you, who missed the session, here a brief overview of it:<br />
<br />
The development process is tedious and complex, we are trying to solve problems in different domains in limited time frames. So a little bit fun and sense of humor can relax the atmosphere in the team and make the work more productive.<br />
<br />
Here are some tools that may help you to add some fun to your development process:<br />
<br />
<br />
<ul style="text-align: left;">
<li>Add profile photo using <a href="https://github.com/grundic/teamcity-avatar" target="_blank">TeamCity Avatar plugin</a></li>
<li>Add gamification using <a href="https://github.com/JetBrains/teamcity-achievements" target="_blank">TeamCity Achievements plugin</a> or <a href="https://getbadges.io/" target="_blank">https://getbadges.io/</a></li>
<li>Add emoji to your Visual Studio using <a href="https://visualstudiogallery.msdn.microsoft.com/88575465-8486-4c5a-8406-05e8d1d5b09d" target="_blank">EmojiVS</a> and <a href="https://github.com/hmemcpy/ReSharper.ReMoji" target="_blank">ReSharper.ReMoji</a></li>
<li>Add @userMention to your commit comments using <a href="https://github.com/borismod/TeamCityZen" target="_blank">TeamCityZen plugin for TeamCity</a></li>
<li>Add selfie to your github comments using <a href="https://github.com/thieman/github-selfies" target="_blank">Github Selfies</a></li>
</ul>
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-53786685425655443672015-08-04T09:00:00.000-07:002015-08-04T23:46:36.334-07:00How to mock file system in tests?<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
You are probably familiar with System.IO namespace in .NET Framework. It contains useful API for file system operations. Unfortunately, most of its methods are static and thus it is impossible to mock them. In this post I would like to show how we write testable code that works with file system.<br />
<br />
Let's see the below simple class that copies a file to a destination directory. If the destination directory does not exist, it creates the directory and then copies the file to the destination.<br />
<br />
<br />
<br /></div>
<script src="https://gist.github.com/borismod/9b54d63c1f25a933dc0a.js"></script>
</div>
In order to make our code testable we'll use System.IO.Abstractions library which can be installed from nuget:<br />
<br />
package-install System.IO.Abstractions<br />
<br />
It provides IFileSystem interface with all the useful interfaces on it:<br />
<script src="https://gist.github.com/borismod/2b6dcd8644299927dfd1.js"></script>
It will allow us to refactor our class by injecting the IFileSystem into our constructor:
<script src="https://gist.github.com/borismod/2af71c4998cd85f06317.js"></script>
As you can see from the above code, all the classes and methods on the System.IO.Abstractions are similar to those on the System.IO. So the transition is very smooth. You also noticed that the IFileSystem is injected via internal constructor, which we'll use in unit tests shortly. Public constructor will be used in our real code and it injects actual implementation of IFileSystem which is FileSystem class.
The last part is the unit test. There is complementary library that contains in memory implementation of IFileSystem interface. It can be installed from nuget as well:
<br>
Install-Package System.IO.Abstractions.TestingHelpers
<br>
<br>
In addition to the implementation of IFileSystem interface, it contains convenient methods for adding files and directories (in memory, of course).
<script src="https://gist.github.com/borismod/c6cb2d30ffb51a6d8cc3.js"></script>
So let's see how our unit test looks like:
<script src="https://gist.github.com/borismod/6dee1bb5950af39eb200.js"></script>
We can even assert, that the file was copied and it exists in the destination folder. The library also works well with all existing stream Read/Write operations.
<BR>
Credits for the library go to: Tatham Oddie
<BR>
<BR>
Enjoy coding,
Boris ModylevskyAnonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-64666890584146389782015-06-17T04:38:00.004-07:002015-06-17T04:49:57.580-07:00How to improve your code quality over time?<div dir="ltr" style="text-align: left;" trbidi="on">
Developers strive to write their code as good as they can. Then they try to refactor it in order to make it clearer and more maintainable. How we can make sure than it improves over time?<br />
<div>
<br /></div>
<div>
<div>
First of all we need to measure its "quality" in order to know what is its current level. Of course quality is not a well defined word. We need some quantitative metrics to measure quality. There are many metrics that could be defined, one of them is Code Coverage. Code Coverage tells us how many percent of the code is covered by tests, i.e. tests pass during their execution on that code. High Code Coverage indicates that the majority of the code is tested and works properly (at least as defined by tests). It does not mean that our software does not have bugs. But it gives a high level of confidence in what the software does. On the other hand low Code Coverage indicates that we don't know anything about the code, whether it works or not.</div>
<div>
<br /></div>
<div>
Let's see how we can measure Code Coverage using TeamCity's build in dotCover. On the the Build Steps page, click Edit on your test step, whether it is NUnit or MSTest: </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh96zjRNnx_E_kVZtuMIBBg8KxdNfIEjjkZb-F-tW2D-JaArGV_gquAHTiQNvMTPySQy2fHUERekZDdGWetLZgx-ObGnTpWEQ1jXqLjPTqJuWrIby3wSuGjLOap0MMaASD_dulNXxor4WYB/s1600/CodeCoverageImprove1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="125" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh96zjRNnx_E_kVZtuMIBBg8KxdNfIEjjkZb-F-tW2D-JaArGV_gquAHTiQNvMTPySQy2fHUERekZDdGWetLZgx-ObGnTpWEQ1jXqLjPTqJuWrIby3wSuGjLOap0MMaASD_dulNXxor4WYB/s400/CodeCoverageImprove1.jpg" width="400" /></a></div>
<div>
<br /></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
<br />
On the .NET Coverage section, select "JetBrains dotCover' in .NET Coverage tool. dotCover is a build in coverage tool within TeamCity. In the Filters section specify assemblies that you don't want to cover, for example your tests assembly.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrF6iFCPonxn-kOqaNwITx2bSpMq1-6YXnLjOwwxSHPHxnq7MdSphJtx129_wQGzcjDj7jqwJdhVB-7P4p9MFBwTFBaC_nHmBnSDRMJ-uHS3O5huvqVnH0BtwHBzoty9Nh0Zx4liP40t5Y/s1600/CodeCoverageImprove2.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrF6iFCPonxn-kOqaNwITx2bSpMq1-6YXnLjOwwxSHPHxnq7MdSphJtx129_wQGzcjDj7jqwJdhVB-7P4p9MFBwTFBaC_nHmBnSDRMJ-uHS3O5huvqVnH0BtwHBzoty9Nh0Zx4liP40t5Y/s400/CodeCoverageImprove2.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
<br />
Run the build and navigate to Code Coverage tab under build:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh29FYhhznnUHealRLhO72TCwi2h9MDDRKy7qPew6DLgbVTKN24hqIrDhFqxSPbqoSl7IZ0-1ikaVtRrTiuRjQ41SByCDK0sJ74KS0_HLij9bjpuyboobxdxSX47wRuvodN4tJr38xLTXd8/s1600/CodeCoverageImprove3.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh29FYhhznnUHealRLhO72TCwi2h9MDDRKy7qPew6DLgbVTKN24hqIrDhFqxSPbqoSl7IZ0-1ikaVtRrTiuRjQ41SByCDK0sJ74KS0_HLij9bjpuyboobxdxSX47wRuvodN4tJr38xLTXd8/s400/CodeCoverageImprove3.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
<br />
It will show the the total Code Coverage per class, method and statements with the option to drill down. The most important number is the percentage of Statements Code Coverage. In the below project it is 34.8%. Which means that approximately third of the code is covered by tests.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixIYxZ09UI1JWstqJqI14w8_DbvhBpLyMXLcaPFIaezzxYeoCS9BrS7gzKB13HUUBzLnWT9fWDUdCGlFECrdagIXAIOW1M9NVE44ulbNgkx3f0PKe5ZHAE5pw0BJD6lLAJ2RMZDK8cHtHH/s1600/CodeCoverageImprove4.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixIYxZ09UI1JWstqJqI14w8_DbvhBpLyMXLcaPFIaezzxYeoCS9BrS7gzKB13HUUBzLnWT9fWDUdCGlFECrdagIXAIOW1M9NVE44ulbNgkx3f0PKe5ZHAE5pw0BJD6lLAJ2RMZDK8cHtHH/s400/CodeCoverageImprove4.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Now given the current level of our Code Coverage we would like to make sure it only increases. We are going to define that if code coverage decreases, the build should fail. It means code coverage is one of our failure conditions. In order to do that we navigate to Build Conditions page and click on "Add failure condition" under "Additional Failure Conditions" section. On the dialog that appears we define as follows and click Save.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhQDg3IxgPdZ5N5ChNf0KfEAYxTkK7yNyqC13qKHrTii8Anaajy3jEgRPHl6d6_wVm1zdw2fDgaPg3vvJp-WgLW6gV58h081YamjUkaieq7WT5bbK-6vXpCJqPvGkJJABqrrCH22KmanAD/s1600/CodeCoverageImprove5.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhQDg3IxgPdZ5N5ChNf0KfEAYxTkK7yNyqC13qKHrTii8Anaajy3jEgRPHl6d6_wVm1zdw2fDgaPg3vvJp-WgLW6gV58h081YamjUkaieq7WT5bbK-6vXpCJqPvGkJJABqrrCH22KmanAD/s400/CodeCoverageImprove5.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Then you can define some more failure conditions on every metrics:</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK75p1j0bNKclPptODh5MWWS5xRqK6wZ3cy2CVO2xrDbsfwmmVC7pzCuo-wzHMxu4jtoMQHJd0wRHLeGW9YlhM6KEdX2Z3UoBPVF9SCCKPVitZaLSl5JIC1XTCZqxde9oyzExU_mL7dwAN/s1600/CodeCoverageImprove6.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="117" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK75p1j0bNKclPptODh5MWWS5xRqK6wZ3cy2CVO2xrDbsfwmmVC7pzCuo-wzHMxu4jtoMQHJd0wRHLeGW9YlhM6KEdX2Z3UoBPVF9SCCKPVitZaLSl5JIC1XTCZqxde9oyzExU_mL7dwAN/s400/CodeCoverageImprove6.jpg" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br />
<br />
Having defined those settings we can assure that our code coverage will increase over time. But is it enough? Of course not, our team will not produce better code just because we set these automatic failure conditions. It need to be trained how to identify code smells, how to write clean code, how to write proper unit tests. It is a long process and requires good coaching.</div>
<div>
<br /></div>
<div>
Let's summarize what we had until now on how to improve your code quality:</div>
<div>
1. Define metrics that important to you and measure their current state.</div>
<div>
2. Make the measurement part of your continuous integration and define failure conditions on its decrease.</div>
<div>
3. Train your team on how to write better code, write good unit tests.</div>
<div>
<br /></div>
<div>
I'd like to read your feedback on how it is done in your company. </div>
<div>
<br /></div>
<div>
P.S. The screenshots above are taken from an OSS project I am contributing to called BizArk. Its continuous integration is generously hosted on Codebetter's TemCity server. TeamCity is provided for free for open source projects by JetBrains.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-81780717685943893952015-02-17T01:50:00.000-08:002015-02-18T00:01:52.393-08:00How to investigate memory leak in .NET applications<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
In .NET eco-system we are used that memory is managed for us. It is allocated and freed up when not in use anymore. We do not have to worry about it. But even in .NET we need to think about such things like memory and external resources.<br />
<br /></div>
I received a complain from one of our customers, that the memory usage of IIS goes to extreme. In addition the following exception was thrown:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Insufficient winsock resources available to complete socket connection initiation. An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 127.0.0.1:8028
</span><br />
<br />
We started with attaching dotMemory profiler to the IIS process. Here is the screenshot of process's memory:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdxzIghZCmvWfNMSCxdU6RuDpCTlRNtRTXQ8AC9UbcCLA6C3y8kJW46bRNOxuDJpx-c6ZtqT_MUWlYyEWqwAwwW6nJSvxOCpfCWXII3Bje4d6w_nfQWjZAochukqMrzYMYTUCfHu_Sr-qd/s1600/dotMemoryMemoryLeakBefore.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdxzIghZCmvWfNMSCxdU6RuDpCTlRNtRTXQ8AC9UbcCLA6C3y8kJW46bRNOxuDJpx-c6ZtqT_MUWlYyEWqwAwwW6nJSvxOCpfCWXII3Bje4d6w_nfQWjZAochukqMrzYMYTUCfHu_Sr-qd/s1600/dotMemoryMemoryLeakBefore.png" height="140" width="400" /></a></div>
We can see from the above picture, that the amount of memory used grows over time. It looks like memory is not released.
<br />
<br />
In order to understand what kind of objects are not being released, we took two snapshots during the profiling: one in the beginning of our profiling session and another one at its end. Then we compared those snapshots. From the comparison we selected Grouped the objects b namespace and then right-click and "Open Survived Objects". Survived objects are those that weren't released between the snapshots.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaeSaJqsgvhIaxhvqlI9Cb9VJ-ZP8WjI_tdI7Ym2_ejiBSPcE703WW8R_emO3JEAdZ1sTV4Uq4h2d9nhAE_Et7fNGxZaBELdwNJ3nlGq1M-1jtz1krxi5mnJeSUBA_LAlDDnT24S_Y_Nkf/s1600/dotMemoryCompareSnapshots.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaeSaJqsgvhIaxhvqlI9Cb9VJ-ZP8WjI_tdI7Ym2_ejiBSPcE703WW8R_emO3JEAdZ1sTV4Uq4h2d9nhAE_Et7fNGxZaBELdwNJ3nlGq1M-1jtz1krxi5mnJeSUBA_LAlDDnT24S_Y_Nkf/s1600/dotMemoryCompareSnapshots.png" height="133" width="400" /></a></div>
<br />
<br />
In the list of survived objects, we grouped them by Dominators and got the following picture:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj51hkV86_AUvgpCkzz-ES2PgDutoYyD_p0G2I37dUeVI7-vy8EHKbO2iWQTYitawerw6ZhsJm4SxepuHQeqlKnEuP6NKPB8g2W4H8I5yAZob-dUTnMqfhWOEJDR9Nt3eQYiGffaFTPZE0c/s1600/dotMemorySurvivedObjects.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj51hkV86_AUvgpCkzz-ES2PgDutoYyD_p0G2I37dUeVI7-vy8EHKbO2iWQTYitawerw6ZhsJm4SxepuHQeqlKnEuP6NKPB8g2W4H8I5yAZob-dUTnMqfhWOEJDR9Nt3eQYiGffaFTPZE0c/s1600/dotMemorySurvivedObjects.png" height="61" width="400" /></a></div>
<br />
From the above picture we understand that instances of TranparentProxy are not closed. It looks very connected to the "insufficient winsock resources" error we receive.<br />
<br />
So now to the easy part: fix the code :-)<br />
We wrapped any service call with a try/finally block. In the finally block we close the open proxy, which also closes the socket.<br />
<br />
After applying the fix we executed dotMemory profiler to see how memory behaves. Here what we got:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga6L-xK2zke34_IOtMEKKofjprDRdeTeI6hbXFX9by_at0PmeVCHY_mx-XZShqcguLmr9xCCVeIZJZiEMypXszQjSXoqav0PBWOjpjuJljxQt9lyNTVmj80tqOMabAYDZOHsHNo8EdwVs6/s1600/dotMemoryNoLeak.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga6L-xK2zke34_IOtMEKKofjprDRdeTeI6hbXFX9by_at0PmeVCHY_mx-XZShqcguLmr9xCCVeIZJZiEMypXszQjSXoqav0PBWOjpjuJljxQt9lyNTVmj80tqOMabAYDZOHsHNo8EdwVs6/s1600/dotMemoryNoLeak.png" height="116" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The picture looks completely different: instead of steady increase, we see those drops in memory usage. The drops are of course result of Garbage Collection. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Happy profiling!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
UPD: As <a href="https://twitter.com/volebamor" target="_blank">@volebamor</a> mentioned in his tweet: "it's more obvious to open new objects instead of survived". Thanks for your comment!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLyVwqKMIpXCTu_8Tyh8xAd81YJYvl7y3Jc90kVebidgUOMgL7qornxWkRcOzdZGsIVsrm2G-EbQ9jcd6CluunLUyIcFdKs1xUVXA891vskub3ReDd8p45of0mWpeSV9Ktb5WBgyRkiK-_/s1600/dotMemoryRomanBelov.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLyVwqKMIpXCTu_8Tyh8xAd81YJYvl7y3Jc90kVebidgUOMgL7qornxWkRcOzdZGsIVsrm2G-EbQ9jcd6CluunLUyIcFdKs1xUVXA891vskub3ReDd8p45of0mWpeSV9Ktb5WBgyRkiK-_/s1600/dotMemoryRomanBelov.png" height="76" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-59209802338966500632015-02-08T04:41:00.002-08:002015-02-13T23:35:35.687-08:00Slides for my talk "Continuous Integration in Action"<div dir="ltr" style="text-align: left;" trbidi="on">
Slides for my recent talk at Clean Code Alliance meetup group titles "Continuous Integration in Action". During my talk I focused on the basic principles of continuous integration and shared from own experience some tips for its successful and effective implementation.<br />
<br />
Here are the slides:<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="355" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/44390807" style="border-width: 1px; border: 1px solid #CCC; margin-bottom: 5px; max-width: 100%;" width="425"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="https://www.slideshare.net/BorisModylevsky/continuous-integration-in-action" target="_blank" title="Continuous Integration in Action">Continuous Integration in Action</a> </strong> from <strong><a href="https://www.slideshare.net/BorisModylevsky" target="_blank">Boris Modylevsky</a></strong> <br />
<br />
I would like to thank <a href="http://itziksaban.blogspot.co.il/">Itzik Saban</a> for reviewing the slides and helping me rehearsing the session. It would not happen without you.<br />
<br />
<br /></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-5426466733184373002014-10-07T06:59:00.000-07:002014-10-07T07:01:45.440-07:00How to improve your ReSharper proficiency<div dir="ltr" style="text-align: left;" trbidi="on">
Many developers that start working with ReSharper realize that the learning curve is steep. There are many hidden features, many shortcuts that need to be memorized, there are many tricks that one can do in order to improve his/her productivity. So here is what I did to help my colleagues to help them learn ReSharper.<br />
<br />
I created a REST API that returns random ReSharper tips or trick. Its source code is available on github:<br />
<br />
<a href="https://github.com/borismod/ReSharperTnT">https://github.com/borismod/ReSharperTnT</a><br />
<br />
I used <a href="https://appharbor.com/">AppHarbor</a> for continuous integration and cloud hosting. So at the end, the REST API is available at the following URL:<br />
<br />
<a href="http://resharpertnt.apphb.com/api/tipsandtricks/">http://resharpertnt.apphb.com/api/tipsandtricks/</a><br />
<br />
It returns random ReSharper tip or trick in JSON format:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQKXunWuKcLypKmJtWNMYzemkIFn2AdfbOTZljhd0pBF0y666uuqEEJh_5ncW365hL2hPSgur6IAJgoWQ2jtjnkCMDWWldNEwNzskmgt70ubadTTtsZqWGERlQm7AisEJzmLL1uwfPCo9C/s1600/resharperjson.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQKXunWuKcLypKmJtWNMYzemkIFn2AdfbOTZljhd0pBF0y666uuqEEJh_5ncW365hL2hPSgur6IAJgoWQ2jtjnkCMDWWldNEwNzskmgt70ubadTTtsZqWGERlQm7AisEJzmLL1uwfPCo9C/s1600/resharperjson.jpg" height="106" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Then I incorporated the above REST API in our command-line build process:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5cFZ6cG1Xd3GjXn25CsanpZxE7Oq-DLJnnE09dZdAKNcrJuP9LN2xJuWFfkmIEVoNyTItck5pTOsyhaHuEWV5U7f0Y0O35Z9v2gE1dSDErEsN1uV3XKv_FG4IB2nHi3HFjR07ZFUVoSGY/s1600/resharperbuild.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5cFZ6cG1Xd3GjXn25CsanpZxE7Oq-DLJnnE09dZdAKNcrJuP9LN2xJuWFfkmIEVoNyTItck5pTOsyhaHuEWV5U7f0Y0O35Z9v2gE1dSDErEsN1uV3XKv_FG4IB2nHi3HFjR07ZFUVoSGY/s1600/resharperbuild.jpg" height="76" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
So every time we build, we see random ReSharper tip or trick.<br />
<br />
Enjoy coding!<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-62462239271108132952014-10-07T01:01:00.000-07:002014-10-07T01:01:13.619-07:00How to write to console from Windows Application<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
When creating a Windows Applicaiton, either WinForms or WPF it does not have console. Converting the application to Console Application seems to solve the problem. If we execute our application from a console, it will be able to print to console and everything seems to be fine. But when we run it not from a console a new console window will appear in addition to the existing Form or WPF Window. So what we can do?<br />
<br />
<script src="https://gist.github.com/borismod/1296ec188db944c75df7.js"></script>
<br />
<div>
<br />
AttachToConsole will actually attach to the parent console from which the Windows Application was executed. Unfortunately, it does not move the cursor to the next line. Thus the next line is required Console.Writeline.<br />
<br />
<br /></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-88021074572207545472014-08-24T05:46:00.002-07:002014-08-24T05:46:39.087-07:00Must have tools for Windows<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Each one of us uses some tools that makes his/her life easier. In this post I would like to share a list of very essential tools save a lot of time and let us focus on what is really important to us. The tools have a common denominator: they help to get things or get things done. Please note the difference in terminology. Sometimes in the past there was File Manager and we had the feeling that we "manage" files. When the amount of files increased it was replaced by Windows Explorer. So we had the feeling or exploring things. Then a Search button was added that should have help us to find thing. Unfortunately it was pretty slow, so we still go lost among the files. Nowadays in the 2014 we want to "get" instead of search, manage or explore. So the tools you'll see here focus on getting programs from the internet, getting files on your computer, getting programs on your computer, getting you passwords etc.<br />
<br />
So here they are:<br />
<br />
1. <a href="http://chocolatey.org/">chocolatey.org</a> - is the ultimate installer for every program for Windows. It has an enormous catalog of pro grams for download with a one line command line. So it is the new way to "get" programs to your computer.<br />
<br />
2. <a href="http://www.voidtools.com/">Everything </a>- is the fastest and most effective way to "get" files on local computer. Unlike built-in Windows Search, it is extremely fast, it does not interfere with other programs, such as anti-virus software or files written by compilers or test runners. And it can be invoked with a shortcut. I prefer WinKey-N, for the similarity for the ReSharper and IntelliJ Ctrl-N, but it is completely your choice.<br />
<br />
3. <a href="http://www.launchy.net/index.php">Launchy </a>- is the fastest and most elegant way to execute eny program on your computer. It can be invoked with a shortcut (I use Alt-Space) and with typing a few characters it finds any program you need. Launchy has also some useful <a href="http://www.launchy.net/plugins.php" target="_blank">pluigns </a>like: Killy, Tasky<br />
<br />
4. Console2 - command-line console has been for many years the way we like to execute things. But the built-in console is poor and lacks of many features. Console2 is the new and must-have console application. Among its features: multiple tabs, copy-paste with keyboard shortcuts, resize. After installing Console2, follow step described by Scot Hanselman <a href="http://www.hanselman.com/blog/Console2ABetterWindowsCommandPrompt.aspx">here</a>.<br />
<br />
5. <a href="https://www.dropbox.com/">Dropbox </a>- needless to say how it is important to keep all your files synced between different machines. Dropbox is one of the popular and convenient ways to do it.<br />
<br />
6. <a href="http://app.prntscr.com/en/index.html">Lightshot</a>- this small and non-intrusive application helps to take screenshot. It allows cropping your screen while taking the snapshot, then editing it on the spot and then copying to clipboard or saving to file. By copying to clipboard and then pasting to the desired application (even to Gmail) you can save a lot of time.<br />
<br />
7. <a href="http://keepass.info/">Keepass </a>- we need to keep track of our passwords and there are plenty of them. Every website, every application require its own authentication. Keepass allows storing all your passwords in a single encrypted file. The file can be protected by master password, external file, Windows User account or any combination of those methods. I suggest saving the Keepass file in Dropbox folder for easy access from different machines.<br />
<br />
All the tools listed above are free.<br />
<br /></div>
<script src="https://gist.github.com/borismod/b1d05f73b86d17ad7a03.js"></script></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com1tag:blogger.com,1999:blog-3090991703190749969.post-53442530743852359982014-08-03T05:59:00.002-07:002014-08-03T05:59:44.351-07:00TeamCityZen - TeamCity communication and socializing extension<div dir="ltr" style="text-align: left;" trbidi="on">
Every organization that uses Continuous Integration can admit, that the continuous integration server became much more than just build-machine. It functions as company's central monitor for the healthiness and readiness of the software being developed. It answers many questions raised by developers, analysts, product managers, development managers, operations etc. But more than this, it became the center of communication for those team members. You can often hear conversations like those:<br />
<br />
- I am waiting for you to finish this feature, can you let me know when you're done?<br />
- I will commit the interface of service, so you could consume it. I'll send you an email when I do.<br />
<br />
Those conversation led me to writing a TeamCity extension named TeamCityZen, since we are sort of citizens of the city named TeamCity. The extension enables mentioning somebody's username in commit comments. User who was mentioned in the comments will be notified by email. Support any kind of Source Control: Git, TFS, Subversion, etc.<br />
<br />
Screenshot from TFS:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbXeDOrkIQn1xS3md_kJqIuE-FucetyqOavSU9Om_932RneA6dLA5BG8OqDxGsv7_5HWLghnvclS-1Ztt5GbjxCYVNwlE6UeRpQ5u4LzuedgK_0H-FCFIRciIP0oh8bE42E2WATDyNF13q/s1600/TeamCityZenTFS.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbXeDOrkIQn1xS3md_kJqIuE-FucetyqOavSU9Om_932RneA6dLA5BG8OqDxGsv7_5HWLghnvclS-1Ztt5GbjxCYVNwlE6UeRpQ5u4LzuedgK_0H-FCFIRciIP0oh8bE42E2WATDyNF13q/s1600/TeamCityZenTFS.jpg" /></a></div>
<br />
<br />
<br />
<br />
<br />
Feel free to download, use and extend.<br />
<br />
More details: <a href="https://github.com/borismod/TeamCityZen" target="_blank">https://github.com/borismod/TeamCityZen</a><br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-15140141661126346372014-08-03T01:22:00.000-07:002014-08-03T01:22:21.304-07:00Clean Code Alliance second meeting summary<div dir="ltr" style="text-align: left;" trbidi="on">
If you are a constant reader of this blog, you must noticed that my friend Itzik Saban and I organized a meetup group: Clean Code Alliance. Recently its second meeting took place at Kenshoo offices. We were really excited to see the growing interest to clean code in general and to our group in particular. Except of the sessions itself there is vital networking that takes place between the sessions.<br />
<br />
On group's second meeting there were two sessions, which can be watched on group's YouTube channel:<br />
<a href="https://www.youtube.com/user/CleanCodeAlliance" target="_blank">https://www.youtube.com/user/CleanCodeAlliance</a><br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/5tIMn1oulFY?list=UUw12VIQ9LeID5CKsKpbaVPw" width="560"></iframe><br />
Clean Code Principles - part II by <a href="http://itziksaban.blogspot.co.il/" target="_blank">Itzik Saban</a><br />
<br />
<iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/nwj2GedMPIY?list=UUw12VIQ9LeID5CKsKpbaVPw" width="560"></iframe><br />
Continuous Delivery in Practice by <a href="http://www.kenshoo.com/author/tzach/" target="_blank">Tzach Zohar </a><br />
<br />
In order to keep in touch between the meetings, feel free to follow the group on twitter: <a href="https://twitter.com/CleanCodeAll" target="_blank">@CleanCodeAll</a><br />
and join discussions on LinkedIn group: <a href="http://www.linkedin.com/groups/Clean-Code-Alliance-8104602" target="_blank">http://www.linkedin.com/groups/Clean-Code-Alliance-8104602</a><br />
<br />
See you on the coming meetup!<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-76562221636850050892014-04-17T07:17:00.001-07:002014-04-17T07:18:06.152-07:00BizArk.Core 2.0.14 was pushed to NuGet<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Bizark.Core 2.0.14 was pushed to NuGet<br />
<br />
<b>Release notes:</b><br />
<a href="https://bizark.codeplex.com/workitem/9290" target="_blank">9290</a> Not parse array of string<br />
<br />
<b>Example:</b><br />
<br /></div>
<pre style="background: #ffffff; color: black;"><pre><span style="color: #808030;">[</span>CmdLineOptions<span style="color: #808030;">(</span>ArgumentPrefix <span style="color: #808030;">=</span> <span style="color: maroon;">"</span><span style="color: #0000e6;">-</span><span style="color: maroon;">"</span><span style="color: #808030;">,</span> AssignmentDelimiter <span style="color: #808030;">=</span> <span style="color: #0000e6;">':'</span><span style="color: #808030;">,</span> ArraySeparator <span style="color: #808030;">=</span> <span style="color: maroon;">"</span><span style="color: #0000e6;">;</span><span style="color: maroon;">"</span><span style="color: #808030;">)</span><span style="color: #808030;">]</span>
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">class</span> CmdLineObjectWithStringArray <span style="color: #808030;">:</span> CmdLineObject
<span style="color: purple;">{</span>
<span style="color: #808030;">[</span>CmdLineArg<span style="color: #808030;">]</span>
<span style="color: maroon; font-weight: bold;">public</span> <span style="color: maroon; font-weight: bold;">string</span><span style="color: #808030;">[</span><span style="color: #808030;">]</span> Names <span style="color: purple;">{</span> get<span style="color: purple;">;</span> set<span style="color: purple;">;</span> <span style="color: purple;">}</span>
<span style="color: purple;">}</span>
</pre>
You can invoke the console application from command line:</pre>
<pre style="background: #ffffff; color: black;"></pre>
<pre style="background: #ffffff; color: black;"><span style="color: #253340; font-family: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.017696380615234px; white-space: normal;">MyConsoleApplication -Names:1;2</span></pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;"></pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;">Bizark.Core will parse the values into string array of Names: { "1", "2"}</pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;"></pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;"></pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;"></pre>
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial;">Enjoy!
</pre>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com1tag:blogger.com,1999:blog-3090991703190749969.post-39617735634058697272014-04-01T04:19:00.001-07:002014-04-01T05:29:26.059-07:00TeamCity hidden shortcuts<div dir="ltr" style="text-align: left;" trbidi="on">
My colleague says, that he hates JetBrains as a company. He cannot find anything wrong or ineffective in their products. He is surprised that they just work. Work as expected and even better. They foresee our needs and our requirements and have already implemented them.<br />
<br />
In this post I would like to share you the keyboard shortcuts I found in TeamCity:<br />
<br />
<b>p</b> is a shortcut for searching among project names. Strike "p" and then start typing a project name Available in TeamCity 7.0<br />
<br />
<b>j</b> is a shortcut for searching projects and build configurations in the same root project. Strike "j" and then start typing a project name or a build configuration name. Available from TeamCity 8.0<br />
<br />
And the most powerful:<br />
<b>q</b> is a shortcut for searching both projects and build configurations. Strike "j" and then start typing a project name or a build configuration name. Available from TeamCity 8.0<br />
<br />
P.S. Thanks to JetBrains and Pluralsignt for supporting <a href="http://www.meetup.com/Clean-Code-Alliance/" target="_blank">CleanCodeAlliance</a> group.<br />
<br />
<b>UPDATE</b>: I've got a reply from JetBrains employee on twitter that there are even more keyboard shortcuts in TeamCity's Changes page in version 8.1:<br />
<br />
up/down to navigate, right/left to expand changes. And 'f', 'b', 't' to open specific tabs of the selected change<br />
<span style="background-color: white; color: #292f33; font-family: Arial, sans-serif; font-size: 14px; line-height: 18px; white-space: pre-wrap;"><br /></span>
<span style="background-color: white;"><span style="color: #292f33; font-family: Arial, sans-serif;"><span style="font-size: 14px; line-height: 18px; white-space: pre-wrap;">Thanks to Kirill Maximov @maxkir</span></span></span><br />
<span style="background-color: white;"><span style="color: #292f33; font-family: Arial, sans-serif;"><span style="font-size: 14px; line-height: 18px; white-space: pre-wrap;"><br /></span></span></span>
<span style="background-color: white;"><span style="color: #292f33; font-family: Arial, sans-serif;"><span style="font-size: 14px; line-height: 18px; white-space: pre-wrap;">According to Kirill there is no official documentation about the shortcuts. So I will maintain this post as a sporadic one.</span></span></span></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-75214604835656067722014-03-17T13:48:00.001-07:002014-03-17T13:48:18.102-07:00Clean Code Alliance group on Meetup<div dir="ltr" style="text-align: left;" trbidi="on">
My friend <a href="http://itziksaban.blogspot.co.il/" target="_blank">Itzik Saban</a> and I opened a new group on Meetup: <a href="http://www.meetup.com/Clean-Code-Alliance/" target="_blank">Clean Code Alliance</a>. You may ask, who needs another group and more meetings when there are a lot of them talking about almost every technical aspect of software engineering. Most of the groups are focused on specific technology or domain. The purpose of Clean Code Alliance is to return to the basics - to quality and clean code. We would like to talk about clean code principles, TDD issues, domain driven design concepts, applicative information security principles, anti-patterns in programming and testing, quality code metrics.<br />
<br />
Feel free to join the group on meetup: <a href="http://www.meetup.com/Clean-Code-Alliance/" target="_blank">Clean Code Alliance</a>. </div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-18608782848706315142014-02-20T08:54:00.001-08:002014-02-20T08:54:46.588-08:00How to follow best practices of NHibernate with WCF integration?<div dir="ltr" style="text-align: left;" trbidi="on">
If you work with NHibernate, you are probably familiar with its best practices. When working with WCF we need to maintain UnitOfWork and transactions. There is a library that makes this integration seamless: NHJump by James Lanng and Richard Penrose.<br />
<br />
Marking your service class with an attribute will do the magic:<br />
<ul style="text-align: left;">
<li>will create a unit of work per request</li>
<li>will open a transaction</li>
<li>will commit it at the end of the request or rollback it if an exception was thrown</li>
</ul>
<div>
<div>
<pre class="prettyprint lang-cs" style="background-color: #eeeeee; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; font-size: 12px; max-width: 70em; overflow: auto; padding: 0.5em;"><span class="pln"> </span><span class="pun" style="color: #666600;">[</span><span class="typ" style="color: #660066;">ServiceContract</span><span class="pun" style="color: #666600;">]</span><span class="pln"> </span><div style="line-height: 1.25em; max-width: 64em;">
</div>
<div style="line-height: 1.25em; max-width: 64em;">
<span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">interface</span><span class="pln"> </span><span class="typ" style="color: #660066;">IPersistenceService</span><span class="pln">
</span><span class="pun" style="color: #666600;">{</span><span class="pln">
</span><span class="pun" style="color: #666600;">...</span><span class="pln">
</span><span class="pun" style="color: #666600;">}</span><span class="pln">
</span></div>
<div style="line-height: 1.25em; max-width: 64em;">
<span class="pun" style="color: #666600;">[</span><span class="typ" style="color: #660066;">UnitOfWork</span><span class="pun" style="color: #666600;">]</span><span class="pln"> </span></div>
<div style="line-height: 1.25em; max-width: 64em;">
<span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">class</span><span class="pln"> </span><span class="typ" style="color: #660066;">PersistenceService</span><span class="pln"> </span><span class="pun" style="color: #666600;">:</span><span class="pln"> </span><span class="typ" style="color: #660066;">IPersistenceService</span><span class="pln">
</span><span class="pun" style="color: #666600;">{</span><span class="pln">
</span><span class="pun" style="color: #666600;">...</span><span class="pln">
</span><span class="pun" style="color: #666600;">}</span></div>
</pre>
</div>
</div>
<div>
<br /></div>
<div>
Sounds nice? It has also ASP.NET MVC integration.</div>
<div>
<br /></div>
<div>
Samples can be found on SVN repository:</div>
<div>
<div>
<br /></div>
<div>
<a href="https://code.google.com/p/nhjump/source/browse/#svn%2Ftrunk%2FSamples">https://code.google.com/p/nhjump/source/browse/#svn%2Ftrunk%2FSamples</a></div>
<div>
<br /></div>
<div>
or can be downloaded from Continuous Integration server (zipped)</div>
<div>
<br /></div>
<div>
<a href="http://teamcity.codebetter.com/repository/download/bt1200/lastSuccessful/NhJump.Persistence.Samples.zip">http://teamcity.codebetter.com/repository/download/bt1200/lastSuccessful/NhJump.Persistence.Samples.zip</a></div>
</div>
<div>
<br /></div>
<div>
<div>
Available on nuget:</div>
<div>
<br /></div>
<div>
<span style="background-color: #202020; color: #e2e2e2; font-family: 'andale mono', 'lucida console', monospace; font-size: 20px; line-height: 30.60000228881836px;">PM> Install-Package NhJump.Persistence</span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-47027877220752732482014-01-29T06:40:00.001-08:002014-01-29T06:45:41.504-08:00How to merge multiple .NET assemblies into one<div dir="ltr" style="text-align: left;" trbidi="on">
Sometimes we need to deliver our code as a single assembly for different reasons. There are a few techniques for doing that.<br />
<br />
The first one and maybe the most obvious is <b>ILMerge</b>. A command line tool that disassembles multiple assemblies into IL code and then reassembles them to a single one.<br />
<br />
<b>When to use ILMerge:</b><br />
- When all the assemblies are from the same provider. If the assemblies have <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="5223cf46-d506-4afc-9bdd-0c29089bec07" id="dd58dd68-1ba0-4098-abfd-fdabc85fbe66">strong name</span>, they will be re-signed with the <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="5223cf46-d506-4afc-9bdd-0c29089bec07" id="ac1c1a2c-ece4-40c9-97c1-5d44c279675e">snk</span> file of the first of them (or executable if exists).<br />
- <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="de274342-2fc8-4ea1-aba5-e751579a8e4e" id="f59b0a41-f2d8-4fe7-9241-17bfc5366931">ILMerge</span> works well <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="de274342-2fc8-4ea1-aba5-e751579a8e4e" id="1bdb5277-3e1e-46e9-a061-f58106150c41">on</span> Microsoft.NET framework only. Supported version is only 2.0 and higher<br />
<br />
<b>When we cannot use <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="b0d064f3-8ea9-48e7-a60c-e07c47b4c853" id="f4e6bd1f-72e6-4cc2-ad6b-6a37d53ca6b0">ILMerge</span>:</b><br />
- When merging assemblies from different providers. For example, one assembly written by our company which references a few 3rd party assemblies.<br />
- When merging WPF assemblies, because they use embedded resources, that needs to be serialized<br />
- <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="33a4abd4-815e-44a7-946d-c0a53c6c18db" id="2914248d-9e9c-4496-8779-2fb9db94ae9f">ILMerge</span> won't work on other .NET frameworks, such as Mono or Rotor.<br />
- <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="741b2e38-43c2-42dc-a5b3-4dfbd103c948" id="92691d77-f86f-41ff-bba2-b454cfb17c7e">ILMerge</span> won't merge assemblies from .NET Framework 1.1<br />
<br />
<br />
Another technique makes use of<b> embedding assemblies as resources</b> within the main assembly. So here are the steps:<br />
1. Add referenced assembly as embedded resource to the main assembly.<br />
2. Don't forget to select "Embedded Resource" in Build Action on File Properties<br />
3. Add a code that loads assembly from the resources (see below)<br />
<br />
<b>When to use loading assemblies from resources:</b><br />
- When we need to load multiple strong named assemblies from different providers.<br />
- Any case that is not supported by ILMerge<br />
<br />
Here is a sample code that loads assemblies from resources. It started from Jeffrey Richter's <a href="http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx" target="_blank">blog post</a> and enhanced to support loading multiple assemblies. When I used the code as is in his post I got an exception saying "Method not found". So here is the modified piece of code. It needs to be initialized in a static constructor of your "main" class, i.e. <span class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="d02f5ad4-25b5-4f6c-9429-d233f1e41cab" id="507e5919-762f-49c1-bae8-3579ecef7b54">the</span> first class user would access before accessing other classes.<br />
<br />
<pre class="brush: js">
public class AssemblyResolver
{
private readonly Dictionary<string,Assembly> m_LoadedAssemblies = new Dictionary<string,Assembly>();
public Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
var assemblyResource = BuildAssemblyResourceName(args.Name);
return m_LoadedAssemblies.ContainsKey(assemblyResource)
? m_LoadedAssemblies[assemblyResource]
: LoadAssembly(assemblyResource);
}
private static string BuildAssemblyResourceName(string requestedAssemblyFullName)
{
var containingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;
var indexOfComma = requestedAssemblyFullName.IndexOf(",", StringComparison.Ordinal);
var requestedAssemblyName = indexOfComma > 0
? requestedAssemblyFullName.Substring(0, indexOfComma)
: requestedAssemblyFullName;
var assemblyFullName = String.Format("{0}.Resources.{1}.dll", containingAssemblyName, requestedAssemblyName);
return assemblyFullName;
}
private Assembly LoadAssembly(string assemblyName)
{
using (var assemblyStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assemblyName))
{
if (assemblyStream == null) return null;
using (var reader = new BinaryReader(assemblyStream))
{
var readBytes = reader.ReadBytes((int) assemblyStream.Length);
var assembly = Assembly.Load(readBytes);
m_LoadedAssemblies.Add(assemblyName, assembly);
return assembly;
}
}
}
public AssemblyResolver Attach()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;
return this;
}
public void Dettach()
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomainAssemblyResolve;
}
}
</pre>
Yes, I know there is a lot of code, but let's try to understand it one by one.<br />
<br />
AssemblyResolver class holds list of already loaded assemblies. If an AssemblyResolve event occurs, the resolver looks up in the m_LoadedAssemblies and return the already preloaded instance from it. If the requested assembly is not loaded yet, LoadAssembly method will load it from the embedded resources and add it to m_LoadedAssemblies. BuildAssemblyResourceName method concatenates resource name assuming that dependend assemblies reside in Resources folder in the main assembly.<br />
<br />
Please note that it ignores the version of the requested assembly and its public key. It assumes that the correct assembly was added to the embedded resources.<br />
<br />
Here is the usage from another class:<br />
<br />
<pre class="brush: js">
public class MainClass : IDisposable
{
static readonly AssemblyResolver Resolver = new AssemblyResolver();
static MainClass()
{
Resolver.Attach();
}
public void Dispose()
{
Resolver.Dettach();
}
}
</pre>
That's all! Hope it helps
<br /></div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com2tag:blogger.com,1999:blog-3090991703190749969.post-49302892139073528372013-12-26T08:08:00.002-08:002013-12-26T08:14:41.517-08:00The process was terminated due to an internal error in the .NET Runtime <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
If your .NET process crashes unexpectedly with the following message in the Event Log: "The process was terminated due to an internal error in the .NET Runtime...", there are a few things we can do to investigate it.
Unfortunately, the exception already occurred, the process crashed and there is nothing interesting in the logs. First of all we'd like to find out what happens that causes to this crash and where in the code it happens. In order to do this we can start by downloading and installing <a href="http://www.microsoft.com/en-us/download/details.aspx?id=40336">Debug Diagnostic tool</a>. Then configuring it in the following matter:
<br />
<br />
Select Crash, because that's what we're investigating:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjheHUG0P7_Z4qbVWlUwnf_WnO78-QckCSuM6t6oNzLcgJVRZT9sBCAB-Hb0k0n_NMaMeOJdpQrNl9T3W8HzvIFGpk1qU5BrZAK6zTO6YiyRPD_52DZFSBmLeFXtQFYH1P_QG65PG7zSmsC/s1600/SelectRuleType.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjheHUG0P7_Z4qbVWlUwnf_WnO78-QckCSuM6t6oNzLcgJVRZT9sBCAB-Hb0k0n_NMaMeOJdpQrNl9T3W8HzvIFGpk1qU5BrZAK6zTO6YiyRPD_52DZFSBmLeFXtQFYH1P_QG65PG7zSmsC/s1600/SelectRuleType.jpg" /></a>
<br />
<br />
Select a specific process, because we know what process crashes:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXl-BAkXXmHt2eDLQC-D3Sf2xlVn2BksOREZv1yi7Q53en50i5SoXns_RhWw3Vx1IQeikr6ot9sCv34IAo2QUKuilutHJWgz2UCZiBGUm5N9_eFAwrCvnCO82wx9AJv4Mm0kfbcDkSyRso/s1600/SelectTargetType.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXl-BAkXXmHt2eDLQC-D3Sf2xlVn2BksOREZv1yi7Q53en50i5SoXns_RhWw3Vx1IQeikr6ot9sCv34IAo2QUKuilutHJWgz2UCZiBGUm5N9_eFAwrCvnCO82wx9AJv4Mm0kfbcDkSyRso/s1600/SelectTargetType.jpg" /></a>
<br />
<br />
Select the process you want to investigate:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6k7OnEhUjzRvSWhnQs_y2Zt8i-Q5DHcZGqQMHr9gG620U-_ha_nzrecJ4GwYNbjEaN5_9A9i2P63Q8ULNkLZzsLndSQgL88xBt-ydQnZ7xeADPpM68eZSuQTDDQWYHiAsy4NjTGIOS-l0/s1600/SelectTarget.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6k7OnEhUjzRvSWhnQs_y2Zt8i-Q5DHcZGqQMHr9gG620U-_ha_nzrecJ4GwYNbjEaN5_9A9i2P63Q8ULNkLZzsLndSQgL88xBt-ydQnZ7xeADPpM68eZSuQTDDQWYHiAsy4NjTGIOS-l0/s1600/SelectTarget.jpg" /></a>
<br />
<br />
Select "Full Userdump":<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxfTqSqiqEucDGnN0nDbVR0kEVcW-69lP91wM-1oQKm2acNn7jTtvXP2z6oQMyJu44zveTVxHl32rbMoZnhAihsq38ASoJ7f-3h6OjchPlV_3XxCeir105_SbEbJQySlMqXlzkumM-Mbzb/s1600/AdvancedConfiguration.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxfTqSqiqEucDGnN0nDbVR0kEVcW-69lP91wM-1oQKm2acNn7jTtvXP2z6oQMyJu44zveTVxHl32rbMoZnhAihsq38ASoJ7f-3h6OjchPlV_3XxCeir105_SbEbJQySlMqXlzkumM-Mbzb/s1600/AdvancedConfiguration.jpg" /></a>
<br />
With the <a href="http://www.microsoft.com/en-us/download/details.aspx?id=40336">DebugDiag</a> running in the background, reproduce the scenario that causes the initial process termination. When the process crashes, we'll find in DebugDiag log folder with a few files. The log folder is
<br />
C:\Program Files\DebugDiag\Logs
<br />
The interesting file is the one with .DMP extension. Double click it and it will be opened in DeBug Diagnostic Analysis. It will convert the DMP file to HTML report and will open it in IE. Yes, yes, IE, even if your favorite browser is Chrome. Ok, ok, just give me the call stack
<br />
<br />
We are looking for any errors, crashes in that HTML log. In my case I found "access violation" exception and call stack of the exception. Surprisingly, the call stack is pretty obvious code. It accesses a property which is null, so I would expect a NullReferenceException. But it was access violation. What is more interesting, is that that piece of code is surrounded by try/catch block.
<br />
<br />
Starting from .NET 4.0, access violation exceptions and similar are not thrown in the regular way. They just terminate the process and are not caught in try block. But there are two still to catch them:
<br />
<ul>
<li>1. Using attribute HandleProcessCorruptedStateExceptions on the suspicious method </li>
<li>2. Using <legacyCorruptedStateExceptionsPolicy enabled="true" /> </li>
</ul>
Below code demonstrates how to apply HandleProcessCorruptedStateExceptions attribute on suspicious method. It enables catching the access violation exception.
<br />
<pre class="brush: js">
internal class Program
{
private static void Main(string[] args)
{
var crashingThread = new Thread(CrashingThread);
crashingThread.Start();
Console.ReadKey();
}
[HandleProcessCorruptedStateExceptions]
private static void CrashingThread()
{
try
{
CrashMe();
}
catch (Exception exception)
{
Console.WriteLine("I caught access violation");
Console.WriteLine(exception.ToString());
}
}
private static unsafe void CrashMe()
{
unsafe
{
int read = *((int*) long.MaxValue - 8);
}
}
}
</pre>
<br><br>
A few last notes about that attribute:
<BR>
It can be applied on any level on the call stack of the suspicious code. Even on the Main method. However it won't work if you apply the attribute on the main method, but the exception occurs in another thread. It should be applied on the method that is on the crashing thread!
<BR><BR>
Please note, that it is not recommended to leave that attribute in production code. It should be used only for debugging purposes.
<BR><BR>
Enjoy your debugging!
</div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-90276084830853731302013-12-11T06:58:00.001-08:002013-12-11T06:59:27.702-08:00BizArk.Core 2.0.9 was pushed to NuGet<div dir="ltr" style="text-align: left;" trbidi="on">
Bizark.Core 2.0.9 was pushed to NuGet<br />
<br />
Release notes:<br />
<a href="https://bizark.codeplex.com/workitem/9151">9151</a><span class="Apple-tab-span" style="white-space: pre;"> </span>Empty argument prefix does not work and does not<br />
<br />
Example:<br />
<pre class="brush: js">
[CmdLineOptions(ArgumentPrefix = "")]
internal class MyCmdLineObject: CmdLineObject
{
[CmdLineArg]
public string Name { get; set; }
}
</pre>
Can be used like this from command-line
<br />
MyConsoleApplication.exe Name Boris
<br />
<br />
In conjunction with ArgumentDelimiter:
<br />
<pre class="brush: js">
[CmdLineOptions(ArgumentPrefix = "", ArgumentDelimiter='=')]
internal class MyCmdLineObject : CmdLineObject
{
[CmdLineArg]
public string Name { get; set; }
}
</pre>
From command line
<br />
MyConsoleApplication.exe Name=Boris
<br />
<br />
Also supports string surrounded by double quotes:
<br />
<pre class="brush: js">
[CmdLineOptions(ArgumentPrefix = "", ArgumentDelimiter='=')]
internal class MyCmdLineObject : CmdLineObject
{
[CmdLineArg]
public string Path { get; set; }
}
</pre>
MyConsoleApplication.exe Path="C:\Program Files (x86)\Microsoft.NET\"
<br />
The value of Path will be @"C:\Program Files (x86)\Microsoft.NET\" without the leading and ending double quotes
<BR>
<BR>
Get from nuget:
<div class="nuget-badge">
<p>
<code>PM> Install-Package BizArk.Core
</code></p>
</div>
</div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-44371682050988823732013-12-04T02:28:00.002-08:002013-12-04T02:28:49.957-08:00Goodbye Autofac<div dir="ltr" style="text-align: left;" trbidi="on">
Autofac is one of my favorite IoC containers, due to its fluent, easy-to-learn syntax and great performance. However recently it let me down in some occasions and I had to get rid of it in the main project, I am working on. But let me explain it from the beginning.<br />
<br />
Since Autofac 3.0, it is compiled against Portable .NET Framework. It is a subset of the usual .NET Framework, which runs on various devices and platforms. Such as Silverlight, mobile etc. The portable framework version number is 2.0.5.0. So far, so good. It worked well in my project with .NET Framework 4.5. But...<br />
<br />
1. When we tried to obfuscate Autofac.dll using Dotfuscator version 4.8, it complained that mscorlib.dll version 2.0.5.0 cannot be found. Although it exists in the corresponding directory under C:\Windows\Microsoft.NET\Framework . <a href="http://www.paraesthesia.com/" target="_blank">Travis Illig</a> suggested me to upgrade the Dotfuscator to latest version, which would definitely resolve the problem.<br />
<br />
From Dotfuscator v 4.9 release notes:<br />
<ul style="background-color: #f4f5f6; border: 0px; color: #595959; font-family: helvetica, Arial, sans-serif; font-size: 13px; line-height: 21px; list-style: none; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<li style="background-image: url(http://cdn-a.preemptive.com/images/web/content_bullet.gif); background-position: 9px 50%; background-repeat: no-repeat no-repeat; border: 0px; line-height: 16px; margin: 0px; outline: 0px; padding: 3px 0px 3px 25px; vertical-align: middle;">Using String Encryption on Portable Class Libraries will no longer cause Windows Store apps to fail certification.</li>
</ul>
<a href="http://www.preemptive.com/support/dotfuscator-support/dotfuscator-pro-change-log/464" target="_blank">http://www.preemptive.com/support/dotfuscator-support/dotfuscator-pro-change-log/464</a><br />
<br />
Unfortunately, upgrading Dotfuscator means purchasing a new license, which is pretty expensive. We managed to overcome this problem by putting mscorlib.dll v2.0.5.0 in one of the internal directories. Dotfuscator scans directories and managed to find it successfully.<br />
<br />
2. The second problem appeared when we started testing the product on clean machines. We get the following exception, despite the fact that Portable Framework exists on the machine:<br />
<br />
<pre class="prettyprint" style="background-color: #eeeeee; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace; font-size: 12px; max-width: 70em; overflow: auto; padding: 0.5em;"><span class="typ" style="color: #660066;">Could</span><span class="pln"> </span><span class="kwd" style="color: #000088;">not</span><span class="pln"> load file </span><span class="kwd" style="color: #000088;">or</span><span class="pln"> assembly </span><span class="str" style="color: #008800;">'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'</span><span class="pln"> </span><span class="kwd" style="color: #000088;">or</span><span class="pln"> one of its dependencies</span><span class="pun" style="color: #666600;">.</span><span class="pln"> </span></pre>
<br />
It happens as a result of Microsoft Known Bug <a href="http://support.microsoft.com/kb/2468871" target="_blank">KB2468871</a>. It was fixed by the Redmond folks, but the relevant update is not installed on the machine.<br />
<br />
So it means, that in order to use Autofac we have to required from our customers to install Windows Updates. Sometimes it might cause issues with corporate customers, that have strict policy regarding machine updates. It was decided that we'll stop using Autofac in this major project and will switch to something less "sensitive".<br />
<br />
Nevertheless, we still use Autofac in many other internal projects. So it is not a real "Goodbye"<br />
<br />
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com1tag:blogger.com,1999:blog-3090991703190749969.post-77375379051450241122013-11-13T08:43:00.001-08:002013-12-04T02:29:28.201-08:00Opt in and opt out using Autofac IoC container<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I am a big fan of dependency injection and inversion of control. I strive to use these techniques in almost every project I am involved with. Usually when I develop the project from the ground, the whole design is ready for automatic types scanning and auto wiring. So it is very easy to wire them up using a short piece of code. All the examples in this post will be using Autofac - the addictive IoC container.<br />
<pre class="brush: js">
public IContainer Initialize()
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(GetType().Assembly).AsImplementedInterfaces();
return builder.Build();
}
</pre>
<br />
But sometimes, I need to prevent some classes from being registered, for example, the instance need to be created in run time with specific context parameters. In this case I use the opt-out, i.e. register all the types except those having a custom attribute:<br />
<pre class="brush: js">
[AttributeUsage(AttributeTargets.Class)]
public class DontRegisterInContainerAttribute : Attribute
{
}
public IContainer Initialize()
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(GetType().Assembly)
.Where(t => !t.HasAttribute<DontRegisterInContainerAttribute>())
.AsImplementedInterfaces();
return builder.Build();
}
</pre>
</div>
In order to use the attribute in this syntax, I am using an extension method:
<br />
<pre class="brush: js">
public static class TypeExtensions
{
public static bool HasAttribute<T>(this Type @this)
{
return @this.GetCustomAttributes(typeof (T), false).Any();
}
}
</pre>
<br />
In some projects, when I am modifying existing code, which is not "IoC-ready", I need to register only a few classes. Hopefully their number will increase in the future. But currently what I am actually want is to type the container: register only these classes, without actually listing them or assume they reside in some namespace or have something in their name. In such cases I use the opposite:<br />
<pre class="brush: js">
public IContainer Initialize()
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(GetType().Assembly)
.Where(t => t.HasAttribute<RegisterInContainerAttribute>())
.AsImplementedInterfaces();
return builder.Build();
}
</pre>
<br />
With the corresponding custom attribute:<br />
<pre class="brush: js">
[AttributeUsage(AttributeTargets.Class)]
public class RegisterInContainerAttribute : Attribute
{
}
</pre>
<br />
Using this method of registering only types marked with the attribute also makes the code clearer to co-workers, who might look up for usages of the attribute and find out what classes are registered in the container. In case they are not familiar with <a href="http://borismod.blogspot.co.il/2012/07/how-to-avoid-is-never-used-resharper.html" target="_blank">Agent Mulder Resharper plugin</a>.<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-13386193702793917222013-10-24T08:24:00.000-07:002013-10-24T08:24:21.943-07:00BizArk documentation on Console application <div dir="ltr" style="text-align: left;" trbidi="on">
It seems that the best documentation is "single page" with code snippets. Projects with such kind of documentation are easy to understand and to use. I've just added such documentation to BizArk project. <div>
<br /></div>
<div>
<a href="https://bizark.codeplex.com/wikipage?title=Console%20application%20with%20command-line%20parsing%20and%20validation&referringTitle=Documentation">https://bizark.codeplex.com/wikipage?title=Console%20application%20with%20command-line%20parsing%20and%20validation&referringTitle=Documentation</a></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0tag:blogger.com,1999:blog-3090991703190749969.post-5558475005183572952013-09-17T06:08:00.002-07:002013-09-17T06:08:51.206-07:00BizArk::Command-line parsing library <div dir="ltr" style="text-align: left;" trbidi="on">
Some time ago I needed a simple command line parsing library. After some research I came to BizArk ToolKit by Brian Brewder. Since then I became addicted to this library, contributed a few features of my own, fixed a few bugs. Now I am proud to tell that its recent release version <b>Bizark.Core 2.0.3</b> is available on nuget. Please don't get confused with the BizArk toolkit of older versions.
Here is a sample usage:
<pre class="brush: js">
public enum ConsoleMode
{
Copy,
Move
}
public class SimpleCommandLineArgs : CmdLineObject
{
[CmdLineArg]
public ConsoleMode Mode { get; set; }
[CmdLineArg]
public string Path { get; set; }
}
public static class Program
{
private static void Main(string[] args)
{
ConsoleApplication.RunProgram<SimpleCommandLineArgs>(Start);
}
private static void Start(SimpleCommandLineArgs args)
{
// Your code goes here
}
}
</pre>
It will parse the following command-line arguments and create an instance of SimpleCommandLineArgs:
<pre class="brush: shell">
C:> YouConsole.exe /Mode Move /Path C:\
</pre>
Now available on <a href="http://www.nuget.org/packages/BizArk.Core/">nuget.org</a>
<div class="nuget-badge">
<p>
<code>PM> Install-Package BizArk.Core </code></p>
</div>
For more info visit project site on CodePlex:
<a href="https://bizark.codeplex.com/">BizArk</a>
</div>Anonymoushttp://www.blogger.com/profile/13864094556362517427noreply@blogger.com0