For this short post, let's go back to basics. Let us try to adjust an image's brightness by trying to add a value between -255 (darkest ) to 255 (lightest) to an image pixel data.

SOURCE CODE - https://jsfiddle.net/HumpreyCogay/upbnvnsb/

NOTE - an image can be loaded to an ImageData, The data attribute of this object contains a Uint8ClampedArray representing a one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (included).

To process these types of jobs, we can take a look on some supermarket lines, where we have 1 long line with several counters catering to 1 customer at a time, when a cashier is done with the current customer, one customer will be called from the line.

On the programming world we have what we call threading and semaphores and luckily .Net Offers built-in classes for these concepts .

Threads allows us to do calculations on a separate thread while leaving the original/main thread busy on the GUI.

Previously we started creating our seed project then we created our first AngularJS2 app, on this post we will try to play with AngularJs2’s Attribute Directives.

Basically, Attribute Directives allows us to change the appearance or behavior of a DOM Element, such us changing colors of DIVS when our mouse enters or exits, or alter the behavior of a DOM element when clicking them.

For this Post, We will use the current state of the project we used on our last post, you can go back to my previous posts if you still haven't done so.

Create a new TypeScript file under our projects APP Folder(not the wwwroot/app folder) and copy and paste the complete codes at the end of this step/procedure.

What’s note worthy here is the @Directive decorator, this will locate all elements on our template HTML that has the [myHighlight] attribute and will inject our Directives capabilities.

We will also have @Hostlistener’s which will allow us to catch the MouseEnter and MouseLeave and insert what we want our Directives to do, on this case we will change the style.backgroundColor of our DIVS.

Now we need to update our app.component.ts so we could use the HighlightDirective we created on step no 3. what’s note worthy here is we change the template: to templateUrland we told our app.component to use our newly created [HighlightDirective]

Starting to play with technologies that are not yet released is a pain in the a#$%. First, because big changes can occur thus breaking our proof of concept projects, Second, looking for a good resource online is not as rich when looking for resources for products that are already released, Third, the list of pains goes on …

To start the series we will begin by preparing what we need. On Part 2 of the series, We will start creating our first AngularJS2 on ASP.Net Core using TypeScript

Updates :

July 2, 2016

ASP.NET Core 1.0 is now released, so I updated the VS and Tools update links Added an item to update TypeScript Manually

NOTE: It is a good idea to have the latest GIT and NODEJS binaries, because Visual Studio 2015 is shipped with an older GIT and NodeJS binaries, you might encounter some errors if you are not going to have the latest versions

On Part 1 we started preparing the stage. If you still haven't done so, please visit http://wblo.gs/lRz

On this Part of the series we will start building our first AngularJS2 on ASP.Net Core using Typescript. On Part 3 we will start coding our own Directives (component that can help us change the appearance or behavior of an HTML elements)

- Open Project>Properties and open Debug Tab and set Launch URL: index.html

14. Run the Project by pressing F5

Additional References/Notes

package.json - https://docs.npmjs.com/files/package.jsongulp.js/grunt/gulp/webpack - https://npmcompare.com/compare/browserify,grunt,gulp,webpackrimraf – This will traverse a folder and delete objects, similar to linux’ rm –rf command taskrunner – task runners help developers to automate tasks by using different tools like GULP, BOWER package.json - A package.json file contains meta data about your app or module. Most importantly, it includes the list of dependencies to install from npm when running npm install

One of the challenges of working with queues is how to properly and neatly process each item using multiple workers, luckily on .Net we have Semaphores. “In computer science, a semaphore is a variable or abstract data type that is used for controlling access, by multiple processes, to a common resource in a concurrent system such as a multiprogramming operating system.” https://en.wikipedia.org/wiki/Semaphore_(programming)

Below is a simple program that demonstrate the use of semaphore with a parametized number of threads and HttpRequest as Payload.

SQL Server together with other RDBMS, are the most memory consuming applications on our servers, and this is because, RDBMs usually cache objects into the memory to take advantage of the speed that physical memory offers.

Sadly when windows feels that its physical memory is currently not enough for a driver and/or processes that is requesting some resources, it is forced to trim some of currently running application’s memory working set. Now that is bad news for SQL Server because windows will be forced to push the objects from the memory to the servers’ paging file. You can verify if windows is doing this to your SQL Server by investigating SQL Server Logs for this entries

A significant part of sql server process memory has been paged out.This may result in a performance degradation. Duration: 0 seconds. Working set (KB): 1086400, committed (KB), memory Utilization: 50%.

Currently there are 2 settings that we can play with to avoid or at least alleviate this situation

1. Properly set SQL Servers’ Max Memory settings, by setting aside enough memory for the OS and other running Processes like Antivirus and Server Monitoring Software.

2. Enable SQL Server Locked Page in Memory (LPIM)

NOTE: Enabling LPIM without fully Understanding how SQL Memory Works and without knowing how your DB Server Behaves specially if it’s in a Virtual Environment might give you negative effects.

For this Post we will be focusing on LPIM. When using LPIM Windows cannot simply touch the memory space used by SQL Servers’ Buffer Pool, it is locked and cannot be paged. SQL Server does this by using Address Windowing Extensions (AWE).

When LPIM is enabled you cannot simply view how much really SQL Server is using by viewing Task Manager. As you can see on the screen shot below, SQLSERVR.EXE is only using 49, 536Kb

You can however use RamMap (A free RAM tool from Sysinternals: www.sysinternals.com). To view how much memory AWE is using.

Or you can also use sys.dm_os_process_memory SQL Server Dynamic Management Views (DMV).

How to Enable LPIM

Use Windows Group Policy tool (gpedit.msc) to enable this policy for the account used by SQL Server. You must be a system administrator to change this policy.

1. On the Start menu, click Run. In the Open box, type gpedit.msc.

2. On the Local Group Policy Editor console, expand Computer Configuration, and then expand Windows Settings.

7. In the Select Users, Service Accounts, or Groups dialog box, add an account with privileges to run sqlservr.exe.

8. Log out and then log back in for this change to take effect.

Note about SQL Server 2008 R2 Standard Edition (64-bit):Microsoft SQL Server 2008 R2 Standard Edition (64-bit, all versions RTM and later) also requires trace flag 845 to be added as a startup parameter so that SQL Server can use locked pages for the Buffer Pool when the SQL Server service account is granted the Lock Pages in Memory security privilege

Note about SQL Server 2012 Standard Edition (64-bit): Microsoft SQL Server 2012 Standard Edition (64-bit) does not require you to enable any trace flag to allow SQL Server use locked pages for the Buffer pool when the SQL Server service account is granted the Lock Pages in Memory security privilege.