Tuesday, December 18, 2018

.NET Generic Configuration Section

If we need to extend an app.config file of .net application with a deep level configuration section like this
  
  <DevicesConfiguration>
    <devices>
      <device type="SM_G920I###6.0.1">
        <touchActivities>
          <touchActivity type="ToggleFlightMode">
            <points>
              <point x="500" y="1800" id="1"/>
              <point x="1300" y="430" id="2"/>
            </points>
          </touchActivity>
          <touchActivity type="ToggleVOLTE">
            <points>
              <point x="500" y="2400" id="1"/>
              <point x="1300" y="1000" id="2"/>
            </points>
          </touchActivity>
        </touchActivities>
      </device>
      <device type="SM_J510FN###7.1.1">
        <touchActivities>
          <touchActivity type="ToggleFlightMode">
            <points>
              <point x="340" y="220" id="1"/>
              <point x="340" y="610" id="2"/>
              <point x="640" y="200" id="3"/>
            </points>
          </touchActivity>
          <touchActivity type="Enable3G">
            <points>
              <point x="340" y="220" id="1"/>
              <point x="360" y="960" id="2"/>
              <point x="370" y="390" id="3"/>
              <point x="270" y="580" id="4"/>
            </points>
          </touchActivity>
        </touchActivities>
      </device>
    </devices>
  </DevicesConfiguration>
we have to create at least 3 classes inherited from ConfigurationElementCollection to incapsulate 'devices', 'touchActivities' and 'points' sections. It could be too much code unless we create generic ConfigurationElementCollection and use it everywhere instead of creation separate classes.

Tuesday, November 27, 2018

JavaScript Array sort by several parameters

Array.prototype allows us to sort array just by 1 parameter. I have created my own method 'sortBy' to fix this gap. The method also allows to sort by desc. Let's say we have the following array
  
var objects = [{'Name': 'John', 'Age': 23, 'Profession': 'Accountant'},
    {'Name': 'Adam', 'Age': 18, 'Profession': 'Engineer'},
    {'Name': 'Vik', 'Age': 46, 'Profession': 'Architect'},
    {'Name': 'Jane', 'Age': 36, 'Profession': 'Developer'},
    {'Name': 'Rikky', 'Age': 28, 'Profession': 'Developer'}];
The following function call sorts the array by 'Profession' then by 'Name' descendantly
  
sortBy(objects, 'Profession', {'Name': 'desc'});
console.table(objects);
The result will be the following:

Now let's have a look at the method implementation.

Wednesday, November 14, 2018

Sorting C3 chart tooltip

C3 is very simple free JavaScript library that allows to create various types of chart literally in few lines of code. C3 is based on D3 so we must plugin it as well

  
  
  
  

  <div id="chart"></div>
  

That small code snippet produces such a beautiful chart with a tooltip:




But as you can see, the data in the tooltip are not sorted. The goal of this post is to show how to sort it. 

Thursday, November 8, 2018

Adding legend to D3 chart

D3 is very powerful free JavaScript library that allows to do many things such as DOM manipulations, working with data and shapes, smoth transitions between UI states etc. I show just a simple example how I adedd a legend into a coloured barchart.


Friday, November 2, 2018

PowerShell Get, Filter, Where, Copy in a single line

The task is the following: create a simple script for gathering textual log files from several different places via network, filter them by name and recent update date, display files information like name, datetime, length and copy them to a specified destination. It is pretty achievable through the PowerShell functionality.

Saturday, October 20, 2018

The simpliest jQuery form validation

Let's start with the following simple example







To achieve this we need to use the following

Monday, October 15, 2018

NAnt msbuild latest .NET Framework versions problem fixed


   The problem with NAnt is that the latest supported version for .net framework is 4.5 (msbuild 13).
So, the following snippet:

    <msbuild project="D:\MyProject\MyProj.sln">
      <property name="nant.settings.currentframework" value="net-4.7.1">
      </property>
    </msbuild>

gives us the error

Target framework could not be changed. "net-4.7.1" is not a valid framework identifier.

The workaround is pretty simple

Friday, October 5, 2018

Open Command Window Here as Administrator with Hotkey



 

   To add a context menu item "Open Command Window Here as Administrator" you need to create AddMenuItem.reg file and paste the following code there: