hit tracker

Blog

Home » Blog

Bind File System in WPF using FileSystemWatcher in C#

in C-Sharp, Programming, UI, WPF by Balamanigandan B Comments are off

C# is one of the most popular languages today and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how to efficiently use the AsEnumerable and AsQueryable in C# LINQ.

FileSystemWatcher Class implements to watch for changes in a specified directory. We can watch for changes in files and subdirectories of the specified directory. We can create a component to watch files on a local computer, a network drive, or a remote computer. FileSystemWatcher is perhaps the most important features in .NET used in the workplace today.

Binding File System

FileSystemViewModel.cs
MainWindow.xaml.cs
MainWindow.xaml
Preview:
C:\MyFolder\Jellyfish.jpg
C:\MyFolder\Mydata.txt
C:\MyFolder\Route.xls

The Property FilesCollection has only get access, get can only read information from that private field and return it. But set can only write information in that private field. But in our scenario, we are accessing the Window’s File System, So, we can’t know when the Folder gets update i.e., File Add / Delete / Rename. So, the above View Model fails to update the UI in dynamic.

Let us see how to overcome this problem. The .NET Framework introduces a new feature as like watchdog to monitor the File System, its called as FileSystemWatcher Class under the namespace System.IO. Let us see how to implement

FileSystemWatcher Class

FileSystemViewModel.cs

FileSystemWatcher Class has four major property, they are

  • Path
  • NotifyFilter
  • Filter
  • Event Handlers
  • Transaction Control Language

Path

It specifies the filesystem physical path to watch.

NotifyFilter

Specifies the type of changes to watch for in a file or folder. It supports the following Notification, they are

  • Attributes
  • CreationTime
  • DirectoryName
  • FileName
  • LastAccess
  • LastWrite
  • Security
  • Size

Filter

It’s used to determine what files are monitored in a directory. For example

  • *.* – All files (default). An empty string (“”) also watches all files.
  • *.txt – All files with a “txt” extension.
  • My*.txt – All files with a “txt” extension only stats with “My”.
  • M*a.txt – All files with a “txt” extension only stats with “M” and ends with “a”.
  • MyData.txt – Watches only MyData.txt
  • Jellyfish.jpg – Watches only Jellyfish.jpg

Event Handlers

It’s triggers the following events

  • OnChanged – Raises the Changed event.
  • OnCreated – Raises the Created event.
  • OnDeleted – Raises the Deleted event.
  • OnError – Raises the Error event.
  • OnRenamed – Raises the Renamed event.

EnableRaisingEvents

The component will not watch the specified directory until the Path property has been set and EnableRaisingEvents is true.

Important Notes:

Please note the following when using the FileSystemWatcher class.

  • Hidden files are not ignored.
  • In some systems, FileSystemWatcher reports changes to files using the short 8.3 file name format. For example, a change to “LongFileName.LongExtension” could be reported as “LongFil~.Lon”.
  • This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands.
  • The maximum size you can set for the InternalBufferSize property for monitoring a directory over the network is 64 KB.
  • Running FileSystemWatcher on Windows 98 is not supported.

 

Conclusion :

This article targets at understanding how efficiently we can Bind File System in WPF using FileSystemWatcher in C#. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality implementation of FileSystemWatcher in C#. Think Big… Start Small… Do Fast…

SQL Server Connectivity using Entity Framework in C# .NET Application

in C-Sharp, Database by Balamanigandan B Comments are off

Entity Framework (.edmx) is one of the most popular frameworks today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently connect the SQL Server Database in a C# .NET Application using Entity Framework.

An .edmx file is an XML file that defines a conceptual model, a storage model, and the mapping between these models. An .edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically. Entity Framework is perhaps the most important Database Connectivity Framework used in the workplace today.

Let us discuss how we have to create EDMX in Visual Studio using Entity Data Model Wizard. Before proceeding to the concept, first create a prerequisite tables and Stored Procedure to perform our task.

Create Table: Person

SQL Server Syntax:

Insert Data:

Insert the data into the Person table.

Select Data:

Select the data from the Person table.

Id firstName lastName dob gender
1 Bala Manigandan 1993-07-03 1
2 Mohan Raj 1975-05-01 1
3 Raj Kumar 1980-10-10 1

Create Table: Person_Address

SQL Server Syntax:

Insert Data:

Insert the data into the Person_Address table.

Select Data:

Select the data from the Person_Address table.

Id pid address City Ispreferred
1 1 15, Car Street Mumbai 1
2 1 24, Paramount Street Delhi 0
3 1 6, Gandhi Road Delhi 0
4 2 24, Nehru Road Delhi 1
5 2 6, Gandhi Road Delhi 0
6 3 6, Gandhi Road Delhi 1

Now, we write logic to fetch a Person Information along with Addresses associated with that particular person using Stored Procedure.

Create Stored Procedure: GetPersonInfo

Execute Stored Procedure:

Execute the Stored Procedure GetPersonInfo.

Mode Id Firstname lastName Dob Gender aid pid address City Ispreferred
P 1 Bala Manigandan 1993-07-03 1 NULL NULL NULL NULL NULL
A NULL NULL NULL NULL NULL 1 1 15, Car Street Mumbai 1
A NULL NULL NULL NULL NULL 2 1 24, Paramount Street Delhi 0
A NULL NULL NULL NULL NULL 3 1 6, Gandhi Road Delhi 0

Now, we are having two tables namely Peson and Person_Address and a Stored Procedure namely GetPersonInfo. Let us see how to connect this database tables and strored procdures with C# .NET application using Entity Framework.

Step 1:

Right Click into the Project File -> Add -> New Items

Step 2:

Select ADO.NET Entity Data Model under Visual C# Items -> Data. Give the Name as PersonModel

Step 3:

Choose Model Contents as EF Designer from database

Step 4:

Choose your Data Connection by clicking New Connection Button and then give the name as BalaEntities

Step 5:

Choose the latest Version (Here I’m choosing Entity Framework 6.x)

Step 6:

Choose the required Database Objects i.e., Tables, Views, Stored Procedures and Functions.

Step 7:

Here I’m Selecting the Table Person and Person_Address as well as Stored Proc finally click Finish

Step 8:

EDMX Files Created namely PersonModel.edmx

Step 9:

Navigate to Model Brower to check the PersonModel.edmx

Step 10:

Right Click into the Stored Procedure GetPersonInfo -> Add Function Import

Step 11:

Give the Function name to GetPersonInfo_Complex and Select the Returns a Collection of to Complex

Step 12:

Generate the Complex Return Collection by clicking the Get Column Information

Step 13:

Now Create the Column Information as a new Data Type by Clicking Create New Complex Type then click OK.

Now the Conectivity Part is Over. EDMX and Custom Data Types were created Successfully. Let us see how to use the Entity in the C# Application. Its very simple, just create a object for the appropriate Entity namely BalaEntities. Using the Object, access all your selected database tables and stored procedures.

C# Source Code:

Conclusion:

This article targets at understanding how efficiently we connect the SQL Server Database into C# .NET Application using Entity Framework. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionalities of Entity Framework. Think Big… Start Small… Do Fast…

Post HTML Embedded Interactive Blog in WordPress

in Programming, UI, Uncategorized by Balamanigandan B Comments are off

WordPress is one of the most popular tool today to publish Websites and Blogs are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently publish HTML embedded Interactive Blog in WordPress

HTML tags or HTML elements, and their respective attributes are used to create HTML documents so that we can view them in browsers like Google Chrome, Internet Explorer, Firefox, etc., and other user agents.

Let us discuss how we have to create HTML Embedded Interactive Blog using WordPress Post Creation Wizard in the Admin Panel.

  1. Log in to your WordPress (Dashboard).
  2. Click the tab.
  3. Click the sub-tab.
  4. Select the ‘Text’ Editor.

The Text Editor is a powerful tool to write up code in HTML along with CSS or by plain Text.

Pragraph :

Text Alignment: Left
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently remove duplicate records in a SQL Server Database table. SQL Server is a Relational Database Management System (RDBMS) and the most widely used client–server model RDBMS in the current trend applications. RDBMS is perhaps the most important Database system used in the workplace today.

Text Alignment: Right
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently remove duplicate records in a SQL Server Database table. SQL Server is a Relational Database Management System (RDBMS) and the most widely used client–server model RDBMS in the current trend applications. RDBMS is perhaps the most important Database system used in the workplace today.

Text Alignment: Justify
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently remove duplicate records in a SQL Server Database table. SQL Server is a Relational Database Management System (RDBMS) and the most widely used client–server model RDBMS in the current trend applications. RDBMS is perhaps the most important Database system used in the workplace today.

Block Quote

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text Alignment: Justify
Preview:

Structured Query Language (SQL) is one of the most popular languages today
to querying database and there are many reasons for this. It has many qualities
that make it suitable for development for users at most all levels.

Text: Bold

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Emphasized

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Italic

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Underline

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Overline

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: delete (or) line-through

Using HTML
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Using CSS
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Insert

Preview:

SQL Update Command is a Data Query Language Data Manipulation Language.

Text: Color

Foreground Color
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Background Color
Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

Text: Hyper Link

Preview:

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels.

List

Ordered List
Preview:
  1. Data Definition Language
  2. Data Manipulation Language
  3. Data Query Language
  4. Data Control Language
  5. Transaction Control Language
UN-Ordered List
Preview:
  • Data Definition Language
  • Data Manipulation Language
  • Data Query Language
  • Data Control Language
  • Transaction Control Language
Data List
Preview:
Types of Language
Data Definition Language
Data Manipulation Language
Data Query Language
Data Control Language
Transaction Control Language

Table

Default Table
Preview:
S.No. Database Launched License SQL
1 Oracle 1980 Proprietary Yes
2 MySQL 1995 Open source Yes
3 Microsoft SQL Server 1989 Proprietary Yes
4 PostgreSQL 1989 Open source Yes
5 MongoDB 2009 Open source Yes
Formatted Table: Border, Padding, Background Color and Text Alignment
Preview:
List of Databases
S.No. Database Launched License SQL
1 Oracle 1980 Proprietary Yes
2 MySQL 1995 Open source Yes
3 Microsoft SQL Server 1989 Proprietary Yes
4 PostgreSQL 1989 Open source Yes
5 MongoDB 2009 Open source No

Image

Preview:
IncRev Corporation

Conclusion:

This article targets at understanding how efficiently we create a Interactive HTML Embedded Blog in WordPress. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality of WordPress Blog Content Formatting. Think Big… Start Small… Do Fast…

ECMAScript 2015/ES 6 features every C# developer would love to use

in C-Sharp, Programming, Uncategorized by Prayag Pavitran Comments are off

JavaScript is constantly evolving and has become one of the most popular languages used. Now a days JavaScript is not only used for building web Applications, it’s now being used for developing Desktop applications as well.

ECMA Script 2015/ES 6 is the current version of ECMA Script Language specification which defines the standard for JavaScript. ES 6 introduces some new features which were missing in ES 5(older JavaScript version) and is already been supported in some of the Transpilers like ‘TypeScript’.

Top Browsers have already started supporting most of the ES 6 features. Even if browser doesn’t support the feature, we can use any of the Transpiler like Babel which can compile code written in ES 6 to older version.

Transpilers or Transcompilers takes the source code of a program written in one programming language and converts the equivalent source code in another language.

Some of the most commonly used Transcompilers are Babel , TypeScript and CoffeeScript

I am listing below some of the ES 6 features which every developer coming from backend programming language like C# would love to use.

1) Constants: – Constants can be defined using “const” keyword. Values of the constants cannot be altered and if we try to change the values of the constants any point of time we’ll get a read-only error.

Try it                      

2) Block scope:- If a variable declared inside some block of code enclosed by curly braces is only visible within that block of code, and that variable is not visible outside of that particular block of code we call it a block scope. If we are familiar with some languages like C# we are already aware of block scope. In ES 6 let keyword is being introduced which helps us to define block scope variables in JavaScript.

Try it

3) Default Parameters: – Another feature which I liked most is Default Parameters. This feature can be compared to the Optional Parameter concept in C#. By using this feature we can set some default values for method parameters. If we pass the values to the parameters it will override the default parameters and if not it will take default value.

Try it

4) Classes: – Classes lower the barrier for people coming from other languages like C# and helps in building large complex systems .Some transpilers like “Transcript” already supports classes.

Try it

5) Inheritance: – This is another important feature that has been introduced in ES 6 and which is very useful for developers when working with large applications. Inheritance helps in reusing the code there by reducing a significant development time. This is also is supported in some of the Transpilers like ‘Transcript’.

Try it

6) String Interpolations: – With this feature we can avoid string manipulation using “+” operator and  have some clean code using back ticks ‘. Also we don’t have to use “\n” for line breaks any more.

Try it

Conclusion
Using ES6 many C# concepts carry over to JavaScript and by using it, you can push more functionality to the client side. With the new ES6 features like Classes and Inheritance we can use them in larger applications. Stay tuned for more features of ES6.

Possible ways to remove Duplicate Records in a Database Table – SQL Server

in Database, Programming by Balamanigandan B Comments are off

Structured Query Language (SQL) is one of the most popular languages today to querying database and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently remove duplicate records in a SQL Server Database table.

SQL Server is a Relational Database Management System (RDBMS) and the most widely used client–server model RDBMS in the current trend applications. RDBMS is perhaps the most important Database system used in the workplace today.

Plan your Data Structure and table design before you start your application. It purely depends on the amount of Data and type of application.

There are two types of table structures, they are

  1. With Unique Column
  2. Without Unique Column

First we discuss about “with Unique Column”. Let us consider the SQL Query to create an EmplyeeInfo Table for our further illustration purpose.

  1. Table Contains Unique Column : Number 
    Create Table:
    EmployeeInfo

SQL Server Syntax:

Insert Data:

Insert the data into the EmployeeInfo table.

Select Data:

Select the data from the EmployeeInfo table.

 

Id firstName lastName dob gender
1 Bala Manigandan 1985-12-06 1
2 Bala Manigandan 1985-12-06 1
3 Bala Manigandan 1985-12-06 1
4 Prayag Pavithran 1985-09-15 1
5 Bala Manigandan 1985-12-06 1
6 Sakthivel G 1986-12-11 1
7 Prayag Pavithran 1985-09-15 1
8 Bala Manigandan 1985-12-06 1
9 Sakthivel G 1986-12-11 1
10 Prayag Pavithran 1985-09-15 1

In the above EmployeeInfo table, id 1, 4, 6 has duplicate values with unique id

Case 1: without Column ‘id’

 

firstName lastName dob Gender
Bala Manigandan 1985-12-06 1
Prayag Pavithran 1985-09-15 1
Sakthivel G 1986-12-11 1

 

Case 2: with Column ‘id’

 

Id firstName lastName dob Gender
1 Bala Manigandan 1985-12-06 1
4 Prayag Pavithran 1985-09-15 1
6 Sakthivel G 1986-12-11 1

The possible way to delete duplicate record in the above table using the following approach, for that first we have the select the duplicate rows in the said table. Let us see the SQL for selecting duplicate rows

 

Id firstName lastName Dob gender
2 Bala Manigandan 1985-12-06 1
3 Bala Manigandan 1985-12-06 1
5 Bala Manigandan 1985-12-06 1
7 Prayag Pavithran 1985-09-15 1
8 Bala Manigandan 1985-12-06 1
9 Sakthivel G 1986-12-11 1
10 Prayag Pavithran 1985-09-15 1

The above SQL find out’s the duplicate rows perfectly, so by using this query we can delete the duplicate rows from the above said database table EmployeeInfo. The SQL is

Table Contains Unique Column: Varchar (Alphabets | Numbers | Special Character)

Create Table: EmployeeInfo

Insert Data:

Insert the data into the EmployeeInfo table.

Select Data:

Select the data from the EmployeeInfo table.

Id firstName lastName dob gender
E001 Bala Manigandan 1985-12-06 1
E002 Bala Manigandan 1985-12-06 1
E003 Bala Manigandan 1985-12-06 1
E004 Prayag Pavithran 1985-09-15 1
E005 Bala Manigandan 1985-12-06 1
E006 Sakthivel G 1986-12-11 1
E007 Prayag Pavithran 1985-09-15 1
E008 Bala Manigandan 1985-12-06 1
E009 Sakthivel G 1986-12-11 1
E010 Prayag Pavithran 1985-09-15 1

In the above EmployeeInfo table, id 1, 4, 6 has duplicate values with unique id

The possible way to delete duplicate record in the above table using the following approach, for that first we have the select the duplicate rows in the said table. Let us see the SQL for selecting duplicate rows

 

Id firstName lastName Dob Gender
E002 Bala Manigandan 1985-12-06 1
E003 Bala Manigandan 1985-12-06 1
E005 Bala Manigandan 1985-12-06 1
E007 Prayag Pavithran 1985-09-15 1
E008 Bala Manigandan 1985-12-06 1
E009 Sakthivel G 1986-12-11 1
E010 Prayag Pavithran 1985-09-15 1

The above SQL find out’s the duplicate rows perfectly, so by using this query we can delete the duplicate rows from the above said database table EmployeeInfo. The SQL is

  1. Table Contains Non – Unique Column

Create Table: EmployeeInfo

Insert Data:

Insert the data into the EmployeeInfo table.

Select Data:

Select the data from the EmployeeInfo table.

 

Id firstName lastName dob gender
1 Bala Manigandan 1985-12-06 1
1 Bala Manigandan 1985-12-06 1
1 Bala Manigandan 1985-12-06 1
2 Prayag Pavithran 1985-09-15 1
1 Bala Manigandan 1985-12-06 1
3 Sakthivel G 1986-12-11 1
2 Prayag Pavithran 1985-09-15 1
1 Bala Manigandan 1985-12-06 1
3 Sakthivel G 1986-12-11 1
4 Ram Kumar 1968-11-02 1

 

In the above EmployeeInfo table, id 1, 2, 3 has duplicate values. The following SQL gives the DISTINCT records

 

 

Id firstName lastName dob Gender
1 Bala Manigandan 1985-12-06 1
2 Prayag Pavithran 1985-09-15 1
3 Sakthivel G 1986-12-11 1
4 Ram Kumar 1968-11-02 1

The possible way to delete duplicate record in the above table using the following approach, for that first we have the select the duplicate rows in the said table. Let us see the SQL for selecting duplicate rows

 

Id firstName lastName dob Gender
1 Bala Manigandan 1985-12-06 1
2 Prayag Pavithran 1985-09-15 1
3 Sakthivel G 1986-12-11 1

The above SQL find out’s the duplicate rows perfectly, append the Row Number with the SELECT Statement, then the SQL is

 

Id firstName lastName dob gender RN
1 Bala Manigandan 1985-12-06 1 1
1 Bala Manigandan 1985-12-06 1 2
2 Bala Manigandan 1985-12-06 1 3
2 Prayag Pavithran 1985-09-15 1 1
1 Bala Manigandan 1985-12-06 1 4
3 Sakthivel G 1986-12-11 1 1
2 Prayag Pavithran 1985-09-15 1 2
1 Bala Manigandan 1985-12-06 1 5
3 Sakthivel G 1986-12-11 1 2
4 Ram Kumar 1968-11-02 1 1

A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query, by using this query we can delete the duplicate rows from the above said database table EmployeeInfo. The SQL is

Conclusion: 

This article targets at understanding how efficiently we delete duplicate records with both scenario with Unique Value / without Unique Value This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality deletion of duplicate records in a SQL Server Database. Think Big… Start Small… Do Fast…

Usage of AsEnumerable and AsQueryable in LINQ

in C-Sharp, Programming by Balamanigandan B Comments are off

C# is one of the most popular languages today and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how to efficiently use the AsEnumerable and AsQueryable in C# LINQ.

Language-Integrated Query (LINQ) introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. LINQ is perhaps the most important features in .NET used in the workplace today.

IEnumerable iterates the collection from Bottom to Top without Filters but IQueryable iterates the collection from Bottom to Top with Filters, it’s derived from IEnumerable.

Both IEmumerable and IQueryable are executes the query in deferred mechanism.

Plan your Search strategy before you start your search. It purely depends on the amount of Data and where we are consuming the data?

The LINQ Query may used for querying database or for local in memory collection. Let us see how .AsEnumerable() and.AsQueryable() works in Database over Entity Framework using deferred execution.

Deferred execution means that the evaluation of an expression is delayed until its realized value is actually required. Deferred execution can greatly improve performance when you have to manipulate large data collections, especially in programs that contain a series of chained queries or manipulations. In the best case, deferred execution enables only a single iteration through the source collection.

The LINQ technologies make extensive use of deferred execution in both the members of core System.Linq classes and in the extension methods in the various LINQ namespaces, such as System.Xml.Linq.Extensions.

Let us consider the SQL Query to create an EmplyeeInfo Table for our further illustration purpose.

AsEnumerable:

.Img1

The above diagram clearly demonstrates how LINQ gets functioned. The .AsEnumerable() splits the LINQ into two parts Before Query and After Query. So, the first part i.e., “Before” .AsEnumerable() is db.Employeeinfo, it initiates to fetch all the records from the database using the automated generated query.

In the Second part i.e., “After” .AsEnumerable() is .Where(s => s.id == 1), it filters the collection which is stored in the local in-memory collection not from the SQL Server. It means it implements the Deferred Query Execution instead of Immediate Query Execution, first it generates the SQL query to fetch the entire records. When it needs, then it execute the query in the database server and then it stores the resultant records in local memory as a read-only collection otherwise just it holds the query. After that .AsEnumerable() method suspends the underlying connection between client and database server. So, the SQL query which is generated in the first part is now transferred to memory as a predicate object, and then it applies the filter over the predicate object.

Now the first question is when the SQL gets execute? It executes the SQL when it gets enumeration; this is called as Deferred Query Execution. For example the Enumerable Collection may transferred into a List or any other data structure, then it executes the SQL and transfers the resultant records in to the local memory as a read-only collection and then the filters gets effect, finally the resultant output is generated as a list or any other preferred data structure. In other words, it executes the query only in the final enumeration statement not for all the statement prior to the final enumeration statement.

Let us consider the C# Code:

Img2

The value stored in the enum1 is

The value stored in the enum2 is

enum2 = {System.Linq.Enumerable.WhereEnumerableIterator<App.PR_EmployeeInfo>}

The value stored in the enum3 is

id empID firstName lastName Dob Gender
1 1089 Balamanigandan B 12-06-1985 Male

 

The above values clearly narrates, the predicate query is generated and awaiting for the Deferred Query Execution instead of an Immediate Query Execution till the third statement execution.

AsQueryable:

Img3

The above diagram clearly demonstrates how the LINQ gets functioned. .AsQueryable() splits the LINQ into two parts Before Query and After Query. So, the first part i.e., Before AsQueryable() is db.Employeeinfo, it initiates to fetch all the records from the database using the automated generated query.

But in the second part, it just appends the filter query with the base query which is generated earlier and the final query would be

IQueryable performs better than IEnumerable in Database related query.

 Because in .AsEnumerable(), it fetches all the records and stores it in a local memory, but .AsQueryable() filters in the SQL Server level and fetches the whatever record needed. So, it reduces the memory requirement and improves the performance of an application.

 What we can’t do in an IQueryable?

 Let us consider the Scenario, and construct a List<EmplyeeBasic>

Now fetch the Employee Recode with the value of id matches with the property id which is present in the above list. The .AsQueryable() LINQ for the said scenario is

NotSupportedException was unhandled

“LINQ to Entities does not recognize the method ‘System.Collections.Generic.List1[System.Int32] ToList[Int32](System.Collections.Generic.IEnumerable1[System.Int32])’ method, and this method cannot be translated into a store expression.”

The above query will converted into a SQL query, within that no Object operation is possible. So, the above LINQ throw an exception NotSupportedException. But we can achieve that in an alternate way, Create a List<int> and then apply filter in a multiple of statement instead of an inline statement. Let us consider

In object, .AsQueryable() would not perform as IQueryable so it internally calls the base inerface IEnumerable. IQueryable is extensively created for an Entity Framework not for the local objects.

It’s a very bad practice of Select an object within IQueryable in LINQ.

Conclusion: This article targets at understanding how efficiently we can use .AsEnumerable() and .AsQueryable(). This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality implementation of LINQ operation in an Entity Framework. Think Big… Start Small… Do Fast…

Transfer a Large Data from Client to WCF and Vice Versa in .Net C#

in C-Sharp, Programming by Balamanigandan B Comments are off

C# is one of the most popular languages today and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently transfer a large data from Client to WCF and Vice Versa Using .Net C#.

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, we can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

Plan your Data usage between WCF and Client before you start your project. Then use the appropriate MessageEncoding and transferMode in your WCF web.config

Let us see the default web.config in WCF

and the default App.config in a Client Application

The default MessageEncoding is “normal text XML” and the transferMode is “Buffered” – Buffered transfers hold the entire message in a memory buffer until the transfer is complete.

In the above configuration the MessageEncoding and transferMode is not defined, but the system by default taken it as

The above configuration does not transfer the file with the size  ≈>18 MB from and to the WCF. During the analysis the maxReceivedMessageSize=”2147483647″ all are seems good. But the default MessageEncoding is “normal text XML” and the transferMode is “Buffered” – Buffered transfers hold the entire message in a memory buffer until the transfer is complete. So, it does not support for the Large Bytes in terms of memory and transport. The Communication may get terminate depends upon the Network Traffic or any other circumstances. Due to this reason the application may get crashed.

So, we need to change the MessageEncoding to “MTOM” (Message Transmission Optimization Mechanism). (MTOM) is an efficient technology for transmitting binary data in Windows Communication Foundation (WCF) messages. The MTOM encoder attempts to strike a balance between efficiency and interoperability. The MTOM encoding transmits most XML in textual form, but optimizes large blocks of binary data by transmitting them as-is, without conversion to text.

Additionally we have to change the transferMode to “StreamedRequest” or “Streamed”. StreamedRequest gives better proformance then Streamed. The request message is streamed and the response message is buffered in StreamedRequest.

Let us consider the modified version of the web.config, it will support the large data transfer. Binding information should be inside the system.ServiceModel of Web.config in WCF Service

and the EndPoint should be

readerQuotas :

It is WCF level setting, especially SOAP message and not about overall length of request. It puts various restrictions on the size of SOAP messages which can be processed by WCF endpoint. Those settings basically needed to prevent various kinds of a denial-of-service (DoS) attack against the service using xml messages prepared in a special way.

But we need some more permission in web server level, so we have to tune setting in web server level, they are

requestLimits  :

It is a web server level setting. When request comes with ContentLength, i.e., it purely speaks about the URL length. It rejects the request with 404 error (Page not available) only if exceeds the limit which is specified in the property maxAllowedContentLength, it will not even get into WCF pipeline. So, this configuration setting is not related to WCF at all. Note that it limits the overall length of request; whatever is inside the request does not matter.

The Completed Version of web.config in a WCF should be

and the Completed Version of App.config in a Client Application should be

Here the endpoint address is refereeing the hosted address of a WCF, via this address the client application consumes the service from the WCF.

Conclusion: This article targets at understanding how efficiently we can transfer large amount of data from a Client application to WCF and vice versa. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality implementation of WCF Configuration. Think Big… Start Small… Do Fast…

Usage of md-autocomplete in Angular Material

in AngularJS, UI by Balamanigandan B Comments are off

AngularJS is one of the most popular Client side Java Script languages today and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how efficiently use the md-autocomplete in Angular Material.

Angular Material md-autocomplete introduces a special input component with a drop-down of all possible matches to a custom query. This component allows us to provide real-time suggestions as the user types in the input area.

md-autocomplete may get the input source via local object or from remote data source. Both are having different paradigms for consuming Suggestion data.

Core Features of md-autocomplete

Let us see the basic syntax of md-autocomplete

 

All the attributes of md-autocomplete is briefly explained in the Angular Material website https://material.angularjs.org/latest/api/directive/mdAutocomplete

 

 

Consider the Data is from Local as like below

 

Now see how the AngularJS should be for a Local Data

 

Consider the Data is from Remote from the sample URL  https://www.example.com/sample.aspx?token=one

 

Now see how the AngularJS should be for a Remote Data

 

 

In Remote Data, we should prefer .then instead of .success

  • .then() – full power of the promise API but slightly more verbose
  • .success() – doesn’t return a promise but offers slightly more convenient syntax

.then() – the $http API is based on the deferred/promise APIs exposed by the $q service, so it returns a promise for us by default.

Advance Features of md-autocomplete

Item Not Found:

 

 

How to set Minimum Length of Search Text:

 

How to set Cache Mode Enabled:

 

The Complete Source Code of HTML with AngularJS

The above Source Code is for Local Data Source, if you need a source code for a Remote Data Source kindly replace the <script> block to the specified Remote <script> block, which is briefly explained in the above.  

Conclusion: 

This article targets at understanding md-autocomplete programmatically using AngularJS especially for Remote Data Source. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality implementation of md-autocomplete TextBox of Angular Material. Think Big… Start Small… Do Fast…

Manipulating Excel Spreadsheet using C#

in Programming by Balamanigandan B Comments are off

C# is one of the most popular languages today and there are many reasons for this. It has many qualities that make it suitable for development for users at most all levels. Let’s discuss how we can create an Excel Spread Sheet using C#.

Microsoft Excel is perhaps the most important computer software program used in the workplace today.

Simple Excel spreadsheet Creation:

Step #1

To use the features of a Microsoft Office application from an Office project, you must use the primary interop assembly (PIA) for the application. The PIA enables managed code to interact with a Microsoft Office application’s COM-based object model.

So, Add an Extension “Microsoft Office Interop Excel“.

Project -> Add Reference -> Extension

BalaBlog1

Step #2

Include the “Microsoft Office Interop Excel” in your class file

 

Step #3

The Following C# Code Creates the Simple Excel Sheet

Classes used

  • Excel.Application -Top level object in the Excel object model, used to specify application level properties and application level methods
  • Excel.Worbook – Represents a single workbook within the Excel application
  • Excel.Worksheet – A member of the Worksheets collection in the Workbook object

 

Let us consider the List of Mobiles which is constructed in the following C# List

 

Now Let us see how to create an Excel Spread Sheet for the above said List<Mobile> MobileList

 

Output Snapshot:

BalaBlog2

Advanced Excel Spread Sheet:

Cell Selection:

To format the Sheet, first select the cells, it may be single, multiple, entire row or entire column. The Interface Excel.Range (Microsoft.Office.Interop.Excel.Range) is used here to select the Cells.

Excel.Range formatRange;

To Select a Single Cell:

 

BalaBlog3

 

To Select a Range of Cells:

 

 

BalaBlog4

 

BalaBlog5

BalaBlog6

To Select a Row:

BalaBlog7

To Select a Column:

BalaBlog8

Font Style and Cell Alignment

Font Bold:

 

Font Color:

 

 

Cell Alignment:

 

 

Cell Background Color:

 

 

Sort data in an Excel table:

 

Filter data in an Excel table:

 

Conclusion: 

This article targets at understanding Excel file manipulations programmatically using C#. This article is intended for the beginner/intermediate level. I hope, this post will solve all your basic functionality implementation of Excel Spread Sheet. Think Big… Start Small… Do Fast…

 

MultiSelectComboBox.XAMLWay

in WPF by Selva Kumar Comments are off

In WPF we have lot of controls which we can customize to achieve our desired result. It can be done either through XAML or by creating custom library file also by combining both the way. Here I’m going to customize a ComboBox to accept multiple values only by using XAML file.

https://github.com/IncRevCorp/MultiSelectComboBox.XAMLWay

Idea behind it

“General idea of this to change the default ItemsPresenter control in the ComboBox to ListBox control which is having the option to accept multiple values”.

The initial code will look like this:

Now we are going to start customizing the look like this:

Screen1

Screen2

It will modify the intial Xaml page like this

And also in App.Xaml we will have code like