Friday, January 6, 2017

Text to speech using C#.net


.Net is provided text to speech functionality, which contains all the functionalities like it can speech the provided text, pause, continue, record the speech, etc… .
To achieve it, below information required to refer the dll and use the namespace:
Dll:System.Speech
Namespace:using System.Speech.Synthesis;

Class and methods for Speech functionalities:
Initialize the main class:
SpeechSynthesizer synthesizerObject = new SpeechSynthesizer();
Speech Method:
synthesizerObject.SpeakAsync(“Good morning Kishan!”);













Select Voice & age of the voice speaker:
synthesizerObject.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);

Volume & Speed of the speech:
synthesizerObject.Rate = 20; // Speed
synthesizerObject.Volume = 80; // Volume
Recording the speach:
synthesizerObject.SetOutputToDefaultAudioDevice()




Wednesday, April 28, 2010

Hyperion

http://businessintelligencedw.blogspot.com/search/label/Hyperion%20Reporting%20and%20Analysis%20Architecture

Wednesday, April 21, 2010

.NET LINQ

Introduction to .NET LINQ


1.What is LINQ?

LINQ (Language Integrated Query) is a new feature in VS 2008 that gives query capabilities using C# and Visual Basic. VS 2008 comes with LINQ provider assemblies with capabilities of querying in memory collections, SQL relational database, ADO.NET datasets, XML documents and other data sources.
This uses the new Standard Query Operations API which is the query language for any collections that implements IEnumerable. It means all collections and arrays can be queried using LINQ as they implement IEnumerable.

2. LINQ Architecture



Figure 1: LINQ Architecture

.NET LINQ (Language Integrated Query) offers developers a new way to query data using strongly-typed queries and strongly-typed results, common across a number of disparate data types including relational databases, .NET objects, XML and other data sources. By using strongly-typed queries and results, LINQ improves developer productivity with the benefits of Intellisense and compile-time error checking.

LINQ provides a set of operators that allow traversal, filtering, grouping, and ordering of data. Datasets, arrays, user-defined objects, dictionaries and lists are all examples of data structures from which information can easily be extracted. In fact, any type that implements IEnumerable can be queried.
By using LINQ we can query and transform the data in
 XML Document
 SQL Databases
 ADO.NET Datasets
 .NET Collections

3. Advantages of LINQ

The major advantage of Microsoft’s LINQ Project is the general approach they have taken because they have integrated a query language irrespective of any specific part. Language Integrated Query can be used with XML, Database or anything which is capable of returning IENUMERABLE.
The biggest one is that we can now structure queries in our code which are compile-time checked, regardless of the back end data source (so if we are using LINQ-to-SQL, then we are going to get compile-time checking on our queries, instead of seeing it at runtime with a query string).
If we are using LINQ-to-Objects, then a big advantage is that we can create complex queries in simple manners which were previously very difficult.
For example, say we want to get all the declared methods on a type which is generic which we want to run some processing on. In .NET 2.0, we will do this:





In .NET 3.5/C# 3.0, we can do this:
LINQ Queries

LINQ Query operation contains three parts
1. Obtain the data source.
2. Create the Query.
3. Execute the Query.
The following example illustrates the three parts of a LINQ Query Operation



The data source in the above example is Array and implicitly supports IEnumerable interface. All types that support IEnumerable are called queryable types.

Query expression contains three clauses from, where and select. The from clause specifies the data source, where clause applies the filter and select clause specifies the types of returned elements.

Query executes in foreach statement in the example. The actual execution of the query starts when iterate over the query variable in foreach statement.


3.1. LINQ Syntax

The following table outlines some of the options available with LINQ syntax.
Destination var = Using type inference to assign the resulting value(s)
Source from in Information source providing a set of item(s)
Filter where , distinct Expression specifying the selection criteria
Order order by , [Ascending Descending] Control the ordering of the results
Aggregate count([]), sum(), min(), max(), avg() Aggregate the source items
Projection select Shaping the output



3.2. LINQ Standard Query Operators

The Standard Query Operators is an API that enables querying of any .NET array or collection. The Standard Query Operators API consists of the methods declared in the System.Query.Sequence static class in the assembly named System.Query.dll.

When using LINQ with any supported data source (in-memory, relational data, XML) we can make use of a set of a standard query operators which empower us to manipulate our data source more effectively. A few standard query operators are given below:

Operator Type Operator Description
Aggregation Aggregate The Aggregate operator applies a function over a sequence.
Average The Average operator computes the average of a sequence of numeric values.
Count The Count operator counts the number of elements in a sequence with a return type of int.
LongCount The LongCount operator counts the number of elements in a sequence with a return type of Long.
Max The Max operator finds the maximum of a sequence of numeric values.
Min The Min operator finds the minimum of a sequence of numeric values.
Sum The Sum operator computes the sum of a sequence of numeric values.
Concatenation Concat The Concat operator concatenates two sequences.
Conversion Cast The Cast operator casts the elements of a sequence to a given type.
OfType The OfType operator filters the elements of a sequence based on a type.
ToArray The ToArray operator creates an array from a sequence.
ToDictionary The ToDictionary operator creates a Dictionary from a sequence.
ToList The ToList operator creates a List from a sequence.
ToLookup The ToLookup operator creates a Lookup from a sequence.
ToSequence The ToSequence operator returns its argument typed as IEnumerable.
Element DefaultIfEmpty The DefaultIfEmpty operator supplies a default element for an empty sequence.
ElementAt The ElementAt operator returns the element at a given index in a sequence.
ElementAtOrDefault The ElementAtOrDefault operator returns the element at a given index in a sequence or a default value if the index is out of range.
First The First operator returns the first element of a sequence.
FirstOrDefault The FirstOrDefault operator returns the first element of a sequence, or a default value if no element is found.
Last The Last operator returns the last element of a sequence.
LastOrDefault The LastOrDefault operator returns the last element of a sequence, or a default value if no element is found.
Single The Single operator returns the single element of a sequence.
SingleOrDefault The SingleOrDefault operator returns the single element of a sequence, or a default value if no element is found.
Equality SequenceEqual The SequenceEqual operator checks whether two sequences are equal.
Generation Empty The Empty operator returns an empty sequence of a given type.
Range The Range operator generates a sequence of integral numbers.
Repeat The Repeat operator generates a sequence by repeating a value a given number of times.
Grouping GroupBy The GroupBy operator groups the elements of a sequence.
Joining GroupJoin The GroupJoin operator performs a grouped join of two sequences based on matching keys extracted from the elements.
Join The Join operator performs an inner join of two sequences based on matching keys extracted from the elements.
Ordering OrderBy The OrderBy operator orders a sequence according to one or more keys in ascending order.
ThenBy The ThenBy operator orders an ordered sequence according to one or more keys in ascending order.
OrderByDescending The OrderBy operator orders a sequence according to one or more keys in descending order.
ThenByDescending The ThenBy operator orders an ordered sequence according to one or more keys in descending order.
Reverse The Reverse operator reverses the elements of a sequence.
Partitioning Skip The Skip operator skips a given number of elements from a sequence and then yields the remainder of the sequence.
SkipWhile The SkipWhile operator skips elements from a sequence while a test is true and then yields the remainder of the sequence.
Take The Take operator yields a given number of elements from a sequence and then skips the remainder of the sequence.
TakeWhile The TakeWhile operator yields elements from a sequence while a test is true and then skips the remainder of the sequence.
Quantifiers All The All operator checks whether all elements of a sequence satisfy a condition.
Any The Any operator checks whether any element of a sequence satisfies a condition.
Contains The Contains operator checks whether a sequence contains a given element.
Restriction Where The Where operator filters a sequence based on a predicate.
Projection Select The Select operator performs a projection over a sequence.
SelectMany The SelectMany operator performs a one to many element projection over a sequence.
Set Distinct The Distinct operator eliminates duplicate elements from a sequence.
Except The Except operator produces the set difference between two sequences.
Intersect The Intersect operator produces the set intersection of two sequences.
Union The Union operator produces the set union of two sequences.



4. LINQ Provider Basic

LINQ (Language Integrated Query) works as a middle tier between data store and the language environment. From a developer’s point of view, it is just a new process for querying data from multiple data structures directly in the IDE. It does a lot of tasks like expression processing, validation and calling the right routine to fetch data or build a query to run in SQL Server. In short, LINQ stands as common query gateway between the language and the data store.
Followings are the different providers of LINQ

4.1. LINQ to Objects

LINQ to Objects allows us to write queries over collections of objects. Working with collections of objects meant writing a lot of looping code using for loops or foreach loops to iterate through a list carrying out filtering using if statements and some action like keeping a running sum of a total property. LINQ frees us from having to write looping code; it allows us to write queries that filter a list or calculate aggregate functions on elements in a collection as a set.

We can write queries against any collection type that implements an interface called IEnumerable. This is almost any collection type built into the .NET class libraries including simple arrays like string [ ] or int [ ] and any List collection we define. Let us look at a few of the simplest examples to understand the basic syntax.

An example of calculating the aggregate sum of all the elements would look like –

LINQ to Objects extends any type that inherits from IEnumerable which is almost every collection class in .NET from simple Arrays to List to support query operations similar to those available in SQL. We can write queries using any of the built-in Standard Query Operators, or add our own operators if we need to.

4.2. LINQ to SQL

LINQ to SQL allows us to write queries in our .NET language of choice to retrieve and manipulate data from a SQL Server database. In a general sense, LINQ to SQL allows us to create SQL queries in our preferred .NET language syntax and work with a strongly types collection of objects as a return result. We can make changes to these objects then save changes back to the database.
LINQ-enabled languages can provide full type-safety and compile-time checking of query expressions and development tools can provide full intellisense, debugging and rich refactoring support when writing LINQ code.
Once we've modeled our database using the LINQ to SQL designer, we can then easily write code to work against it. Below are a few code examples that show off common data tasks:

Figure 2: Product Table

For instance, below is a simple class which defines a class which is mapped to a Product table as shown above. You can see we how the class properties are mapped in one to one mapping with the table. These types of classes are termed as entity classes.

For each LINQ to SQL designer file added to our solution, a custom DataContext class will also be generated. This DataContext class is the main conduit by which we'll query entities from the database as well as apply changes. The DataContext class created will have properties that represent each Table we modeled within the database.

The code below uses LINQ query syntax to retrieve an IEnumerable sequence of Product objects. Note how the code is querying across the Product table to only retrieve those products having price greater than 500.
LINQ to SQL provides a nice, clean way to model the data layer of our application. Once we’ve defined our data model we can easily and efficiently perform queries, inserts, updates and deletes against it

4.3. LINQ to XML
LINQ to XML allows XML data to be queried by using the standard query operators as well as tree-specific operators that provide XPath-like navigation through descendants, ancestors, and siblings. It simplifies working with XML data without having to resort to using additional language syntax like XPath or XQuery. LINQ to XML provides a clean programming model that enables us to read, construct, and write XML data. This Drill covers a number of important techniques required to use LINQ to XML effectively. We will use a simple Product XML file with some elements to query using LINQ

Figure 3: Product.Xml

Now we will query the above XML file using LINQ. The query will return a collection of elements of Products which we will receive in Enumerable XElement collection.