Improve code quality in .Net applications

Writing source code for any requirement is always a head-scratching activity. But when it comes to improving the quality of code, it seems to be a different world.

Though maintaining code quality looks like overhead at the beginning of the project, but as code grows and the development team expands, the initial effort on focusing on setup quality gateways looks fruitful.

Few tools and techniques are summarised here which should become an integral part of each .Net project.


Improve Code Quality in .Net

Find unused code:

ReSharper is one of the best code analysis tools that can be integrated with Visual Studio

To find unused code in your solution right-click on the solution > Select "Find Code Issues" > One of the results is "Unused Symbols". This will show you classes, methods, etc. that aren't used.

Reference - https://stackoverflow.com/questions/245963/find-unused-code

Discover dead code using Visual Studio Code Analysis:

Visual Studio provides this feature out-of-the-box. Right-click on the solution > Analyze > Run Code Analysis on Solution.

Reference - https://blogs.msdn.microsoft.com/habibh/2009/07/31/discover-dead-code-in-your-application-using-code-analysis/

Static code analysis tool:

StyleCop and FxCop are the most popular tools that can be included in the project to maintain coding standards defined by the organisation. 

They are available as a NuGet package and gets auto-configured when added. These tools follow basic coding standards defined by Microsoft but can be customised further as per the need.

It can be configured to fail the build if any of its code quality checks fail. It can also be configured to fail the build if any warnings are identified. This ensures the code delivered is of optimum quality.

Enable Gated check-in using VSTS Build Definition:

Gated check-in builds ensures that the checked-in code is always free from compilation errors. This can be enabled in Visual Studio using TVFS projects using VSTS Build Definition, though this feature is still not available in Git team projects.

Reference - https://www.codeproject.com/Tips/1168853/Enabling-Gated-Check-in-using-Visual-Studio-Team-S

Code coverage analysis:

Code coverage analysis is available out-of-the-box in Visual Studio. This analysis indicates the percentage of unit tests written for the project.

The attribute [ExcludeFromCodeCoverage] can be applied to the class files that need to be excluded from code coverage. Make sure not to apply this attribute on the application code, as it will produce over-inflated coverage metrics.

Class files created automatically by adding service references must be excluded from code coverage. The CodeCoverage.runsettings file can be used to accomplish this.

Include automation scripts:

When development is in progress, there are several instances where fixing one issue or developing a new story would unexpectedly break existing functionality. 

QA team can only focus on testing the specific feature or user story in a sprint. But as the system scales, it becomes practically impossible for the QA team to perform integration testing in each sprint.

Automation scripts are proven to be a boon in such cases which can be executed either manually or scheduled after each deployment. This can also be added into the Continuous Integration pipeline to automatically run after each deployment.

Selenium scripts are recommended for automated testing in .Net applications. Selenium is powerful enough to execute scripts on the server even in absence of any browser. This is made possible by adding a specific browser driver as a NuGet package. Some browsers like chrome can be run in headless mode to execute the scripts faster as this will run chrome in the background.

Though surprising it is not recommended to use Internet Explorer anymore but focuses your application to fully functional on Chrome or Firefox.

Use mocking framework:

Mocking frameworks like NSubstitute or MOQ helps to write unit tests by mocking the reference layer. This means while writing unit tests for the web layer you can mock the business layer; similarly while writing unit tests for the business layer you can mock the service layer.

Design patterns:

Few design patterns are a must-have for any development. They include dependency injection, factory pattern, service pattern and repository pattern.

Dependency injection with Unity framework can be easily integrated with a NuGet package. It is highly recommended to use the DI pattern as it also helps in writing effective unit tests with a mocking framework.

Exclude NuGet packages from code check-in:

TFS or VSTS can be configured to download the NuGet package from nuget.org during the Build process.

Whenever a NuGet package is added to any project, it not only download its assemblies but also adds an entry into packages.config file. Hence it is the best approach to eliminate any NuGet package from check-in into source control and just check-in respective packages.config file.


Build quality checks:

Add task "Build Quality Checks" in the VSTS Build process. Build can be configured to break based on quality metrics like a number of warnings or code coverage.

You can also specify a code coverage threshold that is the minimum code coverage value in percentage terms.

Modify email files arriving into SMTP server

When you send any email it arrives in the Pickup folder of the SMTP server in the form of a .eml file. SMTP server continuously monitors the Pickup folder for any incoming file.

As soon as any email file is received in Pickup, it is picked to check its integrity. If the format of .eml is incorrect then it is sent to the BadFiles folder, otherwise, it is sent to the Queue folder from where SMTP forwards email to specified recipients.

If there a requirement to modify recipients, subject or content of the email after it arrives in the SMTP server, then it can be achieved using a different mechanism.

SMTP server rules:
You can create rules in the SMTP server to modify email before forwarding it to recipients.

Create macros:
Macros are very powerful scripts that can read the content of .eml files. They can be written in VB Script (.vbs file) which can read each incoming .eml file within the Pickup folder and process as needed.

Socket programming:
Write a code based on socket programming or HTTP pipeline that picks the inflow of content to the SMTP server.

Drink green coffee for weight loss

There are ongoing debates around the health benefits of drinking coffee and the controversy on green coffee beans. They gained popularity as a weight-loss supplement after being featured on "The Dr Oz Show".

Drink green coffee for weight lossGreen coffee beans have high levels of chlorogenic acid which is thought to have several health benefits. This compound gets destroyed if the beans are roasted to form regular coffee beans. Green coffee doesn't taste like traditional black coffee flavour as its beans are not roasted.

These beans are a boon for those who want to lose weight naturally without any side effects. Green coffee not only helps in weight loss but also boosts metabolism due to the high level of antioxidants. Green coffee is also thought to be useful in lowering high blood pressure, obesity, Alzheimer's disease and type 2 diabetes but more evidence is required.


The beans extract is sold in the form of capsules and can be found online or in health stores. It is also readily available in the form of beans or powder.


Drink green coffee for weight loss

Green coffee is slightly bitter in taste and can be flavoured by adding honey or cardamom.

Method to prepare green coffee from beans:

Ingredients

  • Whole green coffee beans (1 tsp)
  • Water (1.5 cups)

Steps

  • Take the green coffee beans and wash them in running water to remove any dust or other particles over beans.
  • Then, soak the beans in the water (amount of water required for drinking coffee).
  • Let the beans boil in the water for at least 10 minutes along with continuous stirring.
  • Then, switch off the gas and leave the beans in the water for 10-15 minutes.
  • Then, pour the water into a cup by filtering through a sieve to separate the beans and enjoy the green coffee.

Method to prepare green coffee from beans powder:

Ingredients

  • Green coffee beans powder (1 tsp)
  • Water (1 cup)

Steps

  • Add the green coffee beans powder to the boiling water and stir it for at least 10 minutes and keep the remaining powder for future use.
  • Then, switch off the gas and leave the mixture for 10-15 minutes.
  • Then, pour the water into a cup by filtering through a sieve and drink the green coffee.
Green coffee can be taken empty stomach in the morning as well as afternoon.

Merge, Compress or Convert documents to PDF


Merge, Compress or Convert documents to PDF
We frequently come across the need to merge multiple documents into one document or convert image to PDF document. Even there are requirements to compress large PDF document without losing their quality. Though these are basic requirements in our day-to-day life but are not freely provided out-of-the-box by Adobe Reader.

Here are some of the fantastic websites that swiftly merge, compress or convert any document to a PDF file:

http://jpg2pdf.com - Merge multiple images into a single PDF document and share with others. There is no limit in file size, no registration and no watermark. This service automatically rotates, optimizes and scales down images, but retains the original resolution.

http://combinepdf.com - Merge multiple PDF documents into a single PDF document without installing any software.

http://pdfcompressor.com - Compress PDF files for publishing on web pages, sharing in social networks or sending by email. Unlike other services this tool doesn't change the DPI, thus keeping your documents printable and zoomable.

http://topdf.com - Instantly convert text documents, presentations, spreadsheets and images to PDF format with this free online PDF converter.

How to buy Bitcoin, Ethereum, Ripple in India?

Several virtual currencies are available in the market for years, but they have recently gained much popularity in India. The main reason behind this increased attraction towards cryptocurrencies is a sudden spike in their price which raised public eyeballs all over the world. Bitcoin is the most popular virtual currency that came in highlights when it surged from $1000 to $19000 within just one year.


Bitcoin

Multiple platforms are operating in India through which you can buy or sell cryptocurrencies. A platform having the facility to trade more than one cryptocurrency is also referred to as a currency exchange. This is similar to a stock exchange where you can buy or sell various stocks. The stocks are stored in a Demat account, similarly, cryptocurrencies are stored in currency wallets.

Buying any cryptocurrency like bitcoin, ethereum, ripple, etc. can seem a little scary for the first time but it is just as simple as registering in any shopping cart, authenticating the registration and placing a new order. Follow these four simple steps to accomplish this:
  1. Find a cryptocurrency wallet provided by portals like Zebpay, Unocoin, Ethx, Koinex, etc.
  2. Create an account within the selected portal and complete KYC.
  3. Transfer fund from your linked bank account.
  4. Place order to buy cryptocurrency.


Cryptocurrencies

These wallets offer referral programs through which users gain a small percentage of cryptocurrency as a welcome bonus on registering to their platform. To register to these platforms use the referral links available here:
  • Zebpay and UnoCoin are two popular mobile apps that can be used to buy or sell bitcoins using indian rupees of your bank account.
  • Ethx.in website can be used to buy ethereum at a cheaper rate.
  • Koinex.in can be used to buy bitcoin, ethereum, ripple, litecoin and bitcoin cash.
  • Sragy.com can be used to buy ethereum, ethereum classic, ripple, litecoin, dash and iota.
  • BuyUcoin.com can be used to buy various cryptocurrencies.


A new concept of the crypto community platform is also catching public interest nowadays due to their commitment to very high monthly returns from either lending, staking, mining or trading of tokens provided by them. A detailed analysis should be done before investing in such community platforms.

Few crypto community platforms that are growing at a faster pace are shared below:
  • Crypterium - digital crypto-bank with credit subtoken and open platform.
  • Storiqa - a crypto marketplace that connects one million offline stores worldwide.

What is Cryptocurrency and how to buy them?

The world is evolving rapidly and so is the mode of exchange. Each country has its own currency but when the trade is to be done across borders, then there is no common currency and so the transaction has to be leveraged upon Dollars which is again the currency of the US.

Digital technologies have virtually connected the world via the internet. Blockchain is one such technology through which decentralised digital currency or virtual currency has come into existence. These virtual currencies are nothing but timestamp-based cryptographic identities generated using a very distinct algorithm. These algorithms are very secure and keep detailed traces of each transaction within Blockchain ledgers. This has made economists and technology experts rely on virtual currencies generated by Blockchain technology. 


As these virtual currencies are generated digitally using cryptographic algorithms, they are also known as Cryptocurrency.


Bitcoin is the first cryptocurrency that came into existence in 2009. After its worldwide acceptance, various other virtual currencies were launched with little enhancement over bitcoin. Till the end of the year 2017, there were more than 100 such virtual currencies in existence out of which few popular ones are Ethereum,  Litecoin, Ripple, IOTA and BitcoinPower.


Each physical currency has an acronym: USD for dollar, EUR for euro, INR for rupees, etc. Similarly, an acronym is also specific for each virtual currency: BTC for bitcoin, ETH for ethereum, LTC for litecoin, XRP for ripple, etc.


Similar to the stock exchange available for the stock market, cryptocurrency exchange websites also exist. Through these cryptocurrency exchange, you can buy, sell or exchange cryptocurrencies with other digital currencies or traditional currency like the dollar or euro. Coinbase
Kraken and Bitstamp are the most popular cryptocurrency exchange websites where you can create an account and start trading.

Even though virtual currencies are not yet made legal by many countries, but multinational enterprises have started upgrading their applications to accept cryptocurrencies as a mode of exchange. 
World giants like the US, Japan and Canada have started using cryptocurrencies for long and other countries are also working on this digital revolution to amend their taxation policy.

India has not yet legalised cryptocurrency transactions as its impact on the economy is still being analysed by experts and economists. Its government has given a clear indication that they are amending their taxation policies to restrict unauthorised inflow/outflow of funds so that such transactions can be legalised.

Though it is not necessary to start doing transactions in cryptocurrencies on an immediate basis, it is better to keep the account ready to operate whenever the opportunity grows. Here is a list of few exchanges where cryptocurrencies can be bought in Indian rupees:

These are two mobile apps that can also be kept handy:
Open source, peer-to-peer, community-driven decentralised cryptocurrencies are also available that allow people to store and invest their wealth in a non-government-controlled currency, and even earn a substantial interest in investment. This means anyone holding such currencies in their wallet will receive interest on their balance for helping them maintain the security of the network.

Refer to this article on how to buy Bitcoin, Ethereum and Ripple in India.

Google enables default ad-blocker within Chrome

The use of the internet is flourishing each day as laptop and mobile users are increasing exponentially. This has led to an increase in the digital marketing industry business.

Google has plunged into digital marketing for a long time and also earns a lot of revenue from Adsense. With the help of ads banners, the revenue is generated by either CPC (Cost Per Click) or CPM (Cost Per Impression).

More than 70% of mobile devices operate on Android having Chrome as the default browser that very well supports ads banner. However, this support is so extensive that there is no facility to restrict such ads. Few Chrome extensions are available that can be used as ad-blocker up to some extent.

Some websites are loaded with unpleasant ads that make the browsing experience uncomfortable. To overcome this concern Google has upgraded Chrome to restrict ads while surfing. This decision of Google has created a storm in the digital marketing industry as their business is on the verge of getting ruined, however, Chrome users have greeted this decision with open hands.


Chrome

This upgrade of the ads-free version of Chrome was rolled-out on February 15, 2018. This version enables default adblocker within Chrome which will block most of the intrusive ads including full-page ads, flashing animated ads and auto-playing video ads. Such ads are designed to be disruptive and stands in the way of people using browser for their intended purpose.

Google will not weed out all ads from Chrome but will block all ads that repeatedly violate standards set forth by Coalition of Better Ads - a group of online media and publishing industries including Google, Microsoft, Facebook, Unilever, etc. So the "Better quality ads" that pass Adsense quality checks will still continue to exist.

Read more on registering your website domain on Google and optimizing search with different search parameters.